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
3
votes
1 answer

Require returns an empty object when using jest and supertest to test koa2

I am learning test, for now I using jest and supertest to test koa2 server, and I test features is login, but I always receive false when test login feature, I find the require returns an empty object in my controllers/users.js after long time…
Roy
  • 731
  • 3
  • 10
  • 24
3
votes
1 answer

objectionjs column reference is ambiguous

I try to make a query with a join relation with objection.js. Here is the datastructure: Here is the query: Titres.query() .skipUndefined() .whereIn('typeId', typeIds) .whereIn('domaineId', domaineIds) …
François Romain
  • 13,617
  • 17
  • 89
  • 123
3
votes
0 answers

Insert an array of UUIDs using Objection.js

I am attempting to insert a new row into a table with a column defined as an array or UUIDs: alter table medias add column "order" uuid[]; I am using Objection.js ORM and attempting to execute the following query: const order = [ …
Robert Rossmann
  • 11,931
  • 4
  • 42
  • 73
3
votes
1 answer

Objection.js - Query builder not a function using insert method

I'm new to nodejs Development and I currently practicing CRUD operations on my postgresql. I used Objection.js for the ORM and Model making. I follow some codes from the docs and edit necessary lines but I don't actually get it to success instead…
Ricardo Raz
  • 493
  • 1
  • 10
  • 23
3
votes
1 answer

Can I add non-persistent fields to a model?

Is there a recommended practice for adding non-persistent attributes to an Objection model object such that it that won't overwrite predefined attributes?
Tom Nurkkala
  • 622
  • 1
  • 6
  • 15
3
votes
1 answer

Objection js model fields data trim before saving the record in postgres in nodejs

I am using objection.js ORM for my node.js project. Everything is good, I want to trim all the fields before actually saving the data in the PostGres database table. I have also used mongoose in some of the projects, it allows to define {trim: true}…
Dinesh Rawat
  • 970
  • 10
  • 32
3
votes
1 answer

Self-referencing many-to-many relation with Objection.js

I have Currency and ExchangeRate database tables like below: CREATE TABLE Currency (id INT, code VARCHAR(3), name TEXT); CREATE TABLE ExchangeRate (baseCurrencyId INT, counterCurrencyId INT, rate FLOAT); INSERT INTO Currency (id, code, name)…
conny
  • 9,973
  • 6
  • 38
  • 47
2
votes
1 answer

How to fetch single row using withGraphJoined?

There are two tables users and activities. I am able to join these using withGraphJoined. The response json is like this, [ { user: 'first', activity: [{ type: 'act1' }, { type: 'act2' }], }, { user: 'second', activity: [{…
2
votes
1 answer

ObjectionJs fetch entity with many to many relationship

I'm using knex-objection. I have a simple example of 3 tables: user, authority_user, authority where "user" and "authority" are joined together witha many to many relationship. Relationship code: static get relationMappings() { return { …
user7616817
  • 357
  • 4
  • 18
2
votes
1 answer

Node use ObjectionJS and Knex, 1 to many, return first related row from the many table

To make things simple, I have two tables for a chatbox: Conversation and Message Conversation id status 1 open 2 open Message idConversation text date 1 'ffff' (random date) 1 'asdf' (random date) 1 '3123123123' (random…
qaakmnd
  • 339
  • 2
  • 4
  • 18
2
votes
1 answer

How to insert array of objects into Postgres jsonb column using javascript, knex, objection?

I have been trying to insert and array of objects into this jsonb column, but I guess the following error message: insert into ... (...) values (...) on conflict ("source_id", "source", "type") do update set ... = ... returning "..." - invalid input…
ofundefined
  • 2,692
  • 2
  • 18
  • 35
2
votes
1 answer

Aggregation function in Objection.js

How I can write query with Objection.js? SELECT AVG(field), COUNT(*) FROM tab Please help me
2
votes
1 answer

How to handling error on objectionjs with nestjs exception filters?

I used Objection.js as ORM for my Nest.js app. I tried to implement global error handling for both Http exception and Objection Error (ORM / Database Error). Suppose I make a mistake inserting a same unique value, it would throw…
mandaputtra
  • 922
  • 3
  • 18
  • 36
2
votes
2 answers

ObjectionJS model used in knex migration reports "relation does not exist" when running batch of migrations

When running batch of knex migrations, either through the API or via the CLI, the migrations might fail if they use ObjectionJS models. This can happen particularly in the case where the knexfile itself is resolved as an asynchronous…
Marceli Wac
  • 375
  • 3
  • 13
2
votes
1 answer

Can't relate model with an extra property in objection due to typescript error

I'm trying to relate two models with an extra property of "url": if (typeof session.id === "number") { const sessionUser = await Session.relatedQuery("users") .for(session.id) .relate({ id: 12345, // error here url: "test", …
Andy
  • 364
  • 1
  • 8
  • 21
1 2
3
18 19