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 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.

It is designed to work well with PostgreSQL, MySQL, and SQLite3.

Bookshelf aims to provide a simple library for common tasks when querying relational databases in javascript, and forming relations between these objects, using ideas from DataMapper and Active Record. At ~1000 lines of well documented code, Bookshelf is simple to read, understand, and extend. It doesn't force you to use any specific validation scheme, and provides flexible and efficient relation/nested-relation loading, and first class transaction support.

Bookshelf extends the excellent foundation provided by Backbone.js Models and Collections, using similar patterns, naming conventions, and philosophies to build a lightweight, easy to navigate ORM. If you know how to use Backbone, you probably already know how to use Bookshelf.

Source:http://bookshelfjs.org/

592 questions
24
votes
2 answers

Unit testing with Bookshelf.js and knex.js

I'm relatively new to Node and am working on a project using knex and bookshelf. I'm having a little bit of trouble unit testing my code and I'm not sure what I'm doing wrong. Basically I have a model (called VorcuProduct) that looks like this: var…
Marcos Chicote
  • 315
  • 2
  • 11
23
votes
4 answers

Get count result with knex.js / bookshelf.js

I'm trying to perform a simple count with knex (since it seems to not be supported by bookshelf yet). The following code is working: bookshelf.knex('hosts').count('id').then(function(total) { res.send({ meta: { total:…
Pedro
  • 3,511
  • 2
  • 26
  • 31
22
votes
6 answers

How to loop over rows after .fetchAll Bookshelf js + knex js?

I have a MySQL Database which I need to query from node.js I am using bookshelf and knex for this. I want to get the contents of a table - I have defined a table in my model.js file. I am attempting the query like this: //select * from…
A.D
  • 1,480
  • 2
  • 18
  • 33
21
votes
3 answers

How to ensure the Knex connection in nodejs

I am using NodeJS, Express, and MySQL for my project and want to use Bookshelf ORM with it. Bookshelf uses Knex for querying, modeling, and suggests to setup the DB connection through Knex(http://bookshelfjs.org/#installation). I am having trouble…
Raghav Garg
  • 3,601
  • 2
  • 23
  • 32
19
votes
3 answers

knex.js - debug only SQL

Is there any way to display only SQL queries on console when debugging mode is on? I want to reduce the amount of informations which is displayed. Thanks for the help ;)
rizidoro
  • 13,073
  • 18
  • 59
  • 86
18
votes
4 answers

bookshelf js save() command not updating rows in postgresql db

JS beginner trying to get a PostgreSQL DB talking to express.js through bookshelf.js. github: https://github.com/duskyshelf/bookers-academy/blob/master/booker.js var knex = require('knex')({ client: 'pg', connection:…
David Upsdale
  • 205
  • 1
  • 2
  • 5
15
votes
1 answer

What is the numeric type equivalent in KnexJS (Postgres)?

I am creating a table using Knex.JS, and the table has a column for a currency value. For example, here is the column amount: knex.schema.createTable('payment', function(table) { table.increments(); table.float('amount'); }) Currently, I am…
aashah7
  • 2,075
  • 1
  • 17
  • 24
15
votes
6 answers

How do I specify a single file to be seed only

I am using knex for seeding and I have a folder called development where I have all the seeds files. What I would want is: How to seed single file. The command I am using is: knex seed:run --env=development But this command is to seed all the files…
Lulzim
  • 547
  • 4
  • 9
  • 22
15
votes
1 answer

Bookshelf.js/Knex.js is too "helpful" with UTC DATETIME columns

I have a MySQL table, and this table has a DATETIME column named datetime_utc. It is, as you might expect, a date and time in UTC. In my Bookshelf models, I have defined a virtual getter that converts this into ISO 8601 string format using…
smitelli
  • 6,835
  • 3
  • 31
  • 53
14
votes
2 answers

How do I properly update models with Bookshelf.js?

I'm sure I am missing something but I find the Bookshelf API to be relentlessly confusing for me. Here's what I am trying to do: I have a model called Radio with an application-assigned string primary key named serial and, for the purpose of this…
Jason C
  • 38,729
  • 14
  • 126
  • 182
14
votes
3 answers

Sort Bookshelf.js results with .orderBy()

I am working on a personal project to learn Node.js + express + Bookshelf.js. Where do I build queries? In particular, how do I simply set an 'ORDER BY' or 'WHERE' in the following code? var Accounts =…
user1094128
  • 451
  • 1
  • 6
  • 22
13
votes
2 answers

KNEX Undefined binding(s) detected when compiling SELECT query

var knex = require('knex')(config); var bookshelf = require('bookshelf')(knex); var SKU = bookshelf.Model.extend({ tableName: 'skus', }); SKU.where('id', undefined).fetch().then(function (skus) { if (skus)…
Mrugesh Vaghela
  • 195
  • 1
  • 1
  • 11
13
votes
2 answers

in bluebird / bookshelf.js what does tap function do

What does the bookshelf.js tap function do. I didn't find any entry in documentation return new Library({name: 'Old Books'}) .save(null, {transacting: t}) .tap(function(model) { //code here …
aWebDeveloper
  • 36,687
  • 39
  • 170
  • 242
12
votes
1 answer

Knex silently converts Postgres timestamps with timezone and returns incorrect time

I have a table in my psql database with a "trigger_time" column of type "TIMESTAMP WITH TIME ZONE DEFAULT now()" I data in the row is this 2018-06-27 15:45:00-03. When running from psql console SELECT trigger_time AT TIME ZONE 'UTC' FROM tasks…
Space Bear
  • 755
  • 1
  • 6
  • 18
11
votes
3 answers

How to resolve promises when using app with REPL

I've got a basic Node webserver (Koa.js + a ORM). I like to start it with a REPL meaning I can use my app like a CLI-tool. All my queries return Promises but I don't know how I can resolve them in the REPL. How can I resolve them? For example the…
Hedge
  • 16,142
  • 42
  • 141
  • 246
1
2 3
39 40