@s88d-puppy/dbal

2.0.12 • Public • Published

[PKG-DBAL] Database Abstraction Layer

Required Environment Variables

CACHE_ADAPTER

  • dyanamodb

DB_ADAPTER

  • dyanamodb

MQ_ADAPTER

  • sqs local none

ROOT_DIRECTORY

  • For local development using local MQ_ADAPTER. Can be omitted for cloud deployment.

DYNAMODB_ENDPOINT

  • For local development. Can be omitted for cloud deployment.

TABLE_PREFIX

  • Will yield ${TABLE_PREFIX}_graph

Model Subclass Structure

'use strict'

const Model = require('@s88d-puppy/dbal')

class Entity extends Model {

    constructor() {
        
        super()
    
        this.attributes = {
            [attribute_name] : [
                'identifier',               // Creates index, implies uniqueness
                'foreign',                  // Creates a foreign key (id in another microservice)
                'namespace:field'           // Creates an identifier within a namespace (determined by field)
                'mutable',                  // Makes attribute updateable
                'format:email',
                'format:url',
                'format:slug',
                'format:json',
                'format:mobile',
                'in:value1,value2,value3'
            ]
            ...
        }
        
        this.edges = {
            [label_name]: [
                ordinality,         // 0 or 1
                cardinality         // 1 or N
            ]
            ...
        }
    
    }
    
    async beforeCreate(data) {

        data.key = 'value'

    }
    
    async afterCreate(record) {
        
        // Some logic
    
    }
    
    async beforeUpdate(data) {

        data.key = 'value'

    }
    
    async afterUpdate(data) {
        
        // Some logic
    
    }

}

module.exports = Entity

Model Class Functions

async getAll()
async getByIds(ids)
async getById(id)
async getByIdOrThrow(id)
async getByIdentifier(identifier, value)
async getByIdentifierWithinNamespace(identifier, value, namespace)
async getByForeignKey(foreign_key, value)
async getEdge(id, edge)
async create(data = {}, context = 'create', contextVars = {})
async linkEdge(id, edge_label, edge_id, data = {})
async unlinkEdge(id, edge_label, edge_id)
async updateById(id, data = {}, context = 'update', contextVars = {})
async deleteById(id, context = 'delete', contextVars = {})
async search(query, perPage=10, page=1, sortField, sortOrder)

Model Class Hooks

async beforeCreate(data)
async afterCreate(record)
async beforeUpdate(data)
async afterUpdate(record)

Attribute Formats

  • email
  • url
  • slug
  • json
  • mobile

Error Codes

  • MS1-MOD001: Invalid edge (:edge)
  • MS1-MOD002: Missing edge (:edge)
  • MS1-MOD003: Record not found (:label-:id)
  • MS1-MOD004: Validation error
  • MS1-MOD005: Cannot link more than :cardinality edges on :node-:edge
  • MS1-MOD006: Cannot link less than :ordinality edges on :node-:edge

Readme

Keywords

none

Package Sidebar

Install

npm i @s88d-puppy/dbal

Weekly Downloads

35

Version

2.0.12

License

none

Unpacked Size

53 kB

Total Files

22

Last publish

Collaborators

  • brainspills
  • mariaerika
  • melyo