diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f763d17..9b01156 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -110,15 +110,15 @@ jobs: # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v3.py node test.js" # env: {"LOCAL": "1", "URL": "http://localhost:8080"} - - name: "Non-local test with Hrana 1 over WebSocket" - run: "cd smoke_test/workers && python ../../hrana-test-server/server_v1.py node test.js" - env: {"LOCAL": "0", "URL": "ws://localhost:8080"} - - name: "Non-local test with Hrana 2 over WebSocket" - run: "cd smoke_test/workers && python ../../hrana-test-server/server_v2.py node test.js" - env: {"LOCAL": "0", "URL": "ws://localhost:8080"} - - name: "Non-local test with Hrana 2 over HTTP" - run: "cd smoke_test/workers && python ../../hrana-test-server/server_v2.py node test.js" - env: {"LOCAL": "0", "URL": "http://localhost:8080"} + # - name: "Non-local test with Hrana 1 over WebSocket" + # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v1.py node test.js" + # env: {"LOCAL": "0", "URL": "ws://localhost:8080"} + # - name: "Non-local test with Hrana 2 over WebSocket" + # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v2.py node test.js" + # env: {"LOCAL": "0", "URL": "ws://localhost:8080"} + # - name: "Non-local test with Hrana 2 over HTTP" + # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v2.py node test.js" + # env: {"LOCAL": "0", "URL": "http://localhost:8080"} # - name: "Non-local test with Hrana 3 over WebSocket" # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v3.py node test.js" # env: {"LOCAL": "0", "URL": "ws://localhost:8080"} @@ -126,50 +126,50 @@ jobs: # run: "cd smoke_test/workers && python ../../hrana-test-server/server_v3.py node test.js" # env: {"LOCAL": "0", "URL": "http://localhost:8080"} - "vercel-test": - name: "Build and test with Vercel Edge Functions" - runs-on: ubuntu-latest - env: - VERCEL_TOKEN: "${{ secrets.VERCEL_TOKEN }}" - VERCEL_PROJECT_NAME: "smoke-test" - steps: - - name: "Checkout this repo" - uses: actions/checkout@v3 - - name: "Setup Node.js" - uses: actions/setup-node@v3 - with: - node-version: "lts/Hydrogen" - cache: "npm" - - name: "Install npm dependencies" - run: "npm ci" +# "vercel-test": +# name: "Build and test with Vercel Edge Functions" +# runs-on: ubuntu-latest +# env: +# VERCEL_TOKEN: "${{ secrets.VERCEL_TOKEN }}" +# VERCEL_PROJECT_NAME: "smoke-test" +# steps: +# - name: "Checkout this repo" +# uses: actions/checkout@v3 +# - name: "Setup Node.js" +# uses: actions/setup-node@v3 +# with: +# node-version: "lts/Hydrogen" +# cache: "npm" +# - name: "Install npm dependencies" +# run: "npm ci" - - name: "Checkout hrana-test-server" - uses: actions/checkout@v3 - with: - repository: "libsql/hrana-test-server" - path: "hrana-test-server" - - name: "Setup Python" - uses: actions/setup-python@v4 - with: - python-version: "3.10" - cache: "pip" - - name: "Install pip dependencies" - run: "pip install -r hrana-test-server/requirements.txt" +# - name: "Checkout hrana-test-server" +# uses: actions/checkout@v3 +# with: +# repository: "libsql/hrana-test-server" +# path: "hrana-test-server" +# - name: "Setup Python" +# uses: actions/setup-python@v4 +# with: +# python-version: "3.10" +# cache: "pip" +# - name: "Install pip dependencies" +# run: "pip install -r hrana-test-server/requirements.txt" - - name: "Build" - run: "npm run build" - - name: "Install npm dependencies of the Vercel test" - run: "cd smoke_test/vercel && npm install" +# - name: "Build" +# run: "npm run build" +# - name: "Install npm dependencies of the Vercel test" +# run: "cd smoke_test/vercel && npm install" - - name: "Test with Hrana 1 over WebSocket" - run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v1.py node test.js" - env: {"URL": "ws://localhost:8080"} - - name: "Test with Hrana 2 over WebSocket" - run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v2.py node test.js" - env: {"URL": "ws://localhost:8080"} - - name: "Test with Hrana 2 over HTTP" - run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v2.py node test.js" - env: {"URL": "http://localhost:8080"} +# - name: "Test with Hrana 1 over WebSocket" +# run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v1.py node test.js" +# env: {"URL": "ws://localhost:8080"} +# - name: "Test with Hrana 2 over WebSocket" +# run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v2.py node test.js" +# env: {"URL": "ws://localhost:8080"} +# - name: "Test with Hrana 2 over HTTP" +# run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v2.py node test.js" +# env: {"URL": "http://localhost:8080"} # - name: "Test with Hrana 3 over WebSocket" # run: "cd smoke_test/vercel && python ../../hrana-test-server/server_v3.py node test.js" # env: {"URL": "ws://localhost:8080"} diff --git a/package-lock.json b/package-lock.json index 8fe81fd..7cc2715 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@libsql/hrana-client": "^0.5.5", "js-base64": "^3.7.5", - "libsql": "^0.2.0-pre.1" + "libsql": "^0.2.0-pre.2" }, "devDependencies": { "@types/jest": "^29.2.5", @@ -1015,9 +1015,9 @@ } }, "node_modules/@libsql/darwin-arm64": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.2.0-pre.1.tgz", - "integrity": "sha512-U4+Zer7C5FHgYjYp5687k29W4y8YzizCPJX91OrY4d/ZwXducjIMbIAFp160iZ8R7T2uTsGt6HxV17iXEC0V6w==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.2.0-pre.2.tgz", + "integrity": "sha512-PKXAKBJF6XwfCT3yU1N/kHyUGcsatf/4rYNzdnc6UGeg+yWf3ZDk7sGnHHj9bDQ9oKLRVJQmc+cNIEsF2GOr9w==", "cpu": [ "arm64" ], @@ -1027,9 +1027,9 @@ ] }, "node_modules/@libsql/darwin-x64": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.2.0-pre.1.tgz", - "integrity": "sha512-rxjjpfEQa1NAR8uek/S0naWvCbuL2qV0Wp6YGctTJFUZHUS32/RFYrmT8D5Dv6XlhqIS8XSLUDSAr9lVm4xi2A==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.2.0-pre.2.tgz", + "integrity": "sha512-e3k4LsAFRf8qFfZqkg/VkoXK/UfDYgoDvLmAJpAGKEFp7d/bTmbF1r0YCjtGaPbheRxARAUXNfekvRhdpXE3mg==", "cpu": [ "x64" ], @@ -1087,9 +1087,9 @@ } }, "node_modules/@libsql/linux-arm64-gnu": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.2.0-pre.1.tgz", - "integrity": "sha512-dWq75OHHhcP3W07AON2oi8xg+MqAibzCQdjly59lr60rdarllqggf4ua6ktP82qcdShJqL2nGvvcYCHV1kILWQ==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.2.0-pre.2.tgz", + "integrity": "sha512-ZkN6e129joeUu6cinGMRbCvLTnrM5xV5n9XHs2dRrZfL7yu7utbvrY1l+P6VI1gugs93UhgupqyMsolFjvrPww==", "cpu": [ "arm64" ], @@ -1099,9 +1099,9 @@ ] }, "node_modules/@libsql/linux-arm64-musl": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.2.0-pre.1.tgz", - "integrity": "sha512-6SuESjm0ZRuADhFaXRO7+yK7WJwpdlDWOEEqzZfYRV+twlCRXb8WNSQo3O/WYTFbGIdd4dNSIQCy4+tBmbV7Tg==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.2.0-pre.2.tgz", + "integrity": "sha512-tEy4UAIzHYtjCBJnZoTcX1LCYy+XGR3hQCsdRYujWJhUtmtU/AqCRZV3q8MyfX7UhKyawJKWoQvwQ6Vs7w9jAA==", "cpu": [ "arm64" ], @@ -1111,9 +1111,9 @@ ] }, "node_modules/@libsql/linux-x64-gnu": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.2.0-pre.1.tgz", - "integrity": "sha512-ATHqNP5hhOgJ3QbgBR+AN3taB0CKbWIFdJ5ObCY841i274zFbZoDe0tjjSlamxS2e1EeG4SjBpLhNhBzDm6jIQ==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.2.0-pre.2.tgz", + "integrity": "sha512-jhHKwz5i9mdlpT4EeaKNUfyW5N9YY8wD5lZ0F5HrrPKhwgufnJY0oPEbvhM4KXDcSJetiIcGJ6K6NQyMSgoJ/Q==", "cpu": [ "x64" ], @@ -1123,9 +1123,9 @@ ] }, "node_modules/@libsql/linux-x64-musl": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.2.0-pre.1.tgz", - "integrity": "sha512-ouiAKD0DzuOfLULjn3VrjgU8BEtsE3Dp7wKyeJnhYSipMiBsWzPlBMmME8+zE5SGExBiTBbv1xxi1s3rHQzaFQ==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.2.0-pre.2.tgz", + "integrity": "sha512-HvwZtSQ2eIT968yxAb+htO+wmibdwW1PIyR7iJ5TN7phj7W1gF962l3ZhV1hVYERaMu+liBH1e/cRP1S35q3vQ==", "cpu": [ "x64" ], @@ -1135,9 +1135,9 @@ ] }, "node_modules/@libsql/win32-x64-msvc": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.2.0-pre.1.tgz", - "integrity": "sha512-P4mT0V+LMKzfraklerCvjrC9rTff7/5JFUpsRpAtw7RFQM2vIt5SqzgGNsHQsWW5/s9Ie0tqQB5A97hVSjgyOw==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.2.0-pre.2.tgz", + "integrity": "sha512-BWjInhsZRF9x+W0T5oJVjqoCCdvh82y74b/T3Ge/irXyLdVhHA9Zb1JWDy5uhu8eBR+d2n9B+IO0YwAvhFRTLw==", "cpu": [ "x64" ], @@ -3047,9 +3047,9 @@ } }, "node_modules/libsql": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.2.0-pre.1.tgz", - "integrity": "sha512-wVSUo3S6BY7Yz1fbJGVeHzm2HSeG58iAvCg//81Wv1Z7Zm4MoHedd5/0cbn1v0oM6e5SaGprkYS5lDqHgyHlWA==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.2.0-pre.2.tgz", + "integrity": "sha512-ErF11J/Q0Uo1TMceX1f7RKfFvQ/j4FS8TagzJnAZBwhHsPcr7uItkSTchkuRHm5+cE4dJO7lqf+MpmlDjp/qAQ==", "cpu": [ "x64", "arm64" @@ -3064,13 +3064,13 @@ "detect-libc": "2.0.2" }, "optionalDependencies": { - "@libsql/darwin-arm64": "0.2.0-pre.1", - "@libsql/darwin-x64": "0.2.0-pre.1", - "@libsql/linux-arm64-gnu": "0.2.0-pre.1", - "@libsql/linux-arm64-musl": "0.2.0-pre.1", - "@libsql/linux-x64-gnu": "0.2.0-pre.1", - "@libsql/linux-x64-musl": "0.2.0-pre.1", - "@libsql/win32-x64-msvc": "0.2.0-pre.1" + "@libsql/darwin-arm64": "0.2.0-pre.2", + "@libsql/darwin-x64": "0.2.0-pre.2", + "@libsql/linux-arm64-gnu": "0.2.0-pre.2", + "@libsql/linux-arm64-musl": "0.2.0-pre.2", + "@libsql/linux-x64-gnu": "0.2.0-pre.2", + "@libsql/linux-x64-musl": "0.2.0-pre.2", + "@libsql/win32-x64-msvc": "0.2.0-pre.2" } }, "node_modules/lines-and-columns": { @@ -4988,15 +4988,15 @@ } }, "@libsql/darwin-arm64": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.2.0-pre.1.tgz", - "integrity": "sha512-U4+Zer7C5FHgYjYp5687k29W4y8YzizCPJX91OrY4d/ZwXducjIMbIAFp160iZ8R7T2uTsGt6HxV17iXEC0V6w==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.2.0-pre.2.tgz", + "integrity": "sha512-PKXAKBJF6XwfCT3yU1N/kHyUGcsatf/4rYNzdnc6UGeg+yWf3ZDk7sGnHHj9bDQ9oKLRVJQmc+cNIEsF2GOr9w==", "optional": true }, "@libsql/darwin-x64": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.2.0-pre.1.tgz", - "integrity": "sha512-rxjjpfEQa1NAR8uek/S0naWvCbuL2qV0Wp6YGctTJFUZHUS32/RFYrmT8D5Dv6XlhqIS8XSLUDSAr9lVm4xi2A==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.2.0-pre.2.tgz", + "integrity": "sha512-e3k4LsAFRf8qFfZqkg/VkoXK/UfDYgoDvLmAJpAGKEFp7d/bTmbF1r0YCjtGaPbheRxARAUXNfekvRhdpXE3mg==", "optional": true }, "@libsql/hrana-client": { @@ -5039,33 +5039,33 @@ } }, "@libsql/linux-arm64-gnu": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.2.0-pre.1.tgz", - "integrity": "sha512-dWq75OHHhcP3W07AON2oi8xg+MqAibzCQdjly59lr60rdarllqggf4ua6ktP82qcdShJqL2nGvvcYCHV1kILWQ==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.2.0-pre.2.tgz", + "integrity": "sha512-ZkN6e129joeUu6cinGMRbCvLTnrM5xV5n9XHs2dRrZfL7yu7utbvrY1l+P6VI1gugs93UhgupqyMsolFjvrPww==", "optional": true }, "@libsql/linux-arm64-musl": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.2.0-pre.1.tgz", - "integrity": "sha512-6SuESjm0ZRuADhFaXRO7+yK7WJwpdlDWOEEqzZfYRV+twlCRXb8WNSQo3O/WYTFbGIdd4dNSIQCy4+tBmbV7Tg==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.2.0-pre.2.tgz", + "integrity": "sha512-tEy4UAIzHYtjCBJnZoTcX1LCYy+XGR3hQCsdRYujWJhUtmtU/AqCRZV3q8MyfX7UhKyawJKWoQvwQ6Vs7w9jAA==", "optional": true }, "@libsql/linux-x64-gnu": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.2.0-pre.1.tgz", - "integrity": "sha512-ATHqNP5hhOgJ3QbgBR+AN3taB0CKbWIFdJ5ObCY841i274zFbZoDe0tjjSlamxS2e1EeG4SjBpLhNhBzDm6jIQ==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.2.0-pre.2.tgz", + "integrity": "sha512-jhHKwz5i9mdlpT4EeaKNUfyW5N9YY8wD5lZ0F5HrrPKhwgufnJY0oPEbvhM4KXDcSJetiIcGJ6K6NQyMSgoJ/Q==", "optional": true }, "@libsql/linux-x64-musl": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.2.0-pre.1.tgz", - "integrity": "sha512-ouiAKD0DzuOfLULjn3VrjgU8BEtsE3Dp7wKyeJnhYSipMiBsWzPlBMmME8+zE5SGExBiTBbv1xxi1s3rHQzaFQ==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.2.0-pre.2.tgz", + "integrity": "sha512-HvwZtSQ2eIT968yxAb+htO+wmibdwW1PIyR7iJ5TN7phj7W1gF962l3ZhV1hVYERaMu+liBH1e/cRP1S35q3vQ==", "optional": true }, "@libsql/win32-x64-msvc": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.2.0-pre.1.tgz", - "integrity": "sha512-P4mT0V+LMKzfraklerCvjrC9rTff7/5JFUpsRpAtw7RFQM2vIt5SqzgGNsHQsWW5/s9Ie0tqQB5A97hVSjgyOw==", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.2.0-pre.2.tgz", + "integrity": "sha512-BWjInhsZRF9x+W0T5oJVjqoCCdvh82y74b/T3Ge/irXyLdVhHA9Zb1JWDy5uhu8eBR+d2n9B+IO0YwAvhFRTLw==", "optional": true }, "@neon-rs/load": { @@ -6505,17 +6505,17 @@ "dev": true }, "libsql": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.2.0-pre.1.tgz", - "integrity": "sha512-wVSUo3S6BY7Yz1fbJGVeHzm2HSeG58iAvCg//81Wv1Z7Zm4MoHedd5/0cbn1v0oM6e5SaGprkYS5lDqHgyHlWA==", - "requires": { - "@libsql/darwin-arm64": "0.2.0-pre.1", - "@libsql/darwin-x64": "0.2.0-pre.1", - "@libsql/linux-arm64-gnu": "0.2.0-pre.1", - "@libsql/linux-arm64-musl": "0.2.0-pre.1", - "@libsql/linux-x64-gnu": "0.2.0-pre.1", - "@libsql/linux-x64-musl": "0.2.0-pre.1", - "@libsql/win32-x64-msvc": "0.2.0-pre.1", + "version": "0.2.0-pre.2", + "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.2.0-pre.2.tgz", + "integrity": "sha512-ErF11J/Q0Uo1TMceX1f7RKfFvQ/j4FS8TagzJnAZBwhHsPcr7uItkSTchkuRHm5+cE4dJO7lqf+MpmlDjp/qAQ==", + "requires": { + "@libsql/darwin-arm64": "0.2.0-pre.2", + "@libsql/darwin-x64": "0.2.0-pre.2", + "@libsql/linux-arm64-gnu": "0.2.0-pre.2", + "@libsql/linux-arm64-musl": "0.2.0-pre.2", + "@libsql/linux-x64-gnu": "0.2.0-pre.2", + "@libsql/linux-x64-musl": "0.2.0-pre.2", + "@libsql/win32-x64-msvc": "0.2.0-pre.2", "@neon-rs/load": "^0.0.4", "detect-libc": "2.0.2" } diff --git a/package.json b/package.json index 0176226..018fe23 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "dependencies": { "@libsql/hrana-client": "^0.5.5", "js-base64": "^3.7.5", - "libsql": "^0.2.0-pre.1" + "libsql": "^0.2.0-pre.2" }, "devDependencies": { "@types/jest": "^29.2.5", diff --git a/src/__tests__/client.test.ts b/src/__tests__/client.test.ts index 0add4b1..a9334c9 100644 --- a/src/__tests__/client.test.ts +++ b/src/__tests__/client.test.ts @@ -45,6 +45,19 @@ function withClient( }; } +function withInMemoryClient( + f: (c: libsql.Client) => Promise, +): () => Promise { + return async () => { + const c = createClient({ url: ":memory:" }); + try { + await f(c); + } finally { + c.close(); + } + }; +} + describe("createClient()", () => { test("URL scheme not supported", () => { expect(() => createClient({url: "ftp://localhost"})) @@ -88,6 +101,10 @@ describe("createClient()", () => { // @ts-expect-error expect(() => createClient({...config, intMode: "foo"})).toThrow(/"foo"/); }); + + test("supports in-memory database", () => { + expect(() => createClient({url: ":memory:"})).not.toThrow(); + }); }); describe("execute()", () => { @@ -187,6 +204,21 @@ describe("execute()", () => { `); expect(rs.rowsAffected).toStrictEqual(3); })); + + test("query a single value using an in memory database", withInMemoryClient(async (c) => { + await c.batch([ + "DROP TABLE IF EXISTS t", + "CREATE TABLE t (a)", + "INSERT INTO t VALUES ('one'), ('two')", + ], "write"); + const insertRs = await c.execute("INSERT INTO t VALUES ('three')"); + expect(insertRs.lastInsertRowid).not.toBeUndefined(); + const selectRs = await c.execute({ + sql: "SELECT a FROM t WHERE ROWID = ?", + args: [insertRs.lastInsertRowid!], + }); + expect(Array.from(selectRs.rows[0])).toStrictEqual(["three"]); + })); }); describe("values", () => { diff --git a/src/config.ts b/src/config.ts index 32a881d..994c431 100644 --- a/src/config.ts +++ b/src/config.ts @@ -24,10 +24,32 @@ export function expandConfig(config: Config, preferHttp: boolean): ExpandedConfi throw new TypeError(`Expected client configuration as object, got ${typeof config}`); } - const uri = parseUri(config.url); - let tls: boolean | undefined = config.tls; let authToken = config.authToken; + let syncUrl = config.syncUrl; + const intMode = ""+(config.intMode ?? "number"); + if (intMode !== "number" && intMode !== "bigint" && intMode !== "string") { + throw new TypeError( + `Invalid value for intMode, expected "number", "bigint" or "string", \ + got ${JSON.stringify(intMode)}` + ); + } + + + if(config.url === ':memory:') { + return { + path: ':memory:', + scheme: 'file', + syncUrl, + intMode, + fetch: config.fetch, + tls: false, + authToken: undefined, + authority: undefined, + }; + } + + const uri = parseUri(config.url); for (const {key, value} of uri.query?.pairs ?? []) { if (key === "authToken") { authToken = value ? value : undefined; @@ -50,7 +72,6 @@ export function expandConfig(config: Config, preferHttp: boolean): ExpandedConfi ); } } - let syncUrl = config.syncUrl; const uriScheme = uri.scheme.toLowerCase(); let scheme: ExpandedScheme; @@ -87,14 +108,6 @@ export function expandConfig(config: Config, preferHttp: boolean): ExpandedConfi ); } - const intMode = ""+(config.intMode ?? "number"); - if (intMode !== "number" && intMode !== "bigint" && intMode !== "string") { - throw new TypeError( - `Invalid value for intMode, expected "number", "bigint" or "string", \ - got ${JSON.stringify(intMode)}` - ); - } - return { scheme, tls: tls ?? true,