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
2 answers

How to prevent a field from showing up

I am using Objectionjs In my Model, I have defined a password field. I want to prevent this field from showing up for all queries - select, inserts, updates etc - that is, after making a query, I don't want this field to be present in the object…
callmekatootie
  • 10,989
  • 15
  • 69
  • 104
2
votes
1 answer

ObjectionJS relationship modelClass is not defined

I'm trying to update a relationship between a user and user_profile. I can update the user, but I keep getting this error when I try to update the user_profile: ERROR: Error: UserProfile.relationMappings.user: modelClass is not defined As far as I…
mtpultz
  • 17,267
  • 22
  • 122
  • 201
2
votes
1 answer

How to query .where() using references instead of literal string values in Objection/Knex

I'm trying to generate this postgres SQL with Knex and Objection: select * from "WorkoutEntry" e where EXISTS (    select *    from "WorkoutCategory" c    INNER JOIN "StandardWorkoutDefinition" d on d."workoutCategoryId" = c.id    where c.id = 2 and…
Freewalker
  • 6,329
  • 4
  • 51
  • 70
2
votes
1 answer

How to add a new object to a table using objection.js and knex.js?

I want to add a new object to a table using Objection.js and knex.js. I wrote this code: const Provider = require('../models/provider); Provider .query() .where('ProviderName', name) .then((data) => { if (data.length === 0) { Provider …
2
votes
2 answers

SQL all rows in child 'categories' and child child 'categories' : recursive?

I'm having trouble writing a query that solves the following problem, which I believe needs some kind of recursiveness: I have a table with houses, each of them having a specific house_type, p.e. house, bungalow, etc. The house_types inherit from…
Mats de Swart
  • 538
  • 1
  • 4
  • 10
1
vote
1 answer

Updating json field in objectionjs throws Unknown column 'lng' in 'field list

I have a nestjs app where I am using objectionjs and knex to communicate with my mysql db. The address field is a json like: data = { address: { lat: 12, lng: 20 } } Whenever I run an update using: this.personRepository .query() …
Willower
  • 1,099
  • 8
  • 22
1
vote
1 answer

How to turn class properties into type for array of class properties as strings

How can I turn all class properties (excluding methods, ideally) into a type that represents an array of the class properties as strings? This is what I have (the SomeTableFields type is what I'm trying to figure out). // Objection.js Model export…
nonethewiser
  • 550
  • 1
  • 6
  • 18
1
vote
0 answers

Find in array of objects with arrays using objection.js and postgresql

I need support to solve the following, I am using objection.js with Postgresql 14.5 and node.js, I have a table called articles with a JSON column called properties. the jsonb properties column is structured as follows: { characteristics: [ { …
1
vote
0 answers

Objection.js : How to do an insert with all default values?

I am using Postgresql database. My ORM is objection.js ( with Knex). I am trying to insert a record with all default values like so in raw sql: INSERT INTO public.myTable DEFAULT VALUES; All these default values are defined already in the related…
salouri
  • 760
  • 1
  • 8
  • 19
1
vote
1 answer

Express + Typescript + Objection pass model to super class using generic type not working

class BaseService { public m: Models; constructor(model: Models) { this.m = model; } } class MyService extends BaseService{ constructor() { super(UserModel); //It is require new keyword } } We are…
1
vote
1 answer

Problem with connection acquisition when using knex and serverless-offline

Setup I'm building a serverless application that uses a website frontend. The website sends queries to the API, which connects to the database. The infrastructure is hosted on the AWS, but the problem I have ran into only affected the local…
1
vote
0 answers

one of the identifier columns [id] is null or undefined in Objection.js

I am using Node.js with express, mysql, objection.js, and knex.js for my backend application. I want to refactor my code, especially connecting to database tables. In legacy code I have a folder called models where I created various js files for…
jkalandarov
  • 564
  • 5
  • 15
1
vote
0 answers

In objection.js, how to make `.modifyGraph` return alias or boolean?

I have the following query UserReaction.query().where({ target_id: userId, type, }) .withGraphFetched('[user.[user_data, reactions]]') .modifyGraph('user.reactions', builder => { …
PGT
  • 1,468
  • 20
  • 34
1
vote
2 answers

SQL Distinct / GroupBy

Ok, I’m stuck on an SQL query and tried long enough that it’s time to ask for help :) I'm using Objection.js – but that's not super relevant as I really just can't figure out how to structure the SQL. I have the following example data…
Mike Fogg
  • 559
  • 6
  • 16
1
vote
0 answers

Objectionjs: relation with multiple columns but some column could be null

I have a Model, using Objection JS, with this relation: class Model....{ ... static relationMappings = { ... evs:{ relation: Model.ManyToManyRelation, modelClass: path.join(__dirname, 'evs-model'), join: { from:…
jon_eldiablo
  • 188
  • 2
  • 10