npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sqlite-objects

v2.0.3

Published

Usable sqlite-based persistent objects: database, key-value store (promised based)

Downloads

8

Readme

sqlite-objects

This package contains usable SQLite wrappers.

What does it mean:

  • Promise-based
  • Sane placeholders: db.findOne('SELECT * FROM items WHERE id = @id', { id: 1 })
  • Setup with new Database(dbPath) and that's it

Objects

Database

This is a wrapper around a SQLite database.

const Database = require('sqlite-objects').Database

;(async () => {

  const db = new Database(
    __dirname + '/database.db'
    // , schemaPath /* optional */
  )

  // await db.ready /* if schemaPath is provided */

  await db.run(`CREATE TABLE IF NOT EXISTS items (
      id    integer  primary key,
      value text     not null
  )`)

  await db.insert(
    `INSERT OR REPLACE INTO items VALUES (@id, @value)`,
    { id: 42, value: 'some value' }
  )

  await db.insertMany(
    `INSERT OR REPLACE INTO items VALUES (@id, @value)`, [
      { id: 43, value: 'fourty-three' },
      { id: 44, value: 'fourty-four' },
    ]
  )

  // Variable placeholders use the @name syntax
  const row = await db.findOne(`SELECT * FROM items WHERE id = @id`, { id: 42 })
  // row === { id: 42, value: 'some value' }

  const rows = await db.findAll(`SELECT * FROM items`)
  // rows === [{ id: 42, value: 'some value' }]

  console.log({ row, rows })
})()

Key-value Store

const KeyValueStore = require('sqlite-objects').KeyValueStore

;(async () => {

  const store = new KeyValueStore(__dirname + '/key-value-store.db')

  await store.ready

  await store.set(42, { value: 'some value' })
  await store.set(43, { value: 'other value' })
  await store.set(44, { value: 'final value' })

  const item = await store.get(42)

  const updateItem = await store.update(42, { content: 'other content' })

  const items = await store.values()

  await store.delete(43)

  const updatedItemsKeys = await store.keys()

  for (let [key, value] of await store.entries()) {
    console.log(key, value)
  }

  console.log({
    item,
    updateItem,
    items,
    updatedItemsKeys,
  })
})()