Dan
Dan
TtRPC
Created by Trader Launchpad on 11/9/2023 in #❓-help
[How To?] Create a record in database on form submission...
Just searching through for something else but stumbled across your message. Example of sqlite table for cloudflare:
export const times = sqliteTable('times', {
id: text('id')
.notNull()
.primaryKey()
.$default(() => crypto.randomUUID()),
updatedAt: integer('updated_at', { mode: 'timestamp' })
.notNull()
.$default(() => new Date()),
createdAt: integer('created_at', { mode: 'timestamp' })
.notNull()
.$default(() => new Date()),
location: text('location').notNull(),
content: text('content', { mode: 'json' }).notNull().$type<TimeContent>(),
});
export const times = sqliteTable('times', {
id: text('id')
.notNull()
.primaryKey()
.$default(() => crypto.randomUUID()),
updatedAt: integer('updated_at', { mode: 'timestamp' })
.notNull()
.$default(() => new Date()),
createdAt: integer('created_at', { mode: 'timestamp' })
.notNull()
.$default(() => new Date()),
location: text('location').notNull(),
content: text('content', { mode: 'json' }).notNull().$type<TimeContent>(),
});
It's not as performant as uuid on postgres but the purpose to use uuid in my case is to avoid that people can guess a sequence. If there would be a need for a sortable id based on time, you could use uuidv7, there are some implementations, e.g. https://github.com/LiosK/uuidv7, but they are roughly 4x slower than uuid4.
5 replies