Connection

Extends BaseConnection

Main class for data management

The Connection class is the main connection to a database.

To initialise a constant connection, the Path variable should be pointing towards the database file. There is an Options object which allows you to pass on options to the database.

const DB = new QDB.Connection(Path, Options?, Pool?);

Take a look at the available options below.

Options
  • Polling in ms
    Number | False - Default 'false'
  • Backups
    Boolean - Default 'false'
  • Interval in ms
    Number - Default '18000000'
  • GracefulDisconnect
    Boolean - Default 'true'

Properties

.Path

The path to the file which was inputted.
Type - String

.State

The current state of this connection. When successfully connected, this will be 'CONNECTED'.
Type - String

.Cache

A Cache Collection which is free to use within this connection.
Type - Cache

.Datalength

The amount of database tables this database contains.
Type - Number

.Datatype

The type of the database, either 'Object' or 'Array'.
Type - String

.Pool

Whether this connection is in a pool. Returns the pool class, otherwise a nill value.
Type - Pool | Null

Methods

Refer to functions for the database connection methods for interacting with data.

.Reconnect(PathURL)

Reconnects to a different file and state under this class instance.

Parameter Type Description
PathURL String The URL to the new database file.

Returns - Connection | This
Returns the new connection or the same class if the path is invalid.

.Disconnect()

Disconnects from this database connection, terminates the cache and allows you to shut off gracefully.

Returns - PartialConnection
Returns a partially connected class.

.ToInstance(Instance, Path?, ...Args?)

Converts this database, or a part of it using dotaccess, to any Map-form instance.

Parameter Type Description
Instance Any Instance to be converted to. Should either be an instance of a Map or Set, and this can include extended classes like Collections and DataStores.
Path Dotaccess Optional dotaccess path pointing towards what to serialise.
...Args Any Additional arguments to pass on to the instance.

Returns - Instance<This>
The instance with the target as entries.

.ToCache(Path?)

Converts this database, or a part of it using dotaccess, to a Cache instance.

Parameter Type Description
Path Dotaccess Optional dotaccess path pointing towards what to serialise.

Returns - Cache
A Cache instance with the key/model pairs.

.ToDataStore(Path?)

Converts this database, or a part of it using dotaccess, to a DataStore instance.

Parameter Type Description
Path Dotaccess Optional dotaccess path pointing towards what to serialise.

Returns - DataStore
A DataStore instance with the key/model pairs.

.ToIntegratedManager(Path?, Holds?)

Converts this database, or a part of it using dotaccess, to a DataManager instance.

Parameter Type Description
Path Dotaccess Optional dotaccess path pointing towards what to serialise.
Holds Function Given optional class for which instance this Manager is for.

Returns - BaseManager
A Manager instance with the key/model pairs.