Gathering detailed insights and metrics for pixiedb
Gathering detailed insights and metrics for pixiedb
Gathering detailed insights and metrics for pixiedb
Gathering detailed insights and metrics for pixiedb
A tiny in-memory javascript database with indexing and sql like filters
npm install pixiedb
Typescript
Module System
Node Version
NPM Version
TypeScript (99.68%)
JavaScript (0.32%)
Total Downloads
909
Last Day
3
Last Week
3
Last Month
37
Last Year
909
30 Commits
1 Forks
2 Watching
1 Branches
1 Contributors
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
Cumulative downloads
Total Downloads
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
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.
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"}, ...]
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
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)
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 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" }
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" }, ...]
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" }, ...]
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" }, ...]
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
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
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)
No vulnerabilities found.
No security vulnerabilities found.