bookshelf.js

Strongly-typed database access with Node.JS and TypeScript

半腔热情 提交于 2021-02-07 02:48:32
问题 When we use C# , we can access our database in a strongly-typed manner using Code-First approach: public class Blog { public int BlogId { get; set; } public string Name { get; set; } public virtual List<Post> Posts { get; set; } } ... public class Database : DbContext { public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; } } var db = new Database() var blog = new Blog { Name = "My new blog", BlogId = 1 }; db.Blogs.Add(blog); db.SaveChanges(); // save object to database

Bookshelf.js - Nested relations while querying with andWhere()

99封情书 提交于 2021-01-29 11:11:35
问题 I'm using the strapi framework based on node.js and while creating a query-builder, I'm facing an issue with the andWhere() clause. I am implementing search functionality where a user can input some text in a form input field, which gets passed in, and database table fields are queried based on that text . In the code below, you can see that I query for two things: Search the product model wherever the text is present in the name field. And always check and search the product model wherever

Knex silently converts Postgres timestamps with timezone and returns incorrect time

纵然是瞬间 提交于 2020-12-08 06:58:09
问题 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 WHERE task_id = 1; this query returns "2018-06-27 18:45:00". Similarly when I run SELECT trigger_time AT TIME ZONE 'America/Glace_Bay' FROM tasks WHERE task_id = 1; I get 2018-06-27 15:45:00 Using knex.raw("SELECT trigger_time AT TIME ZONE 'America

Having “Timeout acquiring a connection” after upgrading Knex

一曲冷凌霜 提交于 2020-12-02 12:11:45
问题 In my company, our application runs on NodeJS over multiple EC2 instances and one RDS database. Our application needed some upgrades as some dependencies were already quite old, and one of the upgrades we did that called our attention was updating our database libraries: mysql (from 2.16.0 to 2.17.0), knex (from 0.12.2 to 0.19.1) and bookshelf (0.10.2 to 0.15.1). After checking the changelog, no code changes were required, so we quickly managed to upload it to our staging server. Suddenly our

Having “Timeout acquiring a connection” after upgrading Knex

萝らか妹 提交于 2020-12-02 12:07:40
问题 In my company, our application runs on NodeJS over multiple EC2 instances and one RDS database. Our application needed some upgrades as some dependencies were already quite old, and one of the upgrades we did that called our attention was updating our database libraries: mysql (from 2.16.0 to 2.17.0), knex (from 0.12.2 to 0.19.1) and bookshelf (0.10.2 to 0.15.1). After checking the changelog, no code changes were required, so we quickly managed to upload it to our staging server. Suddenly our

Error: Undefined binding(s) detected when compiling SELECT from Bookshelf.js save()

允我心安 提交于 2020-05-17 06:42:15
问题 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 operation. My model is this: Promotion = bookshelf.model('Promotion', { tableName: 'promotions' }) And the action that triggered the error is this: Promotion.forge({image:"image","featured":false,"price":"2.33","name":"name","description":"description"}).save(null, { method:'insert' }) The insertion

Updating a Morph-One Associated model and receiving “Unhandled rejection Error”

℡╲_俬逩灬. 提交于 2020-04-30 06:38:06
问题 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 same error message. Alternative Implementation let title = await book.related('title'); title.set({value: inputs.title}); title.save().then( (model) => {} ); Error message Unhandled rejection Error: Undefined binding(s) detected when compiling SELECT. Undefined column(s): [titles.titleable_id] query:

How to resolve promises when using app with REPL

拥有回忆 提交于 2020-01-11 05:08:08
问题 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 following code (fetch() queries the database and returns a promise) gives only this output Promise {_bitField: 4325376, _fulfillmentHandler0: undefined, _rejectionHandler0: undefined …} Transaction.where('reference', '1').fetch().then((res) => return

Bookshelf.js save one to many relation

老子叫甜甜 提交于 2020-01-06 14:45:40
问题 I am trying to save a one to many relation My models are Foo foo = bookshelf.Model.extend({ tableName: 'foo', bar: function () { return this.hasMany('bar', 'barId'); } Bar bar = bookshelf.Model.extend({ tableName: 'bar', foo: function () { return this.belongsTo('foo', 'barId'); } What I am trying to do var Foo = { id: 7 } new Bar({ blah: blah.val }) .foo() .attach(foo); The error I am getting (intermediate value).foo().attach is not a function Any help will be appreciated. 回答1: I don't think

How to return value from a Promise

早过忘川 提交于 2019-12-24 04:50:23
问题 I have been struggling with Promises and would like to know how things work with Promises. In my project, I am using Bookshelfjs ORM for fetching the data from Postgres. Here is the code that I am working on right now. I get an array of device ids in this request and each device is running in one of the two modes. router.post('/devices', function (req, res, next) { var currentData = []; var deviceIds = req.body.devices; loadash.forEach(deviceIds, function (device) { var deviceid = device