2.0.0 • Published 1 year ago

adost v2.0.0

Weekly downloads
42
License
ISC
Repository
github
Last release
1 year ago

Adost

A fast postgres CRUD ORM

Documentation

Original base work was a forked from @abeai/node-utils

Classes

Constants

PGActiveModel ⇐ PGEncryptModel

Postgres Active Model class to extend a custom model from.

Kind: global class
Extends: PGEncryptModel

pgActiveModel.addProperty(name, value)

Adds a property to this model that does not affect it from a database perspective.

Kind: instance method of PGActiveModel

ParamTypeDescription
nameStringThe name of the property.
valueAnyThe the value to set the property.

pgActiveModel.find() ⇒ PGActiveModel

Retrieves the current model by its set field with type PGTypes.PK

Kind: instance method of PGActiveModel
Returns: PGActiveModel - Returns it's self.

pgActiveModel.delete() ⇒ PGActiveModel

Deletes the current model by its set field with type PGTypes.PK

Kind: instance method of PGActiveModel
Returns: PGActiveModel - Returns it's self.

pgActiveModel.create() ⇒ PGActiveModel

Creates a new row with the currently set properties.

Kind: instance method of PGActiveModel
Returns: PGActiveModel - Returns it's self.

pgActiveModel.save() ⇒ PGActiveModel

Saves the model with its changed properties.

Kind: instance method of PGActiveModel
Returns: PGActiveModel - Returns it's self.

pgActiveModel.update() ⇒ PGActiveModel

Updates the model with the passed in changed properties.

Kind: instance method of PGActiveModel
Returns: PGActiveModel - Returns it's self.

pgActiveModel.decrypt(...props) ⇒ PGActiveModel

Decrypts the properties on the model based on which stringed names are passed in as arguments.

Kind: instance method of PGActiveModel
Returns: PGActiveModel - Returns it's self.

ParamTypeDescription
...propsStringname of each property.

pgActiveModel.encrypt(...props) ⇒ PGActiveModel

Encrypts the properties on the model based on which stringed names are passed in as arguments.

Kind: instance method of PGActiveModel
Returns: PGActiveModel - Returns it's self.

ParamTypeDescription
...propsStringname of each property.

pgActiveModel.redactSensitiveData(redactionCensor) ⇒ PGActiveModel

Redacts all encrypted fields from the model.

Kind: instance method of PGActiveModel
Returns: PGActiveModel - Returns it's self.

ParamTypeDefaultDescription
redactionCensorString"redacted"The string to replace the encrypted values with.

pgActiveModel.getEncryptedProfile() ⇒ String

Gets the encrypted profile that the model has set.

Kind: instance method of PGActiveModel
Returns: String - Returns it's self.

PGActiveModel.create(model) ⇒ PGActiveModel

Creates a new row with the passed in props and values.

Kind: static method of PGActiveModel
Returns: PGActiveModel - Returns it's self.

ParamTypeDescription
modelObjectA plain object with the name of the properties and their values to be set with the new model.

Example

create({
      username: 'foo',
      email: 'test@test.com',
   });

PGActiveModel.findById(id) ⇒ PGActiveModel

Retrives a model by it's PK.

Kind: static method of PGActiveModel
Returns: PGActiveModel - Returns a new model.

ParamTypeDescription
idStringThe PK of the model to retrieve.

PGActiveModel.findLimtedBy(fieldValues, operator, limit) ⇒ Array.<PGActiveModel>

Retrives a limited amount models by the passed in fieldValues.

Kind: static method of PGActiveModel
Returns: Array.<PGActiveModel> - Returns an array of new models.

ParamTypeDefaultDescription
fieldValuesObjectA plain object with the properties and their values to retrive by.
operatorStringANDThe query operator to use between each of the fieldValues AND, OR, 'NOT'
limitNumberThe limit to stop searching when the records retrived are equal or greater than the set limit.

Example

findLimtedBy({
      username: ['user2', 'OR', 'user3'],
      email: null,
   }, 'AND', 5);

PGActiveModel.findAllBy(fieldValues, operator) ⇒ Array.<PGActiveModel>

Retrives all models by the passed in fieldValues. Will stop searching when the records retrived are equal or greater than limit.

Kind: static method of PGActiveModel
Returns: Array.<PGActiveModel> - Returns an array of new models.

ParamTypeDefaultDescription
fieldValuesObjectA plain object with the properties and their values to retrive by.
operatorStringANDThe query operator to use between each of the fieldValues AND, OR, 'NOT'

Example

findAllBy({
      username: ['user2', 'OR', 'user3'],
      email: null,
   }, 'AND');

PGActiveModel.findAll() ⇒ Array.<PGActiveModel>

Retrives all rows in the table of the model.

Kind: static method of PGActiveModel
Returns: Array.<PGActiveModel> - Returns an array of new models.

PGActiveModel.deleteById(id) ⇒ PGActiveModel

Deletes a model that is found by it's PK with the passed in props and values.

Kind: static method of PGActiveModel
Returns: PGActiveModel - Returns a new model or null

ParamTypeDescription
idStringThe PK of the model to delete.

PGActiveModel.deleteLimitedBy(fieldValues, operator, limit) ⇒ Array.<PGActiveModel>

Deletes a limited amount models by the passed in fieldValues.

Kind: static method of PGActiveModel
Returns: Array.<PGActiveModel> - Returns an array of deleted models.

ParamTypeDefaultDescription
fieldValuesObjectA plain object with the properties and their values to delete by.
operatorStringANDThe query operator to use between each of the fieldValues AND, OR, 'NOT'
limitNumberThe limit to stop deleting when the records retrived are equal or greater than the set limit.

Example

deleteLimitedBy({
      registered: false,
   },'AND', 5);

PGActiveModel.deleteAllBy(fieldValues, operator) ⇒ Array.<PGActiveModel>

Deletes all models by the passed in fieldValues.

Kind: static method of PGActiveModel
Returns: Array.<PGActiveModel> - Returns an array of deleted models.

ParamTypeDefaultDescription
fieldValuesObjectA plain object with the properties and their values to delete by.
operatorStringANDThe query operator to use between each of the fieldValues AND, OR, 'NOT'

Example

deleteAllBy({
      registered: true,
   });

PGActiveModel.deleteAll() ⇒ Array.<PGActiveModel>

Deletes all models in their table.

Kind: static method of PGActiveModel
Returns: Array.<PGActiveModel> - Returns an array of deleted models or null

PGActiveModel.updateById(id, model, returnModel) ⇒ PGActiveModel

Updates a model that is found by it's PK with the passed in props and values.

Kind: static method of PGActiveModel
Returns: PGActiveModel - Returns a new model or null

ParamTypeDefaultDescription
idStringThe PK of the model to update.
modelObjectA plain object with the name of the properties and their values to update the model with.
returnModelBooleantrueIf the updated model should be returned or not. It will return null if this is set to false.

Example

updateById('09A75A84-A921-4F68-8FEF-B8392E3702C2',
  {
    password: 'bestpasswordinalltheland12346969420'
  });

PGActiveModel.updateLimitedBy(fieldValues, model, operator, returnModel, limit) ⇒ Array.<PGActiveModel>

Updates models that are found by the passed in fieldValues with the passed in props and values of the model.

Kind: static method of PGActiveModel
Returns: Array.<PGActiveModel> - Returns an array of updated models or null

ParamTypeDefaultDescription
fieldValuesObjectA plain object with the properties and their values to update by.
modelObjectA plain object with the name of the properties and their values to update the model with.
operatorStringANDThe query operator to use between each of the fieldValues AND, OR, 'NOT'
returnModelBooleantrueIf the updated model should be returned or not. It will return null if this is set to false.
limitNumberThe limit to stop searching when the records retrived are equal or greater than the set limit.

Example

updateLimitedBy({
    password: null
  },
  {
    password: 'bestpasswordinalltheland12346969420'
  },'AND', true, 5);

PGActiveModel.updateAllBy(fieldValues, model, operator, returnModel) ⇒ Array.<PGActiveModel>

Updates all models that are found by the passed in fieldValues with the passed in props and values of the model.

Kind: static method of PGActiveModel
Returns: Array.<PGActiveModel> - Returns an array of updated models or null

ParamTypeDefaultDescription
fieldValuesObjectA plain object with the properties and their values to update by.
modelObjectA plain object with the name of the properties and their values to update the model with.
operatorStringANDThe query operator to use between each of the fieldValues AND, OR, 'NOT'
returnModelBooleantrueIf the updated model should be returned or not. It will return null if this is set to false.

Example

updateAllBy({
    password: null
  },
  {
    password: 'bestpasswordinalltheland12346969420'
  });

PGActiveModel.updateAll(model) ⇒ Array.<PGActiveModel>

Updates all models in their table with the passed in props and values of the model.

Kind: static method of PGActiveModel
Returns: Array.<PGActiveModel> - Returns an array of updated models or null

ParamTypeDescription
modelObjectA plain object with the name of the properties and their values to update the models with.

Example

updateAll({
    password: 'bestpasswordinalltheland12346969420'
  });

PGBaseModel

Postgres Base Model class to extend a custom model from.

Kind: global class

PGConnecter

Postgres Connecter to initialize the singleton for connection.

Kind: global class

new PGConnecter(options)

ParamTypeDefaultDescription
optionsObjectThe connection options.
options.cryptoCryptopostgres/crypto/interface.jsThe implemented crypto interface that follows postgres/crypto/interface.js
options.pgObjectThe options object to pass into pg lib.
options.pg.userStringprocess.env.PGUSERUser's name.
options.pg.passwordStringprocess.env.PGPASSWORDUser's password.
options.pg.databaseStringprocess.env.PGDATABASEDatabase's name.
options.pg.portNumberprocess.env.PGPORTDatabase's port.
options.pg.connectionStringStringPostgres formated connection string. e.g. postgres://user:password@host:5432/database
options.pg.sslTLSSocketOptions to be passed into the native Node.js TLSSocket socket.
options.pg.typespg.typesCustom type parsers. See node-postgres types for more details.
options.pg.statement_timeoutNumber0Number of milliseconds before a statement in query will time out.
options.pg.query_timeoutNumber0number of milliseconds before a query call will timeout.
options.pg.connectionTimeoutMillisNumber0Number of milliseconds to wait before timing out when connecting a new client.
options.pg.idleTimeoutMillisNumber10000Number of milliseconds a client must sit idle in the pool and not be checked out before it is disconnected from the backend and discarded.
options.pg.maxNumber10Maximum number of clients the pool should contain.

Example

var pgOptions = {
    pg: {
        connectionString: 'postgres://postgres@localhost/pgtest',
    }
};

try {
    pgOptions.crypto = require('@abeai/node-crypto').utils.pgCrypto;
} catch (_) {
    console.log(_);
}

var pg = new PGConnecter(pgOptions);

PGEncryptModel ⇐ PGBaseModel

Postgres Encryption Model class to extend a custom model from.

Kind: global class
Extends: PGBaseModel

PGTypes

The types of fields for Postgres Models.

Kind: global constant

PGTypes.PK

The primary key of the table.

Kind: static property of PGTypes

PGTypes.Encrypt

Marks this field to auto encrypt/hash (for look up) but not auto decrypt it on retrieval. The table will need to have a field with the same name as this set field with __ as a prefix.

Kind: static property of PGTypes
Example

//if you have an encrypted field called `phone` the sql query for creating the table may look like this
 CREATE TABLE IF NOT EXISTS users (
   phone VARCHAR (500),
   __phone VARCHAR (500) UNIQUE,
 );

PGTypes.EncryptWithoutHash

Marks this field to auto encrypt but not auto decrypt it on retrieval. Same as Encrypt but with no lookup hash.

Kind: static property of PGTypes

PGTypes.EncryptProfile

Marks this field as the encryption profile for encrypting/decrypting/hashing utilizing aws kms.

Kind: static property of PGTypes

PGTypes.AutoCrypt

Marks this field to auto encrypt/hash (for look up) and to auto decrypt it on retrieval.

Kind: static property of PGTypes

PGTypes.AutoCryptWithoutHash

Marks this field to auto encrypt and auto decrypt it on retrieval. Same as AutoCrypt but with no lookup hash.

Kind: static property of PGTypes

PGTypes.Hash

Marks this field to be hashed on creation (IE: Password and other information you want to protect)

Kind: static property of PGTypes

2.0.0

1 year ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago