项目作者: elmarti

项目描述 :
A NoSQL embedded database written in Typescript
高级语言: TypeScript
项目地址: git://github.com/elmarti/camadb.git
创建时间: 2021-09-30T08:16:18Z
项目社区:https://github.com/elmarti/camadb

开源协议:MIT License

下载


CamaDB

CamaDB is a NoSQL embedded database written in pure TypeScript for Node, Electron and browser-based environments.

semantic-release

Why?

I was struggling to find a solution for Electron-based projects that deal with larger datasets in the main thread.

  • I had issues getting SQLite to work with webpack due to its native build
  • SQLite doesn’t (by default) return native JS data types (Dates in particular)
  • Other NoSQL embedded databases seem to be largely abandoned
  • Most other NoSQL embedded databases seem to be limited by V8’s hard string length limits

Goals

  • Fast querying/insertion/manipulation of data, up to 1 million rows
  • Frictionless integration with all JS runtimes
  • Rich API
  • Full TypeScript support
  • Simplicity and versatility - This is built for storing data in dynamic structures

Current state

This is still under active development and a few features are missing:

  • Indexes - We’re finding that this is fast even without these, but every little helps
  • Rich text search

Getting started

Documentation

Installing

  1. yarn add reflect-metadata
  2. yarn add camadb

OR

  1. npm install reflect-metadata --save
  2. npm install camadb --save

Initializing the database

All of these config options are optional:

  • path - Where you want the data to be stored - default is ./.cama or cama for indexeddb and localstorage
  • persistenceAdapter - How you want to persist your data - fs, indexeddb, localstorage or inmemory
  • logLevel - info or debug
    1. import { Cama } from 'camadb'
    2. const database = new Cama({
    3. path: './.cama',
    4. persistenceAdapter: 'fs',
    5. logLevel: 'debug'
    6. });

Initializing a collection

  • Use the columns field to add specific data types for rows. This does need to be done for each column, but is essential for date objects
  • Indexes aren’t currently implemented, but the lookup is still very fast across 10 million rows
    1. const collection = await database.initCollection('test', {
    2. columns: [{
    3. type:'date',
    4. title:'date'
    5. }],
    6. indexes: [],
    7. });

Insert one

  1. await collection.insertOne({
  2. _id: 'test',
  3. name: 'Dummy field',
  4. description: `Data`,
  5. });

Insert many

  1. await collection.insertMany([{
  2. _id: 'test',
  3. name: 'Dummy field',
  4. description: `Data`,
  5. }]);

Find many

CamaDB uses a MongoDB style query language, powered by SiftJS. Have a look at that project to see the full capabilities of that library.

  1. const findResult = await collection.findMany({
  2. _id: {
  3. $gte: 50000,
  4. },
  5. },
  6. {
  7. sort:{
  8. desc: x => x._id
  9. },
  10. offset: 100,
  11. limit: 100
  12. });

Updating

Again we use a MongoDB style language for data updates, for this we use obop

  1. await collection.updateMany({
  2. _id:3
  3. }, {
  4. $set: {
  5. steve:"steve"
  6. }
  7. });

Aggregation

We use Mingo for aggregation - currently lookup commands aren’t supported.

  1. const aggregationResult = await collection.aggregate([{
  2. $match:{
  3. _id:3
  4. }
  5. }]);