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

How to call custom function from postgresql use objection js knex js

I build api use hapi js and postgresql with ORM objection js (knexjs). I create own function in postgresql with two argument. When I try to call my function use objection .raw it's doesn't work. This one of the codes that I have tried and it doesn't…
Sukma Saputra
  • 1,539
  • 17
  • 32
2
votes
1 answer

Is it possible to get total counts in sub-sub queries in Objection js?

For example I have User which has Posts ( HasMany) and Posts which has Likes which belongs to User and Post. So, I tying to get total count of likes in each post when try to get all users with posts related to each user. const users =…
Anton Kalik
  • 333
  • 2
  • 13
2
votes
1 answer

How to track model changes nodejs/postgresql

I have a app perpetuating data in Postgresql/Express/Knex/Objection. I am looking for. way t track changes in my models, so that I can manage and revert versions similar to paper_trail in rails or this port for sequelize:…
user2799827
  • 1,077
  • 3
  • 18
  • 54
2
votes
1 answer

KnexJs - Sqlite3 On Delete cascade doesn't work

i'm trying to make onDelete('CASCADE') work on knex js but it doesn't seem to work at all. Here's my knexjs migrations : const tableName = 'users' exports.up = function(knex) { return knex.schema.createTable(tableName, table => { …
user7616817
  • 357
  • 4
  • 18
2
votes
2 answers

SQLite: Foreign Key "ON DELETE SET NULL" action not getting triggered

Why is ON DELETE SET NULL failing when deleting a row via the application code, but it behaves correctly when manually executing an SQL statement? I have a todo table and a category table. The todo table has a category_id foreign key that references…
J. Munson
  • 2,275
  • 2
  • 17
  • 22
2
votes
1 answer

How to insert default values to foreign object with relation using Postgresql, Knex.js and Objection.js with HasOneRelation?

I'm setting up simple API using Postgresql, Knex.js and Objection.js. I created User model with "location" property. This "location" property is another table. How I have to insert that user to database with defaults 'city' and 'country' in…
Anton Kalik
  • 333
  • 2
  • 13
2
votes
0 answers

running order by and group by in objection js

I want to add group by and order by in the same query, I have checked so many example where we can do this in mysql but how that will be done in objection. Currently I am doing this with foreach loop which is not good for large result. logs = await…
HKumar
  • 1,535
  • 3
  • 13
  • 28
2
votes
1 answer

How do you insert a reference to a model without creating it?

I have model A that can have one or more rows of model B affiliated with it. The relation only has to go one way. I ran: result = await A.query() .where('id', 123) // 123 is an already existing model A .insertGraph([ { B: [{id: 456}]…
bzupnick
  • 2,646
  • 4
  • 25
  • 34
2
votes
1 answer

How to create a two foreign key relation in Objection.js

Is there any way to create a two foreign key relation in Objection.js. Something like following: static get relationMappings() { return { childs: { relation: Model.HasManyRelation, modelClass: childModel, join: { …
Rashomon
  • 5,962
  • 4
  • 29
  • 67
2
votes
1 answer

Objection.js how to filter a model based on relationship

So I've been trying to find a way to do the following sql in objection.js SELECT u.user_id, u.profile_photo_name, u.first_name, u.last_name, COUNT(*) AS count FROM users AS u INNER JOIN post_users AS pu ON (u.user_id =…
Avedis Kiyici
  • 67
  • 1
  • 7
2
votes
3 answers

Are Objection.js WHERE IN queries slowing my Node.js application down?

Ok, so this is basically a yes/no answer. I have a node application running on Heroku with a postgres plan. I use Objection.js as ORM. I'm facing 300+ms response times on most of the endpoints, and I have a theory about why this is. I would like to…
Gersom
  • 651
  • 3
  • 19
2
votes
1 answer

Why might the same SQL query return different results in SQL Developer and in code?

I have a query in my application that is supposed to return all the surveys due today or earlier for which notifications have not been sent. The query looks like this: select "surveys".* from "surveys" where "reminder_count" = 0 and …
JaffParker
  • 668
  • 8
  • 21
2
votes
1 answer

query within a json array of strings column in postgres with objection.js or knex.js

I have a column in my table (Reviews) called reviewers. It was defined via knex: table.json('reviewers').notNullable(); It's just an array of IDs: ['id1', 'id2', 'idn' ] I would like to query the table based and return all rows that have an…
PGT
  • 1,468
  • 20
  • 34
2
votes
2 answers

ORM - rejection error: column "id" does not exist

I use PostgreSQL and objection.js in Node.js back-end for ORM. I have only two simple tables with one-to-one relationship. I am not able to insert new record into a table. I have a simple database schema with employee and salary table: CREATE TABLE…
Matt
  • 8,195
  • 31
  • 115
  • 225
2
votes
1 answer

Chained API's and Jest expects

I currently have an express app that does a bunch of logic on a controller. One of the steps is to insert a record to the DB ( It uses ObjectionJS models ). let user = await this.User.query(trx).insert(userData); In an attempt to mock out the…
Gayan Hewa
  • 2,277
  • 4
  • 22
  • 41