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

Overview

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: '[email protected]'
});

const findUser = await user.select({email: '[email protected]'});

Documentation

Configuration

LeanCloud

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

Deta

const Model = require('dittorm')('deta');
const userModel = new Model('user', {
  token: 'xxx'
});
Name Required Default Description
token Deta project secret key

InspireCloud

const Model = require('dittorm')('inspirecloud');
const userModel = new Model('user', {
  serviceId: 'xxx',
  serviceSecret: 'xxx'
});
Name Required Default Description
serviceId InspireCloud Service ID
serviceSecret InspireCloud Service Secret

CloudBase

const Model = require('dittorm')('cloudbase');
const userModel = new Model('user', {
  env: 'xxx',
  secretId: 'xxx',
  secretKey: 'xxx'
})
Name Required Default Description
env CloudBase enviroment ID
secretId CloudBase API secret Id, apply it at here
secretKey CloudBase API secret Key, apply it at here

GitHub

const Model = require('dittorm')('github');
const userModel = new Model('user', {
  token: 'xxx',
  repo: 'xxx',
  path: 'xxx',
})
Name Required Default Description
token Personal access tokens
repo repository name, such as walinejs/dittorm
path The 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
})
Name Required Default Description
host 127.0.0.1 MySQL server address
port 3306 MySQL server port
database MySQL database name
user MySQL server username
password MySQL server password
prefix MySQL table prefix
charset MySQL table charset

SQLite

Name Required Default Description
path SQLite storage file path, not include file name
database SQLite storage file name, change it if your filenamed is not waline
prefix SQLite 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,
})
Name Required Default Description
host 127.0.0.1 PostgreSQL server address
port 3211 PostgreSQL server port
database PostgreSQL database name
user PostgreSQL server username
password PostgreSQL server password
prefix PostgreSQL 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
  }
});
Name Required Default Description
host 127.0.0.1 MongoDB server address, support array format
port 27017 MongoDB server port, support array format
database MongoDB database name
user MongoDB server username
password MongoDB server password
replicaset MongoDB replica set
authSourcce MongoDB auth source
ssl use SSL connection

API

add(data)

Save store data.

const data = await userModel.add({ username: 'lizheming', email: '[email protected]' });
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).

Comments
Owner
Waline
A Simple, Safe Comment System inspired by Valine | 一款基于 Valine 衍生的简洁、安全的评论系统
Waline
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server & SQLite

Prisma Quickstart • Website • Docs • Examples • Blog • Slack • Twitter • Prisma 1 What is Prisma? Prisma is a next-generation ORM that consists of the

Prisma 28k Jan 2, 2023
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used

null 30.1k Jan 3, 2023
Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

DbGate 2k Dec 30, 2022
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

bookshelf.js Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features both Promise-based and traditional callback i

Bookshelf.js 6.3k Jan 2, 2023
An adapter-based ORM for Node.js with support for mysql, mongo, postgres, mssql (SQL Server), and more

Waterline is a next-generation storage and retrieval engine, and the default ORM used in the Sails framework. It provides a uniform API for accessing

Balderdash 5.4k Jan 4, 2023
Ecommerce-backend-nestjs - Ecommerce app with Nestjs + Prisma ORM + GraphQL + SQLite

ECOMMERCE BACKEND NESTJS APP Nestjs + Prisma ORM + GraphQL + SQLite USER Create Account Login Product Create Product Get Products Get Product Search P

Rui Paulo Calei 5 Apr 6, 2022
This is a demo sample of linking NODEJS via ORM and MYSQL

Demons(Demo of Nodejs with SQL) This is a demo sample of linking NODEJS with ORM and MYSQL Connecting Node to SQL is a hard task and not much help is

Shivam Sourav Jha 3 Apr 14, 2022
just a graphql example created by typescript + fastify + mikro-orm(postgresql) + mercurius(graphql adaptor) + type-graphql

fastify-mikro-orm-mercurius-graphql-example A MikroORM boilerplate for GraphQL made with Fastify, Mercurius, Typescript using TypeGraphQL ?? Packages

Vigen 10 Aug 28, 2022
A high performance MongoDB ORM for Node.js

Iridium A High Performance, IDE Friendly ODM for MongoDB Iridium is designed to offer a high performance, easy to use and above all, editor friendly O

Sierra Softworks 570 Dec 14, 2022
A query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.

knex.js A SQL query builder that is flexible, portable, and fun to use! A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle

knex 16.9k Jan 4, 2023
Ultimate Script to complete PostgreSQL-to-PostgreSQL Migration right after AWS DMS task done

Ultimate Script to complete PostgreSQL-to-PostgreSQL Migration right after AWS DMS task done

방신우 22 Dec 23, 2022
A Nest JS App that is proxied to deta.sh

Description Nest framework TypeScript starter repository. Installation $ yarn Running the app # development $ yarn start # watch mode $ yarn run star

Julian 7 Nov 18, 2022
Adapter based JavaScript ORM for Node.js and the browser

firenze.js A database agnostic adapter-based object relational mapper (ORM) targetting node.js and the browser. Visit http://firenze.js.org for docume

Fahad Heylaal 130 Jul 14, 2022
The Blog system developed by nest.js based on node.js and the database orm used typeorm, the development language used TypeScript

考拉的 Nest 实战学习系列 readme 中有很多要说的,今天刚开源还没来及更新,晚些慢慢写,其实本人最近半年多没怎么写后端代码,主要在做低代码和中台么内容,操作的也不是原生数据库而是元数据Meta,文中的原生数据库操作也当作复习下,数据库的操作为了同时适合前端和Node开发小伙伴,所以并不是很

程序员成长指北 148 Dec 22, 2022
An easy-to-use multi SQL dialect ORM tool for Node.js

Sequelize Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction s

Sequelize 27.3k Jan 4, 2023
An SQL-friendly ORM for Node.js

Objection.js Objection.js is an ORM for Node.js that aims to stay out of your way and make it as easy as possible to use the full power of SQL and the

Vincit 6.9k Jan 5, 2023
Execute one command (or mount one Node.js middleware) and get an instant high-performance GraphQL API for your PostgreSQL database!

PostGraphile Instant lightning-fast GraphQL API backed primarily by your PostgreSQL database. Highly customisable and extensible thanks to incredibly

Graphile 11.7k Jan 4, 2023
PostgreSQL client for node.js.

node-postgres Non-blocking PostgreSQL client for Node.js. Pure JavaScript and optional native libpq bindings. Monorepo This repo is a monorepo which c

Brian C 10.9k Jan 9, 2023