import { drizzle as pgDrizzle } from 'drizzle-orm/postgres-js';
import { drizzle as awsDrizzle } from 'drizzle-orm/aws-data-api/pg';
import * as schema from '../schema/schema';
import postgres from 'postgres';
import { Resource } from "sst";
import { RDSDataClient } from "@aws-sdk/client-rds-data";
import config from "../constants/config";
const isLocal = config.ENV !== 'production';
const localDrizzle = () => {
const client = postgres(process.env.DB_URL!, { max: 1 });
const db = pgDrizzle(client, { schema: schema });
return { client, db };
};
const remoteDrizzle = () => {
const client = new RDSDataClient({});
const db = awsDrizzle(client, {
database: Resource.RegPostgres.database,
secretArn: Resource.RegPostgres.secretArn,
resourceArn: Resource.RegPostgres.clusterArn,
schema: schema
});
return { client, db };
}
const { client, db } = isLocal ? localDrizzle() : remoteDrizzle();
export { client, db }
import { drizzle as pgDrizzle } from 'drizzle-orm/postgres-js';
import { drizzle as awsDrizzle } from 'drizzle-orm/aws-data-api/pg';
import * as schema from '../schema/schema';
import postgres from 'postgres';
import { Resource } from "sst";
import { RDSDataClient } from "@aws-sdk/client-rds-data";
import config from "../constants/config";
const isLocal = config.ENV !== 'production';
const localDrizzle = () => {
const client = postgres(process.env.DB_URL!, { max: 1 });
const db = pgDrizzle(client, { schema: schema });
return { client, db };
};
const remoteDrizzle = () => {
const client = new RDSDataClient({});
const db = awsDrizzle(client, {
database: Resource.RegPostgres.database,
secretArn: Resource.RegPostgres.secretArn,
resourceArn: Resource.RegPostgres.clusterArn,
schema: schema
});
return { client, db };
}
const { client, db } = isLocal ? localDrizzle() : remoteDrizzle();
export { client, db }