Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 543dfb6

Browse files
committed
rename lit to val and deprecate lit
1 parent b7f43ba commit 543dfb6

File tree

7 files changed

+87
-132
lines changed

7 files changed

+87
-132
lines changed

doc/api/objection/README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ await Person
108108
}));
109109
```
110110

111-
You can nest `ref`, `raw`, `lit` and query builders (both knex and objection) in `raw` calls
111+
You can nest `ref`, `raw`, `val` and query builders (both knex and objection) in `raw` calls
112112

113113
```js
114-
const { lit } = require('objection')
114+
const { val } = require('objection')
115115

116116
await Person
117117
.query()
@@ -120,38 +120,44 @@ await Person
120120
alias: 'ageSum'
121121
}))
122122
.where('age', '<', raw(':value1 + :value2', {
123-
value1: lit(50)
123+
value1: val(50)
124124
value2: knex.raw('25')
125125
}));
126126
```
127127

128128
## lit
129129

130+
::: warning
131+
Deprecated! Will be removed in 3.0. Use [val](#val) instead.
132+
:::
133+
134+
## val
135+
130136
```js
131-
const { lit } = require('objection')
137+
const { val } = require('objection')
132138
```
133139

134-
Factory function that returns a [LiteralBuilder](/api/types/#class-literalbuilder) instance. [LiteralBuilder](/api/types/#class-literalbuilder) helps build literals of different types.
140+
Factory function that returns a [ValueBuilder](/api/types/#class-valuebuilder) instance. [ValueBuilder](/api/types/#class-valuebuilder) helps build values of different types.
135141

136142
##### Examples
137143

138144
```js
139-
const { lit, ref } = require('objection');
145+
const { val, ref } = require('objection');
140146

141147
// Compare json objects
142148
await Model
143149
.query()
144150
.where(
145151
ref('Model.jsonColumn:details'),
146152
'=',
147-
lit({name: 'Jennifer', age: 29})
153+
val({name: 'Jennifer', age: 29})
148154
)
149155

150-
// Insert an array literal
156+
// Insert an array.
151157
await Model
152158
.query()
153159
.insert({
154-
numbers: lit([1, 2, 3]).asArray().castTo('real[]')
160+
numbers: val([1, 2, 3]).asArray().castTo('real[]')
155161
})
156162
```
157163

doc/api/types/README.md

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,9 @@ reference will be json type.
615615

616616
Gives an alias for the reference `.select(ref('age').as('yougness'))`
617617

618-
## `class` LiteralBuilder
618+
## `class` ValueBuilder
619619

620-
An instance of this is returned from the [lit](/api/objection/#lit) helper function. If an object
620+
An instance of this is returned from the [val](/api/objection/#val) helper function. If an object
621621
is given as a value, it is cast to json by default.
622622

623623
### Instance Methods
@@ -650,14 +650,6 @@ Cast to sql type `real`.
650650

651651
Cast to sql type `boolean`.
652652

653-
#### castType()
654-
655-
Give custom type to which referenced value is cast to.
656-
657-
**DEPRECATED:** Use `castTo` instead. `castType` Will be removed in 2.0.
658-
659-
`.castType('mytype') --> CAST(?? as mytype)`
660-
661653
#### castTo()
662654

663655
Give custom type to which referenced value is cast to.
@@ -669,21 +661,15 @@ Give custom type to which referenced value is cast to.
669661
Converts the value to json (jsonb in case of postgresql). The default
670662
cast type for object values.
671663

672-
#### castArray
673-
674-
Converts the value to an array literal.
675-
676-
**DEPRECATED:** Use `asArray` instead. `castArray` Will be removed in 2.0.
677-
678664
#### asArray()
679665

680-
Converts the value to an array literal.
666+
Converts the value to an array.
681667

682-
`lit([1, 2, 3]).asArray() --> ARRAY[?, ?, ?]`
668+
`val([1, 2, 3]).asArray() --> ARRAY[?, ?, ?]`
683669

684670
Can be used in conjuction with `castTo`.
685671

686-
`lit([1, 2, 3]).asArray().castTo('real[]') -> CAST(ARRAY[?, ?, ?] AS real[])`
672+
`val([1, 2, 3]).asArray().castTo('real[]') -> CAST(ARRAY[?, ?, ?] AS real[])`
687673

688674
#### as()
689675

doc/changelog/README.md

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,17 @@
44

55
### What's new
66

7-
* relatedQuery can now be used for more than just subqueries. See the examples [here](/guide/query-examples.html#relation-queries)
7+
* relatedQuery can now be used for more than just subqueries. See the examples [here](/guide/query-examples.html#relation-queries).
8+
9+
* modifiers can now take arguments and are a lot more useful. See [this recipe](https://vincit.github.io/objection.js/recipes/modifiers.html) for more info.
810

911
### Breaking changes
1012

11-
* Objection now uses the native promise instead of bluebird which means that all bluebird specific methods like `map`, `reduce`, `reflect`, `bind`, `asCallback`, `nodeify`, `return` etc. have been removed from the `QueryBuilder`.
13+
* Objection now uses the native promise instead of bluebird which means that all bluebird specific methods like `map`, `reduce`, `reflect`, `bind`, `asCallback`, `nodeify`, `return` etc. have been removed from the `QueryBuilder`.
1214

1315
* Database errors throw by objection are now wrapped using the [db-errors library](https://github.com/Vincit/db-errors). If you have code that uses the properties of the old native database errors, you can access the native error through `err.nativeError`.
1416

15-
#### Only the first argument of [modify](/api/query-builder/other-methods.html#modify) query builder method is interpreted as a modifier name. Rest of the arguments are passed as arguments to the modifier. The first argument can be an array of modifier names.
16-
17-
You need to change code like this:
18-
19-
```js
20-
Person
21-
.query()
22-
.modify('modifier1', 'modifier2')
23-
```
24-
25-
to:
26-
27-
```js
28-
Person
29-
.query()
30-
.modify(['modifier1', 'modifier2'])
31-
```
32-
33-
Now code like this is possible:
34-
35-
```js
36-
class Person extends Model {
37-
static modifiers = {
38-
modifier1: (query, arg1, arg2) => query.where(arg1, arg2)
39-
}
40-
}
41-
42-
Person
43-
.query()
44-
.modify('modifier1', arg1, arg2)
45-
```
17+
* Only the first argument of [modify](/api/query-builder/other-methods.html#modify) query builder method is interpreted as a modifier name. Rest of the arguments are passed as arguments to the modifier. The first argument can be an array of modifier names.
4618

4719
## 1.6.9
4820

lib/objection.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const {
2525
} = require('./utils/identifierMapping');
2626
const { compose, mixin } = require('./utils/mixin');
2727
const { ref } = require('./queryBuilder/ReferenceBuilder');
28-
const { lit } = require('./queryBuilder/LiteralBuilder');
28+
const { val } = require('./queryBuilder/ValueBuilder');
2929
const { raw } = require('./queryBuilder/RawBuilder');
3030

3131
const { inherit } = require('../lib/utils/classUtils');
@@ -80,9 +80,14 @@ module.exports = {
8080
compose,
8181
mixin,
8282
ref,
83-
lit,
83+
val,
8484
raw,
8585

86+
get lit() {
87+
deprecate('`lit` is deprecated. Use `val` instead. `lit` will be removed in 3.0');
88+
return val;
89+
},
90+
8691
snakeCaseMappers,
8792
knexSnakeCaseMappers,
8893
knexIdentifierMapping,

lib/queryBuilder/LiteralBuilder.js renamed to lib/queryBuilder/ValueBuilder.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
const { asArray, isObject } = require('../utils/objectUtils');
44
const { buildArg } = require('../utils/buildUtils');
5-
const { deprecate } = require('../utils/deprecate');
65

7-
class LiteralBuilder {
6+
class ValueBuilder {
87
constructor(value) {
98
this._value = value;
109
this._cast = null;
@@ -52,20 +51,6 @@ class LiteralBuilder {
5251
return this;
5352
}
5453

55-
castArray() {
56-
deprecate(
57-
'castArray() is deprecated. Use asArray() instead. castArray() will be removed in 2.0'
58-
);
59-
return this.asArray();
60-
}
61-
62-
castType(sqlType) {
63-
deprecate(
64-
'castType(type) is deprecated. Use castTo(type) instead. castType(type) will be removed in 2.0'
65-
);
66-
return this.castTo(sqlType);
67-
}
68-
6954
castTo(sqlType) {
7055
this._cast = sqlType;
7156
return this;
@@ -100,11 +85,11 @@ class LiteralBuilder {
10085
}
10186
}
10287

103-
function lit(val) {
104-
return new LiteralBuilder(val);
88+
function val(val) {
89+
return new ValueBuilder(val);
10590
}
10691

10792
module.exports = {
108-
LiteralBuilder,
109-
lit
93+
ValueBuilder,
94+
val
11095
};

0 commit comments

Comments
 (0)