├── .github ├── cover.png └── workflows │ ├── ci.yaml │ ├── pages.yaml │ └── publish.yml ├── .gitignore ├── .husky ├── install.mjs └── pre-commit ├── .lintstagedrc.json ├── .npmrc ├── .prettierignore ├── .prettierrc ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── examples ├── batch │ ├── .gitignore │ ├── README.md │ ├── index.mjs │ ├── package-lock.json │ └── package.json ├── encryption │ ├── .gitignore │ ├── README.md │ ├── index.mjs │ ├── package-lock.json │ └── package.json ├── local │ ├── .gitignore │ ├── README.md │ ├── index.mjs │ ├── package-lock.json │ └── package.json ├── memory │ ├── .gitignore │ ├── README.md │ ├── index.mjs │ ├── package-lock.json │ └── package.json ├── ollama │ ├── .gitignore │ ├── README.md │ ├── index.mjs │ ├── package-lock.json │ └── package.json ├── read-your-writes │ ├── package-lock.json │ ├── package.json │ └── read_your_writes.js ├── remote │ ├── .gitignore │ ├── README.md │ ├── index.mjs │ ├── package-lock.json │ └── package.json ├── sync │ ├── .gitignore │ ├── README.md │ ├── index.mjs │ ├── package-lock.json │ └── package.json ├── transactions │ ├── .gitignore │ ├── README.md │ ├── index.mjs │ ├── package-lock.json │ └── package.json └── vector │ ├── .gitignore │ ├── README.md │ ├── index.mjs │ ├── package-lock.json │ └── package.json ├── package-lock.json ├── package.json └── packages ├── libsql-client-wasm ├── LICENSE ├── examples │ ├── browser │ │ ├── README.md │ │ ├── index.html │ │ ├── index.js │ │ ├── package-lock.json │ │ └── package.json │ └── node │ │ ├── index.js │ │ ├── package-lock.json │ │ └── package.json ├── jest.config.js ├── package-cjs.json ├── package.json ├── src │ └── wasm.ts ├── tsconfig.base.json ├── tsconfig.build-esm.json ├── tsconfig.json └── typedoc.json ├── libsql-client ├── README.md ├── examples │ ├── example.js │ ├── package.json │ ├── shell.js │ ├── sync.js │ ├── sync_offline.js │ └── sync_vector.js ├── jest.config.js ├── package-cjs.json ├── package.json ├── smoke_test │ ├── vercel │ │ ├── .gitignore │ │ ├── app │ │ │ ├── .gitignore │ │ │ ├── api │ │ │ │ └── function.ts │ │ │ └── public │ │ │ │ └── index.html │ │ ├── package.json │ │ ├── test.js │ │ └── tsconfig.json │ └── workers │ │ ├── .gitignore │ │ ├── package.json │ │ ├── test.js │ │ ├── worker.js │ │ └── wrangler.toml ├── src │ ├── __tests__ │ │ ├── client.test.ts │ │ ├── config.test.ts │ │ ├── helpers.ts │ │ ├── mocks │ │ │ ├── handlers.ts │ │ │ └── node.ts │ │ └── uri.test.ts │ ├── hrana.ts │ ├── http.ts │ ├── node.ts │ ├── sql_cache.ts │ ├── sqlite3.ts │ ├── web.ts │ └── ws.ts ├── tsconfig.base.json ├── tsconfig.build-cjs.json ├── tsconfig.build-esm.json ├── tsconfig.json └── typedoc.json └── libsql-core ├── jest.config.js ├── package-cjs.json ├── package.json ├── src ├── api.ts ├── config.ts ├── uri.ts └── util.ts ├── tsconfig.base.json ├── tsconfig.build-cjs.json ├── tsconfig.build-esm.json ├── tsconfig.json └── typedoc.json /.github/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tursodatabase/libsql-client-ts/5fcb14f72317636b86f81651688c177a28b7d66a/.github/cover.png -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: "CI" 2 | on: 3 | push: 4 | branches: ["main"] 5 | pull_request: 6 | 7 | jobs: 8 | "typecheck": 9 | name: "Typecheck" 10 | runs-on: ubuntu-latest 11 | timeout-minutes: 2 12 | steps: 13 | - name: "Checkout this repo" 14 | uses: actions/checkout@v4 15 | - name: "Setup Node.js" 16 | uses: actions/setup-node@v4 17 | with: 18 | node-version: "18.x" 19 | - name: "Install node dependencies and build" 20 | run: "npm ci && npm run build" 21 | - name: "Typecheck" 22 | run: "npm run typecheck" 23 | 24 | "format-check": 25 | name: "Check formatting" 26 | runs-on: ubuntu-latest 27 | timeout-minutes: 2 28 | steps: 29 | - name: "Checkout this repo" 30 | uses: actions/checkout@v4 31 | - name: "Setup Node.js" 32 | uses: actions/setup-node@v4 33 | with: 34 | node-version: "18.x" 35 | - name: "Install node dependencies" 36 | run: "npm ci" 37 | - name: "Check formatting" 38 | run: "npm run format:check" 39 | 40 | "test-against-sqld": 41 | name: "Tests against sqld" 42 | runs-on: ubuntu-latest 43 | timeout-minutes: 2 44 | defaults: 45 | run: 46 | working-directory: ./packages/libsql-client 47 | env: { "NODE_OPTIONS": "--trace-warnings" } 48 | steps: 49 | - name: "Checkout this repo" 50 | uses: actions/checkout@v4 51 | - name: "Setup Node.js" 52 | uses: actions/setup-node@v4 53 | with: 54 | node-version: "18.x" 55 | - name: "Build core" 56 | run: "npm ci && npm run build" 57 | working-directory: ./packages/libsql-core 58 | - name: "Install npm dependencies" 59 | run: "npm ci" 60 | - name: "Build" 61 | run: "npm run build" 62 | - name: Run Docker container in the background 63 | run: docker run -d -p 8080:8080 -e SQLD_NODE=primary ghcr.io/tursodatabase/libsql-server:latest 64 | - name: Verify container is running 65 | run: docker ps 66 | - name: "Test against sqld" 67 | run: "npm test" 68 | env: { "URL": "http://localhost:8080", "SERVER": "sqld" } 69 | 70 | "wasm-test": 71 | name: "Build and test Wasm on Node.js" 72 | runs-on: ubuntu-latest 73 | timeout-minutes: 2 74 | defaults: 75 | run: 76 | working-directory: ./packages/libsql-client-wasm 77 | env: { "NODE_OPTIONS": "--trace-warnings" } 78 | steps: 79 | - name: "Checkout this repo" 80 | uses: actions/checkout@v4 81 | - name: "Setup Node.js" 82 | uses: actions/setup-node@v4 83 | with: 84 | node-version: "18.x" 85 | cache-dependency-path: "packages/libsql-client-wasm" 86 | - name: "Build core" 87 | run: "npm ci && npm run build" 88 | working-directory: ./packages/libsql-core 89 | - name: "Install npm dependencies" 90 | run: "npm ci" 91 | - name: "Build" 92 | run: "npm run build" 93 | - name: "Test example" 94 | run: "cd examples/node && npm i && node index.js" 95 | env: { "URL": "file:///tmp/example.db" } 96 | 97 | "node-test": 98 | name: "Build and test on Node.js" 99 | runs-on: ubuntu-latest 100 | timeout-minutes: 2 101 | defaults: 102 | run: 103 | working-directory: ./packages/libsql-client 104 | env: { "NODE_OPTIONS": "--trace-warnings" } 105 | steps: 106 | - name: "Checkout this repo" 107 | uses: actions/checkout@v4 108 | - name: "Setup Node.js" 109 | uses: actions/setup-node@v4 110 | with: 111 | node-version: "18.x" 112 | - name: "Build core" 113 | run: "npm ci && npm run build" 114 | working-directory: ./packages/libsql-core 115 | - name: "Install npm dependencies" 116 | run: "npm ci" 117 | - name: "Checkout hrana-test-server" 118 | uses: actions/checkout@v4 119 | with: 120 | repository: "libsql/hrana-test-server" 121 | path: "packages/libsql-client/hrana-test-server" 122 | - name: "Setup Python" 123 | uses: actions/setup-python@v4 124 | with: 125 | python-version: "3.10" 126 | - name: "Install pip dependencies" 127 | run: "pip install -r hrana-test-server/requirements.txt" 128 | 129 | - name: "Build" 130 | run: "npm run build" 131 | 132 | - name: "Test Hrana 1 over WebSocket" 133 | run: "python hrana-test-server/server_v1.py npm test" 134 | env: { "URL": "ws://localhost:8080", "SERVER": "test_v1" } 135 | - name: "Test Hrana 2 over WebSocket" 136 | run: "python hrana-test-server/server_v2.py npm test" 137 | env: { "URL": "ws://localhost:8080", "SERVER": "test_v2" } 138 | - name: "Test Hrana 2 over HTTP" 139 | run: "python hrana-test-server/server_v2.py npm test" 140 | env: { "URL": "http://localhost:8080", "SERVER": "test_v2" } 141 | # - name: "Test Hrana 3 over WebSocket" 142 | # run: "python hrana-test-server/server_v3.py npm test" 143 | # env: {"URL": "ws://localhost:8080", "SERVER": "test_v3"} 144 | # - name: "Test Hrana 3 over HTTP" 145 | # run: "python hrana-test-server/server_v3.py npm test" 146 | # env: {"URL": "http://localhost:8080", "SERVER": "test_v3"} 147 | - name: "Test local file" 148 | run: "npm test" 149 | env: { "URL": "file:///tmp/test.db" } 150 | 151 | - name: "Test example" 152 | run: "cd examples && npm i && node example.js" 153 | env: { "URL": "file:///tmp/example.db" } 154 | 155 | "workers-test": 156 | name: "Build and test with Cloudflare Workers" 157 | if: false 158 | runs-on: ubuntu-latest 159 | timeout-minutes: 2 160 | defaults: 161 | run: 162 | working-directory: ./packages/libsql-client 163 | env: 164 | "CLOUDFLARE_API_TOKEN": "${{ secrets.CLOUDFLARE_API_TOKEN }}" 165 | "CLOUDFLARE_ACCOUNT_ID": "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}" 166 | steps: 167 | - name: "Checkout this repo" 168 | uses: actions/checkout@v4 169 | - name: "Setup Node.js" 170 | uses: actions/setup-node@v4 171 | with: 172 | node-version: "lts/Hydrogen" 173 | - name: "Build core" 174 | run: "npm ci && npm run build" 175 | working-directory: ./packages/libsql-core 176 | - name: "Install npm dependencies" 177 | run: "npm ci" 178 | 179 | - name: "Checkout hrana-test-server" 180 | uses: actions/checkout@v4 181 | with: 182 | repository: "libsql/hrana-test-server" 183 | path: "packages/libsql-client/hrana-test-server" 184 | - name: "Setup Python" 185 | uses: actions/setup-python@v4 186 | with: 187 | python-version: "3.10" 188 | - name: "Install pip dependencies" 189 | run: "pip install -r hrana-test-server/requirements.txt" 190 | 191 | - name: "Build" 192 | run: "npm run build" 193 | - name: "Install npm dependencies of the Workers test" 194 | run: "cd smoke_test/workers && npm link ../.." 195 | 196 | - name: "Local test with Hrana 1 over WebSocket" 197 | run: "cd smoke_test/workers && python ../../hrana-test-server/server_v1.py node --dns-result-order=ipv4first test.js" 198 | env: { "LOCAL": "1", "URL": "ws://localhost:8080" } 199 | - name: "Local test with Hrana 2 over WebSocket" 200 | run: "cd smoke_test/workers && python ../../hrana-test-server/server_v2.py node --dns-result-order=ipv4first test.js" 201 | env: { "LOCAL": "1", "URL": "ws://localhost:8080" } 202 | - name: "Local test with Hrana 2 over HTTP" 203 | run: "cd smoke_test/workers && python ../../hrana-test-server/server_v2.py node --dns-result-order=ipv4first test.js" 204 | env: { "LOCAL": "1", "URL": "http://localhost:8080" } 205 | # - name: "Local test with Hrana 3 over WebSocket" 206 | # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v3.py node --dns-result-order=ipv4first test.js" 207 | # env: {"LOCAL": "1", "URL": "ws://localhost:8080"} 208 | # - name: "Local test with Hrana 3 over HTTP" 209 | # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v3.py node --dns-result-order=ipv4first test.js" 210 | # env: {"LOCAL": "1", "URL": "http://localhost:8080"} 211 | 212 | # - name: "Non-local test with Hrana 1 over WebSocket" 213 | # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v1.py node test.js" 214 | # env: {"LOCAL": "0", "URL": "ws://localhost:8080"} 215 | # - name: "Non-local test with Hrana 2 over WebSocket" 216 | # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v2.py node test.js" 217 | # env: {"LOCAL": "0", "URL": "ws://localhost:8080"} 218 | # - name: "Non-local test with Hrana 2 over HTTP" 219 | # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v2.py node test.js" 220 | # env: {"LOCAL": "0", "URL": "http://localhost:8080"} 221 | # - name: "Non-local test with Hrana 3 over WebSocket" 222 | # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v3.py node test.js" 223 | # env: {"LOCAL": "0", "URL": "ws://localhost:8080"} 224 | # - name: "Non-local test with Hrana 3 over HTTP" 225 | # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v3.py node test.js" 226 | # env: {"LOCAL": "0", "URL": "http://localhost:8080"} 227 | 228 | # "vercel-test": 229 | # name: "Build and test with Vercel Edge Functions" 230 | # runs-on: ubuntu-latest 231 | # env: 232 | # VERCEL_TOKEN: "${{ secrets.VERCEL_TOKEN }}" 233 | # VERCEL_PROJECT_NAME: "smoke-test" 234 | # steps: 235 | # - name: "Checkout this repo" 236 | # uses: actions/checkout@v4 237 | # - name: "Setup Node.js" 238 | # uses: actions/setup-node@v4 239 | # with: 240 | # node-version: "lts/Hydrogen" 241 | # cache: "npm" 242 | # - name: "Install npm dependencies" 243 | # run: "npm ci" 244 | 245 | # - name: "Checkout hrana-test-server" 246 | # uses: actions/checkout@v4 247 | # with: 248 | # repository: "libsql/hrana-test-server" 249 | # path: "hrana-test-server" 250 | # - name: "Setup Python" 251 | # uses: actions/setup-python@v4 252 | # with: 253 | # python-version: "3.10" 254 | # cache: "pip" 255 | # - name: "Install pip dependencies" 256 | # run: "pip install -r hrana-test-server/requirements.txt" 257 | 258 | # - name: "Build" 259 | # run: "npm run build" 260 | # - name: "Install npm dependencies of the Vercel test" 261 | # run: "cd smoke_test/vercel && npm install" 262 | 263 | # - name: "Test with Hrana 1 over WebSocket" 264 | # run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v1.py node test.js" 265 | # env: {"URL": "ws://localhost:8080"} 266 | # - name: "Test with Hrana 2 over WebSocket" 267 | # run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v2.py node test.js" 268 | # env: {"URL": "ws://localhost:8080"} 269 | # - name: "Test with Hrana 2 over HTTP" 270 | # run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v2.py node test.js" 271 | # env: {"URL": "http://localhost:8080"} 272 | # - name: "Test with Hrana 3 over WebSocket" 273 | # run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v3.py node test.js" 274 | # env: {"URL": "ws://localhost:8080"} 275 | # - name: "Test with Hrana 3 over HTTP" 276 | # run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v3.py node test.js" 277 | # env: {"URL": "http://localhost:8080"} 278 | -------------------------------------------------------------------------------- /.github/workflows/pages.yaml: -------------------------------------------------------------------------------- 1 | name: "GitHub Pages" 2 | on: 3 | push: 4 | branches: ["main"] 5 | 6 | jobs: 7 | "build": 8 | name: "Build the docs" 9 | runs-on: ubuntu-latest 10 | defaults: 11 | run: 12 | working-directory: ./packages/libsql-client 13 | steps: 14 | - name: "Checkout this repo" 15 | uses: actions/checkout@v4 16 | - name: "Setup Node.js" 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: "${{ matrix.node-version }}" 20 | cache: "npm" 21 | - name: "Build core" 22 | run: "npm ci && npm run build" 23 | working-directory: ./packages/libsql-core 24 | - name: "Install npm dependencies" 25 | run: "npm ci" 26 | - name: "Build" 27 | run: "npm run typedoc" 28 | - name: "Upload GitHub Pages artifact" 29 | uses: actions/upload-pages-artifact@v3 30 | id: deployment 31 | with: 32 | path: "./packages/libsql-client/docs" 33 | 34 | "deploy": 35 | name: "Deploy the docs to GitHub Pages" 36 | needs: "build" 37 | permissions: 38 | pages: write 39 | id-token: write 40 | 41 | environment: 42 | name: github-pages 43 | url: ${{ steps.deployment.outputs.page_url }} 44 | 45 | runs-on: ubuntu-latest 46 | steps: 47 | - name: "Deploy to GitHub Pages" 48 | id: deployment 49 | uses: actions/deploy-pages@v4 50 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: publish 2 | 3 | env: 4 | NPM_REGISTRY: 'https://registry.npmjs.org' 5 | 6 | on: 7 | push: 8 | tags: 9 | - v* 10 | 11 | jobs: 12 | publish-to-npm: 13 | name: "Publish new version to NPM" 14 | runs-on: ubuntu-latest 15 | timeout-minutes: 5 16 | env: 17 | NODE_OPTIONS: "--trace-warnings" 18 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 19 | steps: 20 | - name: "Checkout this repo" 21 | uses: actions/checkout@v3 22 | 23 | - name: "Setup Node.js" 24 | uses: actions/setup-node@v3 25 | with: 26 | node-version: "18.x" 27 | 28 | - name: "Build core" 29 | run: "npm ci && npm run build" 30 | working-directory: ./packages/libsql-core 31 | 32 | - name: "Publish core (pre-release)" 33 | if: contains(github.ref, '-pre') 34 | run: npm publish --tag next 35 | working-directory: ./packages/libsql-core 36 | 37 | - name: "Publish core (latest)" 38 | if: "!contains(github.ref, '-pre')" 39 | run: npm publish 40 | working-directory: ./packages/libsql-core 41 | 42 | 43 | - name: "Install npm dependencies (client)" 44 | run: "npm ci" 45 | working-directory: ./packages/libsql-client 46 | 47 | - name: "Publish client (pre-release)" 48 | if: contains(github.ref, '-pre') 49 | run: npm publish --tag next 50 | working-directory: ./packages/libsql-client 51 | 52 | - name: "Publish client (latest)" 53 | if: "!contains(github.ref, '-pre')" 54 | run: npm publish 55 | working-directory: ./packages/libsql-client 56 | 57 | 58 | - name: "Install npm dependencies (client wasm)" 59 | run: "npm ci" 60 | working-directory: ./packages/libsql-client-wasm 61 | 62 | - name: "Publish client-wasm (pre-release)" 63 | if: contains(github.ref, '-pre') 64 | run: npm publish --tag next 65 | working-directory: ./packages/libsql-client-wasm 66 | 67 | - name: "Publish client-wasm (latest)" 68 | if: "!contains(github.ref, '-pre')" 69 | run: npm publish 70 | working-directory: ./packages/libsql-client-wasm 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | /packages/*/lib-esm 3 | /packages/*/lib-cjs 4 | /docs 5 | *.tsbuildinfo 6 | Session.vim 7 | packages/libsql-client/hrana-test-server 8 | -------------------------------------------------------------------------------- /.husky/install.mjs: -------------------------------------------------------------------------------- 1 | // See https://typicode.github.io/husky/how-to.html#ci-server-and-docker 2 | // Skip Husky install in production and CI 3 | if (process.env.NODE_ENV === "production" || process.env.CI === "true") { 4 | process.exit(0); 5 | } 6 | const husky = (await import("husky")).default; 7 | console.log(husky()); 8 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | lint-staged -------------------------------------------------------------------------------- /.lintstagedrc.json: -------------------------------------------------------------------------------- 1 | { "*.{js,ts,json,md,yaml,yml}": "prettier --write" } 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | //registry.npmjs.org/:_authToken=${NPM_TOKEN} 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | lib-cjs 2 | lib-esm 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 4 3 | } 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.15.7 -- 2025-05-20 4 | 5 | - Bump to latest `libsql` package. 6 | 7 | ## 0.15.6 -- 2025-05-14 8 | 9 | - Bump to latest `libsql` package. 10 | 11 | ## 0.15.5 -- 2025-05-11 12 | 13 | - Bump to latest `libsql` package. 14 | 15 | ## 0.15.4 -- 2025-04-15 16 | 17 | - Bump to latest `libsql` package. 18 | 19 | ## 0.15.3 -- 2025-04-11 20 | 21 | - Bump to latest `libsql` package. 22 | 23 | ## 0.15.2 -- 2025-04-01 24 | 25 | - Bump to latest `libsql` package. 26 | 27 | ## 0.15.1 -- 2025-03-24 28 | 29 | - Bump to latest `libsql` package. 30 | 31 | ## 0.15.0 -- 2025-03-17 32 | 33 | - Bump to latest `libsql` package. 34 | 35 | ## 0.15.0-pre.3 -- 2025-03-11 36 | 37 | - Fix Bun complaint about duplicate "prepare" key in `package.json` 38 | 39 | ## 0.15.0-pre.2 -- 2024-02-11 40 | 41 | - Bump to latest `libsql` package. 42 | 43 | ## 0.15.0-pre.1 -- 2024-11-15 44 | 45 | - Initial support for offline writes. 46 | 47 | ## 0.12.0 -- 2024-09-16 48 | 49 | - Upgrade `hrana-client-ts` to latest 0.7.0 version which has stable `isomorphic-fetch` implementation (see https://github.com/libsql/hrana-client-ts/pull/19) 50 | 51 | ## 0.11.0 -- 2024-09-13 52 | 53 | - Upgrade `libsql-js` to latest 0.4.4 version which brings full vector search support for embedded replicas (see vector search documentation here: https://docs.turso.tech/features/ai-and-embeddings) 54 | 55 | ## 0.10.0 -- 2024-08-26 56 | 57 | - Add a migrate() API that can be used to do migrations on both schema databases and regular databases. It is mostly dedicated to schema migration tools. 58 | 59 | ## 0.8.1 -- 2024-08-03 60 | 61 | - Fix embedded replica sync WAL index path name , which caused "No such file or directory" for local sync in some cases ([#244](https://github.com/tursodatabase/libsql-client-ts/issues/244)). 62 | 63 | ## 0.8.0 -- 2024-07-30 64 | 65 | - No changes from 0.8.0-pre.1. 66 | 67 | ## 0.8.0-pre.1 -- 2024-07-18 68 | 69 | - Bump hrana client to 0.6.2. 70 | - Support `cache=private|shared` [query parameter](https://www.sqlite.org/uri.html#recognized_query_parameters) in the connection string to local SQLite (https://github.com/tursodatabase/libsql-client-ts/pull/220) 71 | - Fix bug in wasm experimental client which appears when transaction are used in local mode (https://github.com/tursodatabase/libsql-client-ts/pull/231) 72 | - Add `execute(sql, args)` overload to make the API similar to other SQLite SDKs 73 | 74 | ## 0.7.0 -- 2024-06-25 75 | 76 | - Add configurable concurrency limit for parallel query execution 77 | (defaults to 20) to address socket hangup errors. 78 | 79 | ## 0.6.2 -- 2024-06-01 80 | 81 | - Fix compatibility issue with libSQL server versions that don't have migrations endpoint. 82 | 83 | ## 0.6.1 -- 2024-05-30 84 | 85 | - Add an option to `batch()` to wait for schema changes to finish when using shared schema. 86 | 87 | ## 0.6.0 -- 2024-04-28 88 | 89 | - Bump hrana client to 0.6.0, which uses native Node fetch(). Note that 90 | `@libsql/client` now requires Node 18 or later. 91 | 92 | ## 0.5.6 -- 2024-03-12 93 | 94 | - Bump `libsql` package dependency to 0.3.10 that adds `wasm32` as 95 | supported CPU, which is needed for StackBlitz compatibility. 96 | 97 | ## 0.5.5 -- 2024-03-11 98 | 99 | - Bump `@libsql/libsql-wasm-experimental"` dependency to 0.0.2, which 100 | fixes a broken sqlite3_get_autocommit() export. 101 | 102 | ## 0.5.4 -- 2024-03-11 103 | 104 | - Bump `libsql` dependency to 0.3.9, which fixes symbol not found errors on Alpine. 105 | 106 | ## 0.5.3 -- 2024-03-06 107 | 108 | - Add `syncInterval` config option to enable periodic sync. 109 | - Bump `libsql` dependency to 0.3.7, which switches default encryption cipher to aes256cbs. 110 | 111 | ## 0.5.2 -- 2024-02-24 112 | 113 | - Disable SQL statemen tracing in Wasm. 114 | 115 | ## 0.5.1 -- 2024-02-19 116 | 117 | - Update `libsql` package to 0.3.2, add `encryptionCipher` option, and switch default cipher to SQLCipher. 118 | 119 | ## 0.5.0 -- 2024-02-15 120 | 121 | - Add a `encryptionKey` config option, which enables encryption at rest for local database files. 122 | 123 | ## 0.4.0 -- 2024-01-26 124 | 125 | - Update hrana-client package to 0.5.6. 126 | - Add a `@libsql/client-wasm` package. 127 | - Fix Bun on Linux/arm64. 128 | 129 | ## 0.3.6 -- 2023-10-20 130 | 131 | - Fix import problems on Cloudflare Workers. 132 | - Add `rawCode` property to errors for local databases. 133 | - Update the `libsql` package to version 0.1.28. 134 | 135 | ## 0.3.5 -- 2023-09-25 136 | 137 | - Performance improvements for local database access by reusing connection in `Client`. 138 | - Embedded replica support. 139 | - Column introspection support via ResultSet.columnTypes property. 140 | 141 | ## 0.3.4 -- 2023-09-11 142 | 143 | - Switch to Hrana 2 by default to let Hrana 3 cook some more. 144 | 145 | ## 0.3.3 -- 2023-09-11 146 | 147 | - Updated `@libsql/hrana-client` to version 0.5.1, which has Bun support. 148 | 149 | - Switched to `libsql` package as a replacement for `better-sqlite3`. 150 | 151 | ## 0.3.2 -- 2023-07-29 152 | 153 | - Updated `@libsql/hrana-client` to version 0.5.0, which implements Hrana 3 154 | - Dropped workarounds for broken WebSocket support in Miniflare 2 155 | - Added a `@libsql/client/node` import for explicit Node.js-specific module 156 | 157 | ## 0.3.1 -- 2023-07-20 158 | 159 | - Added `ResultSet.toJSON()` to provide better JSON serialization. ([#61](https://github.com/libsql/libsql-client-ts/pull/61)) 160 | - Added conditional exports to `package.json` that redirect the default import of `@libsql/client` to `@libsql/client/web` on a few supported edge platforms. ([#65](https://github.com/libsql/libsql-client-ts/pull/65)) 161 | - Added `Config.fetch` to support overriding the `fetch` implementation from `@libsql/isomorphic-fetch`. ([#66](https://github.com/libsql/libsql-client-ts/pull/66)) 162 | 163 | ## 0.3.0 -- 2023-07-07 164 | 165 | - **Changed the order of parameters to `batch()`**, so that the transaction mode is passed as the second parameter. ([#57](https://github.com/libsql/libsql-client-ts/pull/57)) 166 | - **Changed the default transaction mode to `"deferred"`**. ([#57](https://github.com/libsql/libsql-client-ts/pull/57)) 167 | - Added `Client.protocol` property to find out which protocol the client uses ([#54](https://github.com/libsql/libsql-client-ts/pull/54)). 168 | 169 | ## 0.2.2 -- 2023-06-22 170 | 171 | - Added `intMode` field to the `Config`, which chooses whether SQLite integers are represented as numbers, bigints or strings in JavaScript ([#51](https://github.com/libsql/libsql-client-ts/pull/51)). 172 | 173 | ## 0.2.1 -- 2023-06-13 174 | 175 | - Added `TransactionMode` argument to `batch()` and `transaction()` ([#46](https://github.com/libsql/libsql-client-ts/pull/46)) 176 | - Added `Client.executeMultiple()` and `Transaction.executeMultiple()` ([#49](https://github.com/libsql/libsql-client-ts/pull/49)) 177 | - Added `Transaction.batch()` ([#49](https://github.com/libsql/libsql-client-ts/pull/49)) 178 | - **Changed the default transaction mode** from `BEGIN DEFERRED` to `BEGIN IMMEDIATE` 179 | 180 | ## 0.2.0 -- 2023-06-07 181 | 182 | - **Added support for interactive transactions over HTTP** by using `@libsql/hrana-client` version 0.4 ([#44](https://github.com/libsql/libsql-client-ts/pull/44)) 183 | - Added `?tls=0` query parameter to turn off TLS for `libsql:` URLs 184 | - Changed the `libsql:` URL to use HTTP instead of WebSockets 185 | - Changed the `Value` type to include `bigint` (so that we can add support for reading integers as bigints in the future, without breaking compatibility) 186 | - Removed the `./hrana` import, added `./ws` to import the WebSocket-only client 187 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | 3 | - Have `npm` installed and in PATH 4 | - Have `git` installed and in PATH 5 | 6 | # Setting up the repository for contribution 7 | 8 | - Clone this repository: `git clone https://github.com/tursodatabase/libsql-client-ts` 9 | - Change the current working directory to the cloned repository: `cd libsql-client-ts` 10 | - Install dependencies: `npm i` 11 | - Change the current working directory to `libsql-core`'s workspace: `cd packages/libsql-core` 12 | - Built the core package: `npm run build` 13 | - Go back to the root directory to start making changes: `cd ../..` 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 libSQL 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ./packages/libsql-client/README.md -------------------------------------------------------------------------------- /examples/batch/.gitignore: -------------------------------------------------------------------------------- 1 | local.db 2 | -------------------------------------------------------------------------------- /examples/batch/README.md: -------------------------------------------------------------------------------- 1 | # Batch 2 | 3 | This example demonstrates how to use libSQL to execute a batch of SQL statements. 4 | 5 | ## Install Dependencies 6 | 7 | ```bash 8 | npm i 9 | ``` 10 | 11 | ## Running 12 | 13 | Execute the example: 14 | 15 | ```bash 16 | node index.mjs 17 | ``` 18 | 19 | This will setup a SQLite database, execute a batch of SQL statements, and then query the results. 20 | -------------------------------------------------------------------------------- /examples/batch/index.mjs: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | 3 | const client = createClient({ 4 | url: "file:local.db", 5 | }); 6 | 7 | await client.batch( 8 | [ 9 | "CREATE TABLE IF NOT EXISTS users (email TEXT)", 10 | { 11 | sql: "INSERT INTO users VALUES (?)", 12 | args: ["first@example.com"], 13 | }, 14 | { 15 | sql: "INSERT INTO users VALUES (?)", 16 | args: ["second@example.com"], 17 | }, 18 | { 19 | sql: "INSERT INTO users VALUES (?)", 20 | args: ["third@example.com"], 21 | }, 22 | ], 23 | "write", 24 | ); 25 | 26 | const result = await client.execute("SELECT * FROM users"); 27 | 28 | console.log("Users:", result.rows); 29 | -------------------------------------------------------------------------------- /examples/batch/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "batch", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@libsql/client": "^0.14.0" 13 | } 14 | }, 15 | "node_modules/@libsql/client": { 16 | "version": "0.14.0", 17 | "resolved": "https://registry.npmjs.org/@libsql/client/-/client-0.14.0.tgz", 18 | "integrity": "sha512-/9HEKfn6fwXB5aTEEoMeFh4CtG0ZzbncBb1e++OCdVpgKZ/xyMsIVYXm0w7Pv4RUel803vE6LwniB3PqD72R0Q==", 19 | "license": "MIT", 20 | "dependencies": { 21 | "@libsql/core": "^0.14.0", 22 | "@libsql/hrana-client": "^0.7.0", 23 | "js-base64": "^3.7.5", 24 | "libsql": "^0.4.4", 25 | "promise-limit": "^2.7.0" 26 | } 27 | }, 28 | "node_modules/@libsql/core": { 29 | "version": "0.14.0", 30 | "resolved": "https://registry.npmjs.org/@libsql/core/-/core-0.14.0.tgz", 31 | "integrity": "sha512-nhbuXf7GP3PSZgdCY2Ecj8vz187ptHlZQ0VRc751oB2C1W8jQUXKKklvt7t1LJiUTQBVJuadF628eUk+3cRi4Q==", 32 | "license": "MIT", 33 | "dependencies": { 34 | "js-base64": "^3.7.5" 35 | } 36 | }, 37 | "node_modules/@libsql/darwin-arm64": { 38 | "version": "0.4.6", 39 | "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.4.6.tgz", 40 | "integrity": "sha512-45i604CJ2Lubbg7NqtDodjarF6VgST8rS5R8xB++MoRqixtDns9PZ6tocT9pRJDWuTWEiy2sjthPOFWMKwYAsg==", 41 | "cpu": [ 42 | "arm64" 43 | ], 44 | "license": "MIT", 45 | "optional": true, 46 | "os": [ 47 | "darwin" 48 | ] 49 | }, 50 | "node_modules/@libsql/darwin-x64": { 51 | "version": "0.4.6", 52 | "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.4.6.tgz", 53 | "integrity": "sha512-dRKliflhfr5zOPSNgNJ6C2nZDd4YA8bTXF3MUNqNkcxQ8BffaH9uUwL9kMq89LkFIZQHcyP75bBgZctxfJ/H5Q==", 54 | "cpu": [ 55 | "x64" 56 | ], 57 | "license": "MIT", 58 | "optional": true, 59 | "os": [ 60 | "darwin" 61 | ] 62 | }, 63 | "node_modules/@libsql/hrana-client": { 64 | "version": "0.7.0", 65 | "resolved": "https://registry.npmjs.org/@libsql/hrana-client/-/hrana-client-0.7.0.tgz", 66 | "integrity": "sha512-OF8fFQSkbL7vJY9rfuegK1R7sPgQ6kFMkDamiEccNUvieQ+3urzfDFI616oPl8V7T9zRmnTkSjMOImYCAVRVuw==", 67 | "license": "MIT", 68 | "dependencies": { 69 | "@libsql/isomorphic-fetch": "^0.3.1", 70 | "@libsql/isomorphic-ws": "^0.1.5", 71 | "js-base64": "^3.7.5", 72 | "node-fetch": "^3.3.2" 73 | } 74 | }, 75 | "node_modules/@libsql/isomorphic-fetch": { 76 | "version": "0.3.1", 77 | "resolved": "https://registry.npmjs.org/@libsql/isomorphic-fetch/-/isomorphic-fetch-0.3.1.tgz", 78 | "integrity": "sha512-6kK3SUK5Uu56zPq/Las620n5aS9xJq+jMBcNSOmjhNf/MUvdyji4vrMTqD7ptY7/4/CAVEAYDeotUz60LNQHtw==", 79 | "license": "MIT", 80 | "engines": { 81 | "node": ">=18.0.0" 82 | } 83 | }, 84 | "node_modules/@libsql/isomorphic-ws": { 85 | "version": "0.1.5", 86 | "resolved": "https://registry.npmjs.org/@libsql/isomorphic-ws/-/isomorphic-ws-0.1.5.tgz", 87 | "integrity": "sha512-DtLWIH29onUYR00i0GlQ3UdcTRC6EP4u9w/h9LxpUZJWRMARk6dQwZ6Jkd+QdwVpuAOrdxt18v0K2uIYR3fwFg==", 88 | "license": "MIT", 89 | "dependencies": { 90 | "@types/ws": "^8.5.4", 91 | "ws": "^8.13.0" 92 | } 93 | }, 94 | "node_modules/@libsql/linux-arm64-gnu": { 95 | "version": "0.4.6", 96 | "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.4.6.tgz", 97 | "integrity": "sha512-DMPavVyY6vYPAYcQR1iOotHszg+5xSjHSg6F9kNecPX0KKdGq84zuPJmORfKOPtaWvzPewNFdML/e+s1fu09XQ==", 98 | "cpu": [ 99 | "arm64" 100 | ], 101 | "license": "MIT", 102 | "optional": true, 103 | "os": [ 104 | "linux" 105 | ] 106 | }, 107 | "node_modules/@libsql/linux-arm64-musl": { 108 | "version": "0.4.6", 109 | "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.4.6.tgz", 110 | "integrity": "sha512-whuHSYAZyclGjM3L0mKGXyWqdAy7qYvPPn+J1ve7FtGkFlM0DiIPjA5K30aWSGJSRh72sD9DBZfnu8CpfSjT6w==", 111 | "cpu": [ 112 | "arm64" 113 | ], 114 | "license": "MIT", 115 | "optional": true, 116 | "os": [ 117 | "linux" 118 | ] 119 | }, 120 | "node_modules/@libsql/linux-x64-gnu": { 121 | "version": "0.4.6", 122 | "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.4.6.tgz", 123 | "integrity": "sha512-0ggx+5RwEbYabIlDBBAvavdfIJCZ757u6nDZtBeQIhzW99EKbWG3lvkXHM3qudFb/pDWSUY4RFBm6vVtF1cJGA==", 124 | "cpu": [ 125 | "x64" 126 | ], 127 | "license": "MIT", 128 | "optional": true, 129 | "os": [ 130 | "linux" 131 | ] 132 | }, 133 | "node_modules/@libsql/linux-x64-musl": { 134 | "version": "0.4.6", 135 | "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.4.6.tgz", 136 | "integrity": "sha512-SWNrv7Hz72QWlbM/ZsbL35MPopZavqCUmQz2HNDZ55t0F+kt8pXuP+bbI2KvmaQ7wdsoqAA4qBmjol0+bh4ndw==", 137 | "cpu": [ 138 | "x64" 139 | ], 140 | "license": "MIT", 141 | "optional": true, 142 | "os": [ 143 | "linux" 144 | ] 145 | }, 146 | "node_modules/@libsql/win32-x64-msvc": { 147 | "version": "0.4.6", 148 | "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.4.6.tgz", 149 | "integrity": "sha512-Q0axn110zDNELfkEog3Nl8p9BU4eI/UvgaHevGyOiSDN7s0KPfj0j6jwVHk4oz3o/d/Gg3DRIxomZ4ftfTOy/g==", 150 | "cpu": [ 151 | "x64" 152 | ], 153 | "license": "MIT", 154 | "optional": true, 155 | "os": [ 156 | "win32" 157 | ] 158 | }, 159 | "node_modules/@neon-rs/load": { 160 | "version": "0.0.4", 161 | "resolved": "https://registry.npmjs.org/@neon-rs/load/-/load-0.0.4.tgz", 162 | "integrity": "sha512-kTPhdZyTQxB+2wpiRcFWrDcejc4JI6tkPuS7UZCG4l6Zvc5kU/gGQ/ozvHTh1XR5tS+UlfAfGuPajjzQjCiHCw==", 163 | "license": "MIT" 164 | }, 165 | "node_modules/@types/node": { 166 | "version": "22.7.5", 167 | "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz", 168 | "integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==", 169 | "license": "MIT", 170 | "dependencies": { 171 | "undici-types": "~6.19.2" 172 | } 173 | }, 174 | "node_modules/@types/ws": { 175 | "version": "8.5.12", 176 | "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.12.tgz", 177 | "integrity": "sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==", 178 | "license": "MIT", 179 | "dependencies": { 180 | "@types/node": "*" 181 | } 182 | }, 183 | "node_modules/data-uri-to-buffer": { 184 | "version": "4.0.1", 185 | "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", 186 | "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", 187 | "license": "MIT", 188 | "engines": { 189 | "node": ">= 12" 190 | } 191 | }, 192 | "node_modules/detect-libc": { 193 | "version": "2.0.2", 194 | "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", 195 | "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==", 196 | "license": "Apache-2.0", 197 | "engines": { 198 | "node": ">=8" 199 | } 200 | }, 201 | "node_modules/fetch-blob": { 202 | "version": "3.2.0", 203 | "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", 204 | "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", 205 | "funding": [ 206 | { 207 | "type": "github", 208 | "url": "https://github.com/sponsors/jimmywarting" 209 | }, 210 | { 211 | "type": "paypal", 212 | "url": "https://paypal.me/jimmywarting" 213 | } 214 | ], 215 | "license": "MIT", 216 | "dependencies": { 217 | "node-domexception": "^1.0.0", 218 | "web-streams-polyfill": "^3.0.3" 219 | }, 220 | "engines": { 221 | "node": "^12.20 || >= 14.13" 222 | } 223 | }, 224 | "node_modules/formdata-polyfill": { 225 | "version": "4.0.10", 226 | "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", 227 | "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", 228 | "license": "MIT", 229 | "dependencies": { 230 | "fetch-blob": "^3.1.2" 231 | }, 232 | "engines": { 233 | "node": ">=12.20.0" 234 | } 235 | }, 236 | "node_modules/js-base64": { 237 | "version": "3.7.7", 238 | "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.7.tgz", 239 | "integrity": "sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==", 240 | "license": "BSD-3-Clause" 241 | }, 242 | "node_modules/libsql": { 243 | "version": "0.4.6", 244 | "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.4.6.tgz", 245 | "integrity": "sha512-F5M+ltteK6dCcpjMahrkgT96uFJvVI8aQ4r9f2AzHQjC7BkAYtvfMSTWGvRBezRgMUIU2h1Sy0pF9nOGOD5iyA==", 246 | "cpu": [ 247 | "x64", 248 | "arm64", 249 | "wasm32" 250 | ], 251 | "license": "MIT", 252 | "os": [ 253 | "darwin", 254 | "linux", 255 | "win32" 256 | ], 257 | "dependencies": { 258 | "@neon-rs/load": "^0.0.4", 259 | "detect-libc": "2.0.2" 260 | }, 261 | "optionalDependencies": { 262 | "@libsql/darwin-arm64": "0.4.6", 263 | "@libsql/darwin-x64": "0.4.6", 264 | "@libsql/linux-arm64-gnu": "0.4.6", 265 | "@libsql/linux-arm64-musl": "0.4.6", 266 | "@libsql/linux-x64-gnu": "0.4.6", 267 | "@libsql/linux-x64-musl": "0.4.6", 268 | "@libsql/win32-x64-msvc": "0.4.6" 269 | } 270 | }, 271 | "node_modules/node-domexception": { 272 | "version": "1.0.0", 273 | "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", 274 | "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", 275 | "funding": [ 276 | { 277 | "type": "github", 278 | "url": "https://github.com/sponsors/jimmywarting" 279 | }, 280 | { 281 | "type": "github", 282 | "url": "https://paypal.me/jimmywarting" 283 | } 284 | ], 285 | "license": "MIT", 286 | "engines": { 287 | "node": ">=10.5.0" 288 | } 289 | }, 290 | "node_modules/node-fetch": { 291 | "version": "3.3.2", 292 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", 293 | "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", 294 | "license": "MIT", 295 | "dependencies": { 296 | "data-uri-to-buffer": "^4.0.0", 297 | "fetch-blob": "^3.1.4", 298 | "formdata-polyfill": "^4.0.10" 299 | }, 300 | "engines": { 301 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 302 | }, 303 | "funding": { 304 | "type": "opencollective", 305 | "url": "https://opencollective.com/node-fetch" 306 | } 307 | }, 308 | "node_modules/promise-limit": { 309 | "version": "2.7.0", 310 | "resolved": "https://registry.npmjs.org/promise-limit/-/promise-limit-2.7.0.tgz", 311 | "integrity": "sha512-7nJ6v5lnJsXwGprnGXga4wx6d1POjvi5Qmf1ivTRxTjH4Z/9Czja/UCMLVmB9N93GeWOU93XaFaEt6jbuoagNw==", 312 | "license": "ISC" 313 | }, 314 | "node_modules/undici-types": { 315 | "version": "6.19.8", 316 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", 317 | "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", 318 | "license": "MIT" 319 | }, 320 | "node_modules/web-streams-polyfill": { 321 | "version": "3.3.3", 322 | "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", 323 | "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", 324 | "license": "MIT", 325 | "engines": { 326 | "node": ">= 8" 327 | } 328 | }, 329 | "node_modules/ws": { 330 | "version": "8.18.0", 331 | "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", 332 | "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", 333 | "license": "MIT", 334 | "engines": { 335 | "node": ">=10.0.0" 336 | }, 337 | "peerDependencies": { 338 | "bufferutil": "^4.0.1", 339 | "utf-8-validate": ">=5.0.2" 340 | }, 341 | "peerDependenciesMeta": { 342 | "bufferutil": { 343 | "optional": true 344 | }, 345 | "utf-8-validate": { 346 | "optional": true 347 | } 348 | } 349 | } 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /examples/batch/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "main": "index.mjs", 5 | "author": "Giovanni Benussi", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@libsql/client": "^0.14.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/encryption/.gitignore: -------------------------------------------------------------------------------- 1 | encrypted.db 2 | -------------------------------------------------------------------------------- /examples/encryption/README.md: -------------------------------------------------------------------------------- 1 | # Encryption 2 | 3 | This example demonstrates how to create and use an encrypted SQLite database with libSQL. 4 | 5 | ## Install Dependencies 6 | 7 | ```bash 8 | npm i 9 | ``` 10 | 11 | ## Running 12 | 13 | Execute the example: 14 | 15 | ```bash 16 | node index.mjs 17 | ``` 18 | 19 | This will setup an encrypted SQLite database, execute a batch of SQL statements, and then query the results. 20 | -------------------------------------------------------------------------------- /examples/encryption/index.mjs: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | 3 | // You should set the ENCRYPTION_KEY in a environment variable 4 | // For demo purposes, we're using a fixed key 5 | const encryptionKey = "my-safe-encryption-key"; 6 | 7 | const client = createClient({ 8 | url: "file:encrypted.db", 9 | encryptionKey, 10 | }); 11 | 12 | await client.batch( 13 | [ 14 | "CREATE TABLE IF NOT EXISTS users (email TEXT)", 15 | "INSERT INTO users VALUES ('first@example.com')", 16 | "INSERT INTO users VALUES ('second@example.com')", 17 | "INSERT INTO users VALUES ('third@example.com')", 18 | ], 19 | "write", 20 | ); 21 | 22 | const result = await client.execute("SELECT * FROM users"); 23 | 24 | console.log("Users:", result.rows); 25 | -------------------------------------------------------------------------------- /examples/encryption/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "main": "index.mjs", 5 | "author": "Giovanni Benussi", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@libsql/client": "^0.14.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/local/.gitignore: -------------------------------------------------------------------------------- 1 | local.db 2 | -------------------------------------------------------------------------------- /examples/local/README.md: -------------------------------------------------------------------------------- 1 | # Local 2 | 3 | This example demonstrates how to use libSQL with a local SQLite file. 4 | 5 | ## Install Dependencies 6 | 7 | ```bash 8 | npm i 9 | ``` 10 | 11 | ## Running 12 | 13 | Execute the example: 14 | 15 | ```bash 16 | node index.mjs 17 | ``` 18 | 19 | This will setup a local SQLite database, insert some data, and then query the results. 20 | -------------------------------------------------------------------------------- /examples/local/index.mjs: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | 3 | const client = createClient({ 4 | url: "file:local.db", 5 | }); 6 | 7 | await client.batch( 8 | [ 9 | "CREATE TABLE IF NOT EXISTS users (email TEXT)", 10 | "INSERT INTO users VALUES ('first@example.com')", 11 | "INSERT INTO users VALUES ('second@example.com')", 12 | "INSERT INTO users VALUES ('third@example.com')", 13 | ], 14 | "write", 15 | ); 16 | 17 | const result = await client.execute("SELECT * FROM users"); 18 | 19 | console.log("Users:", result.rows); 20 | -------------------------------------------------------------------------------- /examples/local/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "batch", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@libsql/client": "^0.14.0" 13 | } 14 | }, 15 | "node_modules/@libsql/client": { 16 | "version": "0.14.0", 17 | "resolved": "https://registry.npmjs.org/@libsql/client/-/client-0.14.0.tgz", 18 | "integrity": "sha512-/9HEKfn6fwXB5aTEEoMeFh4CtG0ZzbncBb1e++OCdVpgKZ/xyMsIVYXm0w7Pv4RUel803vE6LwniB3PqD72R0Q==", 19 | "license": "MIT", 20 | "dependencies": { 21 | "@libsql/core": "^0.14.0", 22 | "@libsql/hrana-client": "^0.7.0", 23 | "js-base64": "^3.7.5", 24 | "libsql": "^0.4.4", 25 | "promise-limit": "^2.7.0" 26 | } 27 | }, 28 | "node_modules/@libsql/core": { 29 | "version": "0.14.0", 30 | "resolved": "https://registry.npmjs.org/@libsql/core/-/core-0.14.0.tgz", 31 | "integrity": "sha512-nhbuXf7GP3PSZgdCY2Ecj8vz187ptHlZQ0VRc751oB2C1W8jQUXKKklvt7t1LJiUTQBVJuadF628eUk+3cRi4Q==", 32 | "license": "MIT", 33 | "dependencies": { 34 | "js-base64": "^3.7.5" 35 | } 36 | }, 37 | "node_modules/@libsql/darwin-arm64": { 38 | "version": "0.4.6", 39 | "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.4.6.tgz", 40 | "integrity": "sha512-45i604CJ2Lubbg7NqtDodjarF6VgST8rS5R8xB++MoRqixtDns9PZ6tocT9pRJDWuTWEiy2sjthPOFWMKwYAsg==", 41 | "cpu": [ 42 | "arm64" 43 | ], 44 | "license": "MIT", 45 | "optional": true, 46 | "os": [ 47 | "darwin" 48 | ] 49 | }, 50 | "node_modules/@libsql/darwin-x64": { 51 | "version": "0.4.6", 52 | "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.4.6.tgz", 53 | "integrity": "sha512-dRKliflhfr5zOPSNgNJ6C2nZDd4YA8bTXF3MUNqNkcxQ8BffaH9uUwL9kMq89LkFIZQHcyP75bBgZctxfJ/H5Q==", 54 | "cpu": [ 55 | "x64" 56 | ], 57 | "license": "MIT", 58 | "optional": true, 59 | "os": [ 60 | "darwin" 61 | ] 62 | }, 63 | "node_modules/@libsql/hrana-client": { 64 | "version": "0.7.0", 65 | "resolved": "https://registry.npmjs.org/@libsql/hrana-client/-/hrana-client-0.7.0.tgz", 66 | "integrity": "sha512-OF8fFQSkbL7vJY9rfuegK1R7sPgQ6kFMkDamiEccNUvieQ+3urzfDFI616oPl8V7T9zRmnTkSjMOImYCAVRVuw==", 67 | "license": "MIT", 68 | "dependencies": { 69 | "@libsql/isomorphic-fetch": "^0.3.1", 70 | "@libsql/isomorphic-ws": "^0.1.5", 71 | "js-base64": "^3.7.5", 72 | "node-fetch": "^3.3.2" 73 | } 74 | }, 75 | "node_modules/@libsql/isomorphic-fetch": { 76 | "version": "0.3.1", 77 | "resolved": "https://registry.npmjs.org/@libsql/isomorphic-fetch/-/isomorphic-fetch-0.3.1.tgz", 78 | "integrity": "sha512-6kK3SUK5Uu56zPq/Las620n5aS9xJq+jMBcNSOmjhNf/MUvdyji4vrMTqD7ptY7/4/CAVEAYDeotUz60LNQHtw==", 79 | "license": "MIT", 80 | "engines": { 81 | "node": ">=18.0.0" 82 | } 83 | }, 84 | "node_modules/@libsql/isomorphic-ws": { 85 | "version": "0.1.5", 86 | "resolved": "https://registry.npmjs.org/@libsql/isomorphic-ws/-/isomorphic-ws-0.1.5.tgz", 87 | "integrity": "sha512-DtLWIH29onUYR00i0GlQ3UdcTRC6EP4u9w/h9LxpUZJWRMARk6dQwZ6Jkd+QdwVpuAOrdxt18v0K2uIYR3fwFg==", 88 | "license": "MIT", 89 | "dependencies": { 90 | "@types/ws": "^8.5.4", 91 | "ws": "^8.13.0" 92 | } 93 | }, 94 | "node_modules/@libsql/linux-arm64-gnu": { 95 | "version": "0.4.6", 96 | "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.4.6.tgz", 97 | "integrity": "sha512-DMPavVyY6vYPAYcQR1iOotHszg+5xSjHSg6F9kNecPX0KKdGq84zuPJmORfKOPtaWvzPewNFdML/e+s1fu09XQ==", 98 | "cpu": [ 99 | "arm64" 100 | ], 101 | "license": "MIT", 102 | "optional": true, 103 | "os": [ 104 | "linux" 105 | ] 106 | }, 107 | "node_modules/@libsql/linux-arm64-musl": { 108 | "version": "0.4.6", 109 | "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.4.6.tgz", 110 | "integrity": "sha512-whuHSYAZyclGjM3L0mKGXyWqdAy7qYvPPn+J1ve7FtGkFlM0DiIPjA5K30aWSGJSRh72sD9DBZfnu8CpfSjT6w==", 111 | "cpu": [ 112 | "arm64" 113 | ], 114 | "license": "MIT", 115 | "optional": true, 116 | "os": [ 117 | "linux" 118 | ] 119 | }, 120 | "node_modules/@libsql/linux-x64-gnu": { 121 | "version": "0.4.6", 122 | "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.4.6.tgz", 123 | "integrity": "sha512-0ggx+5RwEbYabIlDBBAvavdfIJCZ757u6nDZtBeQIhzW99EKbWG3lvkXHM3qudFb/pDWSUY4RFBm6vVtF1cJGA==", 124 | "cpu": [ 125 | "x64" 126 | ], 127 | "license": "MIT", 128 | "optional": true, 129 | "os": [ 130 | "linux" 131 | ] 132 | }, 133 | "node_modules/@libsql/linux-x64-musl": { 134 | "version": "0.4.6", 135 | "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.4.6.tgz", 136 | "integrity": "sha512-SWNrv7Hz72QWlbM/ZsbL35MPopZavqCUmQz2HNDZ55t0F+kt8pXuP+bbI2KvmaQ7wdsoqAA4qBmjol0+bh4ndw==", 137 | "cpu": [ 138 | "x64" 139 | ], 140 | "license": "MIT", 141 | "optional": true, 142 | "os": [ 143 | "linux" 144 | ] 145 | }, 146 | "node_modules/@libsql/win32-x64-msvc": { 147 | "version": "0.4.6", 148 | "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.4.6.tgz", 149 | "integrity": "sha512-Q0axn110zDNELfkEog3Nl8p9BU4eI/UvgaHevGyOiSDN7s0KPfj0j6jwVHk4oz3o/d/Gg3DRIxomZ4ftfTOy/g==", 150 | "cpu": [ 151 | "x64" 152 | ], 153 | "license": "MIT", 154 | "optional": true, 155 | "os": [ 156 | "win32" 157 | ] 158 | }, 159 | "node_modules/@neon-rs/load": { 160 | "version": "0.0.4", 161 | "resolved": "https://registry.npmjs.org/@neon-rs/load/-/load-0.0.4.tgz", 162 | "integrity": "sha512-kTPhdZyTQxB+2wpiRcFWrDcejc4JI6tkPuS7UZCG4l6Zvc5kU/gGQ/ozvHTh1XR5tS+UlfAfGuPajjzQjCiHCw==", 163 | "license": "MIT" 164 | }, 165 | "node_modules/@types/node": { 166 | "version": "22.7.5", 167 | "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz", 168 | "integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==", 169 | "license": "MIT", 170 | "dependencies": { 171 | "undici-types": "~6.19.2" 172 | } 173 | }, 174 | "node_modules/@types/ws": { 175 | "version": "8.5.12", 176 | "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.12.tgz", 177 | "integrity": "sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==", 178 | "license": "MIT", 179 | "dependencies": { 180 | "@types/node": "*" 181 | } 182 | }, 183 | "node_modules/data-uri-to-buffer": { 184 | "version": "4.0.1", 185 | "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", 186 | "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", 187 | "license": "MIT", 188 | "engines": { 189 | "node": ">= 12" 190 | } 191 | }, 192 | "node_modules/detect-libc": { 193 | "version": "2.0.2", 194 | "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", 195 | "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==", 196 | "license": "Apache-2.0", 197 | "engines": { 198 | "node": ">=8" 199 | } 200 | }, 201 | "node_modules/fetch-blob": { 202 | "version": "3.2.0", 203 | "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", 204 | "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", 205 | "funding": [ 206 | { 207 | "type": "github", 208 | "url": "https://github.com/sponsors/jimmywarting" 209 | }, 210 | { 211 | "type": "paypal", 212 | "url": "https://paypal.me/jimmywarting" 213 | } 214 | ], 215 | "license": "MIT", 216 | "dependencies": { 217 | "node-domexception": "^1.0.0", 218 | "web-streams-polyfill": "^3.0.3" 219 | }, 220 | "engines": { 221 | "node": "^12.20 || >= 14.13" 222 | } 223 | }, 224 | "node_modules/formdata-polyfill": { 225 | "version": "4.0.10", 226 | "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", 227 | "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", 228 | "license": "MIT", 229 | "dependencies": { 230 | "fetch-blob": "^3.1.2" 231 | }, 232 | "engines": { 233 | "node": ">=12.20.0" 234 | } 235 | }, 236 | "node_modules/js-base64": { 237 | "version": "3.7.7", 238 | "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.7.tgz", 239 | "integrity": "sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==", 240 | "license": "BSD-3-Clause" 241 | }, 242 | "node_modules/libsql": { 243 | "version": "0.4.6", 244 | "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.4.6.tgz", 245 | "integrity": "sha512-F5M+ltteK6dCcpjMahrkgT96uFJvVI8aQ4r9f2AzHQjC7BkAYtvfMSTWGvRBezRgMUIU2h1Sy0pF9nOGOD5iyA==", 246 | "cpu": [ 247 | "x64", 248 | "arm64", 249 | "wasm32" 250 | ], 251 | "license": "MIT", 252 | "os": [ 253 | "darwin", 254 | "linux", 255 | "win32" 256 | ], 257 | "dependencies": { 258 | "@neon-rs/load": "^0.0.4", 259 | "detect-libc": "2.0.2" 260 | }, 261 | "optionalDependencies": { 262 | "@libsql/darwin-arm64": "0.4.6", 263 | "@libsql/darwin-x64": "0.4.6", 264 | "@libsql/linux-arm64-gnu": "0.4.6", 265 | "@libsql/linux-arm64-musl": "0.4.6", 266 | "@libsql/linux-x64-gnu": "0.4.6", 267 | "@libsql/linux-x64-musl": "0.4.6", 268 | "@libsql/win32-x64-msvc": "0.4.6" 269 | } 270 | }, 271 | "node_modules/node-domexception": { 272 | "version": "1.0.0", 273 | "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", 274 | "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", 275 | "funding": [ 276 | { 277 | "type": "github", 278 | "url": "https://github.com/sponsors/jimmywarting" 279 | }, 280 | { 281 | "type": "github", 282 | "url": "https://paypal.me/jimmywarting" 283 | } 284 | ], 285 | "license": "MIT", 286 | "engines": { 287 | "node": ">=10.5.0" 288 | } 289 | }, 290 | "node_modules/node-fetch": { 291 | "version": "3.3.2", 292 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", 293 | "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", 294 | "license": "MIT", 295 | "dependencies": { 296 | "data-uri-to-buffer": "^4.0.0", 297 | "fetch-blob": "^3.1.4", 298 | "formdata-polyfill": "^4.0.10" 299 | }, 300 | "engines": { 301 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 302 | }, 303 | "funding": { 304 | "type": "opencollective", 305 | "url": "https://opencollective.com/node-fetch" 306 | } 307 | }, 308 | "node_modules/promise-limit": { 309 | "version": "2.7.0", 310 | "resolved": "https://registry.npmjs.org/promise-limit/-/promise-limit-2.7.0.tgz", 311 | "integrity": "sha512-7nJ6v5lnJsXwGprnGXga4wx6d1POjvi5Qmf1ivTRxTjH4Z/9Czja/UCMLVmB9N93GeWOU93XaFaEt6jbuoagNw==", 312 | "license": "ISC" 313 | }, 314 | "node_modules/undici-types": { 315 | "version": "6.19.8", 316 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", 317 | "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", 318 | "license": "MIT" 319 | }, 320 | "node_modules/web-streams-polyfill": { 321 | "version": "3.3.3", 322 | "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", 323 | "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", 324 | "license": "MIT", 325 | "engines": { 326 | "node": ">= 8" 327 | } 328 | }, 329 | "node_modules/ws": { 330 | "version": "8.18.0", 331 | "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", 332 | "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", 333 | "license": "MIT", 334 | "engines": { 335 | "node": ">=10.0.0" 336 | }, 337 | "peerDependencies": { 338 | "bufferutil": "^4.0.1", 339 | "utf-8-validate": ">=5.0.2" 340 | }, 341 | "peerDependenciesMeta": { 342 | "bufferutil": { 343 | "optional": true 344 | }, 345 | "utf-8-validate": { 346 | "optional": true 347 | } 348 | } 349 | } 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /examples/local/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "main": "index.mjs", 5 | "author": "Giovanni Benussi", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@libsql/client": "^0.14.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/memory/.gitignore: -------------------------------------------------------------------------------- 1 | local.db 2 | -------------------------------------------------------------------------------- /examples/memory/README.md: -------------------------------------------------------------------------------- 1 | # Memory 2 | 3 | This example demonstrates how to use libsql with an in-memory SQLite database. 4 | 5 | ## Install Dependencies 6 | 7 | ```bash 8 | npm i 9 | ``` 10 | 11 | ## Running 12 | 13 | Execute the example: 14 | 15 | ```bash 16 | node index.mjs 17 | ``` 18 | 19 | This will create an in-memory SQLite database, insert some data, and then query the results. 20 | -------------------------------------------------------------------------------- /examples/memory/index.mjs: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | 3 | const client = createClient({ 4 | url: ":memory:", 5 | }); 6 | 7 | await client.batch( 8 | [ 9 | "CREATE TABLE users (email TEXT)", 10 | "INSERT INTO users VALUES ('first@example.com')", 11 | "INSERT INTO users VALUES ('second@example.com')", 12 | "INSERT INTO users VALUES ('third@example.com')", 13 | ], 14 | "write", 15 | ); 16 | 17 | const result = await client.execute("SELECT * FROM users"); 18 | 19 | console.log("Users:", result.rows); 20 | -------------------------------------------------------------------------------- /examples/memory/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "batch", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@libsql/client": "^0.14.0" 13 | } 14 | }, 15 | "node_modules/@libsql/client": { 16 | "version": "0.14.0", 17 | "resolved": "https://registry.npmjs.org/@libsql/client/-/client-0.14.0.tgz", 18 | "integrity": "sha512-/9HEKfn6fwXB5aTEEoMeFh4CtG0ZzbncBb1e++OCdVpgKZ/xyMsIVYXm0w7Pv4RUel803vE6LwniB3PqD72R0Q==", 19 | "license": "MIT", 20 | "dependencies": { 21 | "@libsql/core": "^0.14.0", 22 | "@libsql/hrana-client": "^0.7.0", 23 | "js-base64": "^3.7.5", 24 | "libsql": "^0.4.4", 25 | "promise-limit": "^2.7.0" 26 | } 27 | }, 28 | "node_modules/@libsql/core": { 29 | "version": "0.14.0", 30 | "resolved": "https://registry.npmjs.org/@libsql/core/-/core-0.14.0.tgz", 31 | "integrity": "sha512-nhbuXf7GP3PSZgdCY2Ecj8vz187ptHlZQ0VRc751oB2C1W8jQUXKKklvt7t1LJiUTQBVJuadF628eUk+3cRi4Q==", 32 | "license": "MIT", 33 | "dependencies": { 34 | "js-base64": "^3.7.5" 35 | } 36 | }, 37 | "node_modules/@libsql/darwin-arm64": { 38 | "version": "0.4.6", 39 | "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.4.6.tgz", 40 | "integrity": "sha512-45i604CJ2Lubbg7NqtDodjarF6VgST8rS5R8xB++MoRqixtDns9PZ6tocT9pRJDWuTWEiy2sjthPOFWMKwYAsg==", 41 | "cpu": [ 42 | "arm64" 43 | ], 44 | "license": "MIT", 45 | "optional": true, 46 | "os": [ 47 | "darwin" 48 | ] 49 | }, 50 | "node_modules/@libsql/darwin-x64": { 51 | "version": "0.4.6", 52 | "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.4.6.tgz", 53 | "integrity": "sha512-dRKliflhfr5zOPSNgNJ6C2nZDd4YA8bTXF3MUNqNkcxQ8BffaH9uUwL9kMq89LkFIZQHcyP75bBgZctxfJ/H5Q==", 54 | "cpu": [ 55 | "x64" 56 | ], 57 | "license": "MIT", 58 | "optional": true, 59 | "os": [ 60 | "darwin" 61 | ] 62 | }, 63 | "node_modules/@libsql/hrana-client": { 64 | "version": "0.7.0", 65 | "resolved": "https://registry.npmjs.org/@libsql/hrana-client/-/hrana-client-0.7.0.tgz", 66 | "integrity": "sha512-OF8fFQSkbL7vJY9rfuegK1R7sPgQ6kFMkDamiEccNUvieQ+3urzfDFI616oPl8V7T9zRmnTkSjMOImYCAVRVuw==", 67 | "license": "MIT", 68 | "dependencies": { 69 | "@libsql/isomorphic-fetch": "^0.3.1", 70 | "@libsql/isomorphic-ws": "^0.1.5", 71 | "js-base64": "^3.7.5", 72 | "node-fetch": "^3.3.2" 73 | } 74 | }, 75 | "node_modules/@libsql/isomorphic-fetch": { 76 | "version": "0.3.1", 77 | "resolved": "https://registry.npmjs.org/@libsql/isomorphic-fetch/-/isomorphic-fetch-0.3.1.tgz", 78 | "integrity": "sha512-6kK3SUK5Uu56zPq/Las620n5aS9xJq+jMBcNSOmjhNf/MUvdyji4vrMTqD7ptY7/4/CAVEAYDeotUz60LNQHtw==", 79 | "license": "MIT", 80 | "engines": { 81 | "node": ">=18.0.0" 82 | } 83 | }, 84 | "node_modules/@libsql/isomorphic-ws": { 85 | "version": "0.1.5", 86 | "resolved": "https://registry.npmjs.org/@libsql/isomorphic-ws/-/isomorphic-ws-0.1.5.tgz", 87 | "integrity": "sha512-DtLWIH29onUYR00i0GlQ3UdcTRC6EP4u9w/h9LxpUZJWRMARk6dQwZ6Jkd+QdwVpuAOrdxt18v0K2uIYR3fwFg==", 88 | "license": "MIT", 89 | "dependencies": { 90 | "@types/ws": "^8.5.4", 91 | "ws": "^8.13.0" 92 | } 93 | }, 94 | "node_modules/@libsql/linux-arm64-gnu": { 95 | "version": "0.4.6", 96 | "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.4.6.tgz", 97 | "integrity": "sha512-DMPavVyY6vYPAYcQR1iOotHszg+5xSjHSg6F9kNecPX0KKdGq84zuPJmORfKOPtaWvzPewNFdML/e+s1fu09XQ==", 98 | "cpu": [ 99 | "arm64" 100 | ], 101 | "license": "MIT", 102 | "optional": true, 103 | "os": [ 104 | "linux" 105 | ] 106 | }, 107 | "node_modules/@libsql/linux-arm64-musl": { 108 | "version": "0.4.6", 109 | "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.4.6.tgz", 110 | "integrity": "sha512-whuHSYAZyclGjM3L0mKGXyWqdAy7qYvPPn+J1ve7FtGkFlM0DiIPjA5K30aWSGJSRh72sD9DBZfnu8CpfSjT6w==", 111 | "cpu": [ 112 | "arm64" 113 | ], 114 | "license": "MIT", 115 | "optional": true, 116 | "os": [ 117 | "linux" 118 | ] 119 | }, 120 | "node_modules/@libsql/linux-x64-gnu": { 121 | "version": "0.4.6", 122 | "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.4.6.tgz", 123 | "integrity": "sha512-0ggx+5RwEbYabIlDBBAvavdfIJCZ757u6nDZtBeQIhzW99EKbWG3lvkXHM3qudFb/pDWSUY4RFBm6vVtF1cJGA==", 124 | "cpu": [ 125 | "x64" 126 | ], 127 | "license": "MIT", 128 | "optional": true, 129 | "os": [ 130 | "linux" 131 | ] 132 | }, 133 | "node_modules/@libsql/linux-x64-musl": { 134 | "version": "0.4.6", 135 | "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.4.6.tgz", 136 | "integrity": "sha512-SWNrv7Hz72QWlbM/ZsbL35MPopZavqCUmQz2HNDZ55t0F+kt8pXuP+bbI2KvmaQ7wdsoqAA4qBmjol0+bh4ndw==", 137 | "cpu": [ 138 | "x64" 139 | ], 140 | "license": "MIT", 141 | "optional": true, 142 | "os": [ 143 | "linux" 144 | ] 145 | }, 146 | "node_modules/@libsql/win32-x64-msvc": { 147 | "version": "0.4.6", 148 | "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.4.6.tgz", 149 | "integrity": "sha512-Q0axn110zDNELfkEog3Nl8p9BU4eI/UvgaHevGyOiSDN7s0KPfj0j6jwVHk4oz3o/d/Gg3DRIxomZ4ftfTOy/g==", 150 | "cpu": [ 151 | "x64" 152 | ], 153 | "license": "MIT", 154 | "optional": true, 155 | "os": [ 156 | "win32" 157 | ] 158 | }, 159 | "node_modules/@neon-rs/load": { 160 | "version": "0.0.4", 161 | "resolved": "https://registry.npmjs.org/@neon-rs/load/-/load-0.0.4.tgz", 162 | "integrity": "sha512-kTPhdZyTQxB+2wpiRcFWrDcejc4JI6tkPuS7UZCG4l6Zvc5kU/gGQ/ozvHTh1XR5tS+UlfAfGuPajjzQjCiHCw==", 163 | "license": "MIT" 164 | }, 165 | "node_modules/@types/node": { 166 | "version": "22.7.5", 167 | "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz", 168 | "integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==", 169 | "license": "MIT", 170 | "dependencies": { 171 | "undici-types": "~6.19.2" 172 | } 173 | }, 174 | "node_modules/@types/ws": { 175 | "version": "8.5.12", 176 | "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.12.tgz", 177 | "integrity": "sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==", 178 | "license": "MIT", 179 | "dependencies": { 180 | "@types/node": "*" 181 | } 182 | }, 183 | "node_modules/data-uri-to-buffer": { 184 | "version": "4.0.1", 185 | "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", 186 | "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", 187 | "license": "MIT", 188 | "engines": { 189 | "node": ">= 12" 190 | } 191 | }, 192 | "node_modules/detect-libc": { 193 | "version": "2.0.2", 194 | "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", 195 | "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==", 196 | "license": "Apache-2.0", 197 | "engines": { 198 | "node": ">=8" 199 | } 200 | }, 201 | "node_modules/fetch-blob": { 202 | "version": "3.2.0", 203 | "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", 204 | "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", 205 | "funding": [ 206 | { 207 | "type": "github", 208 | "url": "https://github.com/sponsors/jimmywarting" 209 | }, 210 | { 211 | "type": "paypal", 212 | "url": "https://paypal.me/jimmywarting" 213 | } 214 | ], 215 | "license": "MIT", 216 | "dependencies": { 217 | "node-domexception": "^1.0.0", 218 | "web-streams-polyfill": "^3.0.3" 219 | }, 220 | "engines": { 221 | "node": "^12.20 || >= 14.13" 222 | } 223 | }, 224 | "node_modules/formdata-polyfill": { 225 | "version": "4.0.10", 226 | "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", 227 | "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", 228 | "license": "MIT", 229 | "dependencies": { 230 | "fetch-blob": "^3.1.2" 231 | }, 232 | "engines": { 233 | "node": ">=12.20.0" 234 | } 235 | }, 236 | "node_modules/js-base64": { 237 | "version": "3.7.7", 238 | "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.7.tgz", 239 | "integrity": "sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==", 240 | "license": "BSD-3-Clause" 241 | }, 242 | "node_modules/libsql": { 243 | "version": "0.4.6", 244 | "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.4.6.tgz", 245 | "integrity": "sha512-F5M+ltteK6dCcpjMahrkgT96uFJvVI8aQ4r9f2AzHQjC7BkAYtvfMSTWGvRBezRgMUIU2h1Sy0pF9nOGOD5iyA==", 246 | "cpu": [ 247 | "x64", 248 | "arm64", 249 | "wasm32" 250 | ], 251 | "license": "MIT", 252 | "os": [ 253 | "darwin", 254 | "linux", 255 | "win32" 256 | ], 257 | "dependencies": { 258 | "@neon-rs/load": "^0.0.4", 259 | "detect-libc": "2.0.2" 260 | }, 261 | "optionalDependencies": { 262 | "@libsql/darwin-arm64": "0.4.6", 263 | "@libsql/darwin-x64": "0.4.6", 264 | "@libsql/linux-arm64-gnu": "0.4.6", 265 | "@libsql/linux-arm64-musl": "0.4.6", 266 | "@libsql/linux-x64-gnu": "0.4.6", 267 | "@libsql/linux-x64-musl": "0.4.6", 268 | "@libsql/win32-x64-msvc": "0.4.6" 269 | } 270 | }, 271 | "node_modules/node-domexception": { 272 | "version": "1.0.0", 273 | "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", 274 | "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", 275 | "funding": [ 276 | { 277 | "type": "github", 278 | "url": "https://github.com/sponsors/jimmywarting" 279 | }, 280 | { 281 | "type": "github", 282 | "url": "https://paypal.me/jimmywarting" 283 | } 284 | ], 285 | "license": "MIT", 286 | "engines": { 287 | "node": ">=10.5.0" 288 | } 289 | }, 290 | "node_modules/node-fetch": { 291 | "version": "3.3.2", 292 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", 293 | "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", 294 | "license": "MIT", 295 | "dependencies": { 296 | "data-uri-to-buffer": "^4.0.0", 297 | "fetch-blob": "^3.1.4", 298 | "formdata-polyfill": "^4.0.10" 299 | }, 300 | "engines": { 301 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 302 | }, 303 | "funding": { 304 | "type": "opencollective", 305 | "url": "https://opencollective.com/node-fetch" 306 | } 307 | }, 308 | "node_modules/promise-limit": { 309 | "version": "2.7.0", 310 | "resolved": "https://registry.npmjs.org/promise-limit/-/promise-limit-2.7.0.tgz", 311 | "integrity": "sha512-7nJ6v5lnJsXwGprnGXga4wx6d1POjvi5Qmf1ivTRxTjH4Z/9Czja/UCMLVmB9N93GeWOU93XaFaEt6jbuoagNw==", 312 | "license": "ISC" 313 | }, 314 | "node_modules/undici-types": { 315 | "version": "6.19.8", 316 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", 317 | "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", 318 | "license": "MIT" 319 | }, 320 | "node_modules/web-streams-polyfill": { 321 | "version": "3.3.3", 322 | "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", 323 | "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", 324 | "license": "MIT", 325 | "engines": { 326 | "node": ">= 8" 327 | } 328 | }, 329 | "node_modules/ws": { 330 | "version": "8.18.0", 331 | "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", 332 | "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", 333 | "license": "MIT", 334 | "engines": { 335 | "node": ">=10.0.0" 336 | }, 337 | "peerDependencies": { 338 | "bufferutil": "^4.0.1", 339 | "utf-8-validate": ">=5.0.2" 340 | }, 341 | "peerDependenciesMeta": { 342 | "bufferutil": { 343 | "optional": true 344 | }, 345 | "utf-8-validate": { 346 | "optional": true 347 | } 348 | } 349 | } 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /examples/memory/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "main": "index.mjs", 5 | "author": "Giovanni Benussi", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@libsql/client": "^0.14.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/ollama/.gitignore: -------------------------------------------------------------------------------- 1 | local.db 2 | -------------------------------------------------------------------------------- /examples/ollama/README.md: -------------------------------------------------------------------------------- 1 | # Ollama + Vector Search Example 2 | 3 | This example demonstrates how to use libSQL vector search with a local database and Ollama. 4 | 5 | ## Install Dependencies 6 | 7 | ```bash 8 | npm i 9 | ``` 10 | 11 | ## Install Ollama 12 | 13 | [Download Ollama](https://ollama.com/download) and install it. 14 | 15 | ## Running 16 | 17 | Make sure Ollama is running with the model `mistral`: 18 | 19 | ```bash 20 | ollama run mistral 21 | ``` 22 | 23 | Execute the example: 24 | 25 | ```bash 26 | node index.mjs 27 | ``` 28 | 29 | This will setup a local SQLite database, generate embeddings using Ollama, and insert the data with embeddings, and then query the results using the vector similarity search function. 30 | -------------------------------------------------------------------------------- /examples/ollama/index.mjs: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | import ollama from "ollama"; 3 | 4 | const client = createClient({ 5 | url: "file:local.db", 6 | }); 7 | 8 | await client.batch( 9 | [ 10 | "CREATE TABLE IF NOT EXISTS movies (id INTEGER PRIMARY KEY, title TEXT NOT NULL, description TEXT NOT NULL, embedding F32_BLOB(4096))", 11 | "CREATE INDEX IF NOT EXISTS movies_embedding_idx ON movies(libsql_vector_idx(embedding))", 12 | ], 13 | "write", 14 | ); 15 | 16 | async function getEmbedding(prompt) { 17 | const response = await ollama.embeddings({ 18 | model: "mistral", 19 | prompt, 20 | }); 21 | 22 | return response.embedding; 23 | } 24 | 25 | async function insertMovie(id, title, description) { 26 | const embedding = await getEmbedding(description); 27 | 28 | await client.execute({ 29 | sql: `INSERT OR REPLACE INTO movies (id, title, description, embedding) VALUES (?, ?, ?, vector(?))`, 30 | args: [id, title, description, JSON.stringify(embedding)], 31 | }); 32 | } 33 | 34 | async function insertMovieIfNotExists(id, title, description) { 35 | const existing = await client.execute({ 36 | sql: "SELECT id FROM movies WHERE id = ?", 37 | args: [id], 38 | }); 39 | 40 | if (existing.rows.length === 0) { 41 | await insertMovie(id, title, description); 42 | console.log(`Inserted: ${title} (ID: ${id})`); 43 | } else { 44 | console.log(`Movie already exists: ${title} (ID: ${id})`); 45 | } 46 | } 47 | 48 | async function findSimilarMovies(description, limit = 3) { 49 | const queryEmbedding = await getEmbedding(description); 50 | 51 | const results = await client.execute({ 52 | sql: ` 53 | WITH vector_scores AS ( 54 | SELECT DISTINCT 55 | id, 56 | title, 57 | description, 58 | 1 - vector_distance_cos(embedding, vector32(?)) AS similarity 59 | FROM movies 60 | ORDER BY similarity DESC 61 | LIMIT ? 62 | ) 63 | SELECT id, title, description, similarity FROM vector_scores 64 | `, 65 | args: [JSON.stringify(queryEmbedding), limit], 66 | }); 67 | 68 | return results.rows; 69 | } 70 | 71 | try { 72 | const sampleMovies = [ 73 | { 74 | id: 1, 75 | title: "Inception", 76 | description: 77 | "A thief who enters the dreams of others to steal secrets from their subconscious.", 78 | }, 79 | { 80 | id: 2, 81 | title: "The Matrix", 82 | description: 83 | "A computer programmer discovers that reality as he knows it is a simulation created by machines.", 84 | }, 85 | { 86 | id: 3, 87 | title: "Interstellar", 88 | description: 89 | "Astronauts travel through a wormhole in search of a new habitable planet for humanity.", 90 | }, 91 | ]; 92 | 93 | for (const movie of sampleMovies) { 94 | await insertMovieIfNotExists(movie.id, movie.title, movie.description); 95 | } 96 | 97 | const query = 98 | "A sci-fi movie about virtual reality and artificial intelligence"; 99 | console.log("\nSearching for movies similar to:", query); 100 | 101 | const similarMovies = await findSimilarMovies(query); 102 | console.log("\nSimilar movies found:"); 103 | similarMovies.forEach((movie) => { 104 | console.log(`\nTitle: ${movie.title}`); 105 | console.log(`Description: ${movie.description}`); 106 | console.log(`Similarity: ${movie.similarity.toFixed(4)}`); 107 | }); 108 | } catch (error) { 109 | console.error("Error:", error); 110 | } 111 | -------------------------------------------------------------------------------- /examples/ollama/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ollama", 3 | "private": true, 4 | "main": "index.mjs", 5 | "dependencies": { 6 | "@libsql/client": "^0.14.0", 7 | "ollama": "^0.5.11" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/read-your-writes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "read-your-writes", 3 | "version": "1.0.0", 4 | "main": "index.mjs", 5 | "author": "Levy Albuquerque", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@libsql/client": "^0.14.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/read-your-writes/read_your_writes.js: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | 3 | const client = createClient({ 4 | url: "file:local.db", 5 | syncUrl: process.env.TURSO_DATABASE_URL, 6 | authToken: process.env.TURSO_AUTH_TOKEN, 7 | readYourWrites: false, 8 | }); 9 | 10 | await client.execute("DROP TABLE users"); 11 | await client.execute("CREATE TABLE IF NOT EXISTS users (email TEXT)"); 12 | await client.sync(); 13 | 14 | await client.execute("INSERT INTO users VALUES ('first@example.com')"); 15 | await client.execute("INSERT INTO users VALUES ('second@example.com')"); 16 | await client.execute("INSERT INTO users VALUES ('third@example.com')"); 17 | 18 | { 19 | // No users, sinc no sync has happend since inserts 20 | const result = await client.execute("SELECT * FROM users"); 21 | 22 | console.log("Users:", result.rows); 23 | } 24 | 25 | { 26 | await client.sync(); 27 | 28 | // No users, sinc no sync has happend since inserts 29 | const result = await client.execute("SELECT * FROM users"); 30 | 31 | console.log("Users:", result.rows); 32 | } 33 | -------------------------------------------------------------------------------- /examples/remote/.gitignore: -------------------------------------------------------------------------------- 1 | local.db 2 | -------------------------------------------------------------------------------- /examples/remote/README.md: -------------------------------------------------------------------------------- 1 | # Remote 2 | 3 | This example demonstrates how to use libSQL with a remote database. 4 | 5 | ## Install Dependencies 6 | 7 | ```bash 8 | npm i 9 | ``` 10 | 11 | ## Running 12 | 13 | Execute the example: 14 | 15 | ```bash 16 | TURSO_DATABASE_URL="..." TURSO_AUTH_TOKEN="..." node index.mjs 17 | ``` 18 | 19 | This will connect to a remote SQLite database, insert some data, and then query the results. 20 | -------------------------------------------------------------------------------- /examples/remote/index.mjs: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | 3 | const client = createClient({ 4 | url: process.env.TURSO_DATABASE_URL, 5 | authToken: process.env.TURSO_AUTH_TOKEN, 6 | }); 7 | 8 | await client.batch( 9 | [ 10 | "CREATE TABLE IF NOT EXISTS users (email TEXT)", 11 | "INSERT INTO users VALUES ('first@example.com')", 12 | "INSERT INTO users VALUES ('second@example.com')", 13 | "INSERT INTO users VALUES ('third@example.com')", 14 | ], 15 | "write", 16 | ); 17 | 18 | const result = await client.execute("SELECT * FROM users"); 19 | 20 | console.log("Users:", result.rows); 21 | -------------------------------------------------------------------------------- /examples/remote/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "main": "index.mjs", 5 | "author": "Giovanni Benussi", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@libsql/client": "^0.14.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/sync/.gitignore: -------------------------------------------------------------------------------- 1 | local.db 2 | local.db-client_wal_index 3 | -------------------------------------------------------------------------------- /examples/sync/README.md: -------------------------------------------------------------------------------- 1 | # Sync 2 | 3 | This example demonstrates how to use libSQL with a synced database (local file synced with a remote database). 4 | 5 | ## Install Dependencies 6 | 7 | ```bash 8 | npm i 9 | ``` 10 | 11 | ## Running 12 | 13 | Execute the example: 14 | 15 | ```bash 16 | TURSO_DATABASE_URL="..." TURSO_AUTH_TOKEN="..." node index.mjs 17 | ``` 18 | 19 | This will connect to a remote SQLite database, insert some data, and then query the results. 20 | -------------------------------------------------------------------------------- /examples/sync/index.mjs: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | 3 | const client = createClient({ 4 | url: "file:local.db", 5 | syncUrl: process.env.TURSO_DATABASE_URL, 6 | authToken: process.env.TURSO_AUTH_TOKEN, 7 | }); 8 | 9 | await client.batch( 10 | [ 11 | "CREATE TABLE IF NOT EXISTS users (email TEXT)", 12 | "INSERT INTO users VALUES ('first@example.com')", 13 | "INSERT INTO users VALUES ('second@example.com')", 14 | "INSERT INTO users VALUES ('third@example.com')", 15 | ], 16 | "write", 17 | ); 18 | 19 | const result = await client.execute("SELECT * FROM users"); 20 | 21 | console.log("Users:", result.rows); 22 | -------------------------------------------------------------------------------- /examples/sync/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "batch", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@libsql/client": "^0.14.0" 13 | } 14 | }, 15 | "node_modules/@libsql/client": { 16 | "version": "0.14.0", 17 | "resolved": "https://registry.npmjs.org/@libsql/client/-/client-0.14.0.tgz", 18 | "integrity": "sha512-/9HEKfn6fwXB5aTEEoMeFh4CtG0ZzbncBb1e++OCdVpgKZ/xyMsIVYXm0w7Pv4RUel803vE6LwniB3PqD72R0Q==", 19 | "license": "MIT", 20 | "dependencies": { 21 | "@libsql/core": "^0.14.0", 22 | "@libsql/hrana-client": "^0.7.0", 23 | "js-base64": "^3.7.5", 24 | "libsql": "^0.4.4", 25 | "promise-limit": "^2.7.0" 26 | } 27 | }, 28 | "node_modules/@libsql/core": { 29 | "version": "0.14.0", 30 | "resolved": "https://registry.npmjs.org/@libsql/core/-/core-0.14.0.tgz", 31 | "integrity": "sha512-nhbuXf7GP3PSZgdCY2Ecj8vz187ptHlZQ0VRc751oB2C1W8jQUXKKklvt7t1LJiUTQBVJuadF628eUk+3cRi4Q==", 32 | "license": "MIT", 33 | "dependencies": { 34 | "js-base64": "^3.7.5" 35 | } 36 | }, 37 | "node_modules/@libsql/darwin-arm64": { 38 | "version": "0.4.6", 39 | "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.4.6.tgz", 40 | "integrity": "sha512-45i604CJ2Lubbg7NqtDodjarF6VgST8rS5R8xB++MoRqixtDns9PZ6tocT9pRJDWuTWEiy2sjthPOFWMKwYAsg==", 41 | "cpu": [ 42 | "arm64" 43 | ], 44 | "license": "MIT", 45 | "optional": true, 46 | "os": [ 47 | "darwin" 48 | ] 49 | }, 50 | "node_modules/@libsql/darwin-x64": { 51 | "version": "0.4.6", 52 | "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.4.6.tgz", 53 | "integrity": "sha512-dRKliflhfr5zOPSNgNJ6C2nZDd4YA8bTXF3MUNqNkcxQ8BffaH9uUwL9kMq89LkFIZQHcyP75bBgZctxfJ/H5Q==", 54 | "cpu": [ 55 | "x64" 56 | ], 57 | "license": "MIT", 58 | "optional": true, 59 | "os": [ 60 | "darwin" 61 | ] 62 | }, 63 | "node_modules/@libsql/hrana-client": { 64 | "version": "0.7.0", 65 | "resolved": "https://registry.npmjs.org/@libsql/hrana-client/-/hrana-client-0.7.0.tgz", 66 | "integrity": "sha512-OF8fFQSkbL7vJY9rfuegK1R7sPgQ6kFMkDamiEccNUvieQ+3urzfDFI616oPl8V7T9zRmnTkSjMOImYCAVRVuw==", 67 | "license": "MIT", 68 | "dependencies": { 69 | "@libsql/isomorphic-fetch": "^0.3.1", 70 | "@libsql/isomorphic-ws": "^0.1.5", 71 | "js-base64": "^3.7.5", 72 | "node-fetch": "^3.3.2" 73 | } 74 | }, 75 | "node_modules/@libsql/isomorphic-fetch": { 76 | "version": "0.3.1", 77 | "resolved": "https://registry.npmjs.org/@libsql/isomorphic-fetch/-/isomorphic-fetch-0.3.1.tgz", 78 | "integrity": "sha512-6kK3SUK5Uu56zPq/Las620n5aS9xJq+jMBcNSOmjhNf/MUvdyji4vrMTqD7ptY7/4/CAVEAYDeotUz60LNQHtw==", 79 | "license": "MIT", 80 | "engines": { 81 | "node": ">=18.0.0" 82 | } 83 | }, 84 | "node_modules/@libsql/isomorphic-ws": { 85 | "version": "0.1.5", 86 | "resolved": "https://registry.npmjs.org/@libsql/isomorphic-ws/-/isomorphic-ws-0.1.5.tgz", 87 | "integrity": "sha512-DtLWIH29onUYR00i0GlQ3UdcTRC6EP4u9w/h9LxpUZJWRMARk6dQwZ6Jkd+QdwVpuAOrdxt18v0K2uIYR3fwFg==", 88 | "license": "MIT", 89 | "dependencies": { 90 | "@types/ws": "^8.5.4", 91 | "ws": "^8.13.0" 92 | } 93 | }, 94 | "node_modules/@libsql/linux-arm64-gnu": { 95 | "version": "0.4.6", 96 | "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.4.6.tgz", 97 | "integrity": "sha512-DMPavVyY6vYPAYcQR1iOotHszg+5xSjHSg6F9kNecPX0KKdGq84zuPJmORfKOPtaWvzPewNFdML/e+s1fu09XQ==", 98 | "cpu": [ 99 | "arm64" 100 | ], 101 | "license": "MIT", 102 | "optional": true, 103 | "os": [ 104 | "linux" 105 | ] 106 | }, 107 | "node_modules/@libsql/linux-arm64-musl": { 108 | "version": "0.4.6", 109 | "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.4.6.tgz", 110 | "integrity": "sha512-whuHSYAZyclGjM3L0mKGXyWqdAy7qYvPPn+J1ve7FtGkFlM0DiIPjA5K30aWSGJSRh72sD9DBZfnu8CpfSjT6w==", 111 | "cpu": [ 112 | "arm64" 113 | ], 114 | "license": "MIT", 115 | "optional": true, 116 | "os": [ 117 | "linux" 118 | ] 119 | }, 120 | "node_modules/@libsql/linux-x64-gnu": { 121 | "version": "0.4.6", 122 | "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.4.6.tgz", 123 | "integrity": "sha512-0ggx+5RwEbYabIlDBBAvavdfIJCZ757u6nDZtBeQIhzW99EKbWG3lvkXHM3qudFb/pDWSUY4RFBm6vVtF1cJGA==", 124 | "cpu": [ 125 | "x64" 126 | ], 127 | "license": "MIT", 128 | "optional": true, 129 | "os": [ 130 | "linux" 131 | ] 132 | }, 133 | "node_modules/@libsql/linux-x64-musl": { 134 | "version": "0.4.6", 135 | "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.4.6.tgz", 136 | "integrity": "sha512-SWNrv7Hz72QWlbM/ZsbL35MPopZavqCUmQz2HNDZ55t0F+kt8pXuP+bbI2KvmaQ7wdsoqAA4qBmjol0+bh4ndw==", 137 | "cpu": [ 138 | "x64" 139 | ], 140 | "license": "MIT", 141 | "optional": true, 142 | "os": [ 143 | "linux" 144 | ] 145 | }, 146 | "node_modules/@libsql/win32-x64-msvc": { 147 | "version": "0.4.6", 148 | "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.4.6.tgz", 149 | "integrity": "sha512-Q0axn110zDNELfkEog3Nl8p9BU4eI/UvgaHevGyOiSDN7s0KPfj0j6jwVHk4oz3o/d/Gg3DRIxomZ4ftfTOy/g==", 150 | "cpu": [ 151 | "x64" 152 | ], 153 | "license": "MIT", 154 | "optional": true, 155 | "os": [ 156 | "win32" 157 | ] 158 | }, 159 | "node_modules/@neon-rs/load": { 160 | "version": "0.0.4", 161 | "resolved": "https://registry.npmjs.org/@neon-rs/load/-/load-0.0.4.tgz", 162 | "integrity": "sha512-kTPhdZyTQxB+2wpiRcFWrDcejc4JI6tkPuS7UZCG4l6Zvc5kU/gGQ/ozvHTh1XR5tS+UlfAfGuPajjzQjCiHCw==", 163 | "license": "MIT" 164 | }, 165 | "node_modules/@types/node": { 166 | "version": "22.7.5", 167 | "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz", 168 | "integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==", 169 | "license": "MIT", 170 | "dependencies": { 171 | "undici-types": "~6.19.2" 172 | } 173 | }, 174 | "node_modules/@types/ws": { 175 | "version": "8.5.12", 176 | "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.12.tgz", 177 | "integrity": "sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==", 178 | "license": "MIT", 179 | "dependencies": { 180 | "@types/node": "*" 181 | } 182 | }, 183 | "node_modules/data-uri-to-buffer": { 184 | "version": "4.0.1", 185 | "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", 186 | "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", 187 | "license": "MIT", 188 | "engines": { 189 | "node": ">= 12" 190 | } 191 | }, 192 | "node_modules/detect-libc": { 193 | "version": "2.0.2", 194 | "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", 195 | "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==", 196 | "license": "Apache-2.0", 197 | "engines": { 198 | "node": ">=8" 199 | } 200 | }, 201 | "node_modules/fetch-blob": { 202 | "version": "3.2.0", 203 | "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", 204 | "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", 205 | "funding": [ 206 | { 207 | "type": "github", 208 | "url": "https://github.com/sponsors/jimmywarting" 209 | }, 210 | { 211 | "type": "paypal", 212 | "url": "https://paypal.me/jimmywarting" 213 | } 214 | ], 215 | "license": "MIT", 216 | "dependencies": { 217 | "node-domexception": "^1.0.0", 218 | "web-streams-polyfill": "^3.0.3" 219 | }, 220 | "engines": { 221 | "node": "^12.20 || >= 14.13" 222 | } 223 | }, 224 | "node_modules/formdata-polyfill": { 225 | "version": "4.0.10", 226 | "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", 227 | "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", 228 | "license": "MIT", 229 | "dependencies": { 230 | "fetch-blob": "^3.1.2" 231 | }, 232 | "engines": { 233 | "node": ">=12.20.0" 234 | } 235 | }, 236 | "node_modules/js-base64": { 237 | "version": "3.7.7", 238 | "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.7.tgz", 239 | "integrity": "sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==", 240 | "license": "BSD-3-Clause" 241 | }, 242 | "node_modules/libsql": { 243 | "version": "0.4.6", 244 | "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.4.6.tgz", 245 | "integrity": "sha512-F5M+ltteK6dCcpjMahrkgT96uFJvVI8aQ4r9f2AzHQjC7BkAYtvfMSTWGvRBezRgMUIU2h1Sy0pF9nOGOD5iyA==", 246 | "cpu": [ 247 | "x64", 248 | "arm64", 249 | "wasm32" 250 | ], 251 | "license": "MIT", 252 | "os": [ 253 | "darwin", 254 | "linux", 255 | "win32" 256 | ], 257 | "dependencies": { 258 | "@neon-rs/load": "^0.0.4", 259 | "detect-libc": "2.0.2" 260 | }, 261 | "optionalDependencies": { 262 | "@libsql/darwin-arm64": "0.4.6", 263 | "@libsql/darwin-x64": "0.4.6", 264 | "@libsql/linux-arm64-gnu": "0.4.6", 265 | "@libsql/linux-arm64-musl": "0.4.6", 266 | "@libsql/linux-x64-gnu": "0.4.6", 267 | "@libsql/linux-x64-musl": "0.4.6", 268 | "@libsql/win32-x64-msvc": "0.4.6" 269 | } 270 | }, 271 | "node_modules/node-domexception": { 272 | "version": "1.0.0", 273 | "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", 274 | "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", 275 | "funding": [ 276 | { 277 | "type": "github", 278 | "url": "https://github.com/sponsors/jimmywarting" 279 | }, 280 | { 281 | "type": "github", 282 | "url": "https://paypal.me/jimmywarting" 283 | } 284 | ], 285 | "license": "MIT", 286 | "engines": { 287 | "node": ">=10.5.0" 288 | } 289 | }, 290 | "node_modules/node-fetch": { 291 | "version": "3.3.2", 292 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", 293 | "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", 294 | "license": "MIT", 295 | "dependencies": { 296 | "data-uri-to-buffer": "^4.0.0", 297 | "fetch-blob": "^3.1.4", 298 | "formdata-polyfill": "^4.0.10" 299 | }, 300 | "engines": { 301 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 302 | }, 303 | "funding": { 304 | "type": "opencollective", 305 | "url": "https://opencollective.com/node-fetch" 306 | } 307 | }, 308 | "node_modules/promise-limit": { 309 | "version": "2.7.0", 310 | "resolved": "https://registry.npmjs.org/promise-limit/-/promise-limit-2.7.0.tgz", 311 | "integrity": "sha512-7nJ6v5lnJsXwGprnGXga4wx6d1POjvi5Qmf1ivTRxTjH4Z/9Czja/UCMLVmB9N93GeWOU93XaFaEt6jbuoagNw==", 312 | "license": "ISC" 313 | }, 314 | "node_modules/undici-types": { 315 | "version": "6.19.8", 316 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", 317 | "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", 318 | "license": "MIT" 319 | }, 320 | "node_modules/web-streams-polyfill": { 321 | "version": "3.3.3", 322 | "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", 323 | "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", 324 | "license": "MIT", 325 | "engines": { 326 | "node": ">= 8" 327 | } 328 | }, 329 | "node_modules/ws": { 330 | "version": "8.18.0", 331 | "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", 332 | "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", 333 | "license": "MIT", 334 | "engines": { 335 | "node": ">=10.0.0" 336 | }, 337 | "peerDependencies": { 338 | "bufferutil": "^4.0.1", 339 | "utf-8-validate": ">=5.0.2" 340 | }, 341 | "peerDependenciesMeta": { 342 | "bufferutil": { 343 | "optional": true 344 | }, 345 | "utf-8-validate": { 346 | "optional": true 347 | } 348 | } 349 | } 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /examples/sync/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "main": "index.mjs", 5 | "author": "Giovanni Benussi", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@libsql/client": "^0.14.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/transactions/.gitignore: -------------------------------------------------------------------------------- 1 | local.db 2 | -------------------------------------------------------------------------------- /examples/transactions/README.md: -------------------------------------------------------------------------------- 1 | # Local 2 | 3 | This example demonstrates how to use transactions with libSQL. 4 | 5 | ## Install Dependencies 6 | 7 | ```bash 8 | npm i 9 | ``` 10 | 11 | ## Running 12 | 13 | Execute the example: 14 | 15 | ```bash 16 | node index.mjs 17 | ``` 18 | 19 | This example will: 20 | 21 | 1. Create a new table called `users`. 22 | 2. Start a transaction. 23 | 3. Insert multiple users within the transaction. 24 | 4. Demonstrate how to rollback a transaction. 25 | 5. Start another transaction. 26 | 6. Insert more users and commit the transaction. 27 | 7. Query and display the final state of the `users` table. 28 | -------------------------------------------------------------------------------- /examples/transactions/index.mjs: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | 3 | const client = createClient({ 4 | url: "file:local.db", 5 | }); 6 | 7 | await client.batch( 8 | [ 9 | "DROP TABLE IF EXISTS users", 10 | "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)", 11 | "INSERT INTO users (name) VALUES ('Iku Turso')", 12 | ], 13 | "write", 14 | ); 15 | 16 | const names = ["John Doe", "Mary Smith", "Alice Jones", "Mark Taylor"]; 17 | 18 | let transaction, secondTransaction; 19 | try { 20 | transaction = await client.transaction("write"); 21 | 22 | for (const name of names) { 23 | await transaction.execute({ 24 | sql: "INSERT INTO users (name) VALUES (?)", 25 | args: [name], 26 | }); 27 | } 28 | await transaction.rollback(); 29 | 30 | secondTransaction = await client.transaction("write"); 31 | 32 | for (const name of names) { 33 | await secondTransaction.execute({ 34 | sql: "INSERT INTO users (name) VALUES (?)", 35 | args: [name], 36 | }); 37 | } 38 | 39 | await secondTransaction.commit(); 40 | } catch (e) { 41 | console.error(e); 42 | await transaction?.rollback(); 43 | await secondTransaction?.rollback(); 44 | } 45 | 46 | const result = await client.execute("SELECT * FROM users"); 47 | 48 | console.log("Users:", result.rows); 49 | -------------------------------------------------------------------------------- /examples/transactions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "main": "index.mjs", 5 | "author": "Giovanni Benussi", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@libsql/client": "^0.14.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/vector/.gitignore: -------------------------------------------------------------------------------- 1 | local.db 2 | -------------------------------------------------------------------------------- /examples/vector/README.md: -------------------------------------------------------------------------------- 1 | # Local 2 | 3 | This example demonstrates how to use libSQL vector search with a local database. 4 | 5 | ## Install Dependencies 6 | 7 | ```bash 8 | npm i 9 | ``` 10 | 11 | ## Running 12 | 13 | Execute the example: 14 | 15 | ```bash 16 | node index.mjs 17 | ``` 18 | 19 | This will setup a local SQLite database, insert some data, and then query the results using the vector similarity search function. 20 | -------------------------------------------------------------------------------- /examples/vector/index.mjs: -------------------------------------------------------------------------------- 1 | import { createClient } from "@libsql/client"; 2 | 3 | const client = createClient({ 4 | url: "file:local.db", 5 | }); 6 | 7 | await client.batch( 8 | [ 9 | "DROP TABLE IF EXISTS movies", 10 | "CREATE TABLE IF NOT EXISTS movies (title TEXT, year INT, embedding F32_BLOB(3))", 11 | "CREATE INDEX movies_idx ON movies (libsql_vector_idx(embedding))", 12 | "INSERT INTO movies (title, year, embedding) VALUES ('Napoleon', 2023, vector32('[1,2,3]')), ('Black Hawk Down', 2001, vector32('[10,11,12]')), ('Gladiator', 2000, vector32('[7,8,9]')), ('Blade Runner', 1982, vector32('[4,5,6]'))", 13 | ], 14 | "write", 15 | ); 16 | 17 | const result = await client.execute( 18 | "SELECT title, year FROM vector_top_k('movies_idx', '[4,5,6]', 3) JOIN movies ON movies.rowid = id", 19 | ); 20 | 21 | console.log("Movies:", result.rows); 22 | -------------------------------------------------------------------------------- /examples/vector/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "batch", 3 | "version": "1.0.0", 4 | "main": "index.mjs", 5 | "author": "Giovanni Benussi", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@libsql/client": "^0.14.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "workspaces": [ 3 | "packages/libsql-core", 4 | "packages/libsql-client", 5 | "packages/libsql-client-wasm" 6 | ], 7 | "dependencies": {}, 8 | "scripts": { 9 | "prepare": "node .husky/install.mjs", 10 | "build": "npm run build --workspaces", 11 | "typecheck": "npm run typecheck --workspaces", 12 | "format:check": "npm run format:check --workspaces", 13 | "lint-staged": "lint-staged" 14 | }, 15 | "devDependencies": { 16 | "lint-staged": "^15.2.2", 17 | "husky": "^9.1.5" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/libsql-client-wasm/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 libSQL 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/libsql-client-wasm/examples/browser/README.md: -------------------------------------------------------------------------------- 1 | # libSQL Wasm example for browsers 2 | 3 | ## Building 4 | 5 | Run the following in the `packages/libsql-client-wasm` directory: 6 | 7 | ``` 8 | npm run build 9 | ``` 10 | 11 | Run the following in this directory: 12 | 13 | ``` 14 | npm i 15 | ./node_modules/.bin/esbuild --target=safari16 index.js --bundle --outfile=dist/out.js --format=esm 16 | cp ../../../../node_modules/@libsql/libsql-wasm-experimental/sqlite-wasm/jswasm/sqlite3.wasm dist 17 | ``` 18 | 19 | and open the app in browser: 20 | 21 | ``` 22 | npx http-server -o 23 | ``` 24 | -------------------------------------------------------------------------------- /packages/libsql-client-wasm/examples/browser/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
2 |
3 |
5 |
11 | Databases for all TypeScript and JS multi-tenant apps. 12 |
13 | 14 |15 | Turso · 16 | Docs · 17 | Quickstart · 18 | SDK Reference · 19 | Blog & Tutorials 20 |
21 | 22 |
23 |
24 |
26 |
31 |
36 |
41 |
46 |
This is a smoke-test Vercel app for @libsql/client
.