Questions tagged [objection.js]

An Object Relational Mapper (ORM) for Node.js

Formerly known as moron.js, objection.js is an Promise based ORM built on top of knex.js focusing on the loading and storing of javascript objects into relational databases, specifically the ones supported by knex.js.

It does not currently incorporate a query builder leaving that for knex.js.

Website: https://vincit.github.io/objection.js

Github repo: https://github.com/Vincit/objection.js/

284 questions
0
votes
0 answers

Repository pattern in objection.js throws TS2322 "could be instantiated with a different subtype"

I am implementing the repository pattern using objection.js 2.2.16 for containing common utility methods. But I am encountering the TS2322 error. A minimum reproducible code snippet is as following: import { Model, ModelClass } from…
Eddie Deng
  • 1,399
  • 1
  • 18
  • 30
0
votes
0 answers

HasManyRelation using withGraphFetched in Objection JS problem arising while using limit clause?

I have two tables:- Table 1. Activity Table 2. ActivityAvailability Relation Type: HasManyRelation (table 1 HasManyRelation to table2) I couldn't able use withGraphJoined because it has a limit clause issue with pagination as the objection.js doc…
0
votes
0 answers

Knex / Objection / PostgreSQL - Update of foreign key not working

I use Knex/Objection with PostgreSQL and I'm trying to update the foreign key but it returns null without any error. Car model: export class CarModel extends Model implements Car { public static readonly tableName: string = 'cars'; public static…
blackhard
  • 502
  • 7
  • 26
0
votes
1 answer

Objection.js conditional insertGraph

I'm creating an Import function for our Software, where Excel Files can be used to import Data to the System. We work with objection.js (create Tool) and I'm using insertGraph() to insert content. My problem is I only want to import Relations when…
skuettel
  • 13
  • 2
0
votes
1 answer

How to use COUNT aggregator inside HAVING clause in knex.js?

let duplicates = await Books.query() .select('book_id') .groupBy('book_id') .having(knex.count('book_id'), '>', 1); Here I want to use the count aggregator inside the having clause. How can I do…
0
votes
1 answer

Would ObjectionJS .query() get all the result before executing the where() / findById() function?

For ObjectionJS, as this line will fetch all the persons in db: const people = await Person.query(); Would the query() in the line below fetch all the persons in db before executing the findById function? const person = await…
Unreality
  • 4,111
  • 11
  • 48
  • 67
0
votes
1 answer

Is there a way to only validate input during insertion using Objectionjs and not during update?

const BaseModel = require("./base_model.js"); class CustomerModel extends BaseModel { static get tableName() { return "customers"; } static get jsonSchema() { return { type: "object", required:…
Gpak
  • 3,342
  • 2
  • 21
  • 19
0
votes
1 answer

Migration file failed Knexjs

I'm not sure what is the problem with migration. I'm using knex to connect sqlite3 DB. I'm totally new to this. Created table in migration file and then added a column in table using separate migration. But that file failed. Logs shown above and I…
Ahsan Danish
  • 91
  • 2
  • 12
0
votes
1 answer

Connect to LocalDB\MSSQLLocalDB with Objection.js Knexfile

I am trying to connect to a LocalDB\MSSQLLocalDB SQLExpress instance in my Node.js application that uses Objection.js/Knex for the data layer. When I try to run a migration it fails to connect to the database. But I can connect via SSMS without…
A. Hasemeyer
  • 1,452
  • 1
  • 18
  • 47
0
votes
0 answers

Cannot find module when using require in ts-jest

ts-jest unable to find a module when using require imports. const file = require("./file") const file = require(path.join(__dirname, "file")) Both cases are failing. App runs fine on prod and dev. Its only test where require statements are failing…
0
votes
0 answers

could not resolve Model using modelPaths in objectionjs and ts-jest

Getting this error when running ts-jest. Error: Member.relationMappings.primaryAssignment: modelClass: could not resolve ./MemberAssignment using modelPaths primaryAssignment: { relation: Model.HasOneRelation, modelClass:…
0
votes
1 answer

Mock objection model dependecy in NestJs with Jest

I'm trying to make unit test with nestjs and objection. The problem I have is that I can't mock the "User" Model that is injected with the decorator "@InjectModel". I searched a lot to find a solution but I didn't find anything. users.service.ts …
0
votes
1 answer

Javascript to Typescript Objection.js transaction / query functions not found

I'm converting a Javascript project to Typescript. I'm using Objection.js. The issue is, Typescript is unable to find typing information for the Objection.js built-in transaction and query functions. I have the following type dev dependencies: …
sizzle
  • 2,222
  • 2
  • 21
  • 32
0
votes
1 answer

Knex Objection js Relationship not found Error

I am using Objection.js with Knex in a Node.js application and trying to pull data with a relationship. This has worked for me in the past, but on one of my tables it is saying the relationship does not exist: A model class DashboardLayout doesn't…
A. Hasemeyer
  • 1,452
  • 1
  • 18
  • 47
0
votes
1 answer

Express + knex + Objection Base service class

I'm looking for solution to use BaseService for common Objection model methods. it is working properly on UserService. but i want to write some methods in BaseService class. base.service.ts class BaseService{ public m: Models; …