Comparing version 1.0.2 to 1.0.3
// 人工智能相关能力 | ||
// Google Cloud TTS |
@@ -1,1 +0,23 @@ | ||
// import fetch from 'node-fetch'; | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTushare = void 0; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const getTushare = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const response = yield (0, node_fetch_1.default)('https://eedictionary.com/'); | ||
const body = yield response.text(); | ||
return body; | ||
}); | ||
exports.getTushare = getTushare; | ||
// import from 'tnn'; |
@@ -50,2 +50,4 @@ "use strict"; | ||
const ERROR_USER_NOT_LOGIN = new global_1.VError(global_1.GLOBAL_ERROR._USER_NOT_LOGIN); | ||
// class SQLError extends Error { | ||
// } | ||
exports.registerCache = _Session_1.default.registerCache; | ||
@@ -60,3 +62,7 @@ const start = (options) => { | ||
}); | ||
(0, orm_1.setup)({ getConn: () => _Application_1.fastify.pg }); | ||
(0, orm_1.setup)({ | ||
provider: () => _Application_1.fastify.pg, | ||
pageSize: 15, | ||
// err: SQLError | ||
}); | ||
} | ||
@@ -63,0 +69,0 @@ // REDIS PLUGIN |
@@ -45,1 +45,3 @@ "use strict"; | ||
exports.insert = insert; | ||
// export const insertBatch = async (pg: ClientBase, table: string, obj: any[]) => { | ||
// } |
import type { ClientBase } from 'pg'; | ||
export declare const selectById: (pg: ClientBase, table: string, id: string | number, fields?: string[], key?: string) => Promise<any>; | ||
export declare const selectAll: (pg: ClientBase, table: string, fields?: string) => Promise<any[]>; |
@@ -12,6 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.selectById = void 0; | ||
const _select = (table, id, key) => { | ||
return [`DELETE FROM ${table} WHERE ${key} = $1 `, [id]]; | ||
}; | ||
exports.selectAll = exports.selectById = void 0; | ||
const _selectById = (table, id, fields, key = 'id') => { | ||
@@ -33,4 +30,6 @@ let _fields = '*'; | ||
exports.selectById = selectById; | ||
const _selectPage = (table, id, key) => { | ||
return [`DELETE FROM ${table} WHERE ${key} = $1 `, [id]]; | ||
}; | ||
const selectAll = (pg, table, fields = '*') => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = yield pg.query(`SELECT ${fields} FROM ${table}`); | ||
return result.rows; | ||
}); | ||
exports.selectAll = selectAll; |
import type { QueryResult } from 'pg'; | ||
export declare abstract class BaseQuery { | ||
db(): import("pg").ClientBase; | ||
protected db(): import("pg").ClientBase; | ||
sql(sql: string, params?: (string | number | boolean)[]): Promise<QueryResult>; | ||
} |
import type { TObject, Static } from '@sinclair/typebox'; | ||
import type { QuerySchema } from './types'; | ||
import type { QuerySchema, WhereCondition, WhereItem } from './types'; | ||
import { BaseQuery } from './BaseQuery'; | ||
type DomainOptions = { | ||
type TableOptions = { | ||
/** | ||
@@ -14,17 +14,19 @@ * Table 所在的 Schema 默认为 'public' | ||
/** | ||
* 查询时的字段,默认为对象自带的字段 | ||
* The Table's Default Sorting Rule / Order Field | ||
*/ | ||
fields?: string[]; | ||
/** | ||
* 默认排序字段,默认 key(id) | ||
*/ | ||
default_order?: string; | ||
/** | ||
* 默认排序方式,默认 desc | ||
* The Table's Default Sorting Rule / By Method | ||
*/ | ||
default_by?: 'asc' | 'desc'; | ||
/** | ||
* 每次查询的条数,默认为 DEFAULT_PAGESIZE | ||
* 1. PageSize , if not specified , use DEFAULT_PAGESIZE | ||
* 2. DEFAULT_PAGESIZE can use setup to specified default : 10 | ||
*/ | ||
default_pagesize?: number; | ||
/** | ||
* 默认查询过滤,比如 {field:'disabled',value:0,operation:'<>'} | ||
* 设置后,通过 query / all 拼装的 sql 都会带上 AND disabled <> 0 | ||
*/ | ||
globalQueryCondition: WhereItem[]; | ||
}; | ||
@@ -35,3 +37,21 @@ export declare class BaseTable<T extends TObject> extends BaseQuery { | ||
private _QUERY_CACHE; | ||
constructor(tableName: string, schema: T, options?: DomainOptions); | ||
constructor(tableName: string, schema: T, options?: TableOptions); | ||
private _query; | ||
private toWhereCondition; | ||
/** | ||
* @see WhereCondition | ||
* Use a WhereCondition Query Data | ||
*/ | ||
queryByCondition(query?: WhereCondition): void; | ||
/** | ||
* @see QuerySchema | ||
* Use a QuerySchema Query Data | ||
*/ | ||
query(query?: QuerySchema): Promise<Static<T>[]>; | ||
/** | ||
* @see QuerySchema | ||
* Use a QuerySchema Query Data With Page | ||
* this will return a object with {total:number,list:any[]} | ||
* | ||
*/ | ||
queryPager(query?: QuerySchema): Promise<{ | ||
@@ -43,2 +63,7 @@ total: number; | ||
getById(id: number | string): Promise<Static<T>>; | ||
/** | ||
* check row data while insert or update | ||
* and auto warp the data | ||
* */ | ||
private checkEntity; | ||
deleteById(id: number | string): Promise<number>; | ||
@@ -45,0 +70,0 @@ update(object: Static<T>): Promise<number>; |
@@ -16,6 +16,8 @@ "use strict"; | ||
exports.BaseTable = void 0; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const base_1 = require("../base"); | ||
const BaseQuery_1 = require("./BaseQuery"); | ||
const QueryPagition_1 = require("./QueryPagition"); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const QueryWhere_1 = require("./QueryWhere"); | ||
const QueryBuilder_1 = require("./QueryBuilder"); | ||
const DEFAULT_SCHEMA = 'public'; | ||
@@ -29,20 +31,27 @@ class BaseTable extends BaseQuery_1.BaseQuery { | ||
by: 'desc', | ||
fields: [], | ||
fieldSet: new Set(), | ||
query_fields: '*', | ||
FIELD_MAP: new Map(), | ||
}; | ||
this._QUERY_CACHE = new Map(); | ||
let fields = []; | ||
this._CONFIG.fieldSet = new Set(); | ||
this._CONFIG.FIELD_MAP = new Map(); | ||
lodash_1.default.keys(schema.properties).map(field => { | ||
fields.push(field); | ||
this._CONFIG.fieldSet.add(field); | ||
let properties = schema.properties[field]; | ||
this._CONFIG.FIELD_MAP.set(field, properties); | ||
if (properties.column) { | ||
fields.push(`${properties.column} as ${field}`); | ||
} | ||
if (properties.ignore === false) { | ||
return; | ||
} | ||
else { | ||
fields.push(field); | ||
} | ||
}); | ||
this._table = DEFAULT_SCHEMA + '.' + tableName; | ||
if (options == null) { | ||
this._CONFIG.fields = fields; | ||
this._CONFIG.query_fields = fields.join(','); | ||
if (options == null) | ||
return; | ||
} | ||
if (options.schema) { | ||
if (options.schema) | ||
this._table = options.schema + '.' + tableName; | ||
} | ||
if (options.key) { | ||
@@ -52,12 +61,2 @@ this._CONFIG.key = options.key; | ||
} | ||
if (options.fields) { | ||
options.fields.map(field => { | ||
if (this._CONFIG.fieldSet.has(field)) { | ||
this._CONFIG.fields.push(field); | ||
} | ||
}); | ||
} | ||
else { | ||
options.fields = fields; | ||
} | ||
if (options.default_order) | ||
@@ -68,7 +67,42 @@ this._CONFIG.order = options.default_order; | ||
} | ||
_query(WHERE, PARAM = [], ORDER_BY = '', LIMIT = '') { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const SQL_QUERY = ` | ||
SELECT ${this._CONFIG.query_fields} | ||
FROM ${this._table} | ||
${WHERE} ${ORDER_BY} ${LIMIT}`; | ||
const queryResult = yield this.sql(SQL_QUERY, PARAM); | ||
return queryResult.rows; | ||
}); | ||
} | ||
toWhereCondition(query) { | ||
} | ||
/** | ||
* @see WhereCondition | ||
* Use a WhereCondition Query Data | ||
*/ | ||
queryByCondition(query) { | ||
const WHERE = (0, QueryWhere_1.whereByCondition)(query); | ||
} | ||
/** | ||
* @see QuerySchema | ||
* Use a QuerySchema Query Data | ||
*/ | ||
query(query) { | ||
const { FIELD_MAP, order, by } = this._CONFIG; | ||
const [WHERE, PARAM] = (0, QueryBuilder_1.whereByQuery)(query, FIELD_MAP, this._QUERY_CACHE); | ||
const [ORDER_BY, LIMIT] = (0, QueryPagition_1.orderByLimit)(FIELD_MAP, query, order, by); | ||
return this._query(WHERE, PARAM, ORDER_BY, LIMIT); | ||
} | ||
/** | ||
* @see QuerySchema | ||
* Use a QuerySchema Query Data With Page | ||
* this will return a object with {total:number,list:any[]} | ||
* | ||
*/ | ||
queryPager(query) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let total = 0; | ||
const { key, fieldSet, order, by, fields } = this._CONFIG; | ||
const WHERE = ``; | ||
const { key, order, by, FIELD_MAP } = this._CONFIG; | ||
const [WHERE, PARAM] = (0, QueryBuilder_1.whereByQuery)(query, FIELD_MAP, this._QUERY_CACHE); | ||
if (lodash_1.default.has(query, 'total_') && lodash_1.default.isNumber(query.total_)) { | ||
@@ -79,3 +113,3 @@ total = query.total_; | ||
const SQL_COUNT = `SELECT COUNT(${key}) AS total FROM ${this._table} ${WHERE}`; | ||
const countResult = yield this.sql(SQL_COUNT); | ||
const countResult = yield this.sql(SQL_COUNT, PARAM); | ||
if (countResult.rowCount != 1) { | ||
@@ -89,19 +123,9 @@ return { | ||
} | ||
const [ORDER_BY, LIMIT] = (0, QueryPagition_1.OrderByLimit)(fieldSet, query, order, by); | ||
const SQL_QUERY = `SELECT ${fields.length ? fields.join(',') : '*'} FROM ${this._table} ${WHERE} ${ORDER_BY} ${LIMIT}`; | ||
const queryResult = yield this.sql(SQL_QUERY); | ||
return { | ||
total, | ||
list: queryResult.rows | ||
}; | ||
const [ORDER_BY, LIMIT] = (0, QueryPagition_1.orderByLimit)(FIELD_MAP, query, order, by); | ||
const list = yield this._query(WHERE, PARAM, ORDER_BY, LIMIT); | ||
return { total, list }; | ||
}); | ||
} | ||
all() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { fields } = this._CONFIG; | ||
const SQL_QUERY = `SELECT ${fields.length ? fields.join(',') : '*'} FROM ${this._table}`; | ||
console.log(SQL_QUERY); | ||
const queryResult = yield this.sql(SQL_QUERY); | ||
return queryResult.rows; | ||
}); | ||
return (0, base_1.selectAll)(this.db(), this._table, this._CONFIG.query_fields); | ||
} | ||
@@ -111,2 +135,27 @@ getById(id) { | ||
} | ||
/** | ||
* check row data while insert or update | ||
* and auto warp the data | ||
* */ | ||
checkEntity(obj, isAdd = false) { | ||
let clone = {}; | ||
this._CONFIG.FIELD_MAP.forEach((schema, key) => { | ||
let type = (0, QueryBuilder_1.getFieldType)(schema); | ||
let field = schema.column || key; | ||
if (type == 'date') { | ||
if (schema.isCreate && isAdd) { | ||
clone[field] = new Date(); | ||
return; | ||
} | ||
if (schema.isModify) { | ||
clone[field] = new Date(); | ||
return; | ||
} | ||
} | ||
if (lodash_1.default.has(obj, key)) { | ||
clone[field] = obj[key]; | ||
} | ||
}); | ||
return clone; | ||
} | ||
deleteById(id) { | ||
@@ -116,8 +165,12 @@ return (0, base_1.deleteById)(this.db(), this._table, id, this._CONFIG.key); | ||
update(object) { | ||
return (0, base_1.update)(this.db(), this._table, object, this._CONFIG.key); | ||
let entity = this.checkEntity(object, false); | ||
return (0, base_1.update)(this.db(), this._table, entity, this._CONFIG.key); | ||
} | ||
insert(object) { | ||
return (0, base_1.insert)(this.db(), this._table, object); | ||
let entity = this.checkEntity(object, true); | ||
// console.log(entity) | ||
return (0, base_1.insert)(this.db(), this._table, entity); | ||
// return null; | ||
} | ||
} | ||
exports.BaseTable = BaseTable; |
@@ -6,3 +6,2 @@ export * from './BaseQuery'; | ||
export * from './QueryWhere'; | ||
export * from './Animation'; | ||
export * from './Util'; |
@@ -21,5 +21,3 @@ "use strict"; | ||
__exportStar(require("./QueryPagition"), exports); | ||
// export * from './QueryPaser'; | ||
__exportStar(require("./QueryWhere"), exports); | ||
__exportStar(require("./Animation"), exports); | ||
__exportStar(require("./Util"), exports); |
@@ -8,3 +8,2 @@ "use strict"; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const SUFFIX = ['Min', 'Max', 'Like', 'Eq', 'Bt']; | ||
const GroupBy = (query) => { | ||
@@ -11,0 +10,0 @@ const ROOT = { link: 'AND', items: [] }; |
import type { QuerySchema } from './types'; | ||
export declare const OrderBy: (fieldSet: Set<string>, query?: QuerySchema, default_order?: string, default_by?: string) => string; | ||
export declare const Limit: (query?: QuerySchema) => string; | ||
export declare const OrderByLimit: (fieldSet: Set<string>, query?: QuerySchema, default_order?: string, default_by?: string) => [string, string]; | ||
export declare const orderByLimit: (fieldSet: Map<string, any>, query?: QuerySchema, default_order?: string, default_by?: string) => [string, string]; |
@@ -6,7 +6,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OrderByLimit = exports.Limit = exports.OrderBy = void 0; | ||
exports.orderByLimit = void 0; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const DEFAULT_PAGE_SIZE = 10; | ||
const BY_SET = new Set(['asc', 'desc']); | ||
const OrderBy = (fieldSet, query, default_order = 'id', default_by = 'desc') => { | ||
const orderBy = (fieldSet, query, default_order = 'id', default_by = 'desc') => { | ||
if (!lodash_1.default.has(query, 'order_')) { | ||
@@ -30,4 +30,3 @@ if (fieldSet.has(default_order)) { | ||
}; | ||
exports.OrderBy = OrderBy; | ||
const Limit = (query) => { | ||
const limit = (query) => { | ||
let start = lodash_1.default.has(query, 'start_') ? query.start_ : 0; | ||
@@ -37,6 +36,5 @@ let count = lodash_1.default.has(query, 'count_') ? query.count_ : DEFAULT_PAGE_SIZE; | ||
}; | ||
exports.Limit = Limit; | ||
const OrderByLimit = (fieldSet, query, default_order = 'id', default_by = 'desc') => [ | ||
(0, exports.OrderBy)(fieldSet, query, default_order, default_by), (0, exports.Limit)(query) | ||
const orderByLimit = (fieldSet, query, default_order = 'id', default_by = 'desc') => [ | ||
orderBy(fieldSet, query, default_order, default_by), limit(query) | ||
]; | ||
exports.OrderByLimit = OrderByLimit; | ||
exports.orderByLimit = orderByLimit; |
@@ -1,2 +0,2 @@ | ||
import type { WhereItem, WhereCondition } from './types'; | ||
export declare const buildSQL: (condition: (WhereCondition) | (WhereItem[]), startIdx?: number) => [string, any[]]; | ||
import { WhereItem, WhereCondition } from './types'; | ||
export declare const whereByCondition: (condition: (WhereCondition) | (WhereItem[]), startIdx?: number) => [string, any[]]; |
@@ -6,4 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildSQL = void 0; | ||
// import { Type, Static, TObject } from '@sinclair/typebox'; | ||
exports.whereByCondition = void 0; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
@@ -23,3 +22,3 @@ const ItemToWhere = (item, pos) => { | ||
break; | ||
case 'like': | ||
case 'LIKE': | ||
pos.SQL.push(`${item.field} LIKE '%$${pos.NUM}%'`); | ||
@@ -59,3 +58,3 @@ pos.PARAM.push(item.value); | ||
}; | ||
const buildSQL = (condition, startIdx = 1) => { | ||
const whereByCondition = (condition, startIdx = 1) => { | ||
const pos = { | ||
@@ -73,3 +72,2 @@ SQL: [], | ||
}; | ||
exports.buildSQL = buildSQL; | ||
// export const buildQuery = (schema:) | ||
exports.whereByCondition = whereByCondition; |
@@ -0,16 +1,26 @@ | ||
import type { SchemaOptions } from '@sinclair/typebox'; | ||
/** | ||
* Where 判断条件 | ||
*/ | ||
export type WhereOperaction = '>' | '>=' | '<' | '<=' | '=' | 'like'; | ||
export type WhereItem = { | ||
operation?: WhereOperaction; | ||
export type WhereOperaction = '>' | '>=' | '<' | '<=' | '=' | 'LIKE' | 'NOT'; | ||
export type FieldType = 'string' | 'number' | 'boolean' | 'date'; | ||
export type FieldFunction = 'h' | 'd' | 'm' | 'floor' | 'ceil' | 'lower' | 'upper'; | ||
export type WhereDefine = { | ||
type?: FieldType; | ||
field: string; | ||
value: string | number | boolean; | ||
/** | ||
* 对比判断条件 | ||
*/ | ||
operation: WhereOperaction; | ||
/** | ||
* 调用函数 | ||
* h / d / m = Hour / Day / Month 仅对日期类型有效 | ||
* ceil / floor / 仅对 Number 有效 | ||
* 'lower' / 'upper' = '小写' '大写' 仅对 String 有效 | ||
*/ | ||
fn?: 'h' | 'd' | 'm' | 'floor' | 'ceil' | 'lower' | 'upper'; | ||
fn?: FieldFunction; | ||
}; | ||
export type WhereItem = WhereDefine & { | ||
value: string | number | boolean | Date; | ||
}; | ||
export type WhereCondition = { | ||
@@ -20,14 +30,48 @@ link: 'AND' | 'OR' | 'NOT'; | ||
}; | ||
type QueryPagition = { | ||
export type QuerySuffix = 'Min' | 'Mint' | 'Max' | 'Maxt' | 'MinH' | 'MinD' | 'MinM' | 'MaxH' | 'MaxD' | 'MaxM' | 'Like' | 'Likel' | 'Liker'; | ||
export declare const SUFFIX: QuerySuffix[]; | ||
export type QuerySchema = { | ||
/** | ||
* The Start pos | ||
*/ | ||
start_?: number; | ||
/** | ||
* PageSize | ||
*/ | ||
count_?: number; | ||
/** | ||
* If specify total_ field, The Query will skip the count(total) query and return in total derectly. | ||
* do specify total_ in second can upper the performane in pagition query. | ||
*/ | ||
total_?: number; | ||
}; | ||
type QueryOrder = { | ||
/** | ||
* Not : Not Support yet! | ||
*/ | ||
keyword_?: string; | ||
/** | ||
* The Sort column field | ||
* default {modify_date} desc -> {key} desc -> Not sort | ||
*/ | ||
order_?: string; | ||
/** | ||
* The Sort column method | ||
*/ | ||
by_?: 'asc' | 'desc'; | ||
/** | ||
* Extend Query | ||
* Use Maggic Suffix to build query condition | ||
* */ | ||
[props: string]: string | number | boolean | Date; | ||
}; | ||
export type QuerySchema = QueryPagition & QueryOrder & { | ||
[props: string]: string | number | boolean; | ||
export type USchema = SchemaOptions & { | ||
/** | ||
* 1. if ignore = true , query SELECT will not include this field | ||
* 2. `table.getById()` will return this field. Actually `table.getById()` aways use SELECT * ! | ||
* 3. default : false | ||
*/ | ||
ignore?: boolean; | ||
/** | ||
* please specify column name if table column name not math the model field name. | ||
**/ | ||
column?: string; | ||
}; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SUFFIX = void 0; | ||
exports.SUFFIX = ['Min', 'Max', 'MinH', 'MinD', 'MinM', 'MaxH', 'MaxD', 'MaxM']; |
import type { ClientBase } from 'pg'; | ||
import type { USchema } from './types'; | ||
type Settings = { | ||
getConn?: () => ClientBase; | ||
mode?: 'pg' | 'mysql'; | ||
strict?: boolean; | ||
provider?: () => ClientBase; | ||
pageSize?: number; | ||
/** | ||
* 所以错误直接 throw 出,如果需要自定义错误类型,可以在此传个 Error 子类 | ||
*/ | ||
err?: typeof Error; | ||
}; | ||
export declare const getDB: () => ClientBase; | ||
import type { TProperties, TPartial, TObject, StringOptions, StringFormatOption, DateOptions, NumericOptions } from '@sinclair/typebox'; | ||
type UStringOptions<Format extends string> = USchema & StringOptions<Format> & { | ||
/** | ||
* The Funtion default call on this filed | ||
*/ | ||
fn?: 'lower' | 'upper'; | ||
}; | ||
type UNumericOptions = USchema & NumericOptions; | ||
type UDateOptions = USchema & DateOptions & { | ||
/** | ||
* 1. Create Time can not be modify | ||
* 2. It will be auto fill with Current Time while INSERT | ||
* 3. default;: flase | ||
*/ | ||
isCreate?: boolean; | ||
/** | ||
* 1. Last Modify Time will be fill with Current Time while UPDATE | ||
* 2. default;: flase | ||
*/ | ||
isModify?: boolean; | ||
}; | ||
export declare const setup: (settings: Settings) => void; | ||
export declare const UType: { | ||
Table: <T extends TProperties>(properties: T) => TPartial<TObject<T>>; | ||
Number: (options?: UNumericOptions) => import("@sinclair/typebox").TNumber; | ||
String: <Format extends string>(options?: UStringOptions<StringFormatOption | Format>) => import("@sinclair/typebox").TString<Format>; | ||
Date: (options?: UDateOptions) => import("@sinclair/typebox").TDate; | ||
Boolean: (options?: USchema) => import("@sinclair/typebox").TBoolean; | ||
Integer: (options?: UNumericOptions) => import("@sinclair/typebox").TInteger; | ||
}; | ||
export {}; |
"use strict"; | ||
// pg 版本 | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setup = exports.getDB = void 0; | ||
exports.UType = exports.setup = exports.getDB = void 0; | ||
const typebox_1 = require("@sinclair/typebox"); | ||
const GLOBAL = { | ||
getConn: null, | ||
mode: 'pg', | ||
strict: true | ||
provider: null, | ||
pageSize: 10, | ||
// err:Error, | ||
// mode: 'pg', | ||
// strict: true | ||
}; | ||
const getDB = () => { | ||
if (GLOBAL.getConn == null) { | ||
if (GLOBAL.provider == null) { | ||
throw new Error(); | ||
} | ||
return GLOBAL.getConn(); | ||
return GLOBAL.provider(); | ||
}; | ||
exports.getDB = getDB; | ||
const setup = (settings) => { | ||
if (settings.getConn) { | ||
GLOBAL.getConn = settings.getConn; | ||
if (settings.provider) { | ||
GLOBAL.provider = settings.provider; | ||
} | ||
}; | ||
exports.setup = setup; | ||
exports.UType = { | ||
Table: (properties) => typebox_1.Type.Partial(typebox_1.Type.Object(properties)), | ||
Number: (options) => typebox_1.Type.Number(options), | ||
String: (options) => typebox_1.Type.String(options), | ||
Date: (options) => typebox_1.Type.Date(options), | ||
Boolean: (options) => typebox_1.Type.Boolean(options), | ||
Integer: (options) => typebox_1.Type.Integer(options), | ||
// Required: Type.Required | ||
}; | ||
// const BasePageQuery = Type.Object({ | ||
// start_: Type.Optional(Type.Number()), | ||
// count_: Type.Optional(Type.Number()), | ||
// order_: Type.Optional(Type.String()), | ||
// by_: Type.Optional(Type.Number()), | ||
// }) |
export { BaseTable } from './domain/BaseTable'; | ||
export { setup } from './domain/Util'; | ||
export { setup, UType } from './domain/Util'; | ||
export * from './domain/types'; |
@@ -17,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setup = exports.BaseTable = void 0; | ||
exports.UType = exports.setup = exports.BaseTable = void 0; | ||
var BaseTable_1 = require("./domain/BaseTable"); | ||
@@ -23,2 +23,3 @@ Object.defineProperty(exports, "BaseTable", { enumerable: true, get: function () { return BaseTable_1.BaseTable; } }); | ||
Object.defineProperty(exports, "setup", { enumerable: true, get: function () { return Util_1.setup; } }); | ||
Object.defineProperty(exports, "UType", { enumerable: true, get: function () { return Util_1.UType; } }); | ||
__exportStar(require("./domain/types"), exports); |
@@ -1,3 +0,13 @@ | ||
// import _ from 'lodash'; | ||
// import { Client } from 'pg'; | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.build = void 0; | ||
// Table "public.feedback" | ||
@@ -14,1 +24,17 @@ // Column | Type | Collation | Nullable | Default | ||
// "feedback_pkey" PRIMARY KEY, btree (id) | ||
const build = (pg, schema, table) => __awaiter(void 0, void 0, void 0, function* () { | ||
// console.log(pg.database) | ||
const u = yield pg.query(`SELECT * FROM pg_tables WHERE schemaname = $1 AND tablename = $2 `, [schema, table]); | ||
// const u = await pg.query(`SELECT * FROM pg_tables WHERE tablename = $1 `, [table]); | ||
// const u = await pg.query(` | ||
// select a.attnum,a.attname,concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) | ||
// from '\(.*\)')) as type,d.description | ||
// from pg_class c, pg_attribute a , pg_type t, pg_description d | ||
// where c.relname = '${table}' and a.attnum>0 and a.attrelid = c.oid and a.atttypid = t.oid and d.objoid=a.attrelid and d.objsubid=a.attnum | ||
// `); | ||
console.log(u.rows); | ||
}); | ||
exports.build = build; | ||
// a pg_attribute | ||
// c pg_class | ||
// d pg_description |
{ | ||
"name": "eha", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Eha For ServerLess", | ||
"author": "ada87" | ||
} |
@@ -78,3 +78,3 @@ "use strict"; | ||
console.log('---------------------------------------------------------'); | ||
reply.status(200).send({ code: '9999', message: '此乃测试' }); | ||
reply.status(200).send({ code: '9999', message: '情报收集:测试专用' }); | ||
}); | ||
@@ -81,0 +81,0 @@ yield Promise.all([ |
@@ -26,3 +26,4 @@ "use strict"; | ||
}); | ||
const test = (title, callback) => (0, runner_1.test)(title, callback).setup(() => __awaiter(void 0, void 0, void 0, function* () { | ||
const test = (title, callback) => (0, runner_1.test)(title, callback) | ||
.setup(() => __awaiter(void 0, void 0, void 0, function* () { | ||
yield exports.pg.connect(); | ||
@@ -29,0 +30,0 @@ })).teardown(() => { |
106215
87
2603