-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
presets: ['@babel/preset-env'], | ||
plugins: ['babel-plugin-transform-import-meta'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { S3 } from '@aws-sdk/client-s3' | ||
import { createRequire } from 'module' | ||
import path from 'path' | ||
import * as SQLite from 'wa-sqlite' | ||
import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite-async.mjs' | ||
|
||
import { S3VFS } from '../s3vfs' | ||
|
||
// @ts-ignore | ||
import * as localstackConfig from '../../jest.localstack.js' | ||
|
||
const s3 = new S3({ | ||
credentials: { | ||
accessKeyId: 'access-key', | ||
secretAccessKey: 'secret-key', | ||
}, | ||
forcePathStyle: true, | ||
endpoint: 'http://localhost:4566', | ||
}) | ||
|
||
const { Bucket: bucketName } = localstackConfig.S3Buckets[1] | ||
|
||
|
||
describe('S3VFS with wa-sqlite', function() { | ||
let sqlite3: SQLiteAPI | ||
let db: number | ||
|
||
beforeAll(async () => { | ||
await s3.createBucket({ Bucket: bucketName }) | ||
|
||
const s3vfs = new S3VFS(s3, bucketName) | ||
|
||
const currentDirName = globalThis.__dirname | ||
const originalRequire = globalThis.require | ||
const sqliteDistPath = path.resolve(__dirname, '../../node_modules/wa-sqlite/dist') | ||
|
||
if (typeof process === 'object') { | ||
globalThis.__dirname = sqliteDistPath + '/wa-sqlite-async.mjs' | ||
globalThis.require = createRequire(sqliteDistPath) | ||
} | ||
|
||
// Invoke the ES6 module factory to create the SQLite | ||
// Emscripten module. This will fetch and compile the | ||
// .wasm file. | ||
const module = await SQLiteESMFactory({ locateFile: (path: string) => sqliteDistPath + '/' + path }) | ||
|
||
globalThis.require = originalRequire | ||
globalThis.__dirname = currentDirName | ||
|
||
// Use the module to build the API instance. | ||
sqlite3 = SQLite.Factory(module) | ||
sqlite3.vfs_register(s3vfs, true) | ||
db = await sqlite3.open_v2(bucketName) | ||
}) | ||
it('should return a result for SELECT 1+1', async () => { | ||
const { rows, columns } = await new Promise((resolve) => { | ||
sqlite3.exec(db, 'SELECT 1+1', (rows, columns) => resolve({ rows, columns })) | ||
}) | ||
expect(rows).toStrictEqual([ 2 ]) | ||
expect(columns).toStrictEqual([ '1+1' ]) | ||
}) | ||
it('should CREATE TABLE, INSERT, UPDATE, SELECT', async () => { | ||
await sqlite3.exec(db, 'CREATE TABLE users (x INTEGER PRIMARY KEY ASC, y TEXT)') | ||
await sqlite3.exec(db, "INSERT INTO users (x,y) VALUES (1,'2');") | ||
await sqlite3.exec(db, "UPDATE users SET y='c' WHERE x=1;") | ||
|
||
const { rows, columns } = await new Promise((resolve) => { | ||
sqlite3.exec(db, 'SELECT * from users', (rows, columns) => resolve({ rows, columns })) | ||
}) | ||
expect(rows).toStrictEqual([ 1, 'c' ]) | ||
expect(columns).toStrictEqual([ 'x', 'y' ]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters