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

typeorm / typeorm / 19549987525

20 Nov 2025 08:11PM UTC coverage: 80.769% (+4.3%) from 76.433%
19549987525

push

github

web-flow
ci: run tests on commits to master and next (#11783)

Co-authored-by: Oleg "OSA413" Sokolov <OSA413@users.noreply.github.com>

26500 of 32174 branches covered (82.36%)

Branch coverage included in aggregate %.

91252 of 113615 relevant lines covered (80.32%)

88980.79 hits per line

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

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

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

26✔
18
    /**
26✔
19
     * Connection options.
26✔
20
     */
26✔
21
    options: NativescriptConnectionOptions
26✔
22

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

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

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

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

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

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

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

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

×
68
        return this.queryRunner
×
69
    }
×
70

26✔
71
    normalizeType(column: {
26✔
72
        type?: ColumnType
×
73
        length?: number | string
×
74
        precision?: number | null
×
75
        scale?: number
×
76
    }): string {
×
77
        if ((column.type as any) === Buffer) {
×
78
            return "blob"
×
79
        }
×
80

×
81
        return super.normalizeType(column)
×
82
    }
×
83
    // -------------------------------------------------------------------------
26✔
84
    // Protected Methods
26✔
85
    // -------------------------------------------------------------------------
26✔
86

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

×
105
            new this.sqlite(
×
106
                this.options.database,
×
107
                options,
×
108
                (err: Error, db: any): any => {
×
109
                    if (err) return fail(err)
×
110

×
111
                    // use object mode to work with TypeORM
×
112
                    db.resultType(this.sqlite.RESULTSASOBJECT)
×
113

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

26✔
130
    /**
26✔
131
     * If driver dependency is not given explicitly, then try to load it via "require".
26✔
132
     */
26✔
133
    protected loadDependencies(): void {
26✔
134
        this.sqlite = this.driver
×
135
        if (!this.driver) {
×
136
            throw new DriverPackageNotInstalledError(
×
137
                "Nativescript",
×
138
                "nativescript-sqlite",
×
139
            )
×
140
        }
×
141
    }
×
142
}
26✔
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