Example #1
0
routerUnauthenticated.get("/bar/:barId", async function () {
    var conn = await r.connect(AppConfig.dbConfig);
    this.body = await r.table("locations")
        .get(this.params.barId)
        .run(conn);
    conn.close();
});
Example #2
0
db.connect(async () => {
  console.log('rethink', settings.rethinkdb)
  let conn = await rethink.connect(settings.rethinkdb)
  var dbs = await rethink.dbList().run(conn)
  console.log(dbs)
  let fails = 0
  conn.use('icecondor')
  try {
    const cursor = await rethink.table('users').run(conn)
    const users = await cursor.toArray() // all at once
    for (const user of users) {
      try {
        const eu = await db.ensure_user(user)
        if (eu.error) {
          console.log('user2lmdb result error', eu.error)
        } else {
          if (user.id != eu.id) {
            console.log('user2lmdb save FAIL', user.email, eu.email)
            console.log('rethink user', user)
            console.log('ensure user', eu)
            fails += 1
          }
        }
      } catch (e) {
        console.log('user2lmdb', user.email, 'CATCH', e)
        process.exit(1)
      }
    }

    console.log('*** done', users.length, 'rethink users', fails, 'save fails')
    await db.schema_dump()
  } catch (e) {
    console.log(e)
  }
}).catch(e => { console.log(e); process.exit(1) })
Example #3
0
db.connect(async () => {
  console.log('rethink', settings.rethinkdb)
  let conn = await rethink.connect(settings.rethinkdb)
  var dbs = await rethink.dbList().run(conn)
  console.log(dbs)
  conn.use('icecondor')
  //  let act_total = await rethink.table('activities').count().run(conn)
  //  console.log('icecondor activities', act_total)

  try {
    let start = new Date(await db.activity_last_date() || "2008-08-01")
    let stop = new Date()
    while (stop) {
      console.log('\n** lmdb start', start)
      let time = new Date()
      stop = await pull_group(conn, start, limit)
      let delay_sec = (new Date().getTime() - time.getTime()) / limit
      console.log('group done', start, stop, delay_sec + "s", (limit / delay_sec).toFixed(0), "rows per sec")
      db.schema_dump()
      start = new Date(stop)
    }
  } catch (e) {
    console.log('while loop stopped:', e)
  }
  console.log('el fin')
})
router.get("/api/messages", async function() {
  var conn = await r.connect(config.database);
  this.body = await r.table("messages")
                     .orderBy({index: r.desc("time")})
                     .limit(100).orderBy("time")
                     .run(conn);
  conn.close();
});
router.post("/api/messages/create", async function() {
  var conn = await r.connect(config.database);
  this.body = await r.table("messages").insert({
    user: this.request.body.user,
    text: this.request.body.text,
    time: r.now(),
  }).run(conn);
  conn.close();
});
Example #6
0
routerUnauthenticated.get('/leaderBoard', async function () {
    var conn = await r.connect(AppConfig.dbConfig);
    this.body = await r.table("users")
        .orderBy({ index: r.desc("tagCounter") })
        .limit(100)
        .coerceTo('array')
        .run(conn);
    conn.close();
});
Example #7
0
routerUnauthenticated.get("/tracks/:barId", async function () {
    var conn = await r.connect(AppConfig.dbConfig);
    this.body = await r.table("tracks")
        .filter({ location: this.params.barId })
        //.orderBy({ index: r.desc("begin") })
        .limit(50)
        .run(conn);
    conn.close();
});
Example #8
0
routerUnauthenticated.post("/search/bar", async function () {
    if (this.request.body.latitude && this.request.body.longitude) {
        var currentLocation = r.point(this.request.body.latitude, this.request.body.longitude);
        var conn = await r.connect(AppConfig.dbConfig);
        this.body = await r.table('locations')
        .getNearest(currentLocation, { index: 'location', maxResults: 50 })
        .coerceTo('array')
        .run(conn);
        conn.close();
    } else {
        this.body = [];
    }
});
Example #9
0
export function connect () : Promise<db.Connection> {
    const host : string = settings.db.host.get()
    const port : number = settings.db.port.get()
    const name : string = settings.db.name.get()
    
    return db.connect({host, port})
        .then((conn) => {
            logger.debug(`RethinkDB connected to ${host}:${port}`)
            _conn = conn
            conn.use(name)
            logger.debug(`RethinkDB using database '${name}'`)
            return conn
        })
}
Example #10
0
/*
    isomorphrendering() {
        const store = new FabaStore<IcommonStore>(commonImStore);

        const ev = new InitAccountEvent();
        ev.args = [];

        new InitAccountCommand(store).execute(ev);

        var k = React.createElement(Layout, {model: store.data, childs: ev.view});
        var h = ReactDOM.renderToString(k);
        var c = css();

        var testHtml = `<head><style>${c}</style><body>${h}</body>`;

        console.log(testHtml);
    }
*/
    async createDbConnection(): Promise<void> {
        r.connect({host: 'localhost', port: 28015}, (err, conn) => {
            if (err) throw err;
            dbConnection = conn;

            r.dbCreate('lingua').run(conn, (er, rtr) => {
                //console.log(er);
            });


            db = r.db('lingua');

            new PrepareTablesEvent().dispatch();
        });
    }