Skip to content

Commit

Permalink
update examples: bare-node and bare-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanShang committed Oct 21, 2024
1 parent 458a18b commit ce9922b
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/bare-browser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
15 changes: 15 additions & 0 deletions examples/bare-browser/bundle.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from 'fs';
import path from 'path';
import { createRequire } from 'module';

const require = createRequire(import.meta.url);
const KUZU_DIST = path.dirname(require.resolve('@kuzu/kuzu-wasm'));

function printErr(err) {
if (err) return console.log(err);
}
fs.cp(path.resolve(KUZU_DIST), './dist', { recursive: true }, (err) => {
if (err) {
console.error(err);
}
});
26 changes: 26 additions & 0 deletions examples/bare-browser/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kuzu WASM Example</title>
<script type="module">
import kuzu_wasm from './dist/kuzu-browser.js';

(async () => {
const kuzu = await kuzu_wasm();
window.kuzu = kuzu
const db = await kuzu.Database()
const conn = await kuzu.Connection(db)
await conn.execute(`CREATE NODE TABLE User(name STRING, age INT64, PRIMARY KEY (name))`)
await conn.execute(`CREATE (u:User {name: 'Alice', age: 35});`)
const res = await conn.execute(`MATCH (a:User) RETURN a.*;`)
const res_json = JSON.parse(res.table.toString());
console.log(res_json)
})();
</script>
</head>
<body>
<h1>Kuzu WASM Example</h1>
</body>
</html>
15 changes: 15 additions & 0 deletions examples/bare-browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"private": true,
"name": "kuzu-wasm-examples-bare-browser",
"version": "0.0.1",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@kuzu/kuzu-wasm": "file:../../packages/kuzu-wasm"
},
"devDependencies": {
},
"scripts": {
"build": "node ./bundle.mjs"
}
}
Empty file added examples/bare-node/.gitignore
Empty file.
13 changes: 13 additions & 0 deletions examples/bare-node/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const kuzu_wasm = require('@kuzu/kuzu-wasm');
const path = require('path');
const DUCKDB_DIST = path.dirname(require.resolve('@kuzu/kuzu-wasm'));

(async () => {
const kuzu = await kuzu_wasm();
const db = new kuzu.WebDatabase("memDB", 0, 0, false, false, 4194304 * 16 * 8);
const conn = new kuzu.WebConnection(db, 0);
await conn.query(`CREATE NODE TABLE User(name STRING, age INT64, PRIMARY KEY (name))`)
await conn.query(`CREATE (u:User {name: 'Alice', age: 35});`)
const res = await conn.query(`MATCH (a:User) RETURN a.*;`)
console.log(res.toString())
})();
13 changes: 13 additions & 0 deletions examples/bare-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"name": "kuzu-wasm-examples-bare-node",
"version": "0.0.1",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@kuzu/kuzu-wasm": "file:../../packages/kuzu-wasm"
},
"scripts": {
"test": "node ./index.cjs"
}
}

0 comments on commit ce9922b

Please sign in to comment.