In-memory typesafe database with Queries, Events, Analytics.
npm i @datasco/memorydb # pnpm add @datasco/memorydbYou can use MemoryDB for creating in-memory database with any type of data.
Primitive database:
const db = new MemoryDB<string>("primitives_database")Typed object-based database:
const db = new MemoryDB<{
name: string;
price: number;
}>("complex_database")db.insert({ name: "Bear toy", price: 1000 })db.insert([
{ name: "Cat toy", price: 2000 },
{ name: "Dog toy", price: 3000 },
])db.map(
row => ({ ...row, price: price + 100 })
)db.remove(
row => row.price > 1000
)db.clear()// remove rows, where value of "price" is same
db.removeDuplicatesByPredicate(
(duplicateRows) => [ duplicateRows[0] ],
"price"
)db.removeDuplicates()db.removeColumn("price")// split database into chunks of size 5
db.chunks(5)db.merge(new MemoryDB("another_db"))const { data } = db.list()// 1 page, 50 rows per page
const { data } = db.listPaginated(1, 50)const { data } = db.find(
row => row.name === "Bear toy"
)const { data } = db.search(
row => row.name.includes("toy")
)db.chain([
_ => _.insert({ name: "Test", price: 7500 }),
_ => _.map(row => {...row, price: price + 500 }),
_ => _.map(row => {...row, name: name + " toy" })
])const {analytics} = dbanalytics.head()