Skip to content

Commit d26814d

Browse files
committed
Merge branch 'upstream-master'
2 parents a1f9200 + 76fb48e commit d26814d

File tree

129 files changed

+5543
-4585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+5543
-4585
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ name: tests
22

33
on:
44
push:
5-
branches: [master]
5+
branches: [main]
66
pull_request:
7-
branches: [master]
7+
branches: [main]
88

99
jobs:
1010
run-tests:
1111
runs-on: ubuntu-latest
1212

1313
strategy:
1414
matrix:
15-
node-version: [12.x, 14.x, 16.x, 18.x, 20.x]
15+
node-version: [14.x, 16.x, 18.x, 20.x, 22.x]
1616

1717
steps:
1818
- uses: actions/checkout@v2
@@ -26,7 +26,7 @@ jobs:
2626
run: npm ci
2727

2828
- name: Run docker compose
29-
run: docker-compose up -d
29+
run: docker compose up -d
3030

3131
- name: Setup test db
3232
run: node setup-test-db.js

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ What objection.js gives you:
1717
- **Simple and fun way to [fetch, insert, update and delete](https://vincit.github.io/objection.js/guide/query-examples.html) objects using the full power of SQL**
1818
- **Powerful mechanisms for [eager loading](https://vincit.github.io/objection.js/guide/query-examples.html#eager-loading), [inserting](https://vincit.github.io/objection.js/guide/query-examples.html#graph-inserts) and [upserting](https://vincit.github.io/objection.js/guide/query-examples.html#graph-upserts) object graphs**
1919
- **Easy to use [transactions](https://vincit.github.io/objection.js/guide/transactions.html)**
20-
- **Official [TypeScript](https://github.com/Vincit/objection.js/blob/master/typings/objection/index.d.ts) support**
20+
- **Official [TypeScript](https://github.com/Vincit/objection.js/blob/main/typings/objection/index.d.ts) support**
2121
- **Optional [JSON schema](https://vincit.github.io/objection.js/guide/validation.html) validation**
2222
- **A way to [store complex documents](https://vincit.github.io/objection.js/guide/documents.html) as single rows**
2323

@@ -36,18 +36,18 @@ What objection.js **doesn't** give you:
3636
For simple things it is useful that the database schema is automatically generated from the model definitions,
3737
but usually just gets in your way when doing anything non-trivial. Objection.js leaves the schema related things
3838
to you. knex has a great [migration tool](https://knexjs.org/guide/migrations.html) that we recommend for this job. Check
39-
out the [example project](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts).
39+
out the [example project](https://github.com/Vincit/objection.js/tree/main/examples/koa-ts).
4040

41-
The best way to get started is to clone our [example project](https://github.com/Vincit/objection.js/tree/master/examples/koa) and start playing with it. There's also a [typescript version](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts) available.
41+
The best way to get started is to clone our [example project](https://github.com/Vincit/objection.js/tree/main/examples/koa) and start playing with it. There's also a [typescript version](https://github.com/Vincit/objection.js/tree/main/examples/koa-ts) available.
4242

4343
Check out [this issue](https://github.com/Vincit/objection.js/issues/1069) to see who is using objection and what they think about it.
4444

4545
Shortcuts:
4646

47-
- [Who uses objection.js](https://github.com/Vincit/objection.js/issues/1069)
47+
- [Who uses objection.js](https://github.com/Vincit/objection.js/discussions/2464)
4848
- [API reference](https://vincit.github.io/objection.js/api/query-builder/)
49-
- [Example projects](https://github.com/Vincit/objection.js/tree/master/examples)
49+
- [Example projects](https://github.com/Vincit/objection.js/tree/main/examples)
5050
- [Changelog](https://vincit.github.io/objection.js/release-notes/changelog.html)
51-
- [v1 -> v2 migration guide](https://vincit.github.io/objection.js/release-notes/migration.html)
51+
- [v1 -> v2 -> v3 migration guide](https://vincit.github.io/objection.js/release-notes/migration.html)
5252
- [Contribution guide](https://vincit.github.io/objection.js/guide/contributing.html)
5353
- [Plugins](https://vincit.github.io/objection.js/guide/plugins.html)

doc/.vuepress/theme/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (_, ctx) => ({
1010
const isAlgoliaSearch =
1111
themeConfig.algolia ||
1212
Object.keys((siteConfig.locales && themeConfig.locales) || {}).some(
13-
(base) => themeConfig.locales[base].algolia
13+
(base) => themeConfig.locales[base].algolia,
1414
);
1515

1616
return {

doc/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ What objection.js gives you:
1919
- **Simple and fun way to [fetch, insert, update and delete](/guide/query-examples.html) objects using the full power of SQL**
2020
- **Powerful mechanisms for [eager loading](/guide/query-examples.html#eager-loading), [inserting](/guide/query-examples.html#graph-inserts) and [upserting](/guide/query-examples.html#graph-upserts) object graphs**
2121
- **Easy to use [transactions](/guide/transactions.html)**
22-
- **Official [TypeScript](https://github.com/Vincit/objection.js/blob/master/typings/objection/index.d.ts) support**
22+
- **Official [TypeScript](https://github.com/Vincit/objection.js/blob/main/typings/objection/index.d.ts) support**
2323
- **Optional [JSON schema](/guide/validation.html) validation**
2424
- **A way to [store complex documents](/guide/documents.html) as single rows**
2525

@@ -33,8 +33,8 @@ What objection.js **doesn't** give you:
3333
For simple things it is useful that the database schema is automatically generated from the model definitions,
3434
but usually just gets in your way when doing anything non-trivial. Objection.js leaves the schema related things
3535
to you. knex has a great [migration tool](https://knexjs.org/guide/migrations.html) that we recommend for this job. Check
36-
out the [example project](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts).
36+
out the [example project](https://github.com/Vincit/objection.js/tree/main/examples/koa-ts).
3737

38-
The best way to get started is to clone our [example project](https://github.com/Vincit/objection.js/tree/master/examples/koa) and start playing with it. There's also a [typescript version](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts) available.
38+
The best way to get started is to clone our [example project](https://github.com/Vincit/objection.js/tree/main/examples/koa) and start playing with it. There's also a [typescript version](https://github.com/Vincit/objection.js/tree/main/examples/koa-ts) available.
3939

4040
Check out [this issue](https://github.com/Vincit/objection.js/issues/1069) to see who is using objection and what they think about it.

doc/api/model/instance-methods.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,19 +1036,19 @@ called explicitly when needed.
10361036
| ---------------------------------------------------- | -------------------- |
10371037
| [ValidationError](/api/types/#class-validationerror) | If validation fails. |
10381038

1039-
## $omit()
1039+
## $omitFromJson()
10401040

10411041
```js
1042-
modelInstance.$omit(keys);
1042+
modelInstance.$omitFromJson(props);
10431043
```
10441044

1045-
Omits a set of properties.
1045+
Omits a set of properties when converting the model to JSON.
10461046

10471047
##### Arguments
10481048

1049-
| Argument | Type | Description |
1050-
| -------- | -------------------------------------------------------- | ------------ |
1051-
| keys | string<br>string[]<br>Object&lt;string,&nbsp;boolean&gt; | keys to omit |
1049+
| Argument | Type | Description |
1050+
| -------- | -------------------------------------------------------- | ------------- |
1051+
| props | string<br>string[]<br>Object&lt;string,&nbsp;boolean&gt; | props to omit |
10521052

10531053
##### Return value
10541054

@@ -1058,48 +1058,46 @@ Omits a set of properties.
10581058

10591059
##### Examples
10601060

1061-
Omits a set of properties.
1062-
10631061
```js
10641062
const json = person
10651063
.fromJson({ firstName: 'Jennifer', lastName: 'Lawrence', age: 24 })
1066-
.$omit('lastName')
1067-
.toJSON();
1064+
.$omitFromJson('lastName')
1065+
.$toJson();
10681066

10691067
console.log(_.has(json, 'lastName')); // --> false
10701068
```
10711069

10721070
```js
10731071
const json = person
10741072
.fromJson({ firstName: 'Jennifer', lastName: 'Lawrence', age: 24 })
1075-
.$omit(['lastName'])
1076-
.toJSON();
1073+
.$omitFromJson(['lastName'])
1074+
.$toJson();
10771075

10781076
console.log(_.has(json, 'lastName')); // --> false
10791077
```
10801078

10811079
```js
10821080
const json = person
10831081
.fromJson({ firstName: 'Jennifer', lastName: 'Lawrence', age: 24 })
1084-
.$omit({ lastName: true })
1085-
.toJSON();
1082+
.$omitFromJson({ lastName: true })
1083+
.$toJson();
10861084

10871085
console.log(_.has(json, 'lastName')); // --> false
10881086
```
10891087

1090-
## $pick()
1088+
## $omitFromDatabaseJson()
10911089

10921090
```js
1093-
modelInstance.$pick(keys);
1091+
modelInstance.$omitFromDatabaseJson(props);
10941092
```
10951093

1096-
Picks a set of properties.
1094+
Omits a set of properties when converting the model to database JSON.
10971095

10981096
##### Arguments
10991097

1100-
| Argument | Type | Description |
1101-
| -------- | -------------------------------------------------------- | ------------ |
1102-
| keys | string<br>string[]<br>Object&lt;string,&nbsp;boolean&gt; | keys to pick |
1098+
| Argument | Type | Description |
1099+
| -------- | -------------------------------------------------------- | ------------- |
1100+
| props | string<br>string[]<br>Object&lt;string,&nbsp;boolean&gt; | props to omit |
11031101

11041102
##### Return value
11051103

@@ -1112,26 +1110,26 @@ Picks a set of properties.
11121110
```js
11131111
const json = person
11141112
.fromJson({ firstName: 'Jennifer', lastName: 'Lawrence', age: 24 })
1115-
.$pick('firstName', 'age')
1116-
.toJSON();
1113+
.$omitFromDatabaseJson('lastName')
1114+
.$toDatabaseJson();
11171115

11181116
console.log(_.has(json, 'lastName')); // --> false
11191117
```
11201118

11211119
```js
11221120
const json = person
11231121
.fromJson({ firstName: 'Jennifer', lastName: 'Lawrence', age: 24 })
1124-
.$pick(['firstName', 'age'])
1125-
.toJSON();
1122+
.$omitFromJson(['lastName'])
1123+
.$toDatabaseJson();
11261124

11271125
console.log(_.has(json, 'lastName')); // --> false
11281126
```
11291127

11301128
```js
11311129
const json = person
11321130
.fromJson({ firstName: 'Jennifer', lastName: 'Lawrence', age: 24 })
1133-
.$pick({ firstName: true, age: true })
1134-
.toJSON();
1131+
.$omitFromJson({ lastName: true })
1132+
.$toDatabaseJson();
11351133

11361134
console.log(_.has(json, 'lastName')); // --> false
11371135
```

doc/api/model/static-properties.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Composite id can be specified by giving an array of column names.
118118

119119
Defaults to 'id'.
120120

121+
You can return `null` in order to tell objection there is no primary key. This may be useful in models of join tables.
122+
121123
## `static` jsonSchema
122124

123125
```js

doc/guide/contributing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ When creating an issue there are couple of things you need to remember:
1313
Answer the following questions: Which objection version are you using? What are you doing? What code are you running? What is happening? What are you expecting to happen instead? If you provide code examples (please do!), **use the actual code you are running**. People often leave out details or use made up examples because they think they are only leaving out irrelevant stuff. If you do that, you have already made an assumption about what the problem is and it's usually something else. Also provide all possible stack traces and error messages.
1414

1515
3. **If possible, provide an actual reproduction**
16-
The fastest way to get your bug fixed or problem solved is to create a simple standalone app or a test case that demonstrates your problem. There's a file called [reproduction-template.js](https://github.com/Vincit/objection.js/blob/master/reproduction-template.js) you can use as a starting point for your reproduction.
16+
The fastest way to get your bug fixed or problem solved is to create a simple standalone app or a test case that demonstrates your problem. There's a file called [reproduction-template.js](https://github.com/Vincit/objection.js/blob/main/reproduction-template.js) you can use as a starting point for your reproduction.
1717

1818
Please bear in mind that objection has thousands of tests and if you run into a problem, say with `insert` method, it doesn't mean that `insert` is completely broken, but some small part of it you are using is. That's why enough context is necessary. It's not enough to say, "insert fails". You need to provide the code that fails and usually the models that are used too. And let's say this again: **don't provide made up code examples!** When you do, you only write the parts you think are relevant and usually leave out the useful information. Use the actual code that you have tested to fail.
1919

@@ -41,7 +41,7 @@ git clone [email protected]:<your-account>/objection.js.git objection
4141

4242
3. **Run `npm install` at the root of the repo**
4343

44-
4. **Run `docker-compose up` at the root of the repo**
44+
4. **Run `docker compose up` at the root of the repo**
4545
- If you have local databases running, shut them down or port binding will conflict.
4646

4747
5. **Create test users and databases by running `node setup-test-db` at the root of the repo**
@@ -53,7 +53,7 @@ git clone [email protected]:<your-account>/objection.js.git objection
5353
You can run the tests on a subset of databases by setting the `DATABASES` env variable
5454

5555
```bash
56-
# Only run tests on sqlite. No need for docker-compose.
56+
# Only run tests on sqlite. No need for docker compose.
5757
DATABASES=sqlite3 npm test
5858
```
5959

doc/guide/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ To use objection.js all you need to do is [initialize knex](https://knexjs.org/g
44

55
The next step is to create some migrations and models and start using objection.js. The best way to get started is to check out one of our example projects:
66

7-
- [The minimal example](https://github.com/Vincit/objection.js/tree/master/examples/minimal) contains the bare minimum for you to start testing out things with objection.
7+
- [The minimal example](https://github.com/Vincit/objection.js/tree/main/examples/minimal) contains the bare minimum for you to start testing out things with objection.
88

99
```bash
1010
git clone [email protected]:Vincit/objection.js.git objection
@@ -13,7 +13,7 @@ npm install
1313
npm start
1414
```
1515

16-
- [The koa example project](https://github.com/Vincit/objection.js/tree/master/examples/koa) is a simple [koa](https://koajs.com) server. The `client.js` file contains a bunch of http requests for you to start playing with the REST API.
16+
- [The koa example project](https://github.com/Vincit/objection.js/tree/main/examples/koa) is a simple [koa](https://koajs.com) server. The `client.js` file contains a bunch of http requests for you to start playing with the REST API.
1717

1818
```bash
1919
git clone [email protected]:Vincit/objection.js.git objection
@@ -22,7 +22,7 @@ npm install
2222
npm start
2323
```
2424

25-
We also have a [typescript version](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts) of the example.
25+
We also have a [typescript version](https://github.com/Vincit/objection.js/tree/main/examples/koa-ts) of the example.
2626

2727
Also check out our [API reference](/api/query-builder/) and [recipe book](/recipes/raw-queries.html).
2828

doc/guide/plugins.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ A curated list of plugins and modules for objection. Only plugins that follow [t
1616

1717
- [objection-filter](https://github.com/tandg-digital/objection-filter) - API filtering on data and related models
1818
- [objection-graphql](https://github.com/vincit/objection-graphql) - Automatically generates rich graphql schema for objection models
19+
- [objectionjs-graphql](https://www.npmjs.com/package/objectionjs-graphql) - Automatically generates GraphQl schema for objection models compatible with Objection 3.x (Graph fetch support)
1920

2021
## Plugin development best practices
2122

22-
When possible, objection.js plugins should be implemented as [class mixins](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/). A mixin is simply a function that takes a class as an argument and returns a subclass. Plugins should not modify [objection.Model](/api/model/), [objection.QueryBuilder](/api/query-builder/) or any other global variables directly. See the [example plugin](https://github.com/Vincit/objection.js/tree/master/examples/plugin) for more info. There is also [another example](https://github.com/Vincit/objection.js/tree/master/examples/plugin-with-options) that should be followed if your plugin takes options or configuration parameters.
23+
When possible, objection.js plugins should be implemented as [class mixins](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/). A mixin is simply a function that takes a class as an argument and returns a subclass. Plugins should not modify [objection.Model](/api/model/), [objection.QueryBuilder](/api/query-builder/) or any other global variables directly. See the [example plugin](https://github.com/Vincit/objection.js/tree/main/examples/plugin) for more info. There is also [another example](https://github.com/Vincit/objection.js/tree/main/examples/plugin-with-options) that should be followed if your plugin takes options or configuration parameters.
2324

2425
Mixin is just a function that takes a class and returns an extended subclass.
2526

doc/guide/relations.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,36 @@ class Person extends Model {
134134
}
135135
```
136136

137-
## Require loops
137+
## Require loops (non ECMAScript modules only)
138138

139139
Require loops (circular dependencies, circular requires) are a very common problem when defining relations. Whenever a module `A` imports module `B` that immediately (synchronously) imports module `A`, you create a require loop that node.js or objection cannot solve automatically. A require loop usually leads to the other imported value to be an empty object which causes all kinds of problems. Objection attempts to detect these situations and mention the words `require loop` in the thrown error. Objection offers multiple solutions to this problem. See the circular dependency solutions examples in this section. In addition to objection's solutions, you can always organize your code so that such loops are not created.
140140

141-
Solutions to require loops
141+
If you are using [ECMAScript modules](https://nodejs.org/api/esm.html), circular imports are not a problem. You can just do:
142+
143+
```js
144+
import Animal from "./Animal.js";
145+
146+
class Person extends Model {
147+
static get tableName() {
148+
return "persons";
149+
}
150+
151+
static get relationMappings() {
152+
return {
153+
pets: {
154+
relation: Model.HasManyRelation,
155+
modelClass: Animal,
156+
join: {
157+
from: "persons.id",
158+
to: "animals.ownerId",
159+
},
160+
},
161+
};
162+
}
163+
}
164+
```
165+
166+
However if you are not using ECMAScript modules, solutions to require loops are:
142167

143168
```js
144169
class Person extends Model {
@@ -208,3 +233,4 @@ class Person extends Model {
208233
}
209234
}
210235
```
236+

0 commit comments

Comments
 (0)