How to use the sqlite.all function in sqlite

To help you get started, we’ve selected a few sqlite 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 antonycourtney / tad / test / runQuery.js View on Github external
const main = async () => {
  try {
    const hrProcStart = process.hrtime()
    let hrQueryStart = 0
    await db.open(':memory:')
    await csvimport.importSqlite(testPath, ',', {noHeaderRow: false})
    // await db.open('/Users/antony/data/testdb.sqlite')
    const [es, ens] = process.hrtime(hrProcStart)
    console.info('runQuery: import completed in %ds %dms', es, ens / 1e6)
    // console.log('table import complete: ', md.tableName)
    console.log('running query:\n', tq)
    hrQueryStart = process.hrtime()

    const rows = await db.all(tq)
    const [qes, qens] = process.hrtime(hrQueryStart)
    console.log('read rows from sqlite table.')
    console.table(rows)
    console.info('runQuery: evaluated query in %ds %dms', qes, qens / 1e6)
    await db.close()
  } catch (err) {
    console.error('caught exception running query: ', err, err.stack)
  }
}
github bhj / karaoke-forever / server / Library / Library.js View on Github external
static async getStarCounts () {
    const artists = {}
    const songs = {}

    // get artist star counts
    {
      const query = sql`
        SELECT artistId, COUNT(userId) AS count
        FROM artistStars
        GROUP BY artistId
      `
      const rows = await db.all(String(query), query.parameters)

      rows.forEach(row => { artists[row.artistId] = row.count })
    }

    // get song star counts
    {
      const query = sql`
        SELECT songId, COUNT(userId) AS count
        FROM songStars
        GROUP BY songId
      `
      const rows = await db.all(String(query), query.parameters)

      rows.forEach(row => { songs[row.songId] = row.count })
    }
github bhj / karaoke-forever / server / api / http / library.js View on Github external
router.get('/api/library/scan', async (ctx, next) => {
  const log = debug('app:library:scan')

  if (isScanning) {
    log('ignoring request: scan already in progress')
    return
  }

  isScanning = true

  // get provider configs
  let cfg = {}
  let rows = await db.all('SELECT * FROM config WHERE domain LIKE "%.provider"')

  rows.forEach(function(row){
    const provider = row.domain.substr(0, row.domain.lastIndexOf('.provider'))
    cfg[provider] = JSON.parse(row.data)
  })

  for (let provider in cfg) {
    if (!cfg[provider].enabled) {
      log('Provider "%s" not enabled; skipping', provider)
      continue
    }

    if (!Providers[provider]) {
      log('Provider "%s" is enabled but not loaded', provider)
      continue
    }
github dirigeants / komada / modules / db / sqlite.opt.js View on Github external
.then(() => {
          db.all("SELECT * FROM dataProviderSchemas")
          .then(rows => {
            console.log(rows);
            rows.map(r=> schemaCache.set(r.name, r.schema));
          });
          resolve();
        })
        .catch(reject);
github robcrowley / graphql-demo / server / src / data / connectors.js View on Github external
const getArtistWatches = ids => db
    .all(`SELECT * FROM ArtistWatch WHERE artistWatchId IN (${parameterize(ids)})`, ids);
github Gymnophoria / Arthur / struct / xp.js View on Github external
static async guildLeaderboard (guildID, page, client, locale) {
		let entries = await sql.all(`SELECT userID, level, total FROM xp WHERE guildID = '${guildID}'`);

		if (!entries) return {
			max: 1,
			array: [ i18n.getString('struct.xp.no_one_talked_yet', locale) ]
		};

		entries = entries.sort((a, b) => {
			return a.total < b.total ? 1 : -1;
		});

		let maxPage = Math.ceil(entries.length / 5);
		if (page > maxPage) return false;

		let pageArray = [];
		entries = entries.slice(page * 5 - 5, page * 5);
		let startNum = page * 5 - 4;
github Gymnophoria / Arthur / struct / xp.js View on Github external
static async addXP (message, guildRow) {
		if (message.channel.type !== 'text') return;
		if (message.channel.id === '304429222477299712') return;

		if (!guildRow || guildRow.levels === 'false') return;

		let rows = await sql.all(`SELECT * FROM xp WHERE userID = '${message.author.id}'`);
		let global = Math.max.apply(Math, rows.map(a => a.global));

		let row = await sql.get(`SELECT * FROM xp WHERE userID = '${message.author.id}' AND guildID = '${message.guild.id}'`);
		if (!row) return sql.run(`INSERT INTO xp (userID, guildID, current, total, level, mult, global, lastXP, lastMessage) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, [message.author.id, message.guild.id, 0, 0, 0, 1, 0, 0, Date.now()]);

		if (Date.now() - row.lastXP < config.xp.xpAdd) return sql.run(`UPDATE xp SET lastMessage = ${Date.now()} WHERE userID = '${message.author.id}' AND guildID = '${message.guild.id}'`);

		let mult;
		if (Date.now() - row.lastMessage < 10000) mult = row.mult * 1.02;
		else if (Date.now() - row.lastMessage < 25000) mult = row.mult * 1.01;
		else if (Date.now() - row.lastMessage < 50000) mult = row.mult * 1.005;
		else mult = 1;
		if (mult > config.xp.maxMult) mult = config.xp.maxMult;
		sql.run(`UPDATE xp SET mult = ${mult} WHERE userID = '${message.author.id}' AND guildID = '${message.guild.id}'`);

		let base = Math.round(mult * config.xp.base);
github robcrowley / graphql-demo / server / src / data / connectors.js View on Github external
const getAlbumIdsByLabel = (ids, first) => db
    .all(`SELECT albumId FROM Album WHERE labelId IN (${parameterize(ids)}) LIMIT ?`, asArray(ids).concat(first))
    .then(rows => rows.map(({albumId}) => albumId));
github acarl005 / join-monster-graphql-tools-adapter / src / schema.js View on Github external
return joinMonster(resolveInfo, ctx, sql => {
        return db.all(sql)
      }, { dialect: 'sqlite3' })
    }
github bhj / karaoke-forever / server / Library / Library.js View on Github external
}

    const query = sql`
      SELECT media.*, paths.path, songs.artistId, songs.songId, songs.title
      FROM media
        INNER JOIN (
          SELECT *
          FROM paths
          GROUP BY pathId
        ) paths ON (paths.pathId = media.pathId)
        INNER JOIN songs USING (songId)
        INNER JOIN artists USING (artistId)
      WHERE songId = ${songId}
      ORDER BY paths.priority ASC
    `
    const rows = await db.all(String(query), query.parameters)

    rows.forEach(row => {
      media.result.push(row.mediaId)

      row.file = row.path + path.sep + row.relPath
      media.entities[row.mediaId] = row
    })

    return media
  }

sqlite

SQLite client for Node.js applications with SQL-based migrations API written in Typescript

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis