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

pixiedb

v0.5.3

Published

A tiny in-memory javascript database with indexing and sql like filters.

Downloads

34

Readme

PixieDB

npm version npm downloads bundle JSDocs License

A tiny in-memory javascript database with indexing and sql like filters.

[!WARNING] Please keep in mind that PixieDb is still in under active development.

Usage

import { PixieDb } from "pixiedb";

const products = [
    { id: 1, name: "Apple", price: 5, category: "Fruit" },
    { id: 2, name: "Banana", price: 10, category: "Fruit" },
    { id: 3, name: "Grapes", price: 6, category: "Fruit" },
    { id: 4, name: "Orange", price: 8, category: "Fruit" },
    { id: 5, name: "Potato", price: 18, category: "Vegetable" },
    { id: 6, name: "Milk", price: 7, category: "Dairy" },
    // ...
]

// provide unique key, data and indexes for better performance
// 3rd param data is optional can be load after using the load method
const pd = new PixieDb('id', ["price", "category"], products) 
// or
const pd = new PixieDb<Product>('id', ["price", "category"]) // pass type if using typescript
pd.load(products) // to load data later

const byId = pd.select().eq("id", 2).single()
console.log(byId); // { id: 2, name: "Banana", price: 10, category: "Fruit" }

// can also pass array of fields to select method to pick only those fields/properties
const fruitBelow10 = pd.select(["id", "name", "price"]).eq("category", "Fruit").lte("price", 10).orderBy(["name", ["price", "desc"]]).range(2, 3).data()
console.log(fruitBelow10); // [{ id: 3, name: "Grapes", price: 6 }, ...]

const updatedBanana = pd.where().eq("name", "Banana").update({price: 100})
// [{ id: 2, name: "Banana", price: 100, category: "Fruit" }, ...]

// delete all docs where name equals "Apple"
const deletedApples = pd.where().eq("name", "Apple").delete()
// [{ id: 1, name: "Apple", price: 5, category: "Fruit"}, ...]

Installation

# using npm
npm install pixiedb

# using pnpm
pnpm add pixiedb

# using yarn
yarn add pixiedb

# using bun
bun add pixiedb

Docs

PixieDb

This is a class which create an PixieDb instance to use.

// pass type/interface if using typescript
const pd = new PixieDb<Product>('id', ["price", "category"]) 

// or with data
const pd = new PixieDb<Product>('id', ["price", "category"], products)

Methods

load

Used to import data without cloning (so don't mutate the data or clone before load). Pass true as second parameter to clear the previous data and indexes state. (default: false).

pd.load(products)
// or
pd.load(products, true)
// remove previous data and index state

get

Get single doc/row using key (primary key/unique id). Returns doc/row if present else undefined.

pd.get(2)
// { id: 2, name: "Banana", price: 10, category: "Fruit" }

select

Get single doc/row using key (primary key/unique id). Returns doc/row if present else undefined.

pd.select().eq("category", "Fruit").gte("price", 6).data()
// [{ id: 2, name: "Banana", price: 10, category: "Fruit" }, { id: 3, name: "Grapes", price: 6, category: "Fruit" }, ...]

pd.select(["id", "name", "price"]).eq("category", "Fruit").lte("price", 6).data()
// [{ id: 1, name: "Apple", price: 5 }, ...]

pd.select().eq("category", "Fruit").between("price", [6, 10]).data()
// [{ id: 2, name: "Banana", price: 10, category: "Fruit" }, { id: 3, name: "Grapes", price: 6, category: "Fruit" }, { id: 4, name: "Orange", price: 8, category: "Fruit" }, ...]

where

used to perform delete/update with complex filtering

// this will delete and return all the docs according to the filters
pd.where().eq("category", "Fruit").gte("price", 6).delete()
// [{ id: 2, name: "Banana", price: 10, category: "Fruit" }, { id: 3, name: "Grapes", price: 6, category: "Fruit" }, ...]

pd.where().eq("category", "Fruit").between("price", [6, 10]).update({price: 11})
// [{ id: 2, name: "Banana", price: 11, category: "Fruit" }, { id: 3, name: "Grapes", price: 11, category: "Fruit" }, { id: 4, name: "Orange", price: 11, category: "Fruit" }, ...]

data

Get all docs/rows ordered respect to primary key/unique id. Pass false to get all without clone (don't modify). default: true

pd.data()
// [{ id: 1, name: "Apple", price: 5, category: "Fruit" }, ...]

count

Get all docs/rows ordered respect to primary key/unique id. Pass false to get all without clone (don't modify). default: true

pd.select().count()
// 6

pd.select().eq("category", "Fruit").between("price", [6, 10]).count()
// 4

close

to close/quit/terminate the database and remove all data/indexes and fire "Q" ("quit") event. Pass true to not emit events. default: false

pd.close()
// or
pd.close(true) // doesn't fire event

toJson

return JSON of all data (without cloning), key and index names.

pd.toJSON()
// { key: "id", indexes: ["price", "category", {name: "id", unique: true}], data: [{ id: 1, name: "Apple", price: 10, category: "Fruit" }, ...]

// this will call the above toJSON method
JSON.stringify(pd)

view more