Skip to content

Commit

Permalink
feat: support Objection v3
Browse files Browse the repository at this point in the history
Closes #1182

BREAKING CHANGE: Knex and Objection both have breaking changes, so this
will too.

Signed-off-by: Will Soto <[email protected]>
  • Loading branch information
willsoto committed Sep 23, 2021
1 parent cb8421b commit eed1848
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 3,020 deletions.
3,168 changes: 162 additions & 3,006 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@
"eslint-config-prettier": "~8.3.0",
"eslint-plugin-mocha": "~9.0.0",
"husky": "~7.0.0",
"knex": "~0.21.5",
"knex": "~0.95.11",
"lint-staged": "~11.1.0",
"markdown-toc": "~1.2.0",
"mocha": "~9.1.0",
"nyc": "~15.1.0",
"objection": "~2.2.15",
"objection": "3.0.0-alpha.4",
"prettier": "~2.4.0",
"prettier-plugin-organize-imports": "~2.3.2",
"prettier-plugin-packagejson": "~2.2.11",
Expand All @@ -134,12 +134,16 @@
"peerDependencies": {
"@nestjs/common": "^7.0.0 || ^8.0.0",
"@nestjs/core": "^7.0.0 || ^8.0.0",
"knex": ">=0.16.0",
"objection": "^2.0.0"
"knex": "^0.95.0",
"objection": "^3.0.0"
},
"release": {
"branches": [
"main"
"main",
{
"name": "next",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
Expand Down
6 changes: 3 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ValueProvider,
} from "@nestjs/common";
import { ModuleRef } from "@nestjs/core";
import * as Knex from "knex";
import { knex, Knex } from "knex";
import { Model } from "objection";
import {
KNEX_CONNECTION,
Expand All @@ -34,7 +34,7 @@ export class ObjectionCoreModule implements OnApplicationShutdown {

public static register(options: ObjectionModuleOptions): DynamicModule {
const BaseModel = options.Model || Model;
const connection = Knex(options.config);
const connection = knex(options.config);

BaseModel.knex(connection);

Expand Down Expand Up @@ -73,7 +73,7 @@ export class ObjectionCoreModule implements OnApplicationShutdown {
provide: connectionToken,
inject: [OBJECTION_MODULE_OPTIONS],
useFactory(objectionModuleOptions: ObjectionModuleOptions): Knex {
return Knex(objectionModuleOptions.config);
return knex(objectionModuleOptions.config);
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Type } from "@nestjs/common";
import { ModuleMetadata } from "@nestjs/common/interfaces";
import * as Knex from "knex";
import { Knex } from "knex";
import { Model } from "objection";
export interface ObjectionModuleOptions {
/**
Expand Down
2 changes: 1 addition & 1 deletion test/core.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from "@nestjs/common";
import { Test, TestingModule } from "@nestjs/testing";
import { expect } from "chai";
import * as Knex from "knex";
import { Knex } from "knex";
import { Model } from "objection";
import * as sinon from "sinon";
import {
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Inject, Injectable, Module } from "@nestjs/common";
import * as Knex from "knex";
import { Knex } from "knex";
import { Model } from "objection";
import { Connection, KNEX_CONNECTION, ObjectionModule } from "../src";

@Injectable()
export class ConnectionCheck {
constructor(@Inject(KNEX_CONNECTION) public connection: Connection) {}
Expand Down
2 changes: 1 addition & 1 deletion test/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable new-cap */
import { Test, TestingModule } from "@nestjs/testing";
import { expect } from "chai";
import * as Knex from "knex";
import { Knex } from "knex";
import { KNEX_CONNECTION } from "../src";
import { ConnectionCheck, ConnectionModule } from "./fixtures";
describe("Integration", function () {
Expand Down
2 changes: 1 addition & 1 deletion test/module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Test, TestingModule } from "@nestjs/testing";
import { expect } from "chai";
import * as Knex from "knex";
import { Knex } from "knex";
import { Model } from "objection";
import { KNEX_CONNECTION } from "../src/constants";
import { ObjectionModule } from "../src/module";
Expand Down
3 changes: 2 additions & 1 deletion test/multiple-connections.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Test, TestingModule } from "@nestjs/testing";
import { expect } from "chai";
import * as Knex from "knex";
import { Knex } from "knex";
import { Model } from "objection";
import { ObjectionCoreModule } from "../src/core";

describe("when registering multiple connections", function () {
let testingModule: TestingModule;
let connection1: Knex;
Expand Down

0 comments on commit eed1848

Please sign in to comment.