1.4.3 • Published 3 years ago

@trebossa/localdb v1.4.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Documentation for Multi collection DB (Recommended)

If you want a wrapper for your collections, use the Database constructor

First, import the required classes:

import { Collection, Database } from '@trebossa/localdb'

Define a main interface which represents your database

interface User {
  username: string;
}

interface DB {
  accounts: Collection<User>;
}

Create a db instance and start it:

const db =
  new Database() <
  DB >
  ('my-project',
  {
    absolutePath: path.resolve('./_test/db'),
  },
  [new Collection('accounts')])

await db.start()

Insert documents into your database:

await db.access('accounts').insert({
  username: 'trebossa',
  password: 'MY_SUPER_SECURE_PASSWORD',
})

In this case, you will get autocompletion for the User type

Update documents with a query:

await db.access('accounts').update(
  { username: 'trebossa' },
  {
    $set: {
      password: 'SOME_NEW_PASSWORD',
    },
  }
)

Every atomic operator in the update parameter behave different.

Read values from the database

await db.access('accounts').findOne({ username: 'trebossa' })
await db.access('accounts').find({ username: 'trebossa' })

Create a document and have a reference to that element in the collection, you can update it easily (Auto-syncs the object reference)

const newAccount = db.access('accounts').createDocument({
  username: 'tom',
  password: 'SOME_OTHER_PASSWORD',
})

await newAccount.insert()
1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.2

3 years ago

1.0.0

3 years ago