Skip to content
This repository was archived by the owner on Apr 19, 2020. It is now read-only.

Commit fcdc044

Browse files
committed
Cleanup unnecessary assertions
1 parent aadde9f commit fcdc044

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/index.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export const MongoDBDatabaseEngine: DatabaseEngineFactory = (
5454

5555
const { databaseConfig, engineConfig } = getConfig(uri);
5656

57-
let client: MongoClient | null = null;
58-
let db: Db | null = null;
57+
let client: MongoClient;
58+
let db: Db;
5959

6060
return {
6161
async open() {
@@ -87,9 +87,6 @@ export const MongoDBDatabaseEngine: DatabaseEngineFactory = (
8787
},
8888
async drop() {
8989
debug('in drop function');
90-
if (!db) {
91-
throw new SynorError('Database connection is null');
92-
}
9390
const collections = await (
9491
await db.listCollections(
9592
{},
@@ -101,9 +98,7 @@ export const MongoDBDatabaseEngine: DatabaseEngineFactory = (
10198

10299
await Promise.all(
103100
collections.map(async c => {
104-
if (db) {
105-
await db.dropCollection(c);
106-
}
101+
await db.dropCollection(c);
107102
})
108103
);
109104
},
@@ -119,7 +114,7 @@ export const MongoDBDatabaseEngine: DatabaseEngineFactory = (
119114
? parsedBody
120115
: [parsedBody];
121116
for (const command of commands) {
122-
await db?.command(command);
117+
await db.command(command);
123118
}
124119
} else if (run) {
125120
await run({ db });
@@ -133,10 +128,10 @@ export const MongoDBDatabaseEngine: DatabaseEngineFactory = (
133128
} finally {
134129
const endTime = performance.now();
135130
const nextId = await getNextRecordId(
136-
db!,
131+
db,
137132
engineConfig.migrationRecordCollection
138133
);
139-
await db?.collection(engineConfig.migrationRecordCollection).insert({
134+
await db.collection(engineConfig.migrationRecordCollection).insert({
140135
id: nextId,
141136
version,
142137
type,
@@ -151,9 +146,7 @@ export const MongoDBDatabaseEngine: DatabaseEngineFactory = (
151146
},
152147
async repair(records) {
153148
debug('in repair function');
154-
if (!db) {
155-
throw new SynorError('Database connection is null');
156-
}
149+
157150
await deleteDirtyRecords(db, engineConfig.migrationRecordCollection);
158151

159152
for (const { id, hash } of records) {
@@ -165,9 +158,6 @@ export const MongoDBDatabaseEngine: DatabaseEngineFactory = (
165158
},
166159
async records(startid: number) {
167160
debug('in records function');
168-
if (!db) {
169-
throw new SynorError('Database connection is null');
170-
}
171161

172162
const records = (await (
173163
await db.collection(engineConfig.migrationRecordCollection).find({

0 commit comments

Comments
 (0)