How to use level - 10 common examples

To help you get started, we’ve selected a few level examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethereum-optimism / optimism / packages / data-transport-layer / src / services / main / service.ts View on Github external
protected async _init(): Promise {
    this.logger.info('Initializing L1 Data Transport Service...')

    this.state.db = level(this.options.dbPath)
    await this.state.db.open()

    this.state.l1TransportServer = new L1TransportServer({
      ...this.options,
      db: this.state.db,
    })

    // Optionally enable sync from L1.
    if (this.options.syncFromL1) {
      this.state.l1IngestionService = new L1IngestionService({
        ...this.options,
        db: this.state.db,
      })
    }

    // Optionally enable sync from L2.
github beakerbrowser / beaker / app / background-process / networks / dat.js View on Github external
export function setup () {
  // open databases
  dbPath = path.join(app.getPath('userData'), 'Hyperdrive')
  mkdirp.sync(path.join(dbPath, 'Archives')) // make sure the folders exist
  db = level(dbPath)
  archiveMetaDb = subleveldown(db, 'archive-meta', { valueEncoding: 'json' })
  subscribedArchivesDb = subleveldown(db, 'subscribed-archives', { valueEncoding: 'json' })
  ownedArchivesDb = subleveldown(db, 'owned-archives', { valueEncoding: 'json' })
  drive = hyperdrive(db)

  // watch archives for FS changes
  var watcher = chokidar.watch(path.join(dbPath, 'Archives'), { persistent: true, cwd: path.join(dbPath, 'Archives') })
  watcher.on('ready', () => { // wait till ready, otherwise we get an 'add' for each existing file
    watcher.on('add', onArchiveFSChange.bind(null, 'add', 'file'))
    watcher.on('addDir', onArchiveFSChange.bind(null, 'add', 'directory'))
    watcher.on('change', onArchiveFSChange.bind(null, 'change', 'file'))
    // watcher.on('unlink', onArchiveFSChange.bind(null, 'unlink', 'file')) TODO: dat doesnt support deletes yet
    // watcher.on('unlinkDir', onArchiveFSChange.bind(null, 'unlink', 'directory')) TODO: dat doesnt support deletes yet
  })
  app.once('will-quit', () => watcher.close())
github delvedor / LightFirewall / ipChecker.es6.js View on Github external
constructor(time = 1000 * 60 * 10, attempts = 4) {
    this.time = time; // time before timeout, default value 10 mins
    this.attempts = attempts; // max amount of attempts, default value is 4
    this.ipsTimeout = level('.ipchecker-ipstimeout');
    this.ipsAttempts = level('.ipchecker-ipsattempts');
  }
github voltairelabs / plasma / src / chain / index.js View on Github external
constructor(options = {}) {
    this.options = options
    this.blockDb = level(`${this.options.db}/block`, defaultDBOptions)
    this.detailsDb = level(`${this.options.db}/details`, defaultDBOptions)
    this.txPoolDb = level(`${this.options.db}/txPool`, defaultDBOptions)

    // transaction pool
    this.txPool = new TxPool(this.txPoolDb)

    // sync manager
    this.syncManager = new SyncManager(this, this.options.network)

    // create instance for web3
    this.web3 = new Web3(this.options.web3Provider)

    // create root chain contract
    this.parentContract = new this.web3.eth.Contract(
      RootChain.abi,
      this.options.rootChainContract
    )
github voltairelabs / plasma / src / chain / index.js View on Github external
constructor(options = {}) {
    this.options = options
    this.blockDb = level(`${this.options.db}/block`, defaultDBOptions)
    this.detailsDb = level(`${this.options.db}/details`, defaultDBOptions)
    this.txPoolDb = level(`${this.options.db}/txPool`, defaultDBOptions)

    // transaction pool
    this.txPool = new TxPool(this.txPoolDb)

    // sync manager
    this.syncManager = new SyncManager(this, this.options.network)

    // create instance for web3
    this.web3 = new Web3(this.options.web3Provider)

    // create root chain contract
    this.parentContract = new this.web3.eth.Contract(
      RootChain.abi,
      this.options.rootChainContract
    )
github voltairelabs / plasma / src / chain / index.js View on Github external
constructor(options = {}) {
    this.options = options
    this.blockDb = level(`${this.options.db}/block`, defaultDBOptions)
    this.detailsDb = level(`${this.options.db}/details`, defaultDBOptions)
    this.txPoolDb = level(`${this.options.db}/txPool`, defaultDBOptions)

    // transaction pool
    this.txPool = new TxPool(this.txPoolDb)

    // sync manager
    this.syncManager = new SyncManager(this, this.options.network)

    // create instance for web3
    this.web3 = new Web3(this.options.web3Provider)

    // create root chain contract
    this.parentContract = new this.web3.eth.Contract(
      RootChain.abi,
      this.options.rootChainContract
github zalando / zappr / server / persistence / database.js View on Github external
constructor() {
    // TODO: offer other solutions than LevelDB
    const name = config.get('LEVEL_DB')
    this.db = level(name, {valueEncoding: 'json'})
  }
github codecombat / codecombat / scripts / analytics / mongodb / queries / averageLevelPlaytimes.js View on Github external
function getPlaytimes(levelSlugs) {
  // printjson(levelSlugs);
  var startObj = objectIdWithTimestamp(ISODate(startDay + "T00:00:00.000Z"));
  var endObj = objectIdWithTimestamp(ISODate(endDay + "T00:00:00.000Z"))
  var cursor = db['level.sessions'].find({
    $and:
    [
      {"state.complete": true},
      {"playtime": {$gt: 0}},
      {levelID: {$in: levelSlugs}},
      {_id: {$gte: startObj}},
      {_id: {$lt: endObj}}
    ]
  }, {heroConfig: 1, levelID: 1, playtime: 1});

  var playtimes = {};
  while (cursor.hasNext()) {
    var myDoc = cursor.next();
    var levelID = myDoc.levelID;

    if (!playtimes[levelID]) playtimes[levelID] = {campaign: [], course: []};
github codecombat / codecombat / scripts / analytics / mongodb / queries / LevelPlayedBeforeSub.js View on Github external
]
  });
} else {
  print("No date range specified");
  paymentsCursor = db.payments.find({"stripe.subscriptionID": { "$exists" : true }});
}

while (paymentsCursor.hasNext()) {
  var doc = paymentsCursor.next();
  var purchaseDate = doc.created;
  var user = doc.purchaser.valueOf();

  // print("Processing purchase on " + purchaseDate + " for " + user);

  // Find last level session completed
  var levelSessionCursor = db['level.sessions'].find({
    $and: [{"state.complete" : true}, {creator : user}, {changed: {$lt: ISODate(purchaseDate)}}]
  }).sort({created: -1});
  if (levelSessionCursor.hasNext()) {
    var lastLevelSessionCompleted = levelSessionCursor.next();

    // Find last level completed
    var levelCursor = db.levels.find({"original" : ObjectId(lastLevelSessionCompleted.level.original), "version.isLatestMajor": true, "version.isLatestMinor": true})
    if (levelCursor.hasNext()) {
      var lastLevel = levelCursor.next();
      if (!lastLevelCompleted[lastLevel.name]) lastLevelCompleted[lastLevel.name] = 0;
      lastLevelCompleted[lastLevel.name]++;
    }
    else {
      if (!lastLevelCompleted['unknown']) lastLevelCompleted['unknown'] = 0;
      lastLevelCompleted['unknown']++;
    }
github codecombat / codecombat / scripts / analytics / mongodb / queries / abTestHelpers.js View on Github external
doc.purchased.gems &&
          !doc.stripe.free
        ) {
          countedSubscriberMap[doc._id + ''] = true;
          groupSubscribedMap[group] = (groupSubscribedMap[group] || 0) + 1;
        }
    }
    log("Fetched", Math.min(userOffset, users.length), "users");
  }
  // printjson(userGroupMap);

  log("Fetching level sessions..");
  var lsBrowserMap = {};
  var userBrowserMap = {};
  for (var sessionOffset = 0; sessionOffset < levelSessions.length; sessionOffset += 1000) {
    cursor = db['level.sessions'].find({_id : {$in: levelSessions.slice(sessionOffset, sessionOffset + 1000)}});
    while (cursor.hasNext()) {
      var doc = cursor.next();
      var user = doc._id.valueOf();
      var browser = doc.browser;
      var browserInfo = '';
      if (browser && browser.platform) {
        browserInfo += browser.platform;
      }
      if (browser && browser.name) {
        browserInfo += browser.name;
      }
      if (browserInfo.length > 0) {
        lsBrowserMap[doc._id.valueOf()] = browserInfo;
        userBrowserMap[user] = browserInfo;
      }
    }