decentralised message store
at main 1.5 kB view raw
1import { sql } from "drizzle-orm"; 2import { integer, text, index } from "drizzle-orm/sqlite-core"; 3import { sqliteTable } from "drizzle-orm/sqlite-core"; 4import { createInsertSchema, createSelectSchema } from "drizzle-zod"; 5import { z } from "zod"; 6 7// NOTE:: for an initial mvp, we are supporting only sqlite and storing all the messages in a single table. 8// for an actual production release, we will likely be storing messages in separate tables or separate sqlite files (depending on config). 9export const messagesTable = sqliteTable( 10 "messages", 11 { 12 id: text("id").primaryKey(), 13 channelAtUri: text("channel_at_uri"), 14 authorDid: text("author_did").notNull(), 15 content: text("content").notNull(), 16 sentAt: integer("created_at", { mode: "timestamp" }).notNull(), 17 createdAt: integer("created_at", { mode: "timestamp" }) 18 .notNull() 19 .default(sql`(unixepoch('now'))`), 20 }, 21 (table) => [ 22 index("messages_channel_idx").on(table.channelAtUri, table.createdAt), 23 index("messages_author_idx").on(table.authorDid), 24 ], 25); 26 27export const shardMessagesSelectSchema = createSelectSchema(messagesTable); 28export const shardMessageSelectSchemaArray = z.array(shardMessagesSelectSchema); 29export const shardMessagesInsertSchema = createInsertSchema(messagesTable); 30 31export type ShardMessageSelect = z.infer<typeof shardMessagesSelectSchema>; 32export type ShardMessageInsert = z.infer<typeof shardMessagesInsertSchema>;