-
Notifications
You must be signed in to change notification settings - Fork 45
db hint #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello. Thanks for tips! |
No, you should use a transaction instead, if you change data, or a task, if you are reading data only. |
Ok, Thanks! |
I noticed from here: https://github.com/roaiven/ello/blob/develop/server/helpers.js you use: params: {
schema: 'public'
} but you don't really use variable See QueryFile documentation ;) |
Thanks for tip:) |
This looks wrong in so many ways... :) const columns = _.keys(props).join();
const values = _.values(props).join();
return db.one(
'INSERT INTO $1~($2~) VALUES($3) RETURNING *',
[this.table, columns, values]
); this can't work, For example, for columns you could use: const columns = _.keys(props).map(k=>pgp.as.name(k)); and then use variable |
Hello. Yes, It worked for me, because I've been inserting entries only with one column :) const columns = _.keys(props).map(k => pgp.as.name(k)).join();
const values = _.values(props);
return db.one(
'INSERT INTO $1~($2^) VALUES($3:csv) RETURNING *',
[this.table, columns, values]
); |
That looks right now ;) almost... const columns = _.keys(props).map(k => pgp.as.name(k)).join(', '); join should be with |
This is super inefficient: https://github.com/roaiven/ello/blob/8d25ac96490d2321e948ed2366d7b460cc0597b8/server/db/index.js From here: https://github.com/vitaly-t/pg-promise#query-files
And from here: http://vitaly-t.github.io/pg-promise/QueryFile.html
And you are creating a whole new |
By this way, I am creating tables for my app, if they are not exist. Each table sql code is placed in a separate file, I need them to be created in a strict order. How I can create them more effectively? This way will be inefficient too?
|
Your SQL files are static - right? Just create them statically, when your app starts, and then use those static See the example that accompanies QueryFile. |
Yes, they are static. I don't need them later in my app. I think, I don't need to use QueryFile in this case at all. Or I'm wrong? |
QueryFile is easier to use either way. |
two problems in such code: https://github.com/roaiven/ello/blob/22fea3e6e75d61fa0e71ff3f289d178edfa50a90/server/db/index.js
.than
+.catch
.The text was updated successfully, but these errors were encountered: