
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Event-driven, DB-agnostic, sane ORM.
This is really just a dispatcher that sends everything around, making your database more event-driven. It abstracts away the database making a SQL system resemble more of a document-based store. It has some small opinions about the final schema, but they can be overridden. This system also enables the use of caching engines to squeeze better performance out of your fetch operations.
This is still a WIP and does not contain working code as of yet
npm install dbx --save
var dbx = require('dbx');
// @todo
Constructor to create a new connection, defines the database driver and other driver-specific options. See Database Drivers for more information.
dbx.Connection([identifier, ]options)
identifier
- 'String' (optional): Omit to have returned the default connectionoptions
- 'Object': With the following options:
driver
- Driver implementing dbx
, use require('dbx-mysql')
for mysqlhost
- Hostname to connect toport
- Port to connect to[...]
- Anything else driver-specific (see docs for individual drivers)This is an EventEmitter
with the following events:
Emitted upon successful connection
function (err, connection) { }
err
non-false when an error occurs, instance of dbx.Error
otherwise.Emitted upon disconnect.
function (err, reason) { }
err
instance of dbx.Error
.reason
int (enum)Emitted each time an error occurs.
function (err) { }
err
instance of dbx.Error
.Emitted when a query is ran
function (err, query)
Define a caching engine. See Caching Engines.
Synchronize defined models with upstream schema
Define a new model. See Defining Models.
name
String - Name of the modeloptions
Object - Object containing the model definitionReturns an instance of dbx.Model.
Get the model by its name.
name
String - Name of the model defined previouslyReturns an instance of dbx.Model.
Directly run an SQL query.
sql
stringfromCache
boolean (optional) attempt to load from cachecallback
callback function accepting the following parameters
err
instance of dbx.Error
if error, falsey otherwiserecords
Array, instances of dbx.Record
The base class for all data models. Note that this is only the API documentation, for a more practical introduction to models, see Defining Models. Note that it cannot be used directly, rather only through defining a model, which will have an instance returned to you. The consequence of this is that all events listed here are local to individual models.
This is an EventEmitter
with the following events:
Emitted after a successful write is issued for a new record.
function (record[, callback]) { }
record
instance of dbx.Record
callback
callback function accepting no parametersEmitted after a successful delete has been issued.
See Event 'postCreate' for callback details
Emitted after a fetch operation is issued to the DB.
function (query[, callback]) { }
query
instance of dbx.Query
records
Array of dbx.Record
callback
callback function accepting no parametersEmitted after a successful write is issued for either a new or an existing record.
See Event 'postCreate' for callback details
Emitted after a successful write is issued for an existing record.
See Event 'postCreate' for callback details
Emitted before a write is issued for a new record. Use this hook for formatting data or injecting data into the query before it's run. use the 'validate' event for data validation.
function (record[, callback]) { }
record
instance of dbx.Record
callback
callback function accepting the following parameters:
err
instance of dbx.Error
if error, falsey otherwise. Errors will abort the write and it will bubble uprecord
instance of dbx.Record
(if you wish for any changes to be made) or falsey if nothing is to be changedEmitted before a delete is issued to an existing record.
function (record[, callback]) { }
record
instance of dbx.Record
callback
callback function accepting the following parameters:
err
instance of dbx.Error
if error, falsey otherwise. Errors will abort the delete and it will bubble upEmitted before a fetch operation is issued to the DB
function (query[, callback]) { }
query
instance of dbx.Query
callback
callback function accepting the following parameters:
err
instance of dbx.Error
if error, falsey otherwise. Errors will abort the delete and it will bubble upEmitted before a write is issued for either a new or an existing record.
See Event 'preCreate' for callback details
Emitted before a write is issued for an existing record.
See Event 'preCreate' for callback details
Emitted before any db operations have taken place, this is where you can validate information and error out if needed.
function (record[, callback]) { }
record
instance of dbx.Record
callback
callback function accepting the following parameters
err
instance of dbx.Error
if error, falsey otherwise. Errors will abort the write and it will bubble upCount the number of records in a query.
query
instance of dbx.Query
callback
callback function accepting the following parameters
err
instance of dbx.Error
if error, falsey otherwisecount
NumberCreate a new record, does not issue a create in the DB yet.
obj
key/value hash of fields OR instance of dbx.Record
(to clone an object)callback
callback function accepting the following parameters
err
instance of dbx.Error
if error, falsey otherwiserecord
instance of dbx.Record
Fetch one by the primary key.
id
primary key identifier as defined in the modelfromCache
boolean (optional) attempt to load from cachecallback
callback function accepting the following parameters
err
instance of dbx.Error
if error, falsey otherwiserecord
instance of dbx.Record
Fetch many by an array of primary keys.
ids
Array of primary key identifier as defined in the modelfromCache
boolean (optional) attempt to load from cachecallback
callback function accepting the following parameters
err
instance of dbx.Error
if error, falsey otherwiserecords
Array, instances of dbx.Record
Perform a search on a model.
query
instance of dbx.Query
fromCache
boolean (optional) attempt to load from cachecallback
callback function accepting the following parameters
err
instance of dbx.Error
if error, falsey otherwiserecords
Array, instances of dbx.Record
Alias of connection.query()
Delete the instance record.
callback
callback function accepting the following parameters
err
instance of dbx.Error
if error, falsey otherwiseSaves the current state of the model (updates or creates).
callback
callback function accepting the following parameters
err
instance of dbx.Error
if error, falsey otherwiseNumber - Unix timestamp from when the record was originally created
Number - Unix timestamp from when the record was last updated
Boolean - Whether the record exists in the DB or not
Number|String - Primary key of the record, falsey if this is not used as the main ID.
Boolean - Whether the record exists in the cache or not. Always false if no caching engine is defined.
Number - Time (MS)
Boolean - Has the query been executed yet
Boolean - Were the results in cache?
String - raw SQL query
FAQs
DB-agnostic, hookable, event-driven, ORM
The npm package dbx receives a total of 1 weekly downloads. As such, dbx popularity was classified as not popular.
We found that dbx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.