Make the db module a singleton

We were treating the database class as a singleton, but still having to pass
around the db instance. Now we can simply require the db module and have
access to the database handle.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver
2020-05-28 18:15:33 +01:00
parent 0dc0fc77b6
commit 1d7381327e
32 changed files with 274 additions and 352 deletions

View File

@ -11,7 +11,6 @@ const { expect } = chai;
import Config from '../src/config';
import { RPiConfigBackend } from '../src/config/backend';
import DB from '../src/db';
import DeviceState from '../src/device-state';
import { loadTargetFromFile } from '../src/device-state/preload';
@ -209,8 +208,7 @@ const testTargetInvalid = {
};
describe('deviceState', () => {
const db = new DB();
const config = new Config({ db });
const config = new Config();
const logger = {
clearOutOfDateDBLogs() {
/* noop */
@ -218,7 +216,7 @@ describe('deviceState', () => {
};
let deviceState: DeviceState;
before(async () => {
prepare();
await prepare();
const eventTracker = {
track: console.log,
};
@ -234,7 +232,6 @@ describe('deviceState', () => {
});
deviceState = new DeviceState({
db,
config,
eventTracker: eventTracker as any,
logger: logger as any,
@ -252,7 +249,6 @@ describe('deviceState', () => {
});
(deviceState as any).deviceConfig.configBackend = new RPiConfigBackend();
await db.init();
await config.init();
});