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

Error when implementing havingRaw() with max()

I'm trying to translate this SQL query to knex: select "events".*, "events"."id", "events"."version", "events"."reviewed_at", "events"."source_id" from "events" inner join "events" as "events2" on "events".source_id =…
carotorrehdz
  • 245
  • 1
  • 8
0
votes
1 answer

Converting JSON format to relational data in PostgreSQL?

I'm building a time-tracker app where users can log how many hours per day they are working. Basically, it's a grid with a unique input field for each day, something like this: https://jsfiddle.net/L5u1fc0a/130/ So, the data structure for each row…
erikvm
  • 858
  • 10
  • 30
0
votes
1 answer

How do I get rapid SQL inserts with MAX()+1 to always increment between each call?

I have an REST-ish endpoint that creates a day object and sets its order property to whatever the maximum order is +1. I'm having an issue where calling that endpoint in rapid succession results in some of the days having the same order. How do I…
n a
  • 301
  • 2
  • 10
0
votes
1 answer

Using Postgres's generate_series Function with ObjectionJS/KnexJS

I am trying to do advanced analytic queries to drive a web application. I am using Hapi, Objection, Knex, and Postgres with TimescaleDB. It all is working well for typical relational queries. However, I cannot figure out how to perform this…
technogeek1995
  • 3,185
  • 2
  • 31
  • 52
0
votes
0 answers

Promise chain not aborting on return after exception catch

I'm using Express to build a REST API with Objection.js ORM. One of my controller's method has a chain of Promises: register(req, res) { // ... indicative.validateAll(req.body.data, rules) .then( () => { const data = { …
0
votes
1 answer

javascript async problem with objection.js

OK, I am using Objection.js to handle some database stuffs with node.js I know that the error I am getting is common to someone learning how to use async functions, but I just cant seem to get this to work right. My async function is returning…
skrite
  • 317
  • 4
  • 18
0
votes
1 answer

async $formatDatabaseJson in Objection.js

I need to await a function in my $formatDatabaseJson. Im checking the docs (https://vincit.github.io/objection.js/#_s_formatdatabasejson) and seems not possible. Is there any way to do it manually? class Person extends Model { async…
Rashomon
  • 5,962
  • 4
  • 29
  • 67
0
votes
1 answer

ID column error during insert

I am getting errors when trying to insert new records into my database (Postgres) using Node.js with Objection.js as the ORM/db handler. I have followed the tutorial, but I cannot find a mention of this in their current docs. Here are my…
ps2goat
  • 8,067
  • 1
  • 35
  • 68
0
votes
1 answer

In objection js i am trying to set a role and receiveng error

here is my code (node:10188) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: insert into user (email, name, password, role, username) values ('exam@mail.ru', 'chack', 'password', 'user', 'kkkp') -…
0
votes
1 answer

$relatedQuery method doesn't return modal entity

I use PostgreSQL and objection.js for ORM. When I use $relatedQuery method, I get QueryBuilder object instead of Model entities. Here is example project and how to use $relatedQuery method. podcastListener.js const { Model, snakeCaseMappers } =…
Matt
  • 8,195
  • 31
  • 115
  • 225
0
votes
1 answer

do I need a new field for counting scores form another table?

I have a Users Table it has id, username, A, and B as my columns. I also have a Votes Table. a user can vote on A, and B. it has id, user_id foreign key, A_id foreign key, and B_id foreign key. I would like to do a query to Users and have the…
Amy Coin
  • 141
  • 1
  • 1
  • 4
0
votes
1 answer

Using Knex and Objection with GraphQL, how to return the count()?

I have a GraphQL server using Node, Knew and Objection. I have the following in my model: totalCount = async () => { const totalCount = await Request .query() .count(); console.log(totalCount); return totalCount; } The…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
-1
votes
0 answers

How to make the following use-case of Knex.js queries database agnostic

I have the following table: // names of the attributes are changed. // But I need a column to store a list of JSON. return knex.schema .createTable("table_name", table => { table.string("id", 40).notNullable(); table.string("name",…
Kumar Arnav
  • 301
  • 2
  • 13
-1
votes
1 answer

In objection how to filter based on "child" element?

Well in objection you can use withGraphFetched to help build an object structured view of a database. Considering a mandate that belongs to a customer, one would (after defining the model correctly) call it like: const mandates = await MandateModel …
paul23
  • 8,799
  • 12
  • 66
  • 149
1 2 3
18
19