From 91f7871a23d562422ccc0b2a70fbbac0d82b323a Mon Sep 17 00:00:00 2001 From: Chen Yangjian <252317+cyjake@users.noreply.github.com> Date: Tue, 19 Oct 2021 16:20:17 +0800 Subject: [PATCH] docs: renaming attributes (#203) fixes #199 --- .jsdoc.json | 2 +- docs/api/BIGINT.html | 4 +- docs/api/Bone.html | 1200 ++++++-- docs/api/Collection.html | 6 +- docs/api/DataType.html | 318 +- docs/api/INTEGER.html | 4 +- docs/api/IndexHint.IndexHint.html | 4 +- docs/api/STRING.html | 4 +- docs/api/Spell.html | 16 +- docs/api/global.html | 2560 +++++++++++++++-- docs/api/index.html | 11 +- docs/api/module-lib_bone.html | 328 --- docs/api/module-src_bone.html | 328 +++ ...ule-lib_expr.html => module-src_expr.html} | 8 +- ...e-lib_spell.html => module-src_spell.html} | 776 +---- docs/basics.md | 16 +- docs/index.md | 2 +- docs/querying.md | 2 +- docs/zh/associations.md | 22 +- docs/zh/basics.md | 22 +- docs/zh/index.md | 2 +- docs/zh/querying.md | 2 +- src/bone.js | 2 +- src/spell.js | 2 +- 24 files changed, 4187 insertions(+), 1454 deletions(-) delete mode 100644 docs/api/module-lib_bone.html create mode 100644 docs/api/module-src_bone.html rename docs/api/{module-lib_expr.html => module-src_expr.html} (60%) rename docs/api/{module-lib_spell.html => module-src_spell.html} (53%) diff --git a/.jsdoc.json b/.jsdoc.json index c011bf2f..8e91dff9 100644 --- a/.jsdoc.json +++ b/.jsdoc.json @@ -6,7 +6,7 @@ "plugins/markdown" ], "source": { - "include": ["index.js", "lib", "Readme.md"], + "include": ["index.js", "src", "Readme.md"], "includePattern": ".js$", "excludePattern": "^(?:docs|node_modules|test)" }, diff --git a/docs/api/BIGINT.html b/docs/api/BIGINT.html index 4ad14e53..f12b1a29 100644 --- a/docs/api/BIGINT.html +++ b/docs/api/BIGINT.html @@ -18,7 +18,7 @@
@@ -216,7 +216,7 @@
Example:

diff --git a/docs/api/Bone.html b/docs/api/Bone.html index 6938361d..25839a34 100644 --- a/docs/api/Bone.html +++ b/docs/api/Bone.html @@ -18,7 +18,7 @@
@@ -41,7 +41,7 @@

The base class that provides Object-relational mapping. This class is never intended to be used directly. We need to create models that extends from Bone. Most of the query features of Bone is implemented by Spell such as Spell#$group and Spell#$join. With Bone, you can create models like this:

class Post extends Bone {
-  static describe() {
+  static initialize() {
     this.hasMany('comments')
     this.belongsTo('author', { className: 'User' })
     this.attribute('extra', { type: JSON })
@@ -431,6 +431,63 @@ 
Example
Post.all.batch() // fetches records 1000 by 1000s.
+
+ + + +
+

(static) pool

+ + + + +
+

get the connection pool of the driver

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
@@ -712,7 +769,7 @@

Parameters:
Example:
class Post extends Bone {
-  static describe() {
+  static initialize() {
     Post.attribute('extra', { type: JSON })
   }
 }
@@ -1159,97 +1216,6 @@
Example:
-
- - - -

(static) describe()

- - - - - -
-

Placeholder static method. Sub-classes of Bone can override this method to setup model informations such as associations, attribute renamings, etc.

-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
-
Example:
- -
class Post extends Bone {
-  static describe() {
-    this.belongsTo('author', { className: 'User' })
-    this.renameAttribute('content', 'body')
-  }
-}
- -
- -
- - -
@@ -2480,7 +2446,7 @@
Parameters:
-

association names defined in Bone.describe

+

association names defined in Bone.initialize

@@ -2508,7 +2474,7 @@
Parameters:
Example:
class Post extends Bone {
-  static describe() {
+  static initialize() {
     this.hasMany('comments')
     this.belongsTo('author')
   }
@@ -2526,19 +2492,14 @@ 
Example:
-

(static) remove(conditions, forceDelete) → {Spell}

+

(static) initialize()

-

Remove any record that matches conditions.

-
    -
  • If forceDelete is true, DELETE records from database permanently.
  • -
  • If not, update deletedAt attribute with current date.
  • -
  • If forceDelete isn't true and deleteAt isn't around, throw an Error.
  • -
+

Override this method to setup associations, rename attributes, etc.

@@ -2588,140 +2549,722 @@

(static) remov -

Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
+
Example:
-
+ + +
- -
- + - - +

(static) loadAttribute(name)

- -
NameTypeDefaultDescription
conditions - - -Object - - - - - - -
forceDelete - - -boolean +
class Post extends Bone {
+  static didLoad() {
+    this.belongsTo('author', { className: 'User' })
+    this.renameAttribute('content', 'body')
+  }
+}
+ - -
- - false - - - - -
+
+

Load attribute definition to merge default getter/setter and custom descriptor on prototype

+
+
+ + + + + -
-
Returns:
+ - + -
-
- Type: -
-
- -Spell + + -
-
+ + -
+ + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +

attribute name

+ +
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +

(static) remove(conditions, forceDelete) → {Spell}

+ + + + + +
+

Remove any record that matches conditions.

+
    +
  • If forceDelete is true, DELETE records from database permanently.
  • +
  • If not, update deletedAt attribute with current date.
  • +
  • If forceDelete isn't true and deleteAt isn't around, throw an Error.
  • +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
conditions + + +Object + + + + + + + + +
forceDelete + + +boolean + + + + + + false + + + + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Spell + + +
+
+ + + +
Example:
-
Post.remove({ title: 'Leah' })         // mark Post { title: 'Leah' } as deleted
-Post.remove({ title: 'Leah' }, true)   // delete Post { title: 'Leah' }
-Post.remove({}, true)                  // delete all data of posts
+
Post.remove({ title: 'Leah' })         // mark Post { title: 'Leah' } as deleted
+Post.remove({ title: 'Leah' }, true)   // delete Post { title: 'Leah' }
+Post.remove({}, true)                  // delete all data of posts
+ +
+ +
+ + + +
+ + + +

(static) renameAttribute(originalName, newName)

+ + + + + +
+

Rename attribute. Since Bone manages a separate set of names called attributes instead of using the raw columns, we can rename the attribute names, which is transformed from the column names by convention, to whatever name we fancy.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
originalName + + +string + + + + + + +
newName + + +string + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +

(static) restore(conditions, optsnullable) → {Spell}

+ + + + + +
+

restore rows

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
conditions + + +Object + + + + + + + + + + +

query conditions

+ +
opts + + +Object + + + + + + + + <nullable>
+ + + +
+

query options

+ +
+ + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Spell + + +
+
+ + +
+ +
@@ -2730,14 +3273,14 @@
Example:
-

(static) renameAttribute(originalName, newName)

+

(static) update(conditions, values) → {Spell}

-

Rename attribute. Since Bone manages a separate set of names called attributes instead of using the raw columns, we can rename the attribute names, which is transformed from the column names by convention, to whatever name we fancy.

+

Update any record that matches conditions.

@@ -2812,13 +3355,13 @@
Parameters:
- originalName + conditions -string +Object @@ -2838,13 +3381,13 @@
Parameters:
- newName + values -string +Object @@ -2877,7 +3420,35 @@
Parameters:
+
+
Returns:
+ + + +
+
+ Type: +
+
+ +Spell + + +
+
+ + + +
+ + + +
+
Example:
+ +
Post.update({ title: 'Leah' }, { title: 'Diablo III' })
+
@@ -2887,14 +3458,15 @@
Parameters:
-

(static) update(conditions, values) → {Spell}

+

(static) upsert(values, options)

-

Update any record that matches conditions.

+

Model.upsert +Returns number of affectedRows.

@@ -2969,13 +3541,13 @@
Parameters:
- conditions + values -Object +object @@ -2995,13 +3567,13 @@
Parameters:
- values + options -Object +object @@ -3039,31 +3611,16 @@
Returns:
-
-
- Type: -
-
- -Spell - - -
-
+
+

number of affectedRows.

+
-
-
Example:
- -
Post.update({ title: 'Leah' }, { title: 'Diablo III' })
- -
- @@ -3220,7 +3777,7 @@

attribute -

These getters and setters are automatically generated while Bone.describe is called.

+

These getters and setters are automatically generated while Bone.describe is called.

@@ -3851,6 +4408,14 @@
Returns:
+
+
Example:
+ +
bone.changed('a');  // true
+bone.changed();     // [ 'a', 'b' ]
+ +
+ @@ -4015,6 +4580,14 @@
Returns:
+
+
Example:
+ +
bone.changes('a');  // => { a: [ 1, 2 ] }
+bone.changes();     // => { a: [ 1, 2 ], b: [ true, false ] }
+ +
+ @@ -4281,6 +4854,11 @@

previo +
+

Get previous attribute changes. Please be noted that Bone#changes is about the changes made after the record is saved, and Bone#previousChanges only returns the changes made before the record was previously saved.

+
previousChanges ➡️ [saved] ➡️ changes ➡️ [current]
+
+ @@ -4434,6 +5012,14 @@

Returns:
+
+
Example:
+ +
bone.previousChanges('a');  // => { a: [ 1, 2 ] }
+bone.previousChanges();     // => { a: [ 1, 2 ], b: [ true, false ] }
+ +
+ @@ -4590,7 +5176,7 @@
Returns:
-

changed values comparing current values Bone.raw against previous values Bone.rawSaved

+

changed values comparing current values Bone.raw against previous values Bone.rawPrevious

@@ -4800,6 +5386,174 @@
Returns:
+
+ + + +

(async) restore(querynullable) → {Bone}

+ + + + + +
+

restore data

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
query + + +Object + + + + + + + + <nullable>
+ + + +
+

options

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Bone + + +
+
+ + +
+

instance

+
+ + +
+ + + +
+ + +
@@ -4927,7 +5681,11 @@

toJSON -

Gets called when JSON.stringify(instance) is invoked.

+

Gets called when JSON.stringify(instance) is invoked. +Bone#toJSON might be called on descents of Bone that does not have attributes defined on them directly, hence for..in is preferred.

+
    +
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
  • +

@@ -5035,7 +5793,11 @@

toObject -

This is the loyal twin of Bone#toJSON because when generating the result object, the raw values of attributes are used, instead of the values returned by custom getters (if any).

+

This is the loyal twin of Bone#toJSON because when generating the result object, the raw values of attributes are used, instead of the values returned by custom getters (if any). +Bone#toObject might be called on descents of Bone that does not have attributes defined on them directly, hence for..in is preferred.

+
    +
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
  • +
@@ -5642,7 +6404,7 @@

validate
- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/Collection.html b/docs/api/Collection.html index 3ce04b11..a54a0afb 100644 --- a/docs/api/Collection.html +++ b/docs/api/Collection.html @@ -18,7 +18,7 @@
@@ -354,7 +354,7 @@
Returns:
-

save() → {Array.<Bone>}

+

(async) save() → {Array.<Bone>}

@@ -662,7 +662,7 @@
Returns:

- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/DataType.html b/docs/api/DataType.html index 74149aaa..f3a7a313 100644 --- a/docs/api/DataType.html +++ b/docs/api/DataType.html @@ -18,7 +18,7 @@
@@ -145,6 +145,320 @@
Example:
+

Methods

+ + + +
+ + + +

(static) is(params) → {boolean}

+ + + + + +
+

Check if params is instance of DataType or not

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
params + + +* + + + + + + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +boolean + + +
+
+ + + +
+ + + +
+ + + +
+ + + +

cast()

+ + + + + +
+

cast raw data returned from data packet into js type

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +

uncast()

+ + + + + +
+

uncast js value into database type with precision

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + @@ -161,7 +475,7 @@
Example:

- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/INTEGER.html b/docs/api/INTEGER.html index 8d329c17..5fc5b491 100644 --- a/docs/api/INTEGER.html +++ b/docs/api/INTEGER.html @@ -18,7 +18,7 @@
@@ -220,7 +220,7 @@
Example:

- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/IndexHint.IndexHint.html b/docs/api/IndexHint.IndexHint.html index c4de5f64..25d106bb 100644 --- a/docs/api/IndexHint.IndexHint.html +++ b/docs/api/IndexHint.IndexHint.html @@ -18,7 +18,7 @@
@@ -290,7 +290,7 @@
Parameters:

- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/STRING.html b/docs/api/STRING.html index 8c4fcff2..372804c0 100644 --- a/docs/api/STRING.html +++ b/docs/api/STRING.html @@ -18,7 +18,7 @@
@@ -212,7 +212,7 @@
Example:

- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/Spell.html b/docs/api/Spell.html index 64a7ab79..f2fd175b 100644 --- a/docs/api/Spell.html +++ b/docs/api/Spell.html @@ -18,7 +18,7 @@
@@ -3758,6 +3758,8 @@
Parameters:
+ Default + Description @@ -3783,6 +3785,12 @@
Parameters:
+ + + null + + + @@ -3809,6 +3817,10 @@
Parameters:
+ + + + @@ -4063,7 +4075,7 @@
Returns:

- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/global.html b/docs/api/global.html index 5d4f7476..eefb44ef 100644 --- a/docs/api/global.html +++ b/docs/api/global.html @@ -18,7 +18,7 @@
@@ -395,6 +395,191 @@

Methods

+
+ + + +

collectLiteral(values, ast) → {Array}

+ + + + + +
+

The ... IS NULL predicate is not parameterizable.

+
    +
  • https://github.com/brianc/node-postgres/issues/1751
  • +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
values + + +Array + + + + +

the collected values

+ +
ast + + +Object + + + + +

the abstract syntax tree

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Array + + +
+
+ + +
+

values

+
+ + +
+ + + +
+ + +
@@ -493,49 +678,2098 @@
Parameters:
- -

context

- - - + +

context

+ + + + + + + + + name + + + + + +string + + + + + + + + + + +

validate name

+ + + + + + + + + attribute + + + + + +object + + + + + + + + + + + + + + + + + + + + value + + + + + +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +

findModel(spell, qualifiers)

+ + + + + +
+

Find model by qualifiers.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
spell + + +Spell + + + + + + +
qualifiers + + +Array.<string> + + + + + + +
+ + + + + + + + + + + + + + + + +
+
Example:
+ +
findModel(spell, ['comments'])
+findModel(spell)
+ +
+ +
+ + + +
+ + + +

(async) findModels(dir) → {Array.<Bone>}

+ + + + + +
+

find models in directory

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dir + + +string + + + + + + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Array.<Bone> + + +
+
+ + + +
+ + + +
+ + + +
+ + + +

formatArgs(isInstance, fnName, args, target) → {FormatResult}

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
isInstance + + +boolean + + + + +

class or instance

+ +
fnName + + +string + + + + + + +
args + + +array + + + + + + +
target + + +Bone + + + + +

class or instance

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +FormatResult + + +
+
+ + +
+

result +}

+
+ + +
+ + + +
+ + + +
+ + + +

formatConditions(conditions)

+ + + + + +
+

Format an array of conditions into an expression. Conditions will be joined with AND.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
conditions + + +Array.<Object> + + + + +

An array of parsed where/having/on conditions

+ +
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +

formatExpr(spell, ast)

+ + + + + +
+

Format the abstract syntax tree of an expression into escaped string.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
spell + + +Spell + + + + + + +
ast + + +Object + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +

formatIdentifier(spell, ast)

+ + + + + +
+

Format identifiers into escaped string with qualifiers.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
spell + + +Spell + + + + + + +
ast + + +Object + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +

formatOpExpr(spell, ast)

+ + + + + +
+

Format { type: 'op' } expressions into escaped string.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
spell + + +Spell + + + + + + +
ast + + +Object + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +

instantiatable(spell) → {boolean}

+ + + + + +
+

Check if the query result of spell is instantiatable by examining the query structure.

+
    +
  • https://www.yuque.com/leoric/blog/ciiard#XoI4O (zh-CN)
  • +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
spell + + +Spell + + + + + + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +boolean + + +
+
+ + + +
+ + + +
+ + + +
+ + + +

isLogicalCondition(condition) → {boolean}

+ + + + + +
+

determine if query object is logical condition

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
condition + + +Object + + + + +

query object

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +boolean + + +
+
+ + + +
+ + + +
+ + + +
+ + + +

isLogicalOp(ast)

+ + + + + +
+

Check if current token is logical operator or not, e.g. AND/NOT/OR.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ast + + +Object + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +

isLogicalOperator(operator) → {boolean}

+ + + + + +
+

determin if operator is logical operator

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
operator + + +string + + + + +

lowercased operator

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +boolean + + +
+
+ + + +
+ + + +
+ + + +
+ + + +

isOperatorCondition(condition) → {boolean}

+ + + + + +
+

Check if object condition is an operator condition, such as { $gte: 100, $lt: 200 }.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
condition + + +Object + + + + + + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +boolean + + +
+
+ + + +
+ + + +
+ + + +
+ + + +

parseLogicalOperator($op, value)

+ + + + + +
+

parse logical objects that is already in tree-like structure

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + - - - - name - - - - -string +
Parameters:
+ + + + + + + - - + - + - + - - + + + + - + @@ -561,7 +2795,10 @@
Parameters:
@@ -596,6 +2833,15 @@
Parameters:
+
+
Example:
+ +
{ $or: { title: 'Leah', content: 'Diablo' } }
+{ $or: [ { title: 'Leah' }, { content: 'Diablo' } ] }
+{ $not: [ { title: 'Leah' }, { title: { $like: '%jjj' }} ] }
+ +
+ @@ -604,14 +2850,14 @@
Parameters:
-

(async) findModels(dir) → {Array.<Bone>}

+

parseNamedLogicalOperator(name, condition) → {Object}

-

find models in directory

+

parse logical objects that have column name lifted upper level

@@ -686,7 +2932,7 @@
Parameters:
- + + + + + + + + + + + + + + + + + @@ -736,7 +3008,7 @@
Returns:
-Array.<Bone> +Object
@@ -748,6 +3020,15 @@
Returns:
+
+
Example:
+ +
{ foo: { $not: { $gt: '2021-01-01', $lte: '2021-12-31' } } }
+{ foo: { $not: [ '2021-09-30', { $gte: '2021-10-07' } ] } }
+{ foo: { $not: [ 'Leah', 'Nephalem' ] } }
+ +
+ @@ -756,12 +3037,16 @@
Returns:
-

formatArgs(isInstance, fnName, args, target) → {FormatResult}

+

parseObject(conditions)

+
+

Parse query objects, which is a complete madness because the operator orders vary. The result would be normalized spell ast. See module:src/query_object~OPERATOR_MAP and module:src/query_object~LOGICAL_OPERATOR_MAP for supported $ops.

+
+ @@ -834,65 +3119,13 @@
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - -
NameType -

validate name

- -
Description
attribute$op -object +string @@ -546,7 +2780,7 @@
Parameters:
- +

logical operators, such as $or, $and, and $not.

-* +Object +| + +Array.<Object> @@ -572,7 +2809,7 @@
Parameters:
- +

logical operands

dirname @@ -703,7 +2949,33 @@
Parameters:
+

column name

+ +
condition + +Object + + + + +

logical query objects

isInstance - - -boolean - - - - -

class or instance

- -
fnName - - -string - - - - - - -
argsconditions -array +Object @@ -909,32 +3142,6 @@
Parameters:
target - - -Bone - - - - -

class or instance

- -
@@ -951,34 +3158,24 @@
Parameters:
-
-
Returns:
- - - -
-
- Type: -
-
- -FormatResult - -
-
+
+
Example:
-
-

result -}

-
+
{ foo: null }
+{ foo: { $gt: new Date(2012, 4, 15) } }
+{ foo: { $between: [1, 10] } }
+{ foo: { $or: [ 'Leah', { $like: '%Leah%' } ] } }
+{ foo: [ 1, 2, 3 ] }
+{ foo: { $not: { $gt: '2021-01-01', $lte: '2021-12-31' } } }
+{ foo: { $not: [ '2021-09-30', { $gte: '2021-10-07' } ] } }
+{ foo: { $not: [ 'Leah', 'Nephalem' ] } }
+{ $or: { title: 'Leah', content: 'Diablo' } }
+{ $or: [ { title: 'Leah', content: 'Diablo' }, { title: 'Stranger' } ] }
-
- -
@@ -987,14 +3184,14 @@
Returns:
-

isDispatchable(spell) → {boolean}

+

parseOperator(name, condition) → {Object}

-

Check if current spell is eligible to build models.

+

parse operator condition into expression ast

@@ -1069,13 +3266,39 @@
Parameters:
- spell + name -Spell +string + + + + + + + + + + + + + + + + + + + + condition + + + + + +Object @@ -1119,7 +3342,7 @@
Returns:
-boolean +Object
@@ -1131,6 +3354,14 @@
Returns:
+
+
Example:
+ +
parseOperator('id', { $gt: 0, $lt: 999999 });
+// => { type: 'op', name: 'and', args: [ ... ]}
+ +
+
@@ -1139,14 +3370,14 @@
Returns:
-

setupHooks(target, hooks)

+

parseValue(value) → {Array.<Object>}

-

Batch setup hooks

+

Parse object values as literal or subquery

@@ -1221,13 +3452,13 @@
Parameters:
- target + value -Bone +Object @@ -1244,34 +3475,15 @@
Parameters:
+ + - - - hooks - - - - - -Object.<string, function()> - - - - - - - - - - - - @@ -1279,12 +3491,26 @@
Parameters:
+
+
Returns:
+ +
+
+ Type: +
+
+ +Array.<Object> +
+
+ +
@@ -1916,7 +4142,7 @@
Properties:

- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/index.html b/docs/api/index.html index be6dbfbf..fe26a30f 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -18,7 +18,7 @@
@@ -43,10 +43,11 @@

Leoric

-

NPM Downloads +

Package Quality +NPM Downloads NPM Version Build Status -Coverage Status

+codecov

Leoric is an object-relational mapping for Node.js, which is heavily influenced by Active Record of Ruby on Rails. See the documentation for detail.

Usage

Assume the tables of posts, users, and comments were setup already. We may declare the models as classes by extending from the base class Bone of Leoric. After the models are connected to the database, the columns of the tables are mapped as attributes, the associations are setup, feel free to start querying.

@@ -54,7 +55,7 @@

Usage

// define model class Post extends Bone { - static describe() { + static initialize() { this.belongsTo('author', { Model: 'User' }) this.hasMany('comments') } @@ -167,7 +168,7 @@
- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/module-lib_bone.html b/docs/api/module-lib_bone.html deleted file mode 100644 index 25ceafa4..00000000 --- a/docs/api/module-lib_bone.html +++ /dev/null @@ -1,328 +0,0 @@ - - - - - - lib/bone - Documentation - - - - - - - - - - - - - -
- -

lib/bone

- - - - - - - -
- -
- - - - - -
- -
-
- - -

The Bone to extend models from. This module consists of helper methods like capitalize, and the class Bone.

- - - - -
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - - - - - - - - - - -

Methods

- - - -
- - - -

(inner) copyValues(values) → {Object}

- - - - - -
-

copy values for validation

-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
values - - -Object - - - - - - -
- - - - - - - - - - - - - - -
-
Returns:
- - - -
-
- Type: -
-
- -Object - - -
-
- - -
-

copied values

-
- - -
- - - -
- - - - - - - -
- -
- - - - -
- -
- -
- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. -
- - - - - - - \ No newline at end of file diff --git a/docs/api/module-src_bone.html b/docs/api/module-src_bone.html new file mode 100644 index 00000000..f2783d52 --- /dev/null +++ b/docs/api/module-src_bone.html @@ -0,0 +1,328 @@ + + + + + + src/bone - Documentation + + + + + + + + + + + + + +
+ +

src/bone

+ + + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

The Bone to extend models from. This module consists of helper methods like capitalize, and the class Bone.

+ + + + +
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + + + +

Methods

+ + + +
+ + + +

(inner) copyValues(values) → {Object}

+ + + + + +
+

copy values for validation

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
values + + +Object + + + + + + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Object + + +
+
+ + +
+

copied values

+
+ + +
+ + + +
+ + + + + + + +
+ +
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme. +
+ + + + + + + \ No newline at end of file diff --git a/docs/api/module-lib_expr.html b/docs/api/module-src_expr.html similarity index 60% rename from docs/api/module-lib_expr.html rename to docs/api/module-src_expr.html index 61c2c872..8ab49dff 100644 --- a/docs/api/module-lib_expr.html +++ b/docs/api/module-src_expr.html @@ -3,7 +3,7 @@ - lib/expr - Documentation + src/expr - Documentation @@ -18,12 +18,12 @@
-

lib/expr

+

src/expr

@@ -1585,7 +1585,7 @@
Parameters:

- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/api/module-lib_spell.html b/docs/api/module-src_spell.html similarity index 53% rename from docs/api/module-lib_spell.html rename to docs/api/module-src_spell.html index 10475ad0..c4ffb4b2 100644 --- a/docs/api/module-lib_spell.html +++ b/docs/api/module-src_spell.html @@ -3,7 +3,7 @@ - lib/spell - Documentation + src/spell - Documentation @@ -18,12 +18,12 @@
-

lib/spell

+

src/spell

@@ -306,14 +306,14 @@
Example:
-

(inner) isOperatorCondition(condition) → {boolean}

+

(inner) formatValueSet(spell, obj, strict) → {Object}

-

Check if object condition is an operator condition, such as { $gte: 100, $lt: 200 }.

+

Translate key-value pairs of attributes into key-value pairs of columns. Get ready for the SET part when generating SQL.

@@ -378,6 +378,8 @@
Parameters:
+ Default + Description @@ -388,7 +390,37 @@
Parameters:
- condition + spell + + + + + +Spell + + + + + + + + + + + + + + + + + + + + + + + + obj @@ -403,9 +435,45 @@
Parameters:
+ + + + +

key-value pairs of attributes

+ + + + + + + + + strict + + + + +boolean + + + + + + + + + + + true + + + + + +

check attribute exist or not

@@ -438,7 +506,7 @@
Returns:
-boolean +Object
@@ -609,7 +677,7 @@
Parameters:
-

Might be Model.aliasName, Model.table, or other names given by users

+

Might be Model.tableAlias, Model.table, or other names given by users

@@ -1223,12 +1291,16 @@
Example:
-

(inner) parseLogicalObjectCondition(name, value)

+

(inner) parseSet(spell, obj)

+
+

Translate key-value pairs of attributes into key-value pairs of columns. Get ready for the SET part when generating SQL.

+
+ @@ -1301,13 +1373,13 @@
Parameters:
- name + spell -string +Spell @@ -1318,699 +1390,25 @@
Parameters:
-

logical operators, such as $or, $and

- - - - - - - - - value - - - - -Object -| - -Array.<Object> - - - - - - - - - - -

logical operands

- - - - - - - - - - - - - - - - - - -
-
Example:
- -
{ $or: { title: 'Leah', content: 'Diablo' } }
-{
-  $or: [
-    { title: 'Leah' },
-    { content: 'Diablo' },
-  ],
-}
-{
-  title: {
-    $or: [
-      'Leah',
-      'Diablo',
-    ]
-  }
-}
-{
-  title: {
-    $or: [
-      'Leah',
-      {
-        $like: '%jjj'
-      },
-    ]
-  }
-}
-{
-  title: {
-    $not: [
-      'Leah',
-      'jss'
-    ]
-  }
-}
- -
- -
- - - -
- - - -

(inner) parseObjectConditions(conditions)

- - - - - -
-

parse conditions in MongoDB style, which is quite polular in ORMs for JavaScript. See module:lib/spell~OPERATOR_MAP for supported $ops.

-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - -
NameTypeDescription
conditionsobj Object +| - - - - - -
- - - - - - - - - - - - - - - - -
-
Example:
- -
{ foo: null }
-{ foo: { $gt: new Date(2012, 4, 15) } }
-{ foo: { $between: [1, 10] } }
- -
- -
- - - -
- - - -

(inner) parseObjectValue(value) → {Object}

- - - - - -
-

Parse object values as literal or subquery

-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
value - - -* - - - - - - -
- - - - - - - - - - - - - - -
-
Returns:
- - - -
-
- Type: -
-
- -Object - - -
-
- - - -
- - - -
- - - -
- - - -

(inner) parseOperatorCondition(name, condition) → {Object}

- - - - - -
-

parse operator condition into expression ast

-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
name - - -string - - - - - - -
condition - - -Object - - - - - - -
- - - - - - - - - - - - - - -
-
Returns:
- - - -
-
- Type: -
-
- -Object - - -
-
- - - -
- - - -
-
Example:
- -
parseOperatorCondition('id', { $gt: 0, $lt: 999999 });
-// => { type: 'op', name: 'and', args: [ ... ]}
- -
- -
- - - -
- - - -

(inner) parseSet(spell, obj)

- - - - - -
-

Translate key-value pairs of attributes into key-value pairs of columns. Get ready for the SET part when generating SQL.

-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
spell - - -Spell - - - - - - -
obj - - -Object +Array @@ -2144,7 +1542,7 @@

(inner)
- Generated by JSDoc 3.6.6 on Tue Jun 15 2021 23:08:14 GMT+0800 (China Standard Time) using the Minami theme. + Generated by JSDoc 3.6.6 on Tue Oct 19 2021 14:33:14 GMT+0800 (China Standard Time) using the Minami theme.
diff --git a/docs/basics.md b/docs/basics.md index 36a453ce..14367289 100644 --- a/docs/basics.md +++ b/docs/basics.md @@ -137,17 +137,27 @@ class Shop extends Bone { } ``` -You can rename the attribute names too. By default, these names are transformed from column names by calling `static renameAttribute(oldName, newName)` in the `static describe()` method. +We can rename the attribute names too. By default, these names are transformed from column names by converting them into camel case. If the names don't match, we can specify the column names manually in `static attributes`, such as: ```js class Shop extends Bone { - static describe() { + static attributes = { + deletedAt: { type: DATE, columnName: 'removed_at' }, + } +} +``` + +We can also rename the attribute in the `static initialize()` method, which gets called after models are loaded. + +```js +class Shop extends Bone { + static initialize() { this.renameAttribute('removedAt', 'deletedAt') } } ``` -A lot of schema settings can be done within the `static describe()` method. We'll get to that later. +A lot of schema settings can be done within the `static initialize()` method. We'll get to that later. ## Connecting Models to Database diff --git a/docs/index.md b/docs/index.md index f030f775..3d15565e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -10,7 +10,7 @@ const { Bone, connect } = require('leoric') // define model class Post extends Bone { - static describe() { + static initialize() { this.belongsTo('author', { Model: 'User' }) this.hasMany('comments') } diff --git a/docs/querying.md b/docs/querying.md index 530e83c2..2a59f6af 100644 --- a/docs/querying.md +++ b/docs/querying.md @@ -437,7 +437,7 @@ Predefined associations can be found by examining `Model.relations`, which is ge ```js class Post extends Bone { - static describe() { + static initialize() { this.hasMany('comments') this.belongsTo('author', { foreignKey: 'authorId', Model: 'User' }) } diff --git a/docs/zh/associations.md b/docs/zh/associations.md index 21fb8488..1525f262 100644 --- a/docs/zh/associations.md +++ b/docs/zh/associations.md @@ -47,7 +47,7 @@ Leoric 支持四种关联关系: ```js class Item extends Bone { - static describe() { + static initialize() { this.belongsTo('shop') } } @@ -57,7 +57,7 @@ Leoric 会把关联关系的名称 `shop` 转为驼峰、首字母大写,再 ```js class Item extends Bone { - static describe() { + static initialize() { this.belongsTo('shop', { className: 'Seller' }) } } @@ -73,7 +73,7 @@ class Item extends Bone { ```js class Item extends Bone { - static describe() { + static initialize() { this.belongsTo('shop', { foreignKey: 'sellerId' }) } } @@ -89,7 +89,7 @@ class Item extends Bone { ```js class Shop extends Bone { - static describe() { + static initialize() { this.hasMany('items') } } @@ -103,7 +103,7 @@ Leoric 寻找对应数据模型的方式都是差不多的。首先将关联关 ```js class Shop extends Bone { - static describe() { + static initialize() { this.hasMany('items', { className: 'Commodity' }) } } @@ -113,7 +113,7 @@ class Shop extends Bone { ```js class Shop extends Bone { - static describe() { + static initialize() { this.hasMany('items', { foreignKey: 'sellerId' }) } } @@ -137,7 +137,7 @@ class Shop extends Bone { ```js class Shop extends Bone { - static describe() { + static initialize() { // the extra where is needed if you fancy this generic tag system this.hasMany('tagMaps', { foreignKey: 'targetId', where: { targetType: 0 } }) this.hasMany('tags', { through: 'tagMaps' }) @@ -149,7 +149,7 @@ class Shop extends Bone { ```js class Tag extends Bone { - static describe() { + static initialize() { this.hasMany('shopTagMaps', { className: 'TagMap', where: { targetType: 0 } }) this.hasMany('shops', { through: 'shopTagMaps' }) } @@ -160,7 +160,7 @@ class Tag extends Bone { ```diff class Tag extends Bone { - static describe() { + static initialize() { this.hasMany('shopTagMaps', { className: 'TagMap', where: { targetType: 0 } }) this.hasMany('shops', { through: 'shopTagMaps' }) + this.hasMany('itemTagMaps', { className: 'TagMap', where: { targetType: 1 } }) @@ -185,7 +185,7 @@ class Tag extends Bone { ```js class User extends Bone { - static describe() { + static initialize() { this.hasOne('shop', { foreignKey: 'ownerId' }) } } @@ -195,7 +195,7 @@ class User extends Bone { ```js class Shop extends Bone { - static describe() { + static initialize() { this.belongsTo('owner', { className: 'User' }) } } diff --git a/docs/zh/basics.md b/docs/zh/basics.md index 3303644e..85488993 100644 --- a/docs/zh/basics.md +++ b/docs/zh/basics.md @@ -120,11 +120,11 @@ await Shop.create({ name: 'Horadric Cube' }) ## 覆盖命名约定 -绝大部分命名约定都有对应的覆盖方法,我们可以使用 `static get table()` 覆盖表名: +绝大部分命名约定都有对应的覆盖方法,我们可以使用 `static table` 覆盖表名: ```js class Shop extends Bone { - static get table() { return 'stores' } + static table = 'stores' } ``` @@ -132,21 +132,31 @@ class Shop extends Bone { ```js class Shop extends Bone { - static get primaryKey() { return 'shopId' } + static primaryKey = 'shopId' } } ``` -也可以重命名属性名,在 `static describe()` 方法中调用 `static renameAttribute(oldName, newName)` 即可: +以及使用 `static attributes` 自定义数据模型属性对应的字段名: ```js class Shop extends Bone { - static describe() { + static attributes = { + deletedAt: { type: DATE, columnName: 'removed_at' }, + } +} +``` + +如果数据模型的属性信息不在模型中直接维护,也可以等数据模型信息从数据库加载后,在 `static initialize()` 方法中重命名属性名: + +```js +class Shop extends Bone { + static initialize() { this.renameAttribute('removedAt', 'deletedAt') } } ``` -`static describe()` 方法中可配置的项目有很多。我们之后再详细讨论。 +`static initialize()` 方法中可配置的项目有很多。我们之后再详细讨论。 ## 连接数据模型和数据库 diff --git a/docs/zh/index.md b/docs/zh/index.md index 89c432bf..b57f1682 100644 --- a/docs/zh/index.md +++ b/docs/zh/index.md @@ -10,7 +10,7 @@ const { Bone, connect } = require('leoric') // 基于 Bone 定义模型,映射关系表 class Post extends Bone { - static describe() { + static initialize() { this.belongsTo('author', { Model: 'User' }) this.hasMany('comments') } diff --git a/docs/zh/querying.md b/docs/zh/querying.md index 71dda15c..776db4af 100644 --- a/docs/zh/querying.md +++ b/docs/zh/querying.md @@ -431,7 +431,7 @@ Leoric 提供两种构建 JOIN 查询的方式: ```js class Post extends Bone { - static describe() { + static initialize() { this.hasMany('comments') this.belongsTo('author', { foreignKey: 'authorId', Model: 'User' }) } diff --git a/src/bone.js b/src/bone.js index 27d17e82..73a49afb 100644 --- a/src/bone.js +++ b/src/bone.js @@ -820,7 +820,7 @@ class Bone { * restore rows * @param {Object} conditions query conditions * @param {Object?} opts query options - * @returns + * @returns {Spell} */ static restore(conditions, opts = {}) { const { deletedAt } = this.timestamps; diff --git a/src/spell.js b/src/spell.js index ead5c192..eae17e04 100644 --- a/src/spell.js +++ b/src/spell.js @@ -65,7 +65,7 @@ function parseSelect(spell, ...names) { * @param {Spell} spell * @param {Object} obj - key-value pairs of attributes * @param {boolean} strict - check attribute exist or not - * @returns + * @returns {Object} */ function formatValueSet(spell, obj, strict = true) { const { Model, silent = false, command } = spell;