mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-27 01:40:28 +01:00
Migrate from postgres to sqlite
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import postgres from 'postgres'
|
||||
import { drizzle } from 'drizzle-orm/postgres-js'
|
||||
import { drizzle } from 'drizzle-orm/d1'
|
||||
import * as schema from '../database/schema'
|
||||
|
||||
export { sql, eq, and, or, asc, desc, sum, isNull } from 'drizzle-orm'
|
||||
@@ -7,8 +6,7 @@ export { sql, eq, and, or, asc, desc, sum, isNull } from 'drizzle-orm'
|
||||
export const tables = schema
|
||||
|
||||
export function useDrizzle() {
|
||||
const config = useRuntimeConfig()
|
||||
return drizzle(postgres(config.postgres.url, { prepare: false, max: 50 }), { schema })
|
||||
return drizzle(hubDatabase(), { schema })
|
||||
}
|
||||
|
||||
export type UserInsert = typeof schema.users.$inferInsert
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { serial, timestamp } from 'drizzle-orm/pg-core'
|
||||
/**
|
||||
* A centralized list of standardized Drizzle ORM schema field definitions to prevent duplication errors
|
||||
*/
|
||||
import { integer } from 'drizzle-orm/sqlite-core'
|
||||
|
||||
export const createdAt = timestamp('created_at', { mode: 'string', withTimezone: true, precision: 0 }).defaultNow()
|
||||
export const updatedAt = timestamp('updated_at', { mode: 'string', withTimezone: true, precision: 0 }).defaultNow().$onUpdateFn(() => sql`(current_timestamp)`)
|
||||
export const id = serial('id').primaryKey()
|
||||
export const id = integer('id').primaryKey()
|
||||
|
||||
export const createdAt
|
||||
= integer('created_at', { mode: 'timestamp' })
|
||||
.$defaultFn(() => new Date())
|
||||
|
||||
export const updatedAt
|
||||
= integer('updated_at', { mode: 'timestamp' })
|
||||
.$onUpdateFn(() => new Date())
|
||||
.$defaultFn(() => new Date())
|
||||
|
||||
export const timestamps = {
|
||||
createdAt,
|
||||
|
||||
Reference in New Issue
Block a user