MCPcopy
hub / github.com/drizzle-team/drizzle-orm / prepareServer

Function prepareServer

drizzle-kit/src/serializer/studio.ts:686–848  ·  view source on GitHub ↗
(
	{
		dialect,
		driver,
		packageName,
		databaseName,
		proxy,
		transactionProxy,
		customDefaults,
		schema: drizzleSchema,
		relations,
		dbHash,
		casing,
		schemaFiles,
	}: Setup,
	app?: Hono,
)

Source from the content-addressed store, hash-verified

684};
685
686export const prepareServer = async (
687 {
688 dialect,
689 driver,
690 packageName,
691 databaseName,
692 proxy,
693 transactionProxy,
694 customDefaults,
695 schema: drizzleSchema,
696 relations,
697 dbHash,
698 casing,
699 schemaFiles,
700 }: Setup,
701 app?: Hono,
702): Promise<Server> => {
703 app = app !== undefined ? app : new Hono();
704
705 app.use(compress());
706 app.use(async (ctx, next) => {
707 await next();
708 // * https://wicg.github.io/private-network-access/#headers
709 // * https://github.com/drizzle-team/drizzle-orm/issues/1857#issuecomment-2395724232
710 ctx.header('Access-Control-Allow-Private-Network', 'true');
711 });
712 app.use(cors());
713 app.onError((err, ctx) => {
714 console.error(err);
715 return ctx.json({
716 status: 'error',
717 error: err.message,
718 });
719 });
720
721 const relationalSchema: Record<string, unknown> = {
722 ...Object.fromEntries(
723 Object.entries(drizzleSchema)
724 .map(([schemaName, schema]) => {
725 // have unique keys across schemas
726 const mappedTableEntries = Object.entries(schema).map(
727 ([tableName, table]) => {
728 return [`__${schemaName}__.${tableName}`, table];
729 },
730 );
731
732 return mappedTableEntries;
733 })
734 .flat(),
735 ),
736 ...relations,
737 };
738
739 const relationsConfig = extractTablesRelationalConfig(
740 relationalSchema,
741 createTableRelationsHelpers,
742 );
743

Callers 2

startServerFromSetupFunction · 0.85
schema.tsFile · 0.85

Calls 5

extractRelationsFunction · 0.85
proxyFunction · 0.85
jsonStringifyFunction · 0.85
transactionProxyFunction · 0.85

Tested by

no test coverage detected