Skip to content

Commit 355deae

Browse files
authored
Merge pull request #50 from embark-framework/no_db_option
support disabling database
2 parents 5a7ed72 + 583c7a3 commit 355deae

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed
File renamed without changes.

src/database/nullDatabase.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
class NullDatabase {
3+
4+
constructor(_dbFilename, events, cb) {
5+
this.events = events;
6+
if (cb) {
7+
cb();
8+
}
9+
}
10+
11+
databaseInitialize(cb) {
12+
if (cb) {
13+
cb();
14+
}
15+
}
16+
17+
getLastKnownEvent() {
18+
return {
19+
firstKnownBlock: 0,
20+
lastKnownBlock: 0
21+
};
22+
}
23+
24+
getEventsFor(eventKey) {
25+
return [];
26+
}
27+
28+
eventExists(eventKey, eventId) {
29+
return false;
30+
}
31+
32+
recordEvent(eventKey, values) {
33+
}
34+
35+
deleteEvent(eventKey, eventId) {
36+
}
37+
38+
deleteNewestBlocks(eventKey, gteBlockNum) {
39+
}
40+
41+
}
42+
43+
export default NullDatabase;

src/subspace.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ReplaySubject } from 'rxjs';
22
import { distinctUntilChanged, map } from 'rxjs/operators';
33
import equal from 'fast-deep-equal';
4-
import Database from './database.js';
4+
import Database from './database/database.js';
5+
import NullDatabase from './database/nullDatabase.js';
56
import Events from 'events';
67
import Web3Eth from 'web3-eth';
78
import {isAddress} from './utils';
@@ -25,6 +26,7 @@ export default class Subspace {
2526
this.options.callInterval = options.callInterval || 0;
2627
this.options.dbFilename = options.dbFilename || 'subspace.db';
2728
this.latestBlockNumber = undefined;
29+
this.disableDatabase = options.disableDatabase;
2830

2931
this.newBlocksSubscription = null;
3032
this.intervalTracker = null;
@@ -33,8 +35,11 @@ export default class Subspace {
3335

3436
init() {
3537
return new Promise((resolve, reject) => {
36-
this._db = new Database(this.options.dbFilename, this.events);
37-
this.db = this._db.db;
38+
if (this.disableDatabase === true) {
39+
this._db = new NullDatabase("", this.events);
40+
} else {
41+
this._db = new Database(this.options.dbFilename, this.events);
42+
}
3843
this.eventSyncer = new EventSyncer(this.web3, this.events, this._db);
3944
this.logSyncer = new LogSyncer(this.web3, this.events, this._db);
4045

0 commit comments

Comments
 (0)