Class: Database<T>

Defined in: ridb_core.d.ts:637

Represents a database containing collections of documents. RIDB extends from this class and is used to expose collections.

So if you specify:

typescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const db = new RIDB(
{
schemas: {
demo: {
version: 0,
primaryKey: 'id',
type: SchemaFieldType.object,
properties: {
id: {
type: SchemaFieldType.string,
maxLength: 60
}
}
}
} as const
}
)

The collection will be available as db.collections.demo and all the methods for the collection (find, count, findById, update, create, delete) will be available.

Type Parameters

T

T extends SchemaTypeRecord

A record of schema types.

Constructors

Constructor

typescript
1
new Database<T>(): Database<T>

Returns

Database<T>

Properties

collections

typescript
1
readonly collections: { [name in string | number | symbol]: Collection<Schema<T[name]>> }

Defined in: ridb_core.d.ts:667

The collections in the database.

This is a read-only property where the key is the name of the collection and the value is a Collection instance.


started

typescript
1
readonly started: boolean

Defined in: ridb_core.d.ts:671

Methods

authenticate()

typescript
1
authenticate(password): Promise<boolean>

Defined in: ridb_core.d.ts:660

Parameters

password

string

Returns

Promise<boolean>


close()

typescript
1
close(): Promise<void>

Defined in: ridb_core.d.ts:685

Closes the database.

Returns

Promise<void>

A promise that resolves when the database is closed.


start()

typescript
1
start(): Promise<void>

Defined in: ridb_core.d.ts:678

Starts the database.

Returns

Promise<void>

A promise that resolves when the database is started.


create()

typescript
1
static create<TS>(db_name, schemas, migrations, plugins, options, password?, storage?): Promise<Database<TS>>

Defined in: ridb_core.d.ts:650

Creates a new Database instance with the provided schemas and storage module.

Type Parameters

TS

TS extends SchemaTypeRecord

A record of schema types.

Parameters

db_name

string

schemas

TS

The schemas to use for the collections.

migrations

MigrationPathsForSchemas<TS> | MigrationPathsForSchema<TS[string]>

plugins

typeof BasePlugin[]

options

RIDBModule

password?

string

storage?

BaseStorage<TS>

Returns

Promise<Database<TS>>

A promise that resolves to the created Database instance.