Home / Class/ PgCreateViewConvertor Class — drizzle-orm Architecture

PgCreateViewConvertor Class — drizzle-orm Architecture

Architecture documentation for the PgCreateViewConvertor class in sqlgenerator.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  29c7db66_58e5_7c94_8f18_1ca29e037da6["PgCreateViewConvertor"]
  fe4174c7_3b9c_5b26_98a0_b2395ca21939["sqlgenerator.ts"]
  29c7db66_58e5_7c94_8f18_1ca29e037da6 -->|defined in| fe4174c7_3b9c_5b26_98a0_b2395ca21939
  92517476_8e88_15a1_6b74_3facaa204ce2["can()"]
  29c7db66_58e5_7c94_8f18_1ca29e037da6 -->|method| 92517476_8e88_15a1_6b74_3facaa204ce2
  5e600847_84f4_3f13_272a_c0e1774fe434["convert()"]
  29c7db66_58e5_7c94_8f18_1ca29e037da6 -->|method| 5e600847_84f4_3f13_272a_c0e1774fe434

Relationship Graph

Source Code

drizzle-kit/src/sqlgenerator.ts lines 753–813

class PgCreateViewConvertor extends Convertor {
	can(statement: JsonStatement, dialect: Dialect): boolean {
		return statement.type === 'create_view' && dialect === 'postgresql';
	}

	convert(st: JsonCreatePgViewStatement) {
		const { definition, name: viewName, schema, with: withOption, materialized, withNoData, tablespace, using } = st;

		const name = schema ? `"${schema}"."${viewName}"` : `"${viewName}"`;

		let statement = materialized ? `CREATE MATERIALIZED VIEW ${name}` : `CREATE VIEW ${name}`;

		if (using) statement += ` USING "${using}"`;

		const options: string[] = [];
		if (withOption) {
			statement += ` WITH (`;

			Object.entries(withOption).forEach(([key, value]) => {
				if (typeof value === 'undefined') return;

				options.push(`${key.snake_case()} = ${value}`);
			});

			statement += options.join(', ');

			statement += `)`;
		}

		if (tablespace) statement += ` TABLESPACE ${tablespace}`;

		statement += ` AS (${definition})`;

		if (withNoData) statement += ` WITH NO DATA`;

		statement += `;`;

		return statement;
	}
}

class MySqlCreateViewConvertor extends Convertor {
	can(statement: JsonStatement, dialect: Dialect): boolean {
		return statement.type === 'mysql_create_view' && dialect === 'mysql';
	}

	convert(st: JsonCreateMySqlViewStatement) {
		const { definition, name, algorithm, sqlSecurity, withCheckOption, replace } = st;

		let statement = `CREATE `;
		statement += replace ? `OR REPLACE ` : '';
		statement += algorithm ? `ALGORITHM = ${algorithm}\n` : '';
		statement += sqlSecurity ? `SQL SECURITY ${sqlSecurity}\n` : '';
		statement += `VIEW \`${name}\` AS (${definition})`;
		statement += withCheckOption ? `\nWITH ${withCheckOption} CHECK OPTION` : '';

		statement += ';';

		return statement;
	}
}

Domain

Frequently Asked Questions

What is the PgCreateViewConvertor class?
PgCreateViewConvertor is a class in the drizzle-orm codebase, defined in drizzle-kit/src/sqlgenerator.ts.
Where is PgCreateViewConvertor defined?
PgCreateViewConvertor is defined in drizzle-kit/src/sqlgenerator.ts at line 753.

Analyze Your Own Codebase

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

Try Supermodel Free