Home / Function/ prepareSQLiteSchema() — drizzle-orm Function Reference

prepareSQLiteSchema() — drizzle-orm Function Reference

Architecture documentation for the prepareSQLiteSchema() function in studio.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  102b5c78_8ca8_423e_083d_8ea0d14cc0f1["prepareSQLiteSchema()"]
  82de12f8_a8ca_9d38_8da8_9ac945d81e01["studio.ts"]
  102b5c78_8ca8_423e_083d_8ea0d14cc0f1 -->|defined in| 82de12f8_a8ca_9d38_8da8_9ac945d81e01
  72630e5c_93c3_75d3_29f3_af0928ebe15c["studio.handler()"]
  72630e5c_93c3_75d3_29f3_af0928ebe15c -->|calls| 102b5c78_8ca8_423e_083d_8ea0d14cc0f1
  54221957_c725_0bfe_4345_4f3837d39296["safeRegister()"]
  102b5c78_8ca8_423e_083d_8ea0d14cc0f1 -->|calls| 54221957_c725_0bfe_4345_4f3837d39296
  style 102b5c78_8ca8_423e_083d_8ea0d14cc0f1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/serializer/studio.ts lines 163–198

export const prepareSQLiteSchema = async (path: string | string[]) => {
	const imports = prepareFilenames(path);
	const sqliteSchema: Record<string, Record<string, AnySQLiteTable>> = {
		public: {},
	};
	const relations: Record<string, Relations> = {};

	// files content as string
	const files = imports.map((it, index) => ({
		// get the file name from the path
		name: it.split('/').pop() || `schema${index}.ts`,
		content: fs.readFileSync(it, 'utf-8'),
	}));

	const { unregister } = await safeRegister();
	for (let i = 0; i < imports.length; i++) {
		const it = imports[i];

		const i0: Record<string, unknown> = require(`${it}`);
		const i0values = Object.entries(i0);

		i0values.forEach(([k, t]) => {
			if (is(t, SQLiteTable)) {
				const schema = 'public'; // sqlite does not have schemas
				sqliteSchema[schema][k] = t;
			}

			if (is(t, Relations)) {
				relations[k] = t;
			}
		});
	}
	unregister();

	return { schema: sqliteSchema, relations, files };
};

Domain

Subdomains

Called By

Frequently Asked Questions

What does prepareSQLiteSchema() do?
prepareSQLiteSchema() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/serializer/studio.ts.
Where is prepareSQLiteSchema() defined?
prepareSQLiteSchema() is defined in drizzle-kit/src/serializer/studio.ts at line 163.
What does prepareSQLiteSchema() call?
prepareSQLiteSchema() calls 1 function(s): safeRegister.
What calls prepareSQLiteSchema()?
prepareSQLiteSchema() is called by 1 function(s): studio.handler.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free