Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BetterSqliteDriver

Organizes communication with sqlite DBMS.

Hierarchy

  • AbstractSqliteDriver
    • BetterSqliteDriver

Implements

  • Driver

Index

Constructors

constructor

Properties

connection

connection: Connection

Connection used by driver.

dataTypeDefaults

dataTypeDefaults: DataTypeDefaults

Default values of length, precision and scale depends on column data type. Used in the cases when length/precision/scale is not specified by user.

Optional database

database: string

Master database used to perform all write queries.

databaseConnection

databaseConnection: any

Real database connection with sqlite database.

Private defaultPragma

defaultPragma: string[] = ['cache_size = -4096','journal_mode = WAL','synchronous = NORMAL',]

Default pragma statements for data consistency

isReplicated

isReplicated: boolean

Indicates if replication is enabled.

mappedDataTypes

mappedDataTypes: MappedColumnTypes

Orm has special columns and we need to know what database column types should be for those types. Column types are driver dependant.

Optional maxAliasLength

maxAliasLength: number

No documentation specifying a maximum length for identifiers could be found for SQLite.

options

Connection options.

Optional queryRunner

queryRunner: QueryRunner

Sqlite has a single QueryRunner because it works on a single database connection.

spatialTypes

spatialTypes: ColumnType[]

Gets list of spatial column data types.

sqlite

sqlite: any

SQLite underlying library.

supportedDataTypes

supportedDataTypes: ColumnType[]

Gets list of supported column data types by a driver.

see

https://www.tutorialspoint.com/sqlite/sqlite_data_types.htm

see

https://sqlite.org/datatype3.html

treeSupport

treeSupport: boolean

Indicates if tree tables are supported by this driver.

withLengthColumnTypes

withLengthColumnTypes: ColumnType[]

Gets list of column data types that support length by a driver.

withPrecisionColumnTypes

withPrecisionColumnTypes: ColumnType[]

Gets list of column data types that support precision by a driver.

withScaleColumnTypes

withScaleColumnTypes: ColumnType[]

Gets list of column data types that support scale by a driver.

Methods

afterConnect

  • afterConnect(): Promise<void>
  • Makes any action after connection (e.g. create extensions in Postgres driver).

    Returns Promise<void>

buildTableName

  • buildTableName(tableName: string, schema?: string, database?: string): string
  • Build full table name with database name, schema name and table name. E.g. "myDB"."mySchema"."myTable"

    Returns only simple table name because all inherited drivers does not supports schema and database.

    Parameters

    • tableName: string
    • Optional schema: string
    • Optional database: string

    Returns string

connect

  • connect(): Promise<void>
  • Performs connection to the database.

    Returns Promise<void>

Protected createDatabaseConnection

  • createDatabaseConnection(): Promise<any>
  • Creates connection with the database.

    Returns Promise<any>

Protected createDatabaseDirectory

  • createDatabaseDirectory(fullPath: string): Promise<void>

createFullType

  • createFullType(column: TableColumn): string
  • Normalizes "default" value of the column.

    Parameters

    • column: TableColumn

    Returns string

createGeneratedMap

  • createGeneratedMap(metadata: EntityMetadata, insertResult: any): any
  • Creates generated map of values generated or returned by database after INSERT query.

    Parameters

    • metadata: EntityMetadata
    • insertResult: any

    Returns any

createParameter

  • createParameter(parameterName: string, index: number): string
  • Creates an escaped parameter.

    Parameters

    • parameterName: string
    • index: number

    Returns string

createQueryRunner

  • createQueryRunner(mode?: "master" | "slave"): QueryRunner
  • Creates a query runner used to execute database queries.

    Parameters

    • Default value mode: "master" | "slave" = "master"

    Returns QueryRunner

createSchemaBuilder

  • createSchemaBuilder(): RdbmsSchemaBuilder
  • Creates a schema builder used to build and sync a schema.

    Returns RdbmsSchemaBuilder

customCreateDatabaseConnection

  • customCreateDatabaseConnection(): Promise<void>

disconnect

  • disconnect(): Promise<void>

escape

  • escape(columnName: string): string
  • Escapes a column name.

    Parameters

    • columnName: string

    Returns string

escapeQueryWithParameters

  • escapeQueryWithParameters(sql: string, parameters: ObjectLiteral, nativeParameters: ObjectLiteral): [string, any[]]
  • Replaces parameters in the given sql with special escaping character and an array of parameter names to be passed to a query.

    Parameters

    • sql: string
    • parameters: ObjectLiteral
    • nativeParameters: ObjectLiteral

    Returns [string, any[]]

findChangedColumns

  • findChangedColumns(tableColumns: TableColumn[], columnMetadatas: ColumnMetadata[]): ColumnMetadata[]
  • Differentiate columns of this table and columns from the given column metadatas columns and returns only changed.

    Parameters

    • tableColumns: TableColumn[]
    • columnMetadatas: ColumnMetadata[]

    Returns ColumnMetadata[]

getColumnLength

  • getColumnLength(column: ColumnMetadata): string
  • Calculates column length taking into account the default length values.

    Parameters

    • column: ColumnMetadata

    Returns string

isReturningSqlSupported

  • isReturningSqlSupported(): boolean
  • Returns true if driver supports RETURNING / OUTPUT statement.

    Returns boolean

isUUIDGenerationSupported

  • isUUIDGenerationSupported(): boolean
  • Returns true if driver supports uuid values generation on its own.

    Returns boolean

Protected loadDependencies

  • loadDependencies(): void
  • If driver dependency is not given explicitly, then try to load it via "require".

    Returns void

normalizeDefault

  • normalizeDefault(columnMetadata: ColumnMetadata): string
  • Normalizes "default" value of the column.

    Parameters

    • columnMetadata: ColumnMetadata

    Returns string

normalizeIsUnique

  • normalizeIsUnique(column: ColumnMetadata): boolean
  • Normalizes "isUnique" value of the column.

    Parameters

    • column: ColumnMetadata

    Returns boolean

normalizeType

  • normalizeType(column: { length?: number | string; precision?: number | null; scale?: number; type?: ColumnType }): string
  • Parameters

    • column: { length?: number | string; precision?: number | null; scale?: number; type?: ColumnType }
      • Optional length?: number | string
      • Optional precision?: number | null
      • Optional scale?: number
      • Optional type?: ColumnType

    Returns string

obtainMasterConnection

  • obtainMasterConnection(): Promise<any>
  • Obtains a new database connection to a master server. Used for replication. If replication is not setup then returns default connection's database connection.

    Returns Promise<any>

obtainSlaveConnection

  • obtainSlaveConnection(): Promise<any>
  • Obtains a new database connection to a slave server. Used for replication. If replication is not setup then returns master (default) connection's database connection.

    Returns Promise<any>

prepareHydratedValue

  • prepareHydratedValue(value: any, columnMetadata: ColumnMetadata): any
  • Prepares given value to a value to be hydrated, based on its column type or metadata.

    Parameters

    • value: any
    • columnMetadata: ColumnMetadata

    Returns any

preparePersistentValue

  • preparePersistentValue(value: any, columnMetadata: ColumnMetadata): any
  • Prepares given value to a value to be persisted, based on its column type and metadata.

    Parameters

    • value: any
    • columnMetadata: ColumnMetadata

    Returns any