Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@itcutives/adapter-memory

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@itcutives/adapter-memory

Memory Adapter for ITcutives API

  • 1.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

@itcutives/adapter-memory

Build Status

This repo contains memory adapter for ITcutives Serverless Framework

Usage

Install

npm install @itcutives/adapter-memory

Connection

connection-provider.js

const Adapter = require('../src/adapter');
const Connect = require('../src/connection');

class Memory extends Adapter {
  static CONNECT(config) {
    if (!Memory.CONN) {
      Memory.CONN = new Connect(config);
    }
    return Promise.resolve(Memory.CONN);
  }
}

module.exports = Memory;

Model

user.js

const Abstract = require('./connection-provider');

class User extends Abstract {
  /**
   * @returns {string}
   */
  static get PLURAL() {
    return 'users';
  }

  /**
   * @returns {string}
   */
  static get TABLE() {
    return 'user';
  }

  /**
   * @returns {Array}
   */
  static get FIELDS() {
    return ['id', 'name', 'type', 'attributes'];
  }
}

module.exports = User;

CRUD

/* eslint-disable no-console */
const User = require('./user');

async function init() {
  let records;
  let found;
  let changes;

  await User.CONNECT();

  const user = new User({ type: 'ADMIN', name: 'itcutives', attributes: { phone: '1234-5678' } });
  const insertId = await user.INSERT();

  console.log(`Inserted record with id ${insertId}.`);

  const conditions = [{
    field: 'id',
    operator: '=',
    value: insertId,
    condition: 'AND',
  }];
  records = await user.SELECT(conditions);

  [found] = records;
  console.log(`Found record with name '${found.get('name')}'.`);

  found.set('name', 'new name');
  changes = await found.UPDATE();
  console.log(`Updated ${changes} records.`);

  records = await user.SELECT();
  [found] = records;
  console.log(`Found record with name '${found.get('name')}'.`);

  changes = await found.DELETE();
  console.log(`Deleted ${changes} records.`);

  records = await user.SELECT();
  console.log(`Found ${records.length} records.`);
}

init();

Roadmap

  • Save and load data from file system
  • CSV vs JSON file support

Keywords

FAQs

Package last updated on 07 Nov 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc