notionRecurringTasksmain.tsx4 matches
3import dayjs from "npm:dayjs";
45const DATABASE_ID = "519446a0d3ed47038fffd669b9ece770";
6const notion = new Client({ auth: process.env.NOTION_API_KEY });
71314export default async function(interval: Interval) {
15const response = await notion.databases.query({
16database_id: DATABASE_ID,
17filter: {
18and: [
4041const nextItem = {
42parent: { database_id: DATABASE_ID },
43properties: {
44...item.properties,
bloodyOliveMolluskREADME.md1 match
1WIP SQLite graph database based on https://github.com/dpapathanasiou/simple-graph
26}
2728// generate a new random token, and saves it to the database
29async generateToken(email: string): Promise<string> {
30const { options: { tokenBytes, validDuration } } = this;
43}
4445// check a token against the database that it's valid and not expired
46// a valid match will return the id on record
47// an expired match will return null
69}
7071// remove expired/unclaimed tokens from the database. run this periodically to keep lookups fast
72cull() {
73this.deleteRows(`expires < ${this.now()}`);
featureflagsREADME.md1 match
34# How it works
3536This val works by hashing the `userId` and using the resulting value to determine whether a flag should be enabled or disabled. In a 50% rollout, for example, the numeric hash of the `userId` is taken and divided by the maximum hash value. If the result is less than the rollout percentage, the flag is enabled. This allows for completely stateless feature flags, no database required.
3738To prevent the same users getting features first all of the time, the flag name is prepended to the `userId` before hashing.
tenseRoseTiglonREADME.md1 match
1# VALL-E
23LLM code generation for vals! Make apps with a frontend, backend, and database.
45It's a bit of work to get this running, but it's worth it.
1# VALL-E
23LLM code generation for vals! Make apps with a frontend, backend, and database.
45It's a bit of work to get this running, but it's worth it.
8import { ValTownBlobNotFoundError } from "https://esm.town/v/std/ValTownBlobNotFoundError";
910// Initialize the database
11await sqlite.execute(`
12CREATE TABLE IF NOT EXISTS blobs (
lucia_demomain.tsx2 matches
26interface Register {
27Lucia: typeof lucia;
28DatabaseUserAttributes: DatabaseUserAttributes;
29}
30}
3132interface DatabaseUserAttributes {
33username: string;
34}
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 {
116{
117name: "Use Val Town SQLite to store data",
118prompt: "Write a val that uses an SQLite database",
119code: `import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
120