@ -10,7 +10,6 @@ import type {
MessageEntity ,
} from "./common.ts" ;
import type { CommittedMessage } from "../types" ;
import { env } from "../server/env.js" ;
// export const pool = new Pool({
// connectionString: env.POSTGRES_CONNECTION_STRING as string,
@ -21,19 +20,26 @@ import { env } from "../server/env.js";
// pool,
// });
const dialect = new NeonDialect ( {
neon : neon ( env . POSTGRES_CONNECTION_STRING as string ) ,
} ) ;
export function getDbClient ( POSTGRES_CONNECTION_STRING : string ) {
const dialect = new NeonDialect ( {
neon : neon ( POSTGRES_CONNECTION_STRING as string ) ,
} ) ;
// Database interface is passed to Kysely's constructor, and from now on, Kysely
// knows your database structure.
// Dialect is passed to Kysely's constructor, and from now on, Kysely knows how
// to communicate with your database.
export const dbClient = new Kysely < Database > ( {
// Database interface is passed to Kysely's constructor, and from now on, Kysely
// knows your database structure.
// Dialect is passed to Kysely's constructor, and from now on, Kysely knows how
// to communicate with your database.
const dbClient = new Kysely < Database > ( {
dialect ,
} ) ;
} ) ;
const conversations : ConversationEntity = {
return dbClient ;
}
export function getDb ( POSTGRES_CONNECTION_STRING : string ) {
const dbClient = getDbClient ( POSTGRES_CONNECTION_STRING ) ;
const conversations : ConversationEntity = {
construct : ( conversation ) = > conversation ,
create : async ( conversation ) = > {
const insertedRows = await dbClient
@ -84,9 +90,9 @@ const conversations: ConversationEntity = {
. execute ( ) ;
return rows as Array < CommittedMessage > ;
} ,
} ;
} ;
const facts : FactEntity = {
const facts : FactEntity = {
construct : ( fact ) = > fact ,
create : async ( fact ) = > {
const insertedRows = await dbClient
@ -135,9 +141,9 @@ const facts: FactEntity = {
. execute ( ) ;
return rows ;
} ,
} ;
} ;
const factTriggers : FactTriggerEntity = {
const factTriggers : FactTriggerEntity = {
construct : ( factTrigger ) = > factTrigger ,
create : async ( factTrigger ) = > {
const insertedRows = await dbClient
@ -199,9 +205,9 @@ const factTriggers: FactTriggerEntity = {
. execute ( ) ;
return rows ;
} ,
} ;
} ;
const messages : MessageEntity = {
const messages : MessageEntity = {
construct : ( message ) = > message ,
create : async ( message ) = > {
const insertedRows = await dbClient
@ -254,11 +260,14 @@ const messages: MessageEntity = {
. execute ( ) ) as Array < CommittedMessage > ;
return rows ;
} ,
} ;
} ;
export const db = {
const db = {
conversations ,
facts ,
factTriggers ,
messages ,
} ;
} ;
return db ;
}