@serverless-devs/orm
TypeScript icon, indicating that this package has built-in type declarations

0.0.3-beta.1 • Public • Published

ORM(@serverless-devs/orm)

依赖

安装

$ npm install @serverless-devs/orm --save

使用方式

import ORM from '@serverless-devs/orm';

create

const tableName = 'posts';
const orm = new Orm('./post.json', {
  [tableName]: [],
  users: []
});
const tableValue = 'dankun_1';

await orm.init();
await orm[tableName].create({
    data: {
        name: tableValue,
    },
});

find

findUnique

const data = await orm[tableName].findUnique({
    where: {
      name: 'case_1',
    },
});

findMany

const data = await orm[tableName].findMany({
    where: {
        name: 'case_1',
    },
});

update

const data = await orm[tableName].update({
    where: {
      name: 'case_1',
    },
    data: {
      name: 'case_update',
      age: 23,
    },
});

delete

const data = await orm[tableName].delete({
    where: {
      name: 'case_1',
    },
});

参数解析

query 搜索

初始化参数解析

// path 参数指的是文件路径,比如`~/.s/error.json`
const orm = new Orm($path);
// tableName参数指的是实体名
await orm.init($tableName);

参数解析

  • path 参数指的是文件路径,比如~/.s/error.json
  • tableName tableName参数指的是表的实体名

where搜索

applyFilter({
  where: {
    // the price > 10 && price < 100
    and: [
      {
        price: {
          gt: 10
        }
      },
      {
        price: {
          lt: 100
        }
      },
    ],

    // match Mens Shoes and Womens Shoes and any other type of Shoe
    category: {like: '.* Shoes'},

    // the status is either in-stock or available
    status: {inq: ['in-stock', 'available']}
  }
})

limit

applyFilter(data, {
  where: {
    location: {near: '153.536,-28'}
  },
  limit: 10
})

参考

prisma

Readme

Keywords

none

Package Sidebar

Install

npm i @serverless-devs/orm

Weekly Downloads

1

Version

0.0.3-beta.1

License

MIT

Unpacked Size

43.8 kB

Total Files

30

Last publish

Collaborators

  • serverlessfans
  • heimanba
  • xsahxl