MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / initPrismaClient

Function initPrismaClient

packages/core/fumadb/test/shared.ts:219–322  ·  view source on GitHub ↗
(
  factory: FumaDBFactory<Schemas>,
  version: Version,
  provider: Exclude<Provider, "mongodb">,
)

Source from the content-addressed store, hash-verified

217
218const prismaDir = path.join(import.meta.dirname, "../node_modules/_prisma");
219export async function initPrismaClient<
220 Schemas extends AnySchema[],
221 Version extends Schemas[number]["version"],
222>(
223 factory: FumaDBFactory<Schemas>,
224 version: Version,
225 provider: Exclude<Provider, "mongodb">,
226): Promise<FumaDB<Schemas>> {
227 fs.mkdirSync(prismaDir, { recursive: true });
228 const hash = Date.now();
229 const schemaPath = path.join(
230 prismaDir,
231 `schema-${hash}.${version}.${provider}.prisma`,
232 );
233 const db = databases.find((str) => str.provider === provider)!;
234 const clientPath = path.join(
235 prismaDir,
236 `client-${hash}-${version}-${provider}`,
237 );
238
239 const schema = factory
240 .client(
241 prismaAdapter({
242 prisma: {},
243 provider,
244 }),
245 )
246 .generateSchema(version);
247
248 schema.path = schemaPath;
249 schema.code += `\ndatasource db {
250 provider = "${provider}"
251}
252
253generator client {
254 provider = "prisma-client"
255 output = "${clientPath}"
256}`;
257
258 fs.writeFileSync(schema.path, schema.code);
259 const env = {
260 ...process.env,
261 DATABASE_URL: db.url,
262 PRISMA_SCHEMA: schemaPath,
263 };
264
265 // Push schema to database
266 await x(
267 "node",
268 [
269 "node_modules/prisma/build/index.js",
270 "db",
271 "push",
272 "--force-reset",
273 "--accept-data-loss",
274 ],
275 {
276 nodeOptions: {

Callers 2

query.test.tsFile · 0.90
relations.test.tsFile · 0.90

Calls 2

prismaAdapterFunction · 0.90
logMethod · 0.80

Tested by

no test coverage detected