A tiny in-memory javascript database with indexing and sql like filters
Installations
npm install pixiedb
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
18.17.1
NPM Version
9.6.7
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.68%)
JavaScript (0.32%)
Developer
Download Statistics
Total Downloads
909
Last Day
3
Last Week
3
Last Month
37
Last Year
909
GitHub Statistics
30 Commits
1 Forks
2 Watching
1 Branches
1 Contributors
Package Meta Information
Latest Version
0.5.4
Package Id
pixiedb@0.5.4
Unpacked Size
83.00 kB
Size
18.61 kB
File Count
8
NPM Version
9.6.7
Node Version
18.17.1
Publised On
27 Sept 2024
Total Downloads
Cumulative downloads
Total Downloads
909
Last day
-75%
3
Compared to previous day
Last week
-82.4%
3
Compared to previous week
Last month
-9.8%
37
Compared to previous month
Last year
0%
909
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
PixieDB
A tiny in-memory javascript database with indexing and SQL like filters.
Features
- Speed - PixieDb perform get in the O(1) and other all operations (insert, delete, select*) in log(n) time. Can perform get operation with unique index (18M ops/s) and binary-index (5M ops/s) which is 15-20 times faster than lokijs/lokidb.
- Quick load - loads data 20x faster than lokijs/lokidb.
- Realtime filtering - perform filtering and event calling in realtime.
- Memory efficient - use iterators and Binary indexes (red black tree) for indexes to perform filtering.
- Events - notifies you about load, insert, update, delete, and quit to sync your state with the database.
- Indexes = for fast filtering.
- Chaining = supports filter chaining.
[!WARNING] Please keep in mind that PixieDb is still in under active development.
Usage
1import { PixieDb } from "pixiedb"; 2 3const products = [ 4 { id: 1, name: "Apple", price: 5, category: "Fruit" }, 5 { id: 2, name: "Banana", price: 10, category: "Fruit" }, 6 { id: 3, name: "Grapes", price: 6, category: "Fruit" }, 7 { id: 4, name: "Orange", price: 8, category: "Fruit" }, 8 { id: 5, name: "Potato", price: 18, category: "Vegetable" }, 9 { id: 6, name: "Milk", price: 7, category: "Dairy" }, 10 // ... 11] 12 13// provide unique key, data and indexes for better performance 14// 3rd param data is optional, Can be loaded after using the load method 15const pd = new PixieDb('id', ["price", "category"], products) 16// or 17const pd = new PixieDb<Product>('id', ["price", "category"]) // pass type if using typescript 18pd.load(products) // to load data later 19 20const byId = pd.select().eq("id", 2).single() 21console.log(byId); // { id: 2, name: "Banana", price: 10, category: "Fruit" } 22 23// can also pass an array of fields to select method to pick only those fields/properties 24const fruitBelow10 = pd.select(["id", "name", "price"]).eq("category", "Fruit").lte("price", 10).orderBy(["name", ["price", "desc"]]).range(2, 3).data() 25console.log(fruitBelow10); // [{ id: 3, name: "Grapes", price: 6 }, ...] 26 27const updatedBanana = pd.where().eq("name", "Banana").update({price: 100}) 28// [{ id: 2, name: "Banana", price: 100, category: "Fruit" }, ...] 29 30// delete all docs where name equals "Apple" 31const deletedApples = pd.where().eq("name", "Apple").delete() 32// [{ id: 1, name: "Apple", price: 5, category: "Fruit"}, ...]
Installation
1# using npm 2npm install pixiedb 3 4# using pnpm 5pnpm add pixiedb 6 7# using yarn 8yarn add pixiedb 9 10# using bun 11bun add pixiedb
Docs
PixieDb
This is a class which creates an PixieDb instance to use.
1// pass type/interface if using typescript 2const pd = new PixieDb<Product>('id', ["price", "category"]) 3 4// or with data 5const 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).
1pd.load(products) 2// or 3pd.load(products, true) 4// remove previous data and index state
get
Get single doc/row using key (primary key/unique id). Returns doc/row, if present else undefined.
1pd.get(2) 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.
1pd.select().eq("category", "Fruit").gte("price", 6).data() 2// [{ id: 2, name: "Banana", price: 10, category: "Fruit" }, { id: 3, name: "Grapes", price: 6, category: "Fruit" }, ...] 3 4pd.select(["id", "name", "price"]).eq("category", "Fruit").lte("price", 6).data() 5// [{ id: 1, name: "Apple", price: 5 }, ...] 6 7pd.select().eq("category", "Fruit").between("price", [6, 10]).data() 8// [{ 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
1// this will delete and return all the docs according to the filters 2pd.where().eq("category", "Fruit").gte("price", 6).delete() 3// [{ id: 2, name: "Banana", price: 10, category: "Fruit" }, { id: 3, name: "Grapes", price: 6, category: "Fruit" }, ...] 4 5pd.where().eq("category", "Fruit").between("price", [6, 10]).update({price: 11}) 6// [{ 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 respecting to primary key/unique id. Pass false to get all without clone (don't modify). Default: true
1pd.data() 2// [{ id: 1, name: "Apple", price: 5, category: "Fruit" }, ...]
count
Get all docs/rows ordered respecting to primary key/unique id. Pass false to get all without clone (don't modify). Default: true
1pd.select().count() 2// 6 3 4pd.select().eq("category", "Fruit").between("price", [6, 10]).count() 5// 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
1pd.close() 2// or 3pd.close(true) // doesn't fire event
toJson
return JSON of all data (without cloning), key and index names.
1pd.toJSON() 2// { key: "id", indexes: ["price", "category", {name: "id", unique: true}], data: [{ id: 1, name: "Apple", price: 10, category: "Fruit" }, ...] 3 4// this will call the above toJSON method 5JSON.stringify(pd)
Roadmap
- load docs
- get all docs
- get docs with key
- Events (load, change, insert, update, delete, quit)
- orderBy with multiple keys (sorting)
- single doc with filters
- count of docs with filters
- update of docs with filters
- delete of docs with filters
- Plugin support
- Unique indexes (currently override the previous)
- filters
- eq (equal)
- neq (not equal)
- in (value in)
- nin (value not in)
- between - values within a given range (>= and <=). begin and end values are included.
- nbetween - values not within a given range (< or >). begin and end values are not included.
- gt (greater than)
- gte (greater than or equal to)
- lt (less than)
- lte (less than or equal to)
- custom query method
- range offset (from) and count (limit of docs to return)
- multiple tables
- joins
- changes api
- custom clone method
- custom compare method
- views
- Basic views
- Materialized views (persist)
- plugins
- persist (localStorage, indexedb)
- sync with other databases
- sync with browser tabs
Other Details
query filters that use binary index (perform operation in log(n))
- eq
- in
- between log(n) + count of docs between
- gt log(n) + count of docs
- gte log(n) + count of docs
- lt log(n) + count of docs
- lte log(n) + count of docs
other query filters
- neq O(n)
- nin O(n)
- nbetween log(n) + count of docs (where value less than or equal to)
No vulnerabilities found.
No security vulnerabilities found.