1
- import { freezeDeep , isFunction } from '@sequelize/utils' ;
1
+ import { EMPTY_OBJECT , freezeDeep , getImmutablePojo , isFunction , isString } from '@sequelize/utils' ;
2
2
import cloneDeep from 'lodash/cloneDeep' ;
3
3
import merge from 'lodash/merge' ;
4
4
import type { Class } from 'type-fest' ;
@@ -274,6 +274,22 @@ declare const OptionType: unique symbol;
274
274
275
275
export type DialectOptions < Dialect extends AbstractDialect > = Dialect [ typeof OptionType ] ;
276
276
277
+ export type AbstractDialectParams < Options > = {
278
+ dataTypeOverrides : Record < string , Class < AbstractDataType < any > > > ;
279
+ dataTypesDocumentationUrl : string ;
280
+ /**
281
+ * The character used to delimit identifiers in SQL queries.
282
+ *
283
+ * This can be a string, in which case the character will be used for both the start & end of the identifier,
284
+ * or an object with `start` and `end` properties.
285
+ */
286
+ identifierDelimiter : string | { start : string ; end : string } ;
287
+ minimumDatabaseVersion : string ;
288
+ name : DialectName ;
289
+ options : Options | undefined ;
290
+ sequelize : Sequelize ;
291
+ } ;
292
+
277
293
export abstract class AbstractDialect < Options extends object = { } > {
278
294
declare [ OptionType ] : Options ;
279
295
@@ -475,17 +491,37 @@ export abstract class AbstractDialect<Options extends object = {}> {
475
491
476
492
readonly sequelize : Sequelize ;
477
493
478
- abstract readonly defaultVersion : string ;
479
494
abstract readonly Query : typeof AbstractQuery ;
480
- abstract readonly TICK_CHAR_LEFT : string ;
481
- abstract readonly TICK_CHAR_RIGHT : string ;
482
495
abstract readonly queryGenerator : AbstractQueryGenerator ;
483
496
abstract readonly queryInterface : AbstractQueryInterface ;
484
497
abstract readonly connectionManager : AbstractConnectionManager < any , any > ;
485
- abstract readonly dataTypesDocumentationUrl : string ;
486
498
499
+ /**
500
+ * @deprecated use {@link minimumDatabaseVersion}
501
+ */
502
+ get defaultVersion ( ) : string {
503
+ return this . minimumDatabaseVersion ;
504
+ }
505
+
506
+ /**
507
+ * @deprecated use {@link identifierDelimiter}.start
508
+ */
509
+ get TICK_CHAR_LEFT ( ) : string {
510
+ return this . identifierDelimiter . start ;
511
+ }
512
+
513
+ /**
514
+ * @deprecated use {@link identifierDelimiter}.end
515
+ */
516
+ get TICK_CHAR_RIGHT ( ) : string {
517
+ return this . identifierDelimiter . end ;
518
+ }
519
+
520
+ readonly identifierDelimiter : { readonly start : string ; readonly end : string } ;
521
+ readonly minimumDatabaseVersion : string ;
522
+ readonly dataTypesDocumentationUrl : string ;
523
+ readonly options : Options ;
487
524
readonly name : DialectName ;
488
- readonly DataTypes : Record < string , Class < AbstractDataType < any > > > ;
489
525
490
526
/** dialect-specific implementation of shared data types */
491
527
readonly #dataTypeOverrides: Map < string , Class < AbstractDataType < any > > > ;
@@ -499,14 +535,20 @@ export abstract class AbstractDialect<Options extends object = {}> {
499
535
return Dialect . supports ;
500
536
}
501
537
502
- constructor (
503
- sequelize : Sequelize ,
504
- dialectDataTypes : Record < string , Class < AbstractDataType < any > > > ,
505
- dialectName : DialectName ,
506
- ) {
507
- this . sequelize = sequelize ;
508
- this . DataTypes = dialectDataTypes ;
509
- this . name = dialectName ;
538
+ constructor ( params : AbstractDialectParams < Options > ) {
539
+ this . sequelize = params . sequelize ;
540
+ this . name = params . name ;
541
+ this . dataTypesDocumentationUrl = params . dataTypesDocumentationUrl ;
542
+ this . options = params . options ? getImmutablePojo ( params . options ) : EMPTY_OBJECT ;
543
+
544
+ this . identifierDelimiter = isString ( params . identifierDelimiter )
545
+ ? Object . freeze ( {
546
+ start : params . identifierDelimiter ,
547
+ end : params . identifierDelimiter ,
548
+ } )
549
+ : getImmutablePojo ( params . identifierDelimiter ) ;
550
+
551
+ this . minimumDatabaseVersion = params . minimumDatabaseVersion ;
510
552
511
553
const baseDataTypes = new Map < string , Class < AbstractDataType < any > > > ( ) ;
512
554
for ( const dataType of Object . values ( BaseDataTypes ) as Array < Class < AbstractDataType < any > > > ) {
@@ -532,7 +574,7 @@ export abstract class AbstractDialect<Options extends object = {}> {
532
574
}
533
575
534
576
const dataTypeOverrides = new Map < string , Class < AbstractDataType < any > > > ( ) ;
535
- for ( const dataType of Object . values ( this . DataTypes ) ) {
577
+ for ( const dataType of Object . values ( params . dataTypeOverrides ) ) {
536
578
const replacedDataTypeId : string = (
537
579
dataType as unknown as typeof AbstractDataType
538
580
) . getDataTypeId ( ) ;
0 commit comments