From f2ca523245c41655768b7b39dc67513a9e0d569f Mon Sep 17 00:00:00 2001 From: JimmyDaddy Date: Tue, 26 Apr 2022 20:02:03 +0800 Subject: [PATCH] chore: ts type definition correct, doc --- docs/basics.md | 2 +- docs/querying.md | 1 + docs/zh/basics.md | 2 +- docs/zh/querying.md | 1 + test/types/{custom_driver.ts => custom_driver.test.ts} | 0 test/types/{data_types.ts => data_types.test.ts} | 2 +- types/index.d.ts | 8 +++++++- 7 files changed, 12 insertions(+), 4 deletions(-) rename test/types/{custom_driver.ts => custom_driver.test.ts} (100%) rename test/types/{data_types.ts => data_types.test.ts} (93%) diff --git a/docs/basics.md b/docs/basics.md index 4c0f84ad..60bcda6e 100644 --- a/docs/basics.md +++ b/docs/basics.md @@ -100,7 +100,7 @@ const { BIGINT, STRING } = Bone.DataTypes; class Shop extends Bone { static attributes = { id: { type: BIGINT, primaryKey: true }, - name: { type: STRING }, + name: STRING, } } diff --git a/docs/querying.md b/docs/querying.md index 991ebd7b..b04c3604 100644 --- a/docs/querying.md +++ b/docs/querying.md @@ -507,6 +507,7 @@ We can reference these table aliases futher after the join, such as `.where()` o ```js Post.join(Comment, 'posts.id = comments.postId').where('comments.id = 1') +Post.join(Comment, 'posts.id = comments.postId').where({ 'comments.id': 1 }) ``` ## Scopes diff --git a/docs/zh/basics.md b/docs/zh/basics.md index 32493990..763cf947 100644 --- a/docs/zh/basics.md +++ b/docs/zh/basics.md @@ -99,7 +99,7 @@ const { BIGINT, STRING } = Bone.DataTypes; class Shop extends Bone { static attributes = { id: { type: BIGINT, primaryKey: true }, - name: { type: STRING }, + name: STRING, } } diff --git a/docs/zh/querying.md b/docs/zh/querying.md index e9ed4e7c..598b6b83 100644 --- a/docs/zh/querying.md +++ b/docs/zh/querying.md @@ -501,6 +501,7 @@ SELECT * FROM posts LEFT JOIN comments ON posts.id = comments.post_id LEFT JOIN ```js Post.join(Comment, 'posts.id = comments.postId').where('comments.id = 1') +Post.join(Comment, 'posts.id = comments.postId').where({ 'comments.id': 1 }) ``` ## 查询限定 diff --git a/test/types/custom_driver.ts b/test/types/custom_driver.test.ts similarity index 100% rename from test/types/custom_driver.ts rename to test/types/custom_driver.test.ts diff --git a/test/types/data_types.ts b/test/types/data_types.test.ts similarity index 93% rename from test/types/data_types.ts rename to test/types/data_types.test.ts index 3412c2b0..be661ee9 100644 --- a/test/types/data_types.ts +++ b/test/types/data_types.test.ts @@ -1,5 +1,5 @@ import { strict as assert } from 'assert'; -import Realm, { Bone, DataTypes } from '../..'; +import Realm, { Bone, DataTypes } from '../../types'; describe('=> Data types (TypeScript)', function() { const { STRING, TEXT, BLOB } = DataTypes; diff --git a/types/index.d.ts b/types/index.d.ts index 2d81bea0..bee7e37b 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -179,11 +179,17 @@ export interface ColumnMeta { comment?: string; datetimePrecision?: string; } + +declare type validator = Literal | Function | Array; + export interface AttributeMeta extends ColumnMeta { jsType?: Literal; type: DataType; virtual?: boolean, toSqlString: () => string; + validate: { + [key: string]: validator; + } } interface RelateOptions { @@ -442,7 +448,7 @@ export class Collection extends Array { } export class Bone { - static DataTypes: DataType; + static DataTypes: typeof DataType; /** * get the connection pool of the driver