npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dittorm

v1.0.0

Published

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

Downloads

33

Readme

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).