130but those will have to come later!
131132Another necessary feature for querying against larger databases will be to use the WHERE or JOIN conditions when dumping from them, but this will be more complicated
133134---
videoStorageREADME.md1 match
1415## Others
16* `getAllVideos` Lists all the videos in the database
17* `backfillVideo` Takes a video object and puts it in the DB. Useful if you're iterating over to...you guessed it, backfill content.
18
blogSqliteUniverseREADME.md3 matches
64### SQLite in Wasm
6566There is a [deno package (sqlite)](https://deno.land/x/sqlite@v3.8) which lets you (among other things) create SQLite databases in-memory using WebAssembly. I've created a Val which wraps this to enable it to be a drop-in replacement for @std/sqlite: [@postpostscript/sqliteWasm](https://val.town/v/postpostscript/sqliteWasm)
6768#### Example
123124- Serving a subset of your private data publicly for others to query (Example: [@postpostscript/sqlitePublic](https://val.town/v/postpostscript/sqlitePublic))
125- Backing up your database and querying against that backup (via @postpostscript/sqliteBackup's [sqliteFromBlob](https://postpostscript-modulehighlightvaluelink.web.val.run/?module=@postpostscript/sqliteBackup&name=sqliteFromBlob) and [sqliteToBlob](https://postpostscript-modulehighlightvaluelink.web.val.run/?module=@postpostscript/sqliteBackup&name=sqliteToBlob))
126127But we can do more..! What if we could query from multiple of these data sources.. at the same time! 😱
150The following patterns are accessible through `import { patterns } from "https://esm.town/v/postpostscript/sqliteUniverse"`:
151152- `patterns.blob` - `/^blob:\/\//` (`blob://backup:sqlite:1709960402936`) - import the database from **private** blob `backup:sqlite:1709960402936`
153154### Overriding Default Options
sqlitePublicmain.tsx3 matches
10const dumped = {};
1112async function database() {
13const dump = await sqliteDump(dumped);
14const sqlite = createSqlite();
50app.post("/execute", async (c) => {
51const { statement } = await c.req.json();
52const sqlite = await database();
53const res = await sqlite.execute(statement);
54console.log(typeof res, res);
57app.post("/batch", async (c) => {
58const { statements } = await c.req.json();
59const sqlite = await database();
60return c.json(sqlite.batch(statements));
61});
magentaDogmain.tsx1 match
4function incrementNumber() {
5currentNumber += 1;
6// Here, you would ideally persist the current number to a database or file for long-term storage.
7return currentNumber;
8}
whiteXerinaeREADME.md1 match
30- [ ] add triggers to sidebar
31- [ ] add upload from SQL, CSV and JSON
32- [ ] add ability to connect to a non-val town Turso database
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
whiteThrushREADME.md1 match
34- [ ] add triggers to sidebar
35- [ ] add upload from SQL, CSV and JSON
36- [ ] add ability to connect to a non-val town Turso database
3738
lucia_demomain.tsx2 matches
31interface Register {
32Lucia: typeof lucia;
33DatabaseUserAttributes: DatabaseUserAttributes;
34}
35}
3637interface DatabaseUserAttributes {
38username: string;
39}
lucia_adapter_basemain.tsx22 matches
1import type {
2Adapter,
3DatabaseSession,
4DatabaseUser,
5RegisteredDatabaseSessionAttributes,
6RegisteredDatabaseUserAttributes,
7} from "npm:lucia";
834public async getSessionAndUser(
35sessionId: string,
36): Promise<[session: DatabaseSession | null, user: DatabaseUser | null]> {
37const [databaseSession, databaseUser] = await Promise.all([
38this.getSession(sessionId),
39this.getUserFromSessionId(sessionId),
40]);
41return [databaseSession, databaseUser];
42}
4344public async getUserSessions(userId: string): Promise<DatabaseSession[]> {
45const result = await this.controller.getAll<SessionSchema>(
46`SELECT * FROM ${this.escapedSessionTableName} WHERE user_id = ?`,
48);
49return result.map((val) => {
50return transformIntoDatabaseSession(val);
51});
52}
5354public async setSession(databaseSession: DatabaseSession): Promise<void> {
55const value: SessionSchema = {
56id: databaseSession.id,
57user_id: databaseSession.userId,
58expires_at: Math.floor(databaseSession.expiresAt.getTime() / 1000),
59...databaseSession.attributes,
60};
61const entries = Object.entries(value).filter(([_, v]) => v !== undefined);
87}
8889private async getSession(sessionId: string): Promise<DatabaseSession | null> {
90const result = await this.controller.get<SessionSchema>(
91`SELECT * FROM ${this.escapedSessionTableName} WHERE id = ?`,
93);
94if (!result) return null;
95return transformIntoDatabaseSession(result);
96}
9798private async getUserFromSessionId(sessionId: string): Promise<DatabaseUser | null> {
99const result = await this.controller.get<UserSchema>(
100`SELECT ${this.escapedUserTableName}.* FROM ${this.escapedSessionTableName} INNER JOIN ${this.escapedUserTableName} ON ${this.escapedUserTableName}.id = ${this.escapedSessionTableName}.user_id WHERE ${this.escapedSessionTableName}.id = ?`,
102);
103if (!result) return null;
104return transformIntoDatabaseUser(result);
105}
106}
117}
118119interface SessionSchema extends RegisteredDatabaseSessionAttributes {
120id: string;
121user_id: string;
123}
124125interface UserSchema extends RegisteredDatabaseUserAttributes {
126id: string;
127}
128129function transformIntoDatabaseSession(raw: SessionSchema): DatabaseSession {
130const { id, user_id: userId, expires_at: expiresAtUnix, ...attributes } = raw;
131return {
137}
138139function transformIntoDatabaseUser(raw: UserSchema): DatabaseUser {
140const { id, ...attributes } = raw;
141return {
listSqliteTablesREADME.md1 match
1# listSqliteTables
23Returns a flat array of the names of all tables in your Val Town SQLite database.
45```ts