5/**
6* Every Val Town account comes with its own private
7* [SQLite database](https://www.sqlite.org/) that
8* is accessible from any of your vals.
9* ([Docs ↗](https://docs.val.town/std/sqlite))
115116// adapted from
117// https://github.com/tursodatabase/libsql-client-ts/blob/17dd996b840c950dd22b871adfe4ba0eb4a5ead3/packages/libsql-client/src/sqlite3.ts#L314C1-L337C2
118function rowFromSql(
119sqlRow: Array<unknown>,
sqliteExplorerAppREADME.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
iframeGridInfinitemain.tsx11 matches
1/**
2* This val creates an infinite grid of iframes with thick draggable borders.
3* It includes a welcome modal, fixes the drag state issue, and stores iframe URLs in a database.
4*/
565const [showModal, setShowModal] = useState(true);
66const [iframes, setIframes] = useState([]);
67const [urlDatabase, setUrlDatabase] = useState({});
68const [isLoading, setIsLoading] = useState(false);
69const gridRef = useRef(null);
86useEffect(() => {
87updateIframes();
88}, [position, windowSize, urlDatabase]);
8990useEffect(() => {
91loadUrlDatabase();
92}, []);
93131left,
132top,
133url: urlDatabase[key] || '',
134});
135}
150});
151if (!response.ok) throw new Error('Failed to submit URL');
152const updatedDatabase = await response.json();
153setUrlDatabase(updatedDatabase);
154} catch (error) {
155console.error('Error submitting URL:', error);
160};
161162const loadUrlDatabase = async () => {
163try {
164const response = await fetch('/api/load-urls');
165if (!response.ok) throw new Error('Failed to load URLs');
166const loadedUrls = await response.json();
167setUrlDatabase(loadedUrls);
168} catch (error) {
169console.error('Error loading URLs:', error);
229230const result = await sqlite.execute(`SELECT * FROM ${KEY}_urls`);
231const updatedDatabase = Object.fromEntries(result.rows.map(row => [row.key, row.url]));
232233return new Response(JSON.stringify(updatedDatabase), {
234headers: { 'Content-Type': 'application/json' },
235});
1## Random Maps API
23This val returns one or more random rows from a [SQLite database](https://docs.val.town/std/sqlite/usage/) as a JSON array. Each item represents a digitised map from a collection and contains the following properties:
45```js
bikeInventorymain.tsx4 matches
123const initDb = async () => {
124try {
125const database = await init({ appId: APP_ID });
126setDb(database);
127console.log("InstantDB initialized successfully");
128} catch (err) {
129console.error("Error initializing InstantDB:", err);
130setError(`Failed to initialize database: ${err.message}`);
131}
132};
166}
167} else {
168setError("Database not initialized. Please refresh the page.");
169}
170};
sqliteExplorerAppREADME.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
1This val implements a simple key/value database with GitHub, in a CRUD way.
23The key is a file path within a repository. The value is the file content.
add_to_notion_w_aiREADME.md4 matches
1Uses instructor and open ai (with gpt-4-turbo) to process any content into a notion database entry.
23Use `addToNotion` with any database id and content.
45```
10```
1112Prompts are created based on your database name, database description, property name, property type, property description, and if applicable, property options (and their descriptions).
1314Supports: checkbox, date, multi_select, number, rich_text, select, status, title, url, email
1516- Uses `NOTION_API_KEY`, `OPENAI_API_KEY` stored in env variables and uses [Valtown blob storage](https://esm.town/v/std/blob) to store information about the database.
17- Use `get_notion_db_info` to use the stored blob if exists or create one, use `get_and_save_notion_db_info` to create a new blob (and replace an existing one if exists).
add_to_notion_w_aimain.tsx17 matches
37function createPrompt(title, description, properties) {
38let prompt =
39"You are processing content into a database. Based on the title of the database, its properties, their types and options, and any existing descriptions, infer appropriate values for the fields:\n";
40prompt += `Database Title: ${title}\n`;
4142if (description) {
43prompt += `Database Description: ${description}\n\n`;
44} else {
45prompt += "\n";
111}
112113async function get_and_save_notion_db_processed_properties(databaseId)
114{
115const response = await notion.databases.retrieve({ database_id: databaseId });
116const db_id = response.id.replaceAll("-", "");
117const processed_properties = processProperties(response);
122}
123124async function get_notion_db_info(databaseId) {
125databaseId = databaseId.replaceAll("-", "");
126let db_info = null;
127try {
128db_info = await blob.getJSON(databaseId);
129if (!db_info) {
130throw new Error("db_info is null or undefined");
131}
132} catch (error) {
133db_info = await get_and_save_notion_db_processed_properties(databaseId);
134}
135db_info["zod_schema"] = createZodSchema(db_info["filteredProps"]);
137}
138139async function get_and_save_notion_db_info(databaseId) {
140databaseId = databaseId.replaceAll("-", "");
141let db_info = await get_and_save_notion_db_processed_properties(databaseId);
142db_info["zod_schema"] = createZodSchema(db_info["filteredProps"]);
143return db_info;
283}
284285async function addToNotion(databaseId, text) {
286databaseId = databaseId.replaceAll("-", "");
287const properties = await process_text(databaseId, text);
288console.log(properties);
289const response = await notion.pages.create({
290"parent": {
291"type": "database_id",
292"database_id": databaseId,
293},
294"properties": properties,
1import { Database } from "https://esm.sh/duckdb-async";
23export default async function server(request: Request): Promise<Response> {
1011try {
12const db = await Database.create(':memory:');
13await db.all('LOAD httpfs');
14const result = await db.all(`SELECT * FROM '${dataUrl}' LIMIT 5`);