1use crate::parser::SqlDialect;
12use once_cell::sync::Lazy;
13use regex::Regex;
14
15pub struct TypeMapper;
17
18impl TypeMapper {
19 pub fn convert(stmt: &str, from: SqlDialect, to: SqlDialect) -> String {
21 match (from, to) {
22 (SqlDialect::MySql, SqlDialect::Postgres) => Self::mysql_to_postgres(stmt),
23 (SqlDialect::MySql, SqlDialect::Sqlite) => Self::mysql_to_sqlite(stmt),
24 (SqlDialect::MySql, SqlDialect::Mssql) => Self::mysql_to_mssql(stmt),
25 (SqlDialect::Postgres, SqlDialect::MySql) => Self::postgres_to_mysql(stmt),
26 (SqlDialect::Postgres, SqlDialect::Sqlite) => Self::postgres_to_sqlite(stmt),
27 (SqlDialect::Postgres, SqlDialect::Mssql) => Self::postgres_to_mssql(stmt),
28 (SqlDialect::Sqlite, SqlDialect::MySql) => Self::sqlite_to_mysql(stmt),
29 (SqlDialect::Sqlite, SqlDialect::Postgres) => Self::sqlite_to_postgres(stmt),
30 (SqlDialect::Sqlite, SqlDialect::Mssql) => Self::sqlite_to_mssql(stmt),
31 (SqlDialect::Mssql, SqlDialect::MySql) => Self::mssql_to_mysql(stmt),
32 (SqlDialect::Mssql, SqlDialect::Postgres) => Self::mssql_to_postgres(stmt),
33 (SqlDialect::Mssql, SqlDialect::Sqlite) => Self::mssql_to_sqlite(stmt),
34 _ => stmt.to_string(),
35 }
36 }
37
38 fn mysql_to_postgres(stmt: &str) -> String {
40 let mut result = stmt.to_string();
41
42 result = RE_TINYINT_BOOL.replace_all(&result, "BOOLEAN").to_string();
44 result = RE_TINYINT.replace_all(&result, "SMALLINT").to_string();
45 result = RE_SMALLINT.replace_all(&result, "SMALLINT").to_string();
46 result = RE_MEDIUMINT.replace_all(&result, "INTEGER").to_string();
47 result = RE_INT_SIZE.replace_all(&result, "INTEGER").to_string();
48 result = RE_BIGINT_SIZE.replace_all(&result, "BIGINT").to_string();
49
50 result = RE_DOUBLE
52 .replace_all(&result, "DOUBLE PRECISION")
53 .to_string();
54 result = RE_FLOAT.replace_all(&result, "REAL").to_string();
55
56 result = RE_LONGTEXT.replace_all(&result, "TEXT").to_string();
58 result = RE_MEDIUMTEXT.replace_all(&result, "TEXT").to_string();
59 result = RE_TINYTEXT.replace_all(&result, "TEXT").to_string();
60
61 result = RE_LONGBLOB.replace_all(&result, "BYTEA").to_string();
63 result = RE_MEDIUMBLOB.replace_all(&result, "BYTEA").to_string();
64 result = RE_TINYBLOB.replace_all(&result, "BYTEA").to_string();
65 result = RE_BLOB.replace_all(&result, "BYTEA").to_string();
66 result = RE_VARBINARY.replace_all(&result, "BYTEA").to_string();
67 result = RE_BINARY.replace_all(&result, "BYTEA").to_string();
68
69 result = RE_DATETIME.replace_all(&result, "TIMESTAMP").to_string();
71
72 result = RE_JSON.replace_all(&result, "JSONB").to_string();
74
75 result = RE_ENUM.replace_all(&result, "VARCHAR(255)").to_string();
77
78 result = RE_SET.replace_all(&result, "VARCHAR(255)").to_string();
80
81 result = RE_UNSIGNED.replace_all(&result, "").to_string();
83
84 result = RE_ZEROFILL.replace_all(&result, "").to_string();
86
87 result
88 }
89
90 fn mysql_to_sqlite(stmt: &str) -> String {
92 let mut result = stmt.to_string();
93
94 result = RE_TINYINT.replace_all(&result, "INTEGER").to_string();
98 result = RE_SMALLINT.replace_all(&result, "INTEGER").to_string();
99 result = RE_MEDIUMINT.replace_all(&result, "INTEGER").to_string();
100 result = RE_INT_SIZE.replace_all(&result, "INTEGER").to_string();
101 result = RE_BIGINT_SIZE.replace_all(&result, "INTEGER").to_string();
102
103 result = RE_DOUBLE.replace_all(&result, "REAL").to_string();
105 result = RE_FLOAT.replace_all(&result, "REAL").to_string();
106 result = RE_DECIMAL.replace_all(&result, "REAL").to_string();
107
108 result = RE_LONGTEXT.replace_all(&result, "TEXT").to_string();
110 result = RE_MEDIUMTEXT.replace_all(&result, "TEXT").to_string();
111 result = RE_TINYTEXT.replace_all(&result, "TEXT").to_string();
112 result = RE_VARCHAR.replace_all(&result, "TEXT").to_string();
113 result = RE_CHAR.replace_all(&result, "TEXT").to_string();
114
115 result = RE_LONGBLOB.replace_all(&result, "BLOB").to_string();
117 result = RE_MEDIUMBLOB.replace_all(&result, "BLOB").to_string();
118 result = RE_TINYBLOB.replace_all(&result, "BLOB").to_string();
119 result = RE_VARBINARY.replace_all(&result, "BLOB").to_string();
120 result = RE_BINARY.replace_all(&result, "BLOB").to_string();
121
122 result = RE_DATETIME.replace_all(&result, "TEXT").to_string();
124 result = RE_TIMESTAMP.replace_all(&result, "TEXT").to_string();
125 result = RE_DATE.replace_all(&result, "TEXT").to_string();
126 result = RE_TIME.replace_all(&result, "TEXT").to_string();
127
128 result = RE_JSON.replace_all(&result, "TEXT").to_string();
130
131 result = RE_ENUM.replace_all(&result, "TEXT").to_string();
133 result = RE_SET.replace_all(&result, "TEXT").to_string();
134
135 result = RE_UNSIGNED.replace_all(&result, "").to_string();
137
138 result = RE_ZEROFILL.replace_all(&result, "").to_string();
140
141 result
142 }
143
144 fn postgres_to_mysql(stmt: &str) -> String {
146 let mut result = stmt.to_string();
147
148 result = RE_BIGSERIAL
150 .replace_all(&result, "BIGINT AUTO_INCREMENT")
151 .to_string();
152 result = RE_SERIAL
153 .replace_all(&result, "INT AUTO_INCREMENT")
154 .to_string();
155 result = RE_SMALLSERIAL
156 .replace_all(&result, "SMALLINT AUTO_INCREMENT")
157 .to_string();
158
159 result = RE_BYTEA.replace_all(&result, "LONGBLOB").to_string();
161
162 result = RE_DOUBLE_PRECISION
164 .replace_all(&result, "DOUBLE")
165 .to_string();
166
167 result = RE_REAL.replace_all(&result, "FLOAT").to_string();
169
170 result = RE_BOOLEAN.replace_all(&result, "TINYINT(1)").to_string();
172
173 result = RE_TIMESTAMPTZ.replace_all(&result, "DATETIME").to_string();
175
176 result = RE_TIMESTAMP_WITH_TZ
178 .replace_all(&result, "DATETIME")
179 .to_string();
180
181 result = RE_TIMESTAMP_NO_TZ
183 .replace_all(&result, "DATETIME")
184 .to_string();
185
186 result = RE_JSONB.replace_all(&result, "JSON").to_string();
188
189 result = RE_UUID.replace_all(&result, "VARCHAR(36)").to_string();
191
192 result
193 }
194
195 fn postgres_to_sqlite(stmt: &str) -> String {
197 let mut result = stmt.to_string();
198
199 result = RE_BIGSERIAL.replace_all(&result, "INTEGER").to_string();
201 result = RE_SERIAL.replace_all(&result, "INTEGER").to_string();
202 result = RE_SMALLSERIAL.replace_all(&result, "INTEGER").to_string();
203
204 result = RE_BYTEA.replace_all(&result, "BLOB").to_string();
206
207 result = RE_DOUBLE_PRECISION.replace_all(&result, "REAL").to_string();
209
210 result = RE_BOOLEAN.replace_all(&result, "INTEGER").to_string();
212
213 result = RE_TIMESTAMPTZ.replace_all(&result, "TEXT").to_string();
215 result = RE_TIMESTAMP_WITH_TZ
216 .replace_all(&result, "TEXT")
217 .to_string();
218 result = RE_TIMESTAMP_NO_TZ.replace_all(&result, "TEXT").to_string();
219
220 result = RE_JSONB.replace_all(&result, "TEXT").to_string();
222 result = RE_JSON.replace_all(&result, "TEXT").to_string();
223
224 result = RE_UUID.replace_all(&result, "TEXT").to_string();
226
227 result = RE_VARCHAR.replace_all(&result, "TEXT").to_string();
229
230 result
231 }
232
233 fn sqlite_to_mysql(stmt: &str) -> String {
235 let mut result = stmt.to_string();
236
237 result = RE_REAL.replace_all(&result, "DOUBLE").to_string();
240
241 result
246 }
247
248 fn sqlite_to_postgres(stmt: &str) -> String {
250 let mut result = stmt.to_string();
251
252 result = RE_REAL.replace_all(&result, "DOUBLE PRECISION").to_string();
254
255 result = RE_BLOB.replace_all(&result, "BYTEA").to_string();
257
258 result
262 }
263
264 fn mysql_to_mssql(stmt: &str) -> String {
266 let mut result = stmt.to_string();
267
268 result = RE_TINYINT_BOOL.replace_all(&result, "BIT").to_string();
272 result = RE_TINYINT.replace_all(&result, "TINYINT").to_string();
273 result = RE_SMALLINT.replace_all(&result, "SMALLINT").to_string();
274 result = RE_MEDIUMINT.replace_all(&result, "INT").to_string();
275 result = RE_INT_SIZE.replace_all(&result, "INT").to_string();
276 result = RE_BIGINT_SIZE.replace_all(&result, "BIGINT").to_string();
277
278 result = RE_DOUBLE.replace_all(&result, "FLOAT").to_string();
280 result = RE_FLOAT.replace_all(&result, "REAL").to_string();
281
282 result = RE_LONGTEXT
284 .replace_all(&result, "NVARCHAR(MAX)")
285 .to_string();
286 result = RE_MEDIUMTEXT
287 .replace_all(&result, "NVARCHAR(MAX)")
288 .to_string();
289 result = RE_TINYTEXT
290 .replace_all(&result, "NVARCHAR(255)")
291 .to_string();
292
293 result = RE_LONGBLOB
295 .replace_all(&result, "VARBINARY(MAX)")
296 .to_string();
297 result = RE_MEDIUMBLOB
298 .replace_all(&result, "VARBINARY(MAX)")
299 .to_string();
300 result = RE_TINYBLOB
301 .replace_all(&result, "VARBINARY(255)")
302 .to_string();
303 result = RE_BLOB.replace_all(&result, "VARBINARY(MAX)").to_string();
304
305 result = RE_DATETIME.replace_all(&result, "DATETIME2").to_string();
307
308 result = RE_JSON.replace_all(&result, "NVARCHAR(MAX)").to_string();
310
311 result = RE_ENUM.replace_all(&result, "NVARCHAR(255)").to_string();
313
314 result = RE_SET.replace_all(&result, "NVARCHAR(255)").to_string();
316
317 result = RE_UNSIGNED.replace_all(&result, "").to_string();
319
320 result = RE_ZEROFILL.replace_all(&result, "").to_string();
322
323 result
324 }
325
326 fn postgres_to_mssql(stmt: &str) -> String {
328 let mut result = stmt.to_string();
329
330 result = RE_BIGSERIAL
332 .replace_all(&result, "BIGINT IDENTITY(1,1)")
333 .to_string();
334 result = RE_SERIAL
335 .replace_all(&result, "INT IDENTITY(1,1)")
336 .to_string();
337 result = RE_SMALLSERIAL
338 .replace_all(&result, "SMALLINT IDENTITY(1,1)")
339 .to_string();
340
341 result = RE_BYTEA.replace_all(&result, "VARBINARY(MAX)").to_string();
343
344 result = RE_DOUBLE_PRECISION
346 .replace_all(&result, "FLOAT")
347 .to_string();
348
349 result = RE_BOOLEAN.replace_all(&result, "BIT").to_string();
353
354 result = RE_TIMESTAMPTZ
356 .replace_all(&result, "DATETIMEOFFSET")
357 .to_string();
358
359 result = RE_TIMESTAMP_WITH_TZ
361 .replace_all(&result, "DATETIMEOFFSET")
362 .to_string();
363
364 result = RE_TIMESTAMP_NO_TZ
366 .replace_all(&result, "DATETIME2")
367 .to_string();
368
369 result = RE_JSONB.replace_all(&result, "NVARCHAR(MAX)").to_string();
371
372 result = RE_JSON.replace_all(&result, "NVARCHAR(MAX)").to_string();
374
375 result = RE_UUID.replace_all(&result, "UNIQUEIDENTIFIER").to_string();
377
378 result = RE_TEXT.replace_all(&result, "NVARCHAR(MAX)").to_string();
380
381 result
382 }
383
384 fn sqlite_to_mssql(stmt: &str) -> String {
386 let mut result = stmt.to_string();
387
388 result = RE_REAL.replace_all(&result, "FLOAT").to_string();
390
391 result = RE_BLOB.replace_all(&result, "VARBINARY(MAX)").to_string();
393
394 result = RE_TEXT.replace_all(&result, "NVARCHAR(MAX)").to_string();
396
397 result
398 }
399
400 fn mssql_to_mysql(stmt: &str) -> String {
402 let mut result = stmt.to_string();
403
404 result = RE_BIT.replace_all(&result, "TINYINT(1)").to_string();
408
409 result = RE_NVARCHAR_MAX.replace_all(&result, "LONGTEXT").to_string();
411
412 result = RE_NVARCHAR.replace_all(&result, "VARCHAR$1").to_string();
414
415 result = RE_NCHAR.replace_all(&result, "CHAR$1").to_string();
417
418 result = RE_NTEXT.replace_all(&result, "LONGTEXT").to_string();
420
421 result = RE_VARCHAR_MAX.replace_all(&result, "LONGTEXT").to_string();
423
424 result = RE_VARBINARY_MAX
426 .replace_all(&result, "LONGBLOB")
427 .to_string();
428
429 result = RE_IMAGE.replace_all(&result, "LONGBLOB").to_string();
431
432 result = RE_DATETIME2.replace_all(&result, "DATETIME(6)").to_string();
434
435 result = RE_DATETIMEOFFSET
437 .replace_all(&result, "DATETIME")
438 .to_string();
439
440 result = RE_SMALLDATETIME
442 .replace_all(&result, "DATETIME")
443 .to_string();
444
445 result = RE_MONEY.replace_all(&result, "DECIMAL(19,4)").to_string();
447
448 result = RE_SMALLMONEY
450 .replace_all(&result, "DECIMAL(10,4)")
451 .to_string();
452
453 result = RE_UNIQUEIDENTIFIER
455 .replace_all(&result, "VARCHAR(36)")
456 .to_string();
457
458 result = RE_XML.replace_all(&result, "LONGTEXT").to_string();
460
461 result = RE_MSSQL_TIMESTAMP_BRACKETED
463 .replace_all(&result, "BINARY(8)")
464 .to_string();
465 result = RE_ROWVERSION_ONLY
466 .replace_all(&result, "BINARY(8)")
467 .to_string();
468
469 result = RE_ON_PRIMARY.replace_all(&result, "").to_string();
471 result = RE_CLUSTERED.replace_all(&result, "").to_string();
472 result = RE_NONCLUSTERED.replace_all(&result, "").to_string();
473
474 result
475 }
476
477 fn mssql_to_postgres(stmt: &str) -> String {
479 let mut result = stmt.to_string();
480
481 result = RE_MSSQL_TIMESTAMP_BRACKETED
487 .replace_all(&result, "BYTEA")
488 .to_string();
489 result = RE_ROWVERSION_ONLY.replace_all(&result, "BYTEA").to_string();
490
491 result = RE_BIT.replace_all(&result, "BOOLEAN").to_string();
493
494 result = RE_NVARCHAR_MAX.replace_all(&result, "TEXT").to_string();
496
497 result = RE_NVARCHAR.replace_all(&result, "VARCHAR$1").to_string();
499
500 result = RE_NCHAR.replace_all(&result, "CHAR$1").to_string();
502
503 result = RE_NTEXT.replace_all(&result, "TEXT").to_string();
505
506 result = RE_VARCHAR_MAX.replace_all(&result, "TEXT").to_string();
508
509 result = RE_VARBINARY_MAX.replace_all(&result, "BYTEA").to_string();
511
512 result = RE_VARBINARY.replace_all(&result, "BYTEA").to_string();
514
515 result = RE_IMAGE.replace_all(&result, "BYTEA").to_string();
517
518 result = RE_DATETIME2.replace_all(&result, "TIMESTAMP").to_string();
520
521 result = RE_DATETIME.replace_all(&result, "TIMESTAMP").to_string();
523
524 result = RE_DATETIMEOFFSET
526 .replace_all(&result, "TIMESTAMPTZ")
527 .to_string();
528
529 result = RE_SMALLDATETIME
531 .replace_all(&result, "TIMESTAMP")
532 .to_string();
533
534 result = RE_MONEY.replace_all(&result, "DECIMAL(19,4)").to_string();
536
537 result = RE_SMALLMONEY
539 .replace_all(&result, "DECIMAL(10,4)")
540 .to_string();
541
542 result = RE_UNIQUEIDENTIFIER.replace_all(&result, "UUID").to_string();
544
545 result = RE_FLOAT
549 .replace_all(&result, "DOUBLE PRECISION")
550 .to_string();
551
552 result = RE_ON_PRIMARY.replace_all(&result, "").to_string();
554 result = RE_CLUSTERED.replace_all(&result, "").to_string();
555 result = RE_NONCLUSTERED.replace_all(&result, "").to_string();
556
557 result
558 }
559
560 fn mssql_to_sqlite(stmt: &str) -> String {
562 let mut result = stmt.to_string();
563
564 result = RE_BIT.replace_all(&result, "INTEGER").to_string();
566
567 result = RE_NVARCHAR_MAX.replace_all(&result, "TEXT").to_string();
569 result = RE_NVARCHAR.replace_all(&result, "TEXT").to_string();
570
571 result = RE_NCHAR.replace_all(&result, "TEXT").to_string();
573
574 result = RE_NTEXT.replace_all(&result, "TEXT").to_string();
576
577 result = RE_VARCHAR_MAX.replace_all(&result, "TEXT").to_string();
579
580 result = RE_VARBINARY_MAX.replace_all(&result, "BLOB").to_string();
582 result = RE_VARBINARY.replace_all(&result, "BLOB").to_string();
583
584 result = RE_IMAGE.replace_all(&result, "BLOB").to_string();
586
587 result = RE_DATETIME2.replace_all(&result, "TEXT").to_string();
589 result = RE_DATETIME.replace_all(&result, "TEXT").to_string();
590 result = RE_DATETIMEOFFSET.replace_all(&result, "TEXT").to_string();
591 result = RE_SMALLDATETIME.replace_all(&result, "TEXT").to_string();
592
593 result = RE_MONEY.replace_all(&result, "REAL").to_string();
595 result = RE_SMALLMONEY.replace_all(&result, "REAL").to_string();
596
597 result = RE_UNIQUEIDENTIFIER.replace_all(&result, "TEXT").to_string();
599
600 result = RE_XML.replace_all(&result, "TEXT").to_string();
602
603 result = RE_MSSQL_TIMESTAMP_BRACKETED
605 .replace_all(&result, "BLOB")
606 .to_string();
607 result = RE_ROWVERSION_ONLY.replace_all(&result, "BLOB").to_string();
608
609 result = RE_FLOAT.replace_all(&result, "REAL").to_string();
611
612 result = RE_ON_PRIMARY.replace_all(&result, "").to_string();
614 result = RE_CLUSTERED.replace_all(&result, "").to_string();
615 result = RE_NONCLUSTERED.replace_all(&result, "").to_string();
616
617 result
618 }
619}
620
621static RE_TINYINT_BOOL: Lazy<Regex> =
623 Lazy::new(|| Regex::new(r"(?i)\bTINYINT\s*\(\s*1\s*\)").unwrap());
624static RE_TINYINT: Lazy<Regex> =
625 Lazy::new(|| Regex::new(r"(?i)\bTINYINT\s*(\(\s*\d+\s*\))?").unwrap());
626static RE_SMALLINT: Lazy<Regex> =
627 Lazy::new(|| Regex::new(r"(?i)\bSMALLINT\s*(\(\s*\d+\s*\))?").unwrap());
628static RE_MEDIUMINT: Lazy<Regex> =
629 Lazy::new(|| Regex::new(r"(?i)\bMEDIUMINT\s*(\(\s*\d+\s*\))?").unwrap());
630static RE_INT_SIZE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bINT\s*\(\s*\d+\s*\)").unwrap());
631static RE_BIGINT_SIZE: Lazy<Regex> =
632 Lazy::new(|| Regex::new(r"(?i)\bBIGINT\s*\(\s*\d+\s*\)").unwrap());
633
634static RE_DOUBLE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bDOUBLE\b").unwrap());
635static RE_FLOAT: Lazy<Regex> =
636 Lazy::new(|| Regex::new(r"(?i)\bFLOAT\s*(\(\s*\d+\s*(,\s*\d+\s*)?\))?").unwrap());
637static RE_DECIMAL: Lazy<Regex> =
638 Lazy::new(|| Regex::new(r"(?i)\bDECIMAL\s*\(\s*\d+\s*(,\s*\d+\s*)?\)").unwrap());
639
640static RE_LONGTEXT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bLONGTEXT\b").unwrap());
641static RE_MEDIUMTEXT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bMEDIUMTEXT\b").unwrap());
642static RE_TINYTEXT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bTINYTEXT\b").unwrap());
643static RE_VARCHAR: Lazy<Regex> =
644 Lazy::new(|| Regex::new(r"(?i)\bVARCHAR\s*\(\s*\d+\s*\)").unwrap());
645static RE_CHAR: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bCHAR\s*\(\s*\d+\s*\)").unwrap());
646
647static RE_LONGBLOB: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bLONGBLOB\b").unwrap());
648static RE_MEDIUMBLOB: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bMEDIUMBLOB\b").unwrap());
649static RE_TINYBLOB: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bTINYBLOB\b").unwrap());
650static RE_BLOB: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bBLOB\b").unwrap());
651static RE_VARBINARY: Lazy<Regex> =
652 Lazy::new(|| Regex::new(r"(?i)\bVARBINARY\s*\(\s*\d+\s*\)").unwrap());
653static RE_BINARY: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bBINARY\s*\(\s*\d+\s*\)").unwrap());
654
655static RE_DATETIME: Lazy<Regex> =
656 Lazy::new(|| Regex::new(r"(?i)\bDATETIME(\(\s*\d+\s*\))?").unwrap());
657static RE_TIMESTAMP: Lazy<Regex> =
658 Lazy::new(|| Regex::new(r"(?i)\bTIMESTAMP\s*(\(\s*\d+\s*\))?").unwrap());
659static RE_DATE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bDATE\b").unwrap());
660static RE_TIME: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bTIME\s*(\(\s*\d+\s*\))?").unwrap());
661
662static RE_JSON: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bJSON\b").unwrap());
663
664static RE_ENUM: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bENUM\s*\([^)]+\)").unwrap());
665static RE_SET: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bSET\s*\([^)]+\)").unwrap());
666
667static RE_UNSIGNED: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\s+UNSIGNED\b").unwrap());
668static RE_ZEROFILL: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\s+ZEROFILL\b").unwrap());
669
670static RE_SERIAL: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bSERIAL\b").unwrap());
672static RE_BIGSERIAL: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bBIGSERIAL\b").unwrap());
673static RE_SMALLSERIAL: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bSMALLSERIAL\b").unwrap());
674static RE_BYTEA: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bBYTEA\b").unwrap());
675static RE_DOUBLE_PRECISION: Lazy<Regex> =
676 Lazy::new(|| Regex::new(r"(?i)\bDOUBLE\s+PRECISION\b").unwrap());
677static RE_REAL: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bREAL\b").unwrap());
678static RE_BOOLEAN: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bBOOLEAN\b").unwrap());
679static RE_TIMESTAMPTZ: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bTIMESTAMPTZ\b").unwrap());
680static RE_TIMESTAMP_WITH_TZ: Lazy<Regex> =
681 Lazy::new(|| Regex::new(r"(?i)\bTIMESTAMP\s+WITH\s+TIME\s+ZONE\b").unwrap());
682static RE_TIMESTAMP_NO_TZ: Lazy<Regex> =
683 Lazy::new(|| Regex::new(r"(?i)\bTIMESTAMP\s+WITHOUT\s+TIME\s+ZONE\b").unwrap());
684static RE_JSONB: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bJSONB\b").unwrap());
685static RE_UUID: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bUUID\b").unwrap());
686static RE_TEXT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bTEXT\b").unwrap());
687
688static RE_BIT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bBIT\b").unwrap());
690static RE_NVARCHAR_MAX: Lazy<Regex> =
691 Lazy::new(|| Regex::new(r"(?i)\bNVARCHAR\s*\(\s*MAX\s*\)").unwrap());
692static RE_NVARCHAR: Lazy<Regex> =
693 Lazy::new(|| Regex::new(r"(?i)\bNVARCHAR\s*(\(\s*\d+\s*\))").unwrap());
694static RE_NCHAR: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bNCHAR\s*(\(\s*\d+\s*\))").unwrap());
695static RE_NTEXT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bNTEXT\b").unwrap());
696static RE_VARCHAR_MAX: Lazy<Regex> =
697 Lazy::new(|| Regex::new(r"(?i)\bVARCHAR\s*\(\s*MAX\s*\)").unwrap());
698static RE_VARBINARY_MAX: Lazy<Regex> =
699 Lazy::new(|| Regex::new(r"(?i)\bVARBINARY\s*\(\s*MAX\s*\)").unwrap());
700static RE_IMAGE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bIMAGE\b").unwrap());
701static RE_DATETIME2: Lazy<Regex> =
702 Lazy::new(|| Regex::new(r"(?i)\bDATETIME2\s*(\(\s*\d+\s*\))?").unwrap());
703static RE_DATETIMEOFFSET: Lazy<Regex> =
704 Lazy::new(|| Regex::new(r"(?i)\bDATETIMEOFFSET\s*(\(\s*\d+\s*\))?").unwrap());
705static RE_SMALLDATETIME: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bSMALLDATETIME\b").unwrap());
706static RE_MONEY: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bMONEY\b").unwrap());
707static RE_SMALLMONEY: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bSMALLMONEY\b").unwrap());
708static RE_UNIQUEIDENTIFIER: Lazy<Regex> =
709 Lazy::new(|| Regex::new(r"(?i)\bUNIQUEIDENTIFIER\b").unwrap());
710static RE_XML: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bXML\b").unwrap());
711static RE_MSSQL_TIMESTAMP_BRACKETED: Lazy<Regex> =
715 Lazy::new(|| Regex::new(r"(?i)\[\s*TIMESTAMP\s*\]").unwrap());
716static RE_ROWVERSION_ONLY: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bROWVERSION\b").unwrap());
717
718static RE_ON_PRIMARY: Lazy<Regex> =
720 Lazy::new(|| Regex::new(r"(?i)\s*ON\s*\[\s*PRIMARY\s*\]").unwrap());
721static RE_CLUSTERED: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bCLUSTERED\s+").unwrap());
722static RE_NONCLUSTERED: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\bNONCLUSTERED\s+").unwrap());