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

How do I check if an array column contains a value in Postgres using Objection JS?

I tried using an array of integers, then an array of strings. However, I keep getting the same error: ERROR: operator does not exist: jsonb ?| integer[] My query looks like this: Bet.query() .select( 'id', 'status' ) …
LondonGuy
  • 10,778
  • 11
  • 79
  • 151
0
votes
0 answers

Objection-find No way to search in postgres arrays ( array column not json or jsonb)

I have one region array in column. When i am trying to findquery and applying query into it. Searching inside array column doesn't work when array have more than one entry. Case 1. array column(i.e. region) is [NA-US] and search query is…
Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
0
votes
1 answer

Objection.js alias to relationMapping

I have a working relation mapping with Objection / Knex / Sql server that is causing a problem when the results are paged. components: { relation: BaseModel.HasManyRelation, modelClass: Component, join: { from:…
0
votes
1 answer

How to select two properties from array of objects as array on knex?

I use objextion.js and knex on project. And I wanna select two properties from relation and and nest them in an array. That relation contains array of object with properties lat and lng, I need receive array of arrays with lat and lng [[lat, lng]].…
Drop
  • 1,394
  • 3
  • 15
  • 25
0
votes
0 answers

Seed with relation in knex

Hi guys I'm trying to seed my data with knex and knex cli I have 2 models: User & User Profile User CREATE TABLE users( id SERIAL PRIMARY KEY NOT NULL, name TEXT, screenname TEXT, created_at TIMESTAMPTZ NOT NULL…
Loki
  • 1,064
  • 2
  • 26
  • 55
0
votes
0 answers

WebStorm marks $query() of Objection.js as unresolved

I'm currently using Objection.js with WebStorm to build a Rest API. But, when I want to make a relationQuery of Objection.js, my WebStorm shows me one out of two times that $query() is unresolved. I have installed the Objection.js TypeScript, but it…
0
votes
1 answer

How to define and use a related Model in Objection.js

Using the following code (which uses ES6's "type":"module" in package.json), I can't seem to access the related Model Group: import db from "../connection.js"; import objection from "objection"; const { Model } = objection; Model.knex(db); class…
Raj
  • 1,555
  • 18
  • 32
0
votes
2 answers

How to correctly add and use Objection.js

I am trying to add Objection.js to my project (using ES6 "type": "module"), and getting this error which points to ./models/user.js: import { Model } from "objection"; ^^^^^ SyntaxError: The requested module 'objection' does not provide an…
Raj
  • 1,555
  • 18
  • 32
0
votes
0 answers

How to Find matching string in array in knex

Knex has the ability to find records by matching string in the target column. just like https://github.com/knex/knex/issues/2009. But i have nested schema like User: { id: 1, email: 'test_user@test.com' active: true, profiles: [ …
Ahmad Raza
  • 21
  • 7
0
votes
2 answers

Using sql where in operator with numbers

I was trying to fetch distinct users with similar interests and stumbled upon this problem. Basically I wanted to do something like: SELECT DISTINCT(uid) FROM interest WHERE (interest , score) IN (('family' , > 0.32), ('paris' , > 0.77)); I get…
Brook MG
  • 601
  • 10
  • 20
0
votes
2 answers

in SQL Trying to return all users who are members of the same groups as a specific user

This query is getting me a bit turned around. In a Postgresql (Express/Knex/Objection) database, I have three tables, Users, Groups and an associative table Memberships s.t. Users have_many Groups through Memberships. For a specific User's Groups, I…
user2799827
  • 1,077
  • 3
  • 18
  • 54
0
votes
1 answer

how to make $beforeValidate wait till async operation has completed

I want the $beforeValidate to wait for the async operation to complete as it updates the object to make it pass validation. But currently the $beforeValidate completes and rejects the record as it is not waiting for the async operation to…
user566245
  • 4,011
  • 1
  • 30
  • 36
0
votes
2 answers

Transaction in feathersjs using Objection ORM

feathers-objection - A service adapter for Objection.js - A minimal SQL ORM built on top of Knex. Transactions are atomic and isolated units of work in relational databases. We want to create and use transaction in feathersjs application generated…
0
votes
1 answer

Nodejs Objection.js conditional patch

I need to run a patch (or an update) in Objection.js, based on a condition. I have this code: if (leavenMachine.ping == true){ MachinesInit.query() .patch({status: 'OK', online:"yes"}) .where('machine', 'leaven…
Dav
  • 33
  • 5
0
votes
1 answer

How can I reduce code repetition in these before/after actions?

I'm trying to do integration testing against a real database and I'm new to jest and knex.. Here's what I have so far: describe('FooRepository', () => { let dbName; let conn; beforeAll(async () => { conn = getConnection(); dbName =…
user1354934
  • 8,139
  • 15
  • 50
  • 80