import postgres from 'postgres'
import { drizzle } from 'drizzle-orm/postgres-js'
import type { PostgresJsDatabase } from 'drizzle-orm/postgres-js'
import type { Schema } from '../index.js'

export function createPostgresJsClient<S extends Schema>(opts: {
  connectionString: string
  schema?: S
}): PostgresJsDatabase<S> {
  const client = postgres(opts.connectionString)
  return drizzle(client, { schema: opts.schema })
}
