Skip to content

Commit

Permalink
Now type switch checks types in lowercase (fixes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukairo-02 committed Jul 1, 2024
1 parent 4c1afe7 commit 4f34bce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
20 changes: 10 additions & 10 deletions src/util/generators/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ const prismaToDrizzleType = (type: string, colDbName: string, prismaEnum?: UnRea
return `mysqlEnum('${colDbName}', [${prismaEnum.values.map((val) => `'${val.dbName ?? val.name}'`).join(', ')}])`;
}

switch (type) {
case 'BigInt':
switch (type.toLowerCase()) {
case 'bigint':
mySqlImports.add('bigint');
return `bigint('${colDbName}', { mode: 'bigint' })`;
case 'Boolean':
case 'boolean':
mySqlImports.add('boolean');
return `boolean('${colDbName}')`;
case 'Bytes':
case 'bytes':
// Drizzle doesn't support it yet...
throw new GeneratorError("Drizzle ORM doesn't support binary data type for MySQL");
case 'DateTime':
case 'datetime':
mySqlImports.add('datetime');
return `datetime('${colDbName}', { fsp: 3 })`;
case 'Decimal':
case 'decimal':
mySqlImports.add('decimal');
return `decimal('${colDbName}', { precision: 65, scale: 30 })`;
case 'Float':
case 'float':
mySqlImports.add('double');
return `double('${colDbName}')`;
case 'JSON':
case 'json':
mySqlImports.add('json');
return `json('${colDbName}')`;
case 'Int':
case 'int':
mySqlImports.add('int');
return `int('${colDbName}')`;
case 'String':
case 'string':
mySqlImports.add('varchar');
return `varchar('${colDbName}', { length: 191 })`;
default:
Expand Down
20 changes: 10 additions & 10 deletions src/util/generators/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ const drizzleImports = new Set<string>();
pgImports.add('pgTable');

const prismaToDrizzleType = (type: string, colDbName: string, defVal?: string) => {
switch (type) {
case 'BigInt':
switch (type.toLowerCase()) {
case 'bigint':
pgImports.add('bigint');
return `bigint('${colDbName}', { mode: 'bigint' })`;
case 'Boolean':
case 'boolean':
pgImports.add('boolean');
return `boolean('${colDbName}')`;
case 'Bytes':
case 'bytes':
// Drizzle doesn't support it yet...
throw new GeneratorError("Drizzle ORM doesn't support binary data type for PostgreSQL");
case 'DateTime':
case 'datetime':
pgImports.add('timestamp');
return `timestamp('${colDbName}', { precision: 3 })`;
case 'Decimal':
case 'decimal':
pgImports.add('decimal');
return `decimal('${colDbName}', { precision: 65, scale: 30 })`;
case 'Float':
case 'float':
pgImports.add('doublePrecision');
return `doublePrecision('${colDbName}')`;
case 'JSON':
case 'json':
pgImports.add('jsonb');
return `jsonb('${colDbName}')`;
case 'Int':
case 'int':
if (defVal === 'autoincrement') {
pgImports.add('serial');
return `serial('${colDbName}')`;
}

pgImports.add('integer');
return `integer('${colDbName}')`;
case 'String':
case 'string':
pgImports.add('text');
return `text('${colDbName}')`;
default:
Expand Down
20 changes: 10 additions & 10 deletions src/util/generators/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ const sqliteImports = new Set<string>(['sqliteTable']);
const drizzleImports = new Set<string>([]);

const prismaToDrizzleType = (type: string, colDbName: string) => {
switch (type) {
case 'BigInt':
switch (type.toLowerCase()) {
case 'bigint':
sqliteImports.add('int');
return `int('${colDbName}')`;
case 'Boolean':
case 'boolean':
sqliteImports.add('int');
return `int('${colDbName}', { mode: 'boolean' })`;
case 'Bytes':
case 'bytes':
sqliteImports.add('blob');
return `blob('${colDbName}', { mode: 'buffer' })`;
case 'DateTime':
case 'datetime':
sqliteImports.add('numeric');
return `numeric('${colDbName}')`;
case 'Decimal':
case 'decimal':
sqliteImports.add('numeric');
return `numeric('${colDbName}')`;
case 'Float':
case 'float':
sqliteImports.add('real');
return `real('${colDbName}')`;
case 'JSON':
case 'json':
sqliteImports.add('text');
return `text('${colDbName}', { mode: 'json' })`;
case 'Int':
case 'int':
sqliteImports.add('int');
return `int('${colDbName}')`;
case 'String':
case 'string':
sqliteImports.add('text');
return `text('${colDbName}')`;
default:
Expand Down

0 comments on commit 4f34bce

Please sign in to comment.