import { Raw } from './raw'; import { Builder } from './builder'; import { AttrBuilder } from './attr_builder'; import { UNSET } from './json_where'; /** * 位置类型 */ export type PointType = { x: number; y: number; }; /** * 基本类型 */ export type BasicType = string | number | boolean | Date | Buffer | PointType | null; /** * SQL 模版参数类型 */ export type SQLTemplateArg = Raw | AttrBuilder | BasicType | BasicType[]; /** * 字段类型 */ export type FieldType = Raw | AttrBuilder | string | { [as: string]: FieldType; }; /** * 值类型 */ export type ValueType = Raw | AttrBuilder | BasicType; /** * 行值 */ export type ValueRow = { [column: string]: ValueType; }; /** * 排序字段类型 */ export type OrderFieldType = string | Raw | AttrBuilder; /** * SQL 构建结果 */ export interface BuildResult { /** * SQL 语句 * - 输入参数使用 ? 占位符 */ sql: string; /** * 输入参数 */ params?: ValueType[]; } /** * 查询方法参数 */ export type WhereType = JsonWhere | AttrBuilder; export type FieldsType = (FieldType | { [key: string]: FieldType | FieldType[] | Builder; })[]; interface $Q { /** 转译为字段 */ $quote?: string | UNSET; /** 原始内容拼接入SQL中不做任何处理。 注意:小心SQL注入漏洞 */ $raw?: string | UNSET; } type $Value = ValueType | $Q; export interface JsonWhereOp extends $Q { /** = */ $eq?: $Value | UNSET; /** != */ $ne?: $Value | UNSET; /** \>= */ $gte?: $Value | UNSET; /** \> */ $gt?: $Value | UNSET; /** \<= */ $lte?: $Value | UNSET; /** \< */ $lt?: $Value | UNSET; /** IS */ $is?: $Value | UNSET; /** IS NOT */ $isnot?: $Value | UNSET; /** IS NOT */ $not?: $Value | UNSET; /** LIKE */ $like?: $Value | UNSET; /** NOT LIKE */ $notlike?: $Value | UNSET; /** ILIKE */ $ilike?: $Value | UNSET; /** NOT ILIKE */ $notilike?: $Value | UNSET; /** REGEXP */ $regexp?: $Value | UNSET; /** NOT REGEXP */ $notregexp?: $Value | UNSET; /** IN */ $in?: $Value[] | UNSET; /** NOT IN */ $notin?: $Value[] | UNSET; /** BETWEEN [start] AND [end] */ $between?: [start: $Value | undefined, end: $Value | undefined] | UNSET; /** NOT BETWEEN [start] AND [end] */ $notbetween?: [start: $Value | undefined, end: $Value | undefined] | UNSET; /** MATCH(field) AGAINST(value mode) */ $match?: string | { expr: string; modifier?: string; } | UNSET; /** 是否包含在集合中: FIND_IN_SET */ $include?: string; $or?: JsonWhereOp | UNSET; $and?: JsonWhereOp | UNSET; } export interface JsonWhere { [field: string]: ValueType | ValueType[] | JsonWhereOp | JsonWhere | JsonWhere[] | UNSET; } export type IndexType = 'USE' | 'FORCE' | 'IGNORE'; export type IndexFor = 'JOIN' | 'ORDER BY' | 'GROUP BY'; export {};