• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 23061937701

13 Mar 2026 05:07PM UTC coverage: 74.804% (-0.01%) from 74.816%
23061937701

push

github

web-flow
refactor!: remove `Buffer` polyfill and replace `Buffer` with `Uint8Array` on non-node platforms (#11935)

26317 of 31729 branches covered (82.94%)

Branch coverage included in aggregate %.

99 of 122 new or added lines in 20 files covered. (81.15%)

3 existing lines in 1 file now uncovered.

83389 of 114929 relevant lines covered (72.56%)

65201.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.52
/src/driver/nativescript/NativescriptDriver.ts
1
import type { DataSource } from "../../data-source/DataSource"
23✔
2
import { DriverPackageNotInstalledError } from "../../error/DriverPackageNotInstalledError"
23✔
3
import type { QueryRunner } from "../../query-runner/QueryRunner"
23✔
4
import { AbstractSqliteDriver } from "../sqlite-abstract/AbstractSqliteDriver"
23✔
5
import type { ColumnType } from "../types/ColumnTypes"
23✔
6
import type { ReplicationMode } from "../types/ReplicationMode"
23✔
7
import type { NativescriptDataSourceOptions } from "./NativescriptDataSourceOptions"
23✔
8
import { NativescriptQueryRunner } from "./NativescriptQueryRunner"
23✔
9

23✔
10
/**
23✔
11
 * Organizes communication with sqlite DBMS within Nativescript.
23✔
12
 */
23✔
13
export class NativescriptDriver extends AbstractSqliteDriver {
23✔
14
    // -------------------------------------------------------------------------
23✔
15
    // Public Properties
23✔
16
    // -------------------------------------------------------------------------
23✔
17

23✔
18
    /**
23✔
19
     * Connection options.
23✔
20
     */
23✔
21
    options: NativescriptDataSourceOptions
23✔
22

23✔
23
    /**
23✔
24
     * Nativescript driver module
23✔
25
     * this is most likely `nativescript-sqlite`
23✔
26
     * but user can pass his own
23✔
27
     */
23✔
28
    driver: any
23✔
29

23✔
30
    // -------------------------------------------------------------------------
23✔
31
    // Constructor
23✔
32
    // -------------------------------------------------------------------------
23✔
33

23✔
34
    constructor(connection: DataSource) {
23✔
35
        super(connection)
×
36

×
37
        this.connection = connection
×
38
        this.options = connection.options as NativescriptDataSourceOptions
×
39
        this.database = this.options.database
×
40
        this.driver = this.options.driver
×
41

×
42
        // load sqlite package
×
43
        this.loadDependencies()
×
44
    }
×
45

23✔
46
    // -------------------------------------------------------------------------
23✔
47
    // Public Methods
23✔
48
    // -------------------------------------------------------------------------
23✔
49

23✔
50
    /**
23✔
51
     * Closes connection with database.
23✔
52
     */
23✔
53
    async disconnect(): Promise<void> {
23✔
54
        return new Promise<void>((ok, fail) => {
×
55
            this.queryRunner = undefined
×
56
            this.databaseConnection.close().then(ok).catch(fail)
×
57
        })
×
58
    }
×
59

23✔
60
    /**
23✔
61
     * Creates a query runner used to execute database queries.
23✔
62
     * @param mode
23✔
63
     */
23✔
64
    createQueryRunner(mode: ReplicationMode): QueryRunner {
23✔
65
        if (!this.queryRunner) {
×
66
            this.queryRunner = new NativescriptQueryRunner(this)
×
67
        }
×
68

×
69
        return this.queryRunner
×
70
    }
×
71

23✔
72
    normalizeType(column: {
23✔
73
        type?: ColumnType
×
74
        length?: number | string
×
75
        precision?: number | null
×
76
        scale?: number
×
77
    }): string {
×
NEW
78
        if (
×
NEW
79
            typeof column.type === "function" &&
×
NEW
80
            column.type.prototype instanceof Uint8Array
×
NEW
81
        ) {
×
82
            return "blob"
×
83
        }
×
84

×
85
        return super.normalizeType(column)
×
86
    }
×
87
    // -------------------------------------------------------------------------
23✔
88
    // Protected Methods
23✔
89
    // -------------------------------------------------------------------------
23✔
90

23✔
91
    /**
23✔
92
     * Creates connection with the database.
23✔
93
     */
23✔
94
    protected createDatabaseConnection() {
23✔
95
        return new Promise<void>((ok, fail) => {
×
96
            const options = Object.assign(
×
97
                {},
×
98
                {
×
99
                    readOnly: this.options.readOnly,
×
100
                    key: this.options.key,
×
101
                    multithreading: this.options.multithreading,
×
102
                    migrate: this.options.migrate,
×
103
                    iosFlags: this.options.iosFlags,
×
104
                    androidFlags: this.options.androidFlags,
×
105
                },
×
106
                this.options.extra || {},
×
107
            )
×
108

×
109
            new this.sqlite(
×
110
                this.options.database,
×
111
                options,
×
112
                (err: Error, db: any): any => {
×
113
                    if (err) return fail(err)
×
114

×
115
                    // use object mode to work with TypeORM
×
116
                    db.resultType(this.sqlite.RESULTSASOBJECT)
×
117

×
118
                    // we need to enable foreign keys in sqlite to make sure all foreign key related features
×
119
                    // working properly. this also makes onDelete work with sqlite.
×
120
                    db.execSQL(
×
121
                        `PRAGMA foreign_keys = ON`,
×
122
                        [],
×
123
                        (err: Error, result: any): any => {
×
124
                            if (err) return fail(err)
×
125
                            // We are all set
×
126
                            ok(db)
×
127
                        },
×
128
                    )
×
129
                },
×
130
            )
×
131
        })
×
132
    }
×
133

23✔
134
    /**
23✔
135
     * If driver dependency is not given explicitly, then try to load it via "require".
23✔
136
     */
23✔
137
    protected loadDependencies(): void {
23✔
138
        this.sqlite = this.driver
×
139
        if (!this.driver) {
×
140
            throw new DriverPackageNotInstalledError(
×
141
                "Nativescript",
×
142
                "nativescript-sqlite",
×
143
            )
×
144
        }
×
145
    }
×
146
}
23✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc