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

pushSQLiteSchema() — drizzle-orm Function Reference

Architecture documentation for the pushSQLiteSchema() function in api.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  c7dae276_9495_03b3_6785_ff0423e3125c["pushSQLiteSchema()"]
  e668bfef_9125_1ef0_2f94_a0f9605584bd["api.ts"]
  c7dae276_9495_03b3_6785_ff0423e3125c -->|defined in| e668bfef_9125_1ef0_2f94_a0f9605584bd
  116b704a_4069_7b7b_bc9f_8c24642fc375["generateSQLiteDrizzleJson()"]
  c7dae276_9495_03b3_6785_ff0423e3125c -->|calls| 116b704a_4069_7b7b_bc9f_8c24642fc375
  5f4d3311_e879_6740_786e_659afa534b5a["sqlitePushIntrospect()"]
  c7dae276_9495_03b3_6785_ff0423e3125c -->|calls| 5f4d3311_e879_6740_786e_659afa534b5a
  dec1e114_a97f_91d6_7d9a_a12a7c1789b4["squashSqliteScheme()"]
  c7dae276_9495_03b3_6785_ff0423e3125c -->|calls| dec1e114_a97f_91d6_7d9a_a12a7c1789b4
  5e0b1139_8050_e207_b519_7736291ee6af["logSuggestionsAndReturn()"]
  c7dae276_9495_03b3_6785_ff0423e3125c -->|calls| 5e0b1139_8050_e207_b519_7736291ee6af
  style c7dae276_9495_03b3_6785_ff0423e3125c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/api.ts lines 270–327

export const pushSQLiteSchema = async (
	imports: Record<string, unknown>,
	drizzleInstance: LibSQLDatabase<any>,
) => {
	const { applySqliteSnapshotsDiff } = await import('./snapshotsDiffer');
	const { sql } = await import('drizzle-orm');

	const db: SQLiteDB = {
		query: async (query: string, params?: any[]) => {
			const res = drizzleInstance.all<any>(sql.raw(query));
			return res;
		},
		run: async (query: string) => {
			return Promise.resolve(drizzleInstance.run(sql.raw(query))).then(
				() => {},
			);
		},
	};

	const cur = await generateSQLiteDrizzleJson(imports);
	const { schema: prev } = await sqlitePushIntrospect(db, []);

	const validatedPrev = sqliteSchema.parse(prev);
	const validatedCur = sqliteSchema.parse(cur);

	const squashedPrev = squashSqliteScheme(validatedPrev, 'push');
	const squashedCur = squashSqliteScheme(validatedCur, 'push');

	const { statements, _meta } = await applySqliteSnapshotsDiff(
		squashedPrev,
		squashedCur,
		tablesResolver,
		columnsResolver,
		sqliteViewsResolver,
		validatedPrev,
		validatedCur,
		'push',
	);

	const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn(
		db,
		statements,
		squashedPrev,
		squashedCur,
		_meta!,
	);

	return {
		hasDataLoss: shouldAskForApprove,
		warnings: infoToPrint,
		statementsToExecute,
		apply: async () => {
			for (const dStmnt of statementsToExecute) {
				await db.query(dStmnt);
			}
		},
	};
};

Domain

Subdomains

Frequently Asked Questions

What does pushSQLiteSchema() do?
pushSQLiteSchema() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/api.ts.
Where is pushSQLiteSchema() defined?
pushSQLiteSchema() is defined in drizzle-kit/src/api.ts at line 270.
What does pushSQLiteSchema() call?
pushSQLiteSchema() calls 4 function(s): generateSQLiteDrizzleJson, logSuggestionsAndReturn, sqlitePushIntrospect, squashSqliteScheme.

Analyze Your Own Codebase

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

Try Supermodel Free