Skip to content

Commit

Permalink
Merge pull request #152 from tursodatabase/wasm
Browse files Browse the repository at this point in the history
libSQL client Wasm package
  • Loading branch information
penberg authored Jan 19, 2024
2 parents 6d3deea + 95f5057 commit 6e69755
Show file tree
Hide file tree
Showing 24 changed files with 8,579 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ on:
pull_request:

jobs:
"wasm-test":
name: "Build and test Wasm on Node.js"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./packages/libsql-client-wasm
env: {"NODE_OPTIONS": "--trace-warnings"}
steps:
- name: "Checkout this repo"
uses: actions/checkout@v3
- name: "Setup Node.js"
uses: actions/setup-node@v3
with:
node-version: "16.x"
cache: "npm"
cache-dependency-path: "packages/libsql-client-wasm"
- name: "Build core"
run: "npm ci && npm run build"
working-directory: ./packages/libsql-core
- name: "Install npm dependencies"
run: "npm ci"
- name: "Build"
run: "npm run build"
- name: "Test example"
run: "cd examples/node && npm i && node index.js"
env: {"URL": "file:///tmp/example.db"}

"node-test":
name: "Build and test on Node.js"
runs-on: ubuntu-latest
Expand Down
49 changes: 48 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"workspaces": [ "packages/libsql-core", "packages/libsql-client" ]
"workspaces": [ "packages/libsql-core", "packages/libsql-client", "packages/libsql-client-wasm" ]
}
21 changes: 21 additions & 0 deletions packages/libsql-client-wasm/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 libSQL

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions packages/libsql-client-wasm/examples/browser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# libSQL Wasm example for browsers

## Building

Run the following in top-level directory of this repository:

```
npm run build
```

Then run the following in this directory:

```
./node_modules/.bin/esbuild --target=safari16 index.js --bundle --outfile=dist/out.js --format=esm
```

and open the app in browser:

```
npx http-server -o .
```
10 changes: 10 additions & 0 deletions packages/libsql-client-wasm/examples/browser/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<meta charset="utf-8" />
<title>libSQL SDK Wasm Demo</title>
<script type="module" src="dist/out.js"></script>
</head>
<body>
<h1>Hello libSQL and Wasm!</h1>
</body>
</html>
16 changes: 16 additions & 0 deletions packages/libsql-client-wasm/examples/browser/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createClient } from "@libsql/client-wasm";

async function main() {
const config = {
url: "file:local.db",
sqliteWasmPath: "/node_modules/@libsql/client/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3.wasm"
};
const db = await createClient(config);
const rs = await db.execute("SELECT * FROM users");
console.log(rs);
}

main()
.catch((error) => {
console.log(error);
});
Loading

0 comments on commit 6e69755

Please sign in to comment.