@@ -32,11 +32,19 @@ export const imports = [
3232 'varchar' ,
3333 'year' ,
3434 'mysqlEnum' ,
35+ 'singlestoreEnum' ,
36+ // TODO: add new type BSON
37+ // TODO: add new type Blob
38+ // TODO: add new type UUID
39+ // TODO: add new type GUID
40+ // TODO: add new type Vector
41+ // TODO: add new type GeoPoint
3542] as const ;
3643export type Import = typeof imports [ number ] ;
3744
3845const mysqlImportsList = new Set ( [
3946 'mysqlTable' ,
47+ 'singlestoreTable' ,
4048 ...imports ,
4149] ) ;
4250
@@ -106,6 +114,7 @@ export const ddlToTypeScript = (
106114 ddl : MysqlDDL ,
107115 viewColumns : ViewColumn [ ] ,
108116 casing : Casing ,
117+ vendor : 'mysql' | 'singlestore' ,
109118) => {
110119 const withCasing = prepareCasing ( casing ) ;
111120
@@ -115,9 +124,9 @@ export const ddlToTypeScript = (
115124 }
116125
117126 const imports = new Set < string > ( [
118- ' mysqlTable',
119- ' mysqlSchema',
120- ' AnyMySqlColumn',
127+ vendor === 'mysql' ? ' mysqlTable' : 'signlestoreTable ',
128+ vendor === 'mysql' ? ' mysqlSchema' : 'singlestoreSchema ',
129+ vendor === 'mysql' ? ' AnyMySqlColumn' : 'AnySinsgleStoreColumn ',
121130 ] ) ;
122131
123132 const viewEntities = viewColumns . map ( ( it ) => {
@@ -132,24 +141,25 @@ export const ddlToTypeScript = (
132141 if ( it . entityType === 'fks' ) imports . add ( 'foreignKey' ) ;
133142 if ( it . entityType === 'pks' && ( it . columns . length > 1 || it . nameExplicit ) ) imports . add ( 'primaryKey' ) ;
134143 if ( it . entityType === 'checks' ) imports . add ( 'check' ) ;
135- if ( it . entityType === 'views' ) imports . add ( ' mysqlView') ;
144+ if ( it . entityType === 'views' ) imports . add ( vendor === 'mysql' ? ' mysqlView' : 'singlestoreView ') ;
136145
137146 if ( it . entityType === 'columns' || it . entityType === 'viewColumn' ) {
138147 const grammarType = typeFor ( it . type ) ;
139- if ( grammarType ) imports . add ( grammarType . drizzleImport ( ) ) ;
148+ if ( grammarType ) imports . add ( grammarType . drizzleImport ( vendor ) ) ;
140149 if ( mysqlImportsList . has ( it . type ) ) imports . add ( it . type ) ;
141150 }
142151 }
143152
144153 const tableStatements = [ ] as string [ ] ;
145154 for ( const table of ddl . tables . list ( ) ) {
146- let statement = `export const ${ withCasing ( table . name ) } = mysqlTable ("${ table . name } ", {\n` ;
155+ let statement = `export const ${ withCasing ( table . name ) } = ${ vendor } Table ("${ table . name } ", {\n` ;
147156 statement += createTableColumns (
148157 ddl . columns . list ( { table : table . name } ) ,
149158 ddl . pks . one ( { table : table . name } ) ,
150159 ddl . fks . list ( { table : table . name } ) ,
151160 withCasing ,
152161 casing ,
162+ vendor ,
153163 ) ;
154164 statement += '}' ;
155165
@@ -190,8 +200,8 @@ export const ddlToTypeScript = (
190200 const columns = viewColumns . filter ( ( x ) => x . view === view . name ) ;
191201
192202 let statement = '' ;
193- statement += `export const ${ withCasing ( name ) } = mysqlView ("${ name } ", {\n` ;
194- statement += createViewColumns ( columns , withCasing , casing ) ;
203+ statement += `export const ${ withCasing ( name ) } = ${ vendor } View ("${ name } ", {\n` ;
204+ statement += createViewColumns ( columns , withCasing , casing , vendor ) ;
195205 statement += '})' ;
196206
197207 statement += algorithm ? `.algorithm("${ algorithm } ")` : '' ;
@@ -206,7 +216,7 @@ export const ddlToTypeScript = (
206216 [ ...imports ] . join (
207217 ', ' ,
208218 )
209- } } from "drizzle-orm/mysql -core"\nimport { sql } from "drizzle-orm"\n\n`;
219+ } } from "drizzle-orm/${ vendor } -core"\nimport { sql } from "drizzle-orm"\n\n`;
210220
211221 let decalrations = '' ;
212222 decalrations += tableStatements . join ( '\n\n' ) ;
@@ -250,12 +260,12 @@ const column = (
250260 rawCasing : Casing ,
251261 defaultValue : Column [ 'default' ] ,
252262 autoincrement : boolean ,
253- onUpdate : boolean ,
263+ vendor : 'mysql' | 'singlestore' ,
254264) => {
255265 let lowered = type . startsWith ( 'enum(' ) ? type : type . toLowerCase ( ) ;
256266 if ( lowered . startsWith ( 'enum' ) ) {
257267 const values = parseEnum ( lowered ) . map ( ( it ) => `"${ it . replaceAll ( "''" , "'" ) . replaceAll ( '"' , '\\"' ) } "` ) . join ( ',' ) ;
258- let out = `${ casing ( name ) } : mysqlEnum (${ dbColumnName ( { name, casing : rawCasing , withMode : true } ) } [${ values } ])` ;
268+ let out = `${ casing ( name ) } : ${ vendor } Enum (${ dbColumnName ( { name, casing : rawCasing , withMode : true } ) } [${ values } ])` ;
259269
260270 const { default : def } = Enum . toTs ( '' , defaultValue ) ;
261271 out += def ? `.default(${ def } )` : '' ;
@@ -290,14 +300,15 @@ const createTableColumns = (
290300 fks : ForeignKey [ ] ,
291301 casing : ( val : string ) => string ,
292302 rawCasing : Casing ,
303+ vendor : 'mysql' | 'singlestore' ,
293304) : string => {
294305 let statement = '' ;
295306
296307 for ( const it of columns ) {
297308 const isPK = pk && pk . columns . length === 1 && pk . columns [ 0 ] === it . name ;
298309
299310 statement += '\t' ;
300- statement += column ( it . type , it . name , casing , rawCasing , it . default , it . autoIncrement , it . onUpdateNow ) ;
311+ statement += column ( it . type , it . name , casing , rawCasing , it . default , it . autoIncrement , vendor ) ;
301312
302313 statement += isPK ? '.primaryKey()' : '' ;
303314 statement += it . notNull && ! isPK ? '.notNull()' : '' ;
@@ -317,7 +328,7 @@ const createTableColumns = (
317328 const onUpdate = fk . onUpdate !== 'NO ACTION' ? fk . onUpdate : null ;
318329 const params = { onDelete, onUpdate } ;
319330
320- const typeSuffix = isCyclic ( fk ) ? ' : AnyMySqlColumn' : '' ;
331+ const typeSuffix = isCyclic ( fk ) ? vendor === 'mysql' ? ' : AnyMySqlColumn' : ': AnySinsgleStoreColumn ' : '' ;
321332
322333 const paramsStr = objToStatement2 ( params ) ;
323334 if ( paramsStr ) {
@@ -340,12 +351,17 @@ const createTableColumns = (
340351 return statement ;
341352} ;
342353
343- const createViewColumns = ( columns : ViewColumn [ ] , casing : ( value : string ) => string , rawCasing : Casing ) => {
354+ const createViewColumns = (
355+ columns : ViewColumn [ ] ,
356+ casing : ( value : string ) => string ,
357+ rawCasing : Casing ,
358+ vendor : 'mysql' | 'singlestore' ,
359+ ) => {
344360 let statement = '' ;
345361
346362 for ( const it of columns ) {
347363 statement += '\n' ;
348- statement += column ( it . type , it . name , casing , rawCasing , null , false , false ) ;
364+ statement += column ( it . type , it . name , casing , rawCasing , null , false , vendor ) ;
349365 statement += it . notNull ? '.notNull()' : '' ;
350366 statement += ',\n' ;
351367 }
0 commit comments