convert() — drizzle-orm Function Reference
Architecture documentation for the convert() function in sqlgenerator.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 5e600847_84f4_3f13_272a_c0e1774fe434["convert()"] 29c7db66_58e5_7c94_8f18_1ca29e037da6["PgCreateViewConvertor"] 5e600847_84f4_3f13_272a_c0e1774fe434 -->|defined in| 29c7db66_58e5_7c94_8f18_1ca29e037da6 style 5e600847_84f4_3f13_272a_c0e1774fe434 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/sqlgenerator.ts lines 758–812
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
Subdomains
Defined In
Source
Frequently Asked Questions
What does convert() do?
convert() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/sqlgenerator.ts.
Where is convert() defined?
convert() is defined in drizzle-kit/src/sqlgenerator.ts at line 758.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free