← Winnitude! Search  ·  Reader Mode (783 ms)
Links: Direct URLs Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 51 LINKS

GitHub - APIJSON/APIJSON-Node: 字节跳动工程师开发的 APIJSON 的 Node 版后端实现,本仓库为副本,请给原仓库右上角点亮 ⭐️ Star

Repository navigation

APIJSON-Node
Public
forked from kevinaskin/apijson-node

About

字节跳动工程师开发的 APIJSON 的 Node 版后端实现,本仓库为副本,请给原仓库右上角点亮 ⭐️ Star

github.com/kevinaskin/apijson-node

Resources

Readme Activity Custom properties

Stars

13 stars

Watchers

0 watching

Forks

1 fork Report repository
Branches

Tags
Go to Branches page Go to Tags page    

Latest commit

 

History


25 Commits
View commit history for this file.

Folders and files

Name Name Last commit message Last commit date
src src    
.gitignore .gitignore    
README.md README.md    
apijson.sql apijson.sql    
index.js index.js    
jest.json jest.json    
nestconfig.json nestconfig.json    
nodemon.json nodemon.json    
ormconfig.js.example ormconfig.js.example    
package-lock.json package-lock.json    
package.json package.json    
pm2.config.json pm2.config.json    
tsconfig.json tsconfig.json    

Repository files navigation

ApiJson Node版

A ApiJson Server build with Nest.js and TypeORM


起步

安装依赖

$ npm install

Database数据库配置

修改 ormconfig.js 参照 ormconfig.js.example

测试数据库为 apijson.sql, 如需体验可自行导入本地数据库测试

{
  "type": "mysql",
  "host": "localhost",
  "port": 3306,
  "username": "",
  "password": "",
  "database": "",
  "entities": ["src/**/**.entity{.ts,.js}"],
  "synchronize": false
}

NPM 命令

  • npm run dev - 开发模式
  • npm start - 启动应用
  • npm run start:prod - 生产模式

启动应用

  • npm start
  • 健康检查 http://localhost:3000/test 正常情况下会返回 ok
  • 使用 pm2 可以直接 用 pm2 start ./pm2.config.json 启动

Swagger API 文档

This example repo uses the NestJS swagger module for API documentation. NestJS Swagger - www.swagger.io

使用文档

以下例子中 默认存在两张表(Comment, User),实际使用时,需要在添加对应的entity,在service中引入即可

查看当前可用的table 可访问 GET /table

  • 通用查询接口 POST /apijson/get
  • 通用新增接口 POST /apijson/add
  • 通用修改接口 POST /apijson/update

已经实现的操作符

  • 单条记录查询

    {
        "Comment": {
          "User": {}
        }
    }
  • []

    操作符名称: 列表查询

    例子:

      // 这里[]前的字符串将作为response的字段名
      {
        "XXX[]": {
          "Comment": {}
        }
      }
  • #

    操作符名称: 别名

    例子:

    {
      "SingleComment#": {
        "Comment": {}
      }
    }
  • @column

    操作符名称: 字段筛选

    例子:

    {
      "User": {
        "@column": "role,nickname"
      }
    }
  • 联表查询

    例子:

    // 查询叫tony的User
    // 查询一条userId为User中id的Comment
    {
      "User": {
        "user": "tony"
      },
      "Comment": {
        "userId@": "User/id"
      }
    }
    // 查询所有符合条件的comment 显示 第1页 每页2条
    // (因为默认page = 1 count = 10 所以默认最多为10条)
    {
      "User": {
        "user": "tony"
      },
      "msgList[]": {
      	"Comment": {
          "userId@": "User/id"
      },
      "count": 2,
      "page": 1
      }
    }
    
  • 综合例子

     {
       "userInfo#": {
         "User": {
           "user": "tony"
         }
       },
       "testAlias#": {
         "msgList[]": {
           "Comment": {
           "userId@": "userInfo#/User/id",
           "@column": "comment"
           },
           "count": 2,
           "page": 1
         }
       }
     }

About

字节跳动工程师开发的 APIJSON 的 Node 版后端实现,本仓库为副本,请给原仓库右上角点亮 ⭐️ Star

github.com/kevinaskin/apijson-node

Resources

Readme Activity Custom properties

Stars

13 stars

Watchers

0 watching

Forks

1 fork Report repository

Contributors

Languages