import * as schema from '@crumbs/core/db'
import {SQL} from 'bun'
import {drizzle} from 'drizzle-orm/bun-sql'

import {env} from '../env'

const client = new SQL(env.DATABASE_URL)

export const db = drizzle({client, schema})
export {schema}

export type DbOrTx =
  | typeof db
  | Parameters<Parameters<typeof db.transaction>[0]>[0]
