Skip to content

Commit

Permalink
graphql has finished mainly.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoutk committed Apr 10, 2019
1 parent b2aea68 commit 2af69bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ gels -- 凝胶,希冀该项目能成为联结设计、开发,前端、后端
框架会根据数据表及特殊业务文件自动生成schema。
> 一些数据库设计原则约定
- 每个表必须有字段id(类型为整数或字符串),作为主键或建立unique索引
- 每个表必须有字段id,类型为整数(自增)或8位字符串(uuid),作为主键或建立unique索引
- 表名为小写字母,使用名词单数,以下划作为单词分隔
- 表关联约定:book关联到author,表book中关联字段设为author_id,关联到author.id
- 表关联自动在相关中嵌入相关对象,Book对象增加Author对象,Author对象增加books列表
Expand Down
13 changes: 7 additions & 6 deletions src/db/baseDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ export default class BaseDao {
else {
let rs, id = params['id']
try {
if (!id && params['uuid']) {
id = G.tools.uuid()
delete params['uuid']
} else if (params['uuid']) {
delete params['uuid']
}
if (!id) {
let idType = G.DataTables[this.table]['id']['COLUMN_TYPE']
let leftBracket = idType.indexOf('(')
if (leftBracket > 3 && idType.substr(leftBracket - 3, 3) !== 'int') {
id = G.tools.uuid()
}
}
rs = await BaseDao.dao.insert(this.table, Object.assign(params, id ? { id } : {}))
} catch (err) {
err.message = `data insert fail: ${err.message}`
Expand Down
4 changes: 3 additions & 1 deletion src/middlewares/graphql/schema_generate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import BaseDao from '../../db/baseDao'
import { customDefs, queryDefs, customResolvers } from '../../graphql/reviseResult'
let requireDir = require('require-dir')

const TYPEFROMMYSQLTOGRAPHQL = {
int: 'Int',
varchar: 'String',
datetime: 'String',
double: 'Float',
float: 'Float',
decimal: 'Float',
}

const NOTMUTATION = ['create_time', 'update_time']
Expand Down

0 comments on commit 2af69bc

Please sign in to comment.