Questions tagged [bookshelf.js]
Bookshelf is a promise based ORM for Node.js, built on Knex query builder. It extends the Model & Collection foundations of Backbone.js, providing transaction support, eager/nested-eager relation loading, polymorphic associations, and support for one-to-one, one-to-many, and many-to-many relations.
bookshelf.js
593
questions
0
votes
0
answers
24
views
Using Bookshelf Models and knex, How can I fetch data from first table withRelated to second table with a condition of data related to third table
I am using bookshelf with knex query builder. I have 3 sql tables: forms, users, exams and their related models: formsModel,usersModel, examsModel. I am successfully fetching data from forms table ...
0
votes
1
answer
73
views
can't create view in bookshelf knex. getting migration error as: schema.createView is not a function
I wish to create view that collectively shows data from multiple tables in my mysql database. Project is nodeJS based.
npm versions using "bookshelf": "^0.14.2" & "knex&...
1
vote
0
answers
196
views
Strapi v4 Bookshelf query builder similar to v3
So we’ve been using strapi v3 for quite many years and are now migrating our app to v4.
In v3 we could use bookshelf query builder to build our apis as per the v3 docs here: https://docs-v3.strapi.io/...
0
votes
0
answers
166
views
Is there an actively maintained replacement for Bookshelf.js?
The most recent Bookshelf.js version is over two years old.
What is the recommended replacement?
2
votes
0
answers
209
views
How to add nolock condition in the bookshelf or knex nodejs before fetch
I am using a bookshelf and wanted to add the default value as WITH(NO LOCK)
Update: is it possible to achieve this using knex as I have that library installed in my code?
User.forge()
....
0
votes
1
answer
128
views
How to update primary key and it's references to other tables at the same time
I have a main table with primary key as 'main_id'.
This 'main_id' is being used a foreign key in two tables : 'sub_table1', 'sub_table2'
I have a requirement where I need to change the 'main_id' and ...
0
votes
1
answer
127
views
How can I hide certain attribute from response with Bookshelf?
I am building a simple REST API. When registering a new user, my API returns:
{
"status": "success",
"data": {
"email": "[email protected]&...
0
votes
1
answer
659
views
Filtering items by relation using knex query
I'm trying to filter items by relation using a knex query. I'm almost there (I think) but struggling a little and could use some help as this is new to me.
I have a list of users who are following ...
0
votes
2
answers
278
views
How to us CASE WHEN aggregation with bookshelf
I'm working with PostgreSQL and bookshelf and trying to run a simple SQL query in order to get multiple counts in a single query.
This query look like:
SELECT SUM(CASE WHEN date_last_check > (now() ...
1
vote
0
answers
58
views
How to join two tables, apply where on both tables , apply pagination with bookshelf node js
I have two tables mentioned below:
Reports
Id |status
1 |Active
Reports_details
Id| Cntry| State | City
1 | IN | UP | Delhi
1 | US | Texas | Salt lake
Now my requirement is
Select distinct r....
1
vote
0
answers
367
views
Strapi: trouble populating multi-valued attribute for nested relation
I have a collection called dish-category which contains many dishes, and a dish collection that contains many dish-options (another collection).
the list of dishes from each dish-category is ...
1
vote
1
answer
2k
views
How to deep fetch In Strapi cms compnents?
I have the following user API from Strapi cms to which I want to deep fetch address component(repeatable component).
So, what I want to fetch is the user whose address is 63 Southlands Road... I ...
0
votes
1
answer
1k
views
Strapi filter by many to many relation
I have two tables in postgresql in strapi: goods and labels
Goods:
id | title
---------
1 | some name
2 | some name 2
3 | some name 4
…………………
Labels
id | title
------------
1 | some label 1
2 | some ...
0
votes
1
answer
469
views
Convert Raw SQL to Bookshelf/Knex
I'm trying to convert a simple raw SQL to use Bookshelf/Knex in JavaScript:
Original SQL: select * from o where o.id = 1 or o.id = 2 and (o.is_a = true or o.is_b = true) and o.status = 'good';
I've ...
1
vote
1
answer
132
views
MySQL degrading performance over many (~10-100K) short select queries
I'm currently building an app on Node with MySQL database where on the initial run I have to calculate ~250M items. Each calculation takes 3 SELECT statements.
I'm testing with a couple of thousands ...
5
votes
1
answer
6k
views
How to use a uuid as default ID with postgres?
Currently in the process of migrating to to postgres after the announcement about dropping mongodb, Just noticed that the ID's are just numbers and auto-incremented.
I have tried:
Setting the default ...
0
votes
0
answers
130
views
TypeError: ModelName.forge(...).destroy is not a function
I'm working on a API using node, where ModelName means the model built using bookshelf.js like this:
const bookshelf = require('./bookshelf')
const Intake = require('./intake')
const ModelName = ...
1
vote
0
answers
166
views
How to update data fields on the server-side?
How I write a script and update a collection field from my server?
I need to update a field of 100 users.
I was wondering if I can change them from the server, instead of sending update mutations over ...
1
vote
1
answer
187
views
How do I select specific column data to be displayed in my bookshelf model belongsTo relationship in Nodejs?
This is a contrived example of what I would like to do:
Suppose I have a database of teams and players:
team:
->id
->color
->rank
->division
player:
->id
->team_id
->number
-&...
1
vote
1
answer
264
views
Bookshelf.js withRelated TypeScript error
So, in my app I have categories and articles that are interrelated. At first I retrieve all of categories and there are articles inside each of them. The problem is I wanna filter both categories and ...
2
votes
1
answer
3k
views
Strapi update many-to-many relationships in strapi?
I have two collection types in Strapi, created with many-to-many relation.
What is the proper way to write a custom query to update only the relation?
**user**
id name
1 user1
**store**
id ...
1
vote
2
answers
2k
views
React: Converting DateTime from Database within my Axios Call
I'm trying to figure out how to convert my database's dates with LUXON within the axios call, is this possible or should I change it within the database data itself?
Here's my code below:
const ...
0
votes
1
answer
83
views
Only 1 orWhere in Bookshelf query?
I have the following Bookshelf method in my controller:
const transaction = await Transaction.query({
where: { status: "paid", id: req.params.transaction_id },
orWhere: { status: &...
0
votes
1
answer
401
views
Bookshelfjs destroy where and where
Is it safe to do this?
await MyModel.where(toSnakeCase(userID), user.id).
where(toSnakeCase(shopId), user.shopId).destroy();
within bookshelf model. I would like to do a delete where ...
1
vote
0
answers
98
views
Bookshelf.js fetchAll() performance
I have +20k records in my MySQL table that uses InnoDB engine and utf8_general comparison.
When I am trying to fetch all the data using Bookshelf.js fetchAll() it takes around 6 seconds.
I tried using ...
0
votes
1
answer
106
views
How to join/populate 3 tables with Bookshelf in Node.js
[This is different from already asked question]
I have 3 tables book, chapter, paragraph.
Book related to chapter.(one to many)
Chapter related to Paragraph(one to many)
How can I query Book and get ...
0
votes
0
answers
73
views
How to include deleted items in query BookshelfJS?
How to include deleted items in query BookshelfJS? I tried this query
User.forge().where('deleted_at', "IS NOT", null).fetchAll();
In the debugging output
select * from users where `...
0
votes
0
answers
17
views
Bookshelf.js return promise pending on fetchAll [duplicate]
i am new at JS and Node. I am trying to make a task list in Expressjs. I have a bookshlef.js ODM. I traing to get all tasks from DB in function getAllTasks :
module.exports.getAllTasks = async ...
0
votes
1
answer
421
views
How do I get data from currency exchange rates API and save into MSSql database with Nodejs? [closed]
I want to fetch data from https://openexchangerates.org/ API once I get the data from API I want to save API data into MSSql database and want to schedule at 10am
Anyone can provide similar example I ...
1
vote
1
answer
593
views
Bookshelf andWhere / orWhere syntax problem
await bookshelf
.model('User')
.where({ org_id: this.get('id'), isAdministrator: 1 })
.fetchAll()
.then...
This works and selects those records with a certain org_id and for which ...
2
votes
1
answer
391
views
Bookshelf.js relation with foreign key from a property in json
I have 2 models
Book: id, name, data (json)
Author: id, name
I want to extend Book model with method author which return the author when query withRelated. This could be easy to achieve with below ...
1
vote
1
answer
751
views
Extending bookshelf model with typescript causes error
I have instantiated bookshelf like this in a configuration file:
// irrelevant code omitted
const knex = Knex(knexfile[env]);
const bookshelf = Bookshelf(knex as any);
const { Model } = bookshelf;
...
0
votes
1
answer
356
views
Successful query response won't display in Postman..?
I am working on a GET request, and I am having issues with getting my response to appear when using Postman. It prints to the console appropriately, but I would like to get it working in Postman if ...
1
vote
0
answers
320
views
Scheduling localhost serverless cron: The model could not be resolved in registry
I'm hosting an ExpressJS/NodeJS API on AWS Lambda with Serverless framework. The API uses Knex.js and Bookshelf.js ORM.
I want to test scheduling a cron job locally. I'm using serverless-offline-...
2
votes
1
answer
274
views
Bookshelf.js : Avoid fetch call after call to save (update)
We are using bookshelf.js with MySQL.
We have a Table: Contact(id, name, email_Id, updated_Contact_At)
bookshelf Query :
new Contact({id: 1}).save(
{name: 'Jhon Snow', email_Id: 'jhonsnow42@...
0
votes
1
answer
250
views
How can I query in Bookshelf/Knex on a BelongsToMany join table?
I am running Bookshelf over MySQL in a Node application.
I have a model called Document and another called Tag, which are joined through a belongsToMany relationship via a table called "...
0
votes
2
answers
440
views
Bookshelf - get the id when a new record is created
I'm using bookshelf with mysql for my project and can't figure out how I can get the id when I'm creating a new record. Instead it just returns undefined.
// model.js
const User = bookshelf.model('...
0
votes
1
answer
1k
views
How to get only one component from dymamiczone strapi bookshelf
I have this dynamiczone field in the model and i need this field for some endpoints so i made this "autoPopulate": false now I need to fetch only one component for e.g "extra-options.file-upload" but ...
0
votes
1
answer
227
views
bookshelf.js retrieve model name & assign it to instance via virtuals-plugin #beginner
I feel like this is a very stupid question, but as much as I try, I don't get any closer to solving it on my own;
So, here we go:
I install & setup the virtual plugin:
bookshelf.plugin('...
0
votes
1
answer
1k
views
How to select columns from a relation
so I'm using Strapi and Bookshelf. The .query() is a normal bookshelf query.
const result = await strapi.query('friendship').model
.query({
where: { user1: 1 },
orWhere: { user2: ...
0
votes
2
answers
184
views
Updating a Morph-One Associated model and receiving "Unhandled rejection Error"
Code
Preferred way
this.related('title').save({value: input});
But as this line is cut and pasted from a middle of some abstract class, below is a more decoupled way of directly reproducing the ...
2
votes
0
answers
2k
views
include all includes in recursive relationship - strapi
I have a collection type component which includes a set of components. In a tree structure, They can have multiple components too. This include-depth can be any number.
component : {
components []
...
0
votes
1
answer
286
views
Inserting data in postgres with bookshelf ORM nodejs, getting error as relation does not exist
Inserting records, with bookshelf..
But getting bad luck on inserting, getting err as give below:
let {mobile, email, name, active=1} = req.body
let insert = {
'mobile_number': mobile,
'...
0
votes
1
answer
101
views
Bookshelf JS Messing With Tablename
Introduction
I'm trying to make a simple query on a table in mssql 2019 using the bookshelf.js and knex.js libraries. The table is part of a schema.
Issue Description
I get a sql error in my ...
0
votes
1
answer
902
views
How to hard delete by bookshelf when soft delete enable
Suppose, I want to delete temporarily so I can use soft delete by bookshelf, but in that case when I need to delete the permanently row of the table. So, How I can do that when soft delete is enabled ...
1
vote
1
answer
138
views
How to combine and with or in bookshelfjs query builder?
I'm having problems with figuring out how to add multiple "and" queries that contain 'or' queries inside them
The result i want in the end is something like this:
select * from model where ...
0
votes
1
answer
480
views
Heroku fails in deploying node.js with bcrypt
after adding bookshelf-secure-password to my server heroku has been failing in deploying my server it keeps saying it can't install bcrypt.
NPM_CONFIG_DISTURL=https://nodejs.org/download/release/
...
0
votes
2
answers
419
views
How to check if email exist with bookshelf and mysql
I have been trying to check if email exist with bookshelfjs, but I always get empty response each time. If I try other fields it works perfectly.
( I prefer if this could work, is there something I ...
0
votes
0
answers
123
views
Bookshelf- how to order by relation
` new RevisionModel()
.query('where', 'bbid', '=', req.params.bbid)
.fetchPage({
limit: size,
offset: from,
withRelated: ['revision']
});`
I want to sort the ...
0
votes
1
answer
3k
views
Error: Undefined binding(s) detected when compiling SELECT from Bookshelf.js save()
While testing a Bookshelf model insert using the oracledb client (versions bellow), I'm having an strange error. I've tested same code with mysql, pg and sqlite3 clients with no problem in this ...