knex.js

Knex with PostgreSQL select query extremely performance degradation on multiple parallel requests

杀马特。学长 韩版系。学妹 提交于 2019-12-23 07:16:09
问题 In brief I'm developing a game(of dream) and my backend stack is Node.js and PostgreSQL(9.6) with Knex. I hold all players data here and I need to request it frequently. One of the requests need to make 10 simple selects that would pull the data and this is where the problem starts: these queries are quite fast(~1ms), if server serves only 1 request at the same time. But if server server many requests in parallel(100-400), queries execution time degradates extremely (can be up to several

how to decode chinese character from mysql with nodejs

孤街醉人 提交于 2019-12-23 04:19:13
问题 I am trying to query a comments table from mysql database by language. Whenever I query by language to fetch chinese comments it displays encoded gibberish characters. but whenever I use python to query, it works. Cloud Platform: Google Cloud SQL Database location: Google Cloud SQL Programming Language: Nodejs Below is my code // Require process, so we can mock environment variables const process = require('process'); const Knex = require('knex'); const express = require('express'); const app

Can we always fetch date column as string (varchar) with knex and postgres?

微笑、不失礼 提交于 2019-12-22 09:56:35
问题 I have a column in postgres database with type date . It is a column like birthday, which is just a date and does not need to have a time part. When fetching this column with knex, the result is a javascript Date object. It is presumably doing new Date(row.birthday) , and this is the result that is sent to the client. The problem now is that the value that the client receives is in the standard ISO 8601 format with the time part and the Z . When the client tries to create a new Date object

How can I retrieve unique values from a column with Knex.js?

对着背影说爱祢 提交于 2019-12-22 09:23:33
问题 I use Knex.js to communicate to Postgres database. I have rows in a table with a column named 'state' which represents a US state. How can I retrieve all unique values from this column? 回答1: You are probably looking for knex.distinct + knex.pluck combo. knex .distinct() .from('tablename') .pluck('state') .then(states => { console.log(states) }) 来源: https://stackoverflow.com/questions/47263583/how-can-i-retrieve-unique-values-from-a-column-with-knex-js

KnexJS Migration With Associated Seed Data

喜夏-厌秋 提交于 2019-12-22 08:37:35
问题 I'm, in the process of learning BookshelfJS/KnexJS (switching from SequelizeJS), and I'm running into an issue with importing data into multiple tables that were created via the migrations feature within KnexJS. There's 4 tables: servers operating_systems applications applications_servers With the following constraints: servers . operating_system_id references operating_systems . id applications_servers . server_id references servers . id applications_servers . application_id references

How to do raw query in Bookshelf.js

空扰寡人 提交于 2019-12-21 11:34:08
问题 I want to achieve this SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20; from https://developers.google.com/maps/articles/phpsqlsearch_v3?hl=fr#createtable How can I make this query with Bookshelf. I have this now: var raw = '( 3959 * acos( cos( radians(37) ) * cos( radians( '+ req.params.lat + ' ) ) * cos(

Does Knex.js prevent sql injection?

限于喜欢 提交于 2019-12-21 07:27:32
问题 I'm using a MySql database and was trying to find a MySQL alternative to tedious.js (a SQL server parameterised query builder).I'm using Node.js for my backend. I read that the .raw() command from knex.js is susceptible to sql injection, if not used with bindings. But are the other commands and knex.js as a whole safe to use to prevent sql injection? Or am I barking up the wrong tree? 回答1: Read carefully from knex documentation how to pass values to knex raw (http://knexjs.org/#Raw). If you

Knex.js - How To Update a Field With An Expression

依然范特西╮ 提交于 2019-12-19 19:39:11
问题 How do we get Knex to create the following SQL statement: UPDATE item SET qtyonhand = qtyonhand + 1 WHERE rowid = 8 We're currently using the following code: knex('item') .transacting(trx) .update({qtyonhand: 10}) .where('rowid', 8) However, in order for our inventory application to work in a multi-user environment we need the qtyonhand value to add or subtract with what's actually in the database at that moment rather than passing a value that may be stale by the time the update statement is

Tracking DB querying time - Bookshelf/knex

送分小仙女□ 提交于 2019-12-19 11:06:43
问题 I would like to monitor the time taken by a query on my API's db. I so created the following function, using bookshelf-signals, a Bookshelf plugin. : bookshelf.on('fetching', () => { server.app.fetching = new Date().valueOf(); }); bookshelf.on('counting', () => { server.app.fetching = new Date().valueOf(); }); bookshelf.on('fetched', () => { server.statsd.gauge('db_query', new Date().valueOf() - server.app.fetching); }); ... so that I can retrieve the time just before and just after a fetch

KNEX Undefined binding(s) detected when compiling SELECT query

纵然是瞬间 提交于 2019-12-13 14:53:46
问题 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) console.log(skus.toJSON()); }).catch(function (err) { console.error(err); }); It throws Undefined binding(s) detected when compiling SELECT query. It is working fine with 0.11.5, it stopped working with 0.11.6 onwards. I am pointing to 0.13.0 right now. useNullAsDefault: true works fine