Socket
Socket
Sign inDemoInstall

dittorm

Package Overview
Dependencies
505
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dittorm

A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.


Version published
Weekly downloads
9
increased by200%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Dittorm

A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.

Installation

npm install dittorm --save

Quick Start

const Model = require('dittorm')('leancloud');
const userModel = new Model('user', {
  appId: 'xxx',
  appKey: 'xxx',
  masterKey: 'xxx'
});

const user = await userModel.add({
  username: 'lizheming',
  email: 'i@imnerd.org'
});

const findUser = await user.select({email: 'i@imnerd.org'});

Documentation

Configuration

LeanCloud
const Model = require('dittorm')('leancloud');
const userModel = new Model('user', {
  appId: 'xxx',
  appKey: 'xxx',
  masterKey: 'xxx'
});
NameRequiredDefaultDescription
appId
appKey
masterKey
Deta
const Model = require('dittorm')('deta');
const userModel = new Model('user', {
  token: 'xxx'
});
NameRequiredDefaultDescription
tokenDeta project secret key
InspireCloud
const Model = require('dittorm')('inspirecloud');
const userModel = new Model('user', {
  serviceId: 'xxx',
  serviceSecret: 'xxx'
});
NameRequiredDefaultDescription
serviceIdInspireCloud Service ID
serviceSecretInspireCloud Service Secret
CloudBase
const Model = require('dittorm')('cloudbase');
const userModel = new Model('user', {
  env: 'xxx',
  secretId: 'xxx',
  secretKey: 'xxx'
})
NameRequiredDefaultDescription
envCloudBase enviroment ID
secretIdCloudBase API secret Id, apply it at here
secretKeyCloudBase API secret Key, apply it at here
GitHub
const Model = require('dittorm')('github');
const userModel = new Model('user', {
  token: 'xxx',
  repo: 'xxx',
  path: 'xxx',
})
NameRequiredDefaultDescription
tokenPersonal access tokens
reporepository name, such as walinejs/dittorm
pathThe data storage directory, such as data means it is stored in the data directory, root directory by default
MySQL
const Model = require('dittorm')('mysql');
const userModel = new Model('user', {
  host: '127.0.0.1',
  port: 3306,
  database: 'blog',
  user: 'admin',
  password: 'admin',
  prefix: 'dt_',
  charset: 'utf8mb4',
  dateString: true
})
NameRequiredDefaultDescription
host127.0.0.1MySQL server address
port3306MySQL server port
databaseMySQL database name
userMySQL server username
passwordMySQL server password
prefixMySQL table prefix
charsetMySQL table charset
SQLite
NameRequiredDefaultDescription
pathSQLite storage file path, not include file name
databaseSQLite storage file name, change it if your filenamed is not waline
prefixSQLite table prefix
PostgreSQL
const Model = require('dittorm')('postgresql');
const userModel = new Model('user', {
  host: '127.0.0.1',
  port: 5432,
  database: 'blog',
  user: 'admin',
  password: 'admin',
  prefix: 'dt_',
  connectionLimit: 1,
})
NameRequiredDefaultDescription
host127.0.0.1PostgreSQL server address
port3211PostgreSQL server port
databasePostgreSQL database name
userPostgreSQL server username
passwordPostgreSQL server password
prefixPostgreSQL table prefix
MongoDB
const Model = require('dittorm')('mongodb');
const userModel = new Model('user', {
  host: '127.0.0.1',
  port: 27017,
  database: 'blog',
  user: 'admin',
  password: 'admin',
  options: {
    replicaset: 'xxx',
    authSource: 'admin',
    ssl: true
  }
});
NameRequiredDefaultDescription
host127.0.0.1MongoDB server address, support array format
port27017MongoDB server port, support array format
databaseMongoDB database name
userMongoDB server username
passwordMongoDB server password
replicasetMongoDB replica set
authSourcceMongoDB auth source
ssluse SSL connection

API

add(data)

Save store data.

const data = await userModel.add({ username: 'lizheming', email: 'i@imnerd.org' });
console.log(data.id);
select(where, options)

Find store data by condition.

// SELECT * FROM user WHERE username = 'lizheming';
const data = await userModel.select({ username: 'lizheming' });

// SELECT email FROM user WHERE username = 'lizheming' ORDER BY email DESC LIMIT 1 OFFSET 1;
const data = await userModel.select({ username: 'lizheming' }, {
  field: ['email'],
  desc: 'email',
  limit: 1,
  offset: 1
});

// SELECT * FROM user WHERE username != 'lizheming';
const data = await userModel.select({ username: ['!=', 'lizheming'] });

// SELECT * FROM user WHERE create_time > '2022-01-01 00:00:00';
const data = await userModel.select({ username: ['>', '2022-01-01 00:00:00'] });

// SELECT * FROM user WHERE username IN ('lizheming', 'michael');
const data = await userModel.select({ username: ['IN', ['lizheming', 'michael']] });

// SELECT * FROM user WHERE username NOT IN ('lizheming', 'michael');
const data = await userModel.select({ username: ['NOT IN', ['lizheming', 'michael']] });

// SELECT * FROM user WHERE username LIKE '%li%';
const data = await userModel.select({ username: ['LIKE', '%li%'] });

// SELECT * FROM user WHERE username = 'lizheming' AND create_time > '2022-01-01 00:00:00';
const data = await userModel.select({ 
  username: 'lizheming',
  create_time: ['>', '2022-01-01 00:00:00'] 
});

// SELECT * FROM user WHERE username = 'lizheming' OR create_time > '2022-01-01 00:00:00';
const data = await userModel.select({
  _complex: { 
    username: 'lizheming',
    create_time: ['>', '2022-01-01 00:00:00'],
    _logic: 'OR'
  }
});
update(data, where)

Update store data by condition. where format same as select(where, options).

count(where)

Return store data count by condition. where format same as select(where, options).

delete(where)

Clean store data by condition. where format same as select(where, options).

Keywords

FAQs

Last updated on 04 May 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc