From 2af69bc34126c629de8550eda761afcb636a0ac5 Mon Sep 17 00:00:00 2001 From: zhoutk Date: Wed, 10 Apr 2019 22:34:01 +0800 Subject: [PATCH] graphql has finished mainly. --- README.md | 2 +- src/db/baseDao.ts | 13 +++++++------ src/middlewares/graphql/schema_generate.ts | 4 +++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6408932..8fcf7bd 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ gels -- 凝胶,希冀该项目能成为联结设计、开发,前端、后端 框架会根据数据表及特殊业务文件自动生成schema。 > 一些数据库设计原则约定 -- 每个表必须有字段id(类型为整数或字符串),作为主键或建立unique索引 +- 每个表必须有字段id,类型为整数(自增)或8位字符串(uuid),作为主键或建立unique索引 - 表名为小写字母,使用名词单数,以下划作为单词分隔 - 表关联约定:book关联到author,表book中关联字段设为author_id,关联到author.id - 表关联自动在相关中嵌入相关对象,Book对象增加Author对象,Author对象增加books列表 diff --git a/src/db/baseDao.ts b/src/db/baseDao.ts index 852ddef..a45f062 100644 --- a/src/db/baseDao.ts +++ b/src/db/baseDao.ts @@ -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}` diff --git a/src/middlewares/graphql/schema_generate.ts b/src/middlewares/graphql/schema_generate.ts index 9a1a463..9bdd20f 100644 --- a/src/middlewares/graphql/schema_generate.ts +++ b/src/middlewares/graphql/schema_generate.ts @@ -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']