Skip to content

Commit e32c897

Browse files
committed
feat: update kitesql wasm to 0.3.2
1 parent 623a729 commit e32c897

8 files changed

Lines changed: 89 additions & 51 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A small Vite site for KiteSQL that works as both:
44

55
- a lightweight landing page for the project
6-
- an in-browser playground powered by the published WebAssembly build
6+
- an in-browser playground powered by the published `kite_sql@0.3.2` WebAssembly build
77

88
The site lives next to the main repository so it can be deployed independently to GitHub Pages, Cloudflare Pages, Netlify, or any other static host.
99

@@ -42,7 +42,7 @@ npm run preview
4242

4343
## WebAssembly source
4444

45-
The site currently uses the published npm package for KiteSQL wasm assets through `@kipdata/kite_sql`.
45+
The site currently uses the published npm package for KiteSQL wasm assets through `kite_sql@0.3.2`.
4646
That keeps the website simple to deploy because no local Rust build is required.
4747

48-
After publishing a newer npm package, bump the dependency version here if you want the website to track the latest release.
48+
When KiteSQL publishes a newer npm package, bump the `kite_sql` dependency and refresh the browser wrapper if the generated wasm-bindgen glue changes.

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
name="description"
99
content="KiteSQL is an embedded relational engine for Rust with SQL, native APIs, ORM workflows, schema migration, and an in-browser WebAssembly playground."
1010
/>
11-
<link rel="icon" href="/favicon.ico" />
11+
<link rel="icon" type="image/jpeg" href="/favicon.jpeg" />
1212
<link rel="preconnect" href="https://fonts.googleapis.com" />
1313
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1414
<link

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"build": "vite build",
99
"preview": "vite preview"
1010
},
11-
"dependencies": {
12-
"@kipdata/kite_sql": "^0.1.6"
13-
},
1411
"devDependencies": {
1512
"@types/node": "^22.9.0",
1613
"typescript": "^5.6.3",
1714
"vite": "^5.4.10"
15+
},
16+
"dependencies": {
17+
"kite_sql": "0.3.2"
1818
}
1919
}

src/kite-sql-web.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
// Browser-friendly wrapper around the npm-published `kite_sql` package.
1+
// Browser-friendly wrapper around the npm-published `kite_sql` 0.3.2 package.
22
// The package ships a Node-focused glue file; this adapts it to load the wasm
33
// via fetch and expose the same APIs (WasmDatabase, WasmResultIter).
44
// Based on the upstream glue with minimal changes for ESM + browsers.
55
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
66
// @ts-nocheck
7-
import wasmUrl from "@kipdata/kite_sql/kite_sql_bg.wasm?url";
7+
import wasmUrl from "kite_sql/kite_sql_bg.wasm?url";
88

99
const placeholder: any = {};
1010
// The wasm expects its JS imports under the module name `__wbindgen_placeholder__`.
1111
const imports: any = { "__wbindgen_placeholder__": placeholder };
1212
let wasm: any;
1313

1414
function addToExternrefTable0(obj) {
15-
const idx = wasm.__externref_table_alloc_command_export();
15+
const idx = wasm.__externref_table_alloc();
1616
wasm.__wbindgen_externrefs.set(idx, obj);
1717
return idx;
1818
}
@@ -48,7 +48,7 @@ function handleError(f, args) {
4848
return f.apply(this, args);
4949
} catch (e) {
5050
const idx = addToExternrefTable0(e);
51-
wasm.__wbindgen_exn_store_command_export(idx);
51+
wasm.__wbindgen_exn_store(idx);
5252
}
5353
}
5454

@@ -91,7 +91,7 @@ function passStringToWasm0(arg, malloc, realloc) {
9191

9292
function takeFromExternrefTable0(idx) {
9393
const value = wasm.__wbindgen_externrefs.get(idx);
94-
wasm.__externref_table_dealloc_command_export(idx);
94+
wasm.__externref_table_dealloc(idx);
9595
return value;
9696
}
9797

@@ -150,7 +150,7 @@ class WasmDatabase {
150150
* @returns {WasmResultIter}
151151
*/
152152
run(sql) {
153-
const ptr0 = passStringToWasm0(sql, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
153+
const ptr0 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
154154
const len0 = WASM_VECTOR_LEN;
155155
const ret = wasm.wasmdatabase_run(this.__wbg_ptr, ptr0, len0);
156156
if (ret[2]) {
@@ -162,13 +162,35 @@ class WasmDatabase {
162162
* @param {string} sql
163163
*/
164164
execute(sql) {
165-
const ptr0 = passStringToWasm0(sql, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
165+
const ptr0 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
166166
const len0 = WASM_VECTOR_LEN;
167167
const ret = wasm.wasmdatabase_execute(this.__wbg_ptr, ptr0, len0);
168168
if (ret[1]) {
169169
throw takeFromExternrefTable0(ret[0]);
170170
}
171171
}
172+
/**
173+
* @param {string} sql
174+
*/
175+
ddl(sql) {
176+
const ptr0 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
177+
const len0 = WASM_VECTOR_LEN;
178+
const ret = wasm.wasmdatabase_ddl(this.__wbg_ptr, ptr0, len0);
179+
if (ret[1]) {
180+
throw takeFromExternrefTable0(ret[0]);
181+
}
182+
}
183+
/**
184+
* @param {string} table_name
185+
*/
186+
analyze(table_name) {
187+
const ptr0 = passStringToWasm0(table_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
188+
const len0 = WASM_VECTOR_LEN;
189+
const ret = wasm.wasmdatabase_analyze(this.__wbg_ptr, ptr0, len0);
190+
if (ret[1]) {
191+
throw takeFromExternrefTable0(ret[0]);
192+
}
193+
}
172194
}
173195
if (Symbol.dispose) WasmDatabase.prototype[Symbol.dispose] = WasmDatabase.prototype.free;
174196
placeholder.WasmDatabase = WasmDatabase;
@@ -244,7 +266,7 @@ placeholder.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
244266

245267
placeholder.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
246268
const ret = String(arg1);
247-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
269+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
248270
const len1 = WASM_VECTOR_LEN;
249271
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
250272
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
@@ -298,6 +320,16 @@ placeholder.__wbg_now_69d776cd24f5215b = function() {
298320
return ret;
299321
};
300322

323+
placeholder.__wbg_push_7d9be8f38fc13975 = function(arg0, arg1) {
324+
const ret = arg0.push(arg1);
325+
return ret;
326+
};
327+
328+
placeholder.__wbg_set_781438a03c0c3c81 = function() { return handleError(function(arg0, arg1, arg2) {
329+
const ret = Reflect.set(arg0, arg1, arg2);
330+
return ret;
331+
}, arguments); };
332+
301333
placeholder.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
302334
arg0[arg1] = arg2;
303335
};

src/main.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ui.innerHTML = `
5454
<div class="hero-points">
5555
<div class="metric"><strong>Rust-native</strong><span>typed APIs alongside SQL</span></div>
5656
<div class="metric"><strong>Model-driven</strong><span>ORM, CRUD, migrations, query builder</span></div>
57-
<div class="metric"><strong>Browser-ready</strong><span>same engine available through wasm</span></div>
57+
<div class="metric"><strong>Browser-ready</strong><span>npm wasm package at 0.3.2</span></div>
5858
</div>
5959
</div>
6060
<div class="hero-side">
@@ -70,13 +70,17 @@ struct User {
7070
score: i32,
7171
}
7272
73-
db.migrate::<User>()?;
74-
db.insert(&user)?;
75-
let rows = db
76-
.select::<User>()
77-
.filter(User::score().gte(90))
78-
.order_by(User::score().desc())
79-
.fetch()?;</code></pre>
73+
database.migrate::<User>()?;
74+
database.insert_many(users)?;
75+
76+
let rows = database
77+
.bind(|ctx| {
78+
ctx.from::<User>()?
79+
.filter(|e| e.column(User::score())?.gte(90))?
80+
.project_scalars((User::id(), User::email()))?
81+
.finish()
82+
})?
83+
.project_tuple::<(i32, String)>();</code></pre>
8084
</div>
8185
<div class="mini-card secondary sql-card">
8286
<pre><code>SELECT team, AVG(score) AS avg_score
@@ -114,7 +118,7 @@ ORDER BY avg_score DESC;</code></pre>
114118
</article>
115119
<article class="feature-card card-lite">
116120
<h3>Runs in the browser</h3>
117-
<p>The published WebAssembly build lets users explore KiteSQL in a browser tab with no backend service and no local database server.</p>
121+
<p>The published <code>kite_sql@0.3.2</code> WebAssembly build lets users explore KiteSQL in a browser tab with no backend service and no local database server.</p>
118122
</article>
119123
</div>
120124
</section>
@@ -140,20 +144,23 @@ ORDER BY avg_score DESC;</code></pre>
140144
</div>
141145
</div>
142146
<div class="card-lite info-panel code-panel">
143-
<div class="eyebrow">Typical flow</div>
144-
<pre><code>let db = DataBaseBuilder::path("./data").build()?;
145-
146-
db.migrate::<User>()?;
147-
db.insert(&user)?;
148-
149-
let ranked = db
150-
.select::<User>()
151-
.filter(User::score().gte(80))
152-
.order_by(User::score().desc())
153-
.limit(20)
154-
.fetch()?;
155-
156-
let rows = db.run("select count(*) from users")?;</code></pre>
147+
<div class="eyebrow">Typical flow in 0.3.2</div>
148+
<pre><code>let mut database = DataBaseBuilder::path("./data").build_rocksdb()?;
149+
150+
database.migrate::<User>()?;
151+
database.insert_many(users)?;
152+
153+
let ranked = database
154+
.bind(|ctx| {
155+
ctx.from::<User>()?
156+
.filter(|e| e.column(User::score())?.gte(80))?
157+
.project_scalars((User::id(), User::email()))?
158+
.limit(20)?
159+
.finish()
160+
})?
161+
.project_tuple::<(i32, String)>();
162+
163+
let rows = database.run("select count(*) from users")?;</code></pre>
157164
</div>
158165
</section>
159166
@@ -163,7 +170,7 @@ let rows = db.run("select count(*) from users")?;</code></pre>
163170
<div class="eyebrow">WebAssembly playground</div>
164171
<h2>Open a browser tab and play with KiteSQL</h2>
165172
</div>
166-
<p>This playground runs fully in your browser using the published <code>kite_sql</code> wasm bundle. No server, no backend, no setup beyond loading the page.</p>
173+
<p>This playground runs fully in your browser using the published <code>kite_sql@0.3.2</code> wasm bundle. No server, no backend, no setup beyond loading the page.</p>
167174
</div>
168175
169176
<div class="playground card">
@@ -212,7 +219,7 @@ let rows = db.run("select count(*) from users")?;</code></pre>
212219
</main>
213220
214221
<footer class="footer-strip">
215-
<div>Runs entirely in the browser through the published WebAssembly build.</div>
222+
<div>Runs entirely in the browser through the published <code>kite_sql@0.3.2</code> WebAssembly build.</div>
216223
<div class="footer-links">
217224
<a href="https://github.com/KipData/KiteSQL" target="_blank" rel="noreferrer">GitHub</a>
218225
<a href="https://crates.io/crates/kite_sql" target="_blank" rel="noreferrer">crates.io</a>
@@ -397,12 +404,13 @@ async function seedDemoData(showResult = true) {
397404
if (!db) return;
398405

399406
const steps = [
400-
"drop table if exists contributors",
401-
"create table contributors(id int primary key, name varchar, team varchar, score int)",
402407
"insert into contributors values (1, 'Ada', 'engine', 98), (2, 'Lin', 'engine', 91), (3, 'Mia', 'product', 87), (4, 'Kai', 'research', 94), (5, 'Ivy', 'product', 89), (6, 'Noah', 'research', 96)",
403408
"update contributors set score = score + 1 where team = 'product'",
404409
];
405410

411+
db.ddl("drop table if exists contributors");
412+
db.ddl("create table contributors(id int primary key, name varchar, team varchar, score int)");
413+
406414
for (const sql of steps) {
407415
await db.execute(sql);
408416
}
@@ -412,7 +420,6 @@ async function seedDemoData(showResult = true) {
412420
const schema = typeof (result as any).schema === "function" ? (result as any).schema() : null;
413421
const columns = columnNamesFromSchema(schema);
414422
const rows = result.rows();
415-
result.finish();
416423
renderRows(rows, columns);
417424
}
418425

@@ -451,7 +458,6 @@ async function runSql(sqlText: string) {
451458
const schema = typeof (result as any).schema === "function" ? (result as any).schema() : null;
452459
lastColumns = columnNamesFromSchema(schema);
453460
lastRows = result.rows();
454-
result.finish();
455461
} else {
456462
await db!.execute(sql);
457463
}

static/favicon.ico

-4.18 KB
Binary file not shown.

static/favicon.jpeg

9.9 KB
Loading

0 commit comments

Comments
 (0)