Knex.js - TypeError: db(…).return(…).insert is not a function
I am getting the error : TypeError: db(...).return(...).insert is not a function
For some reason the code runs 'db.select('*')'
without a problem but when it gets to
'db('courses')
.return('*')
.insert({'
it gives the error : TypeError: db(...).return(...).insert is not a function.
I can not figure out what is going on, I've been stuck on this for 4 hours.
My code sample :
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const knex = require('knex');
const db = knex({
client:'pg',
connection:{
host:'127.0.0.1',
port:'5432',
user:'postgres',
password:'',
database:'YouList'
}
})
const app = express();
app.use(bodyParser.json());
app.use(cors())
db.select('*').from('users').then(data => {
console.log(data,'oia a data ai');
});
/*testando sem API*/
db('courses')
.return('*')
.insert({
title: "o grande curso",
description : "uma introducao aos ventos do leste",
user_id : 78,
urlimage : "https://i.imgur.com/TiavcG9.jpg",
created : new Date()
})
.then(console.log)
.then(user => {
res.json(user[0]);
})
.catch(err => res.status(400).json('unable to register'))
node.js express knex.js
add a comment |
I am getting the error : TypeError: db(...).return(...).insert is not a function
For some reason the code runs 'db.select('*')'
without a problem but when it gets to
'db('courses')
.return('*')
.insert({'
it gives the error : TypeError: db(...).return(...).insert is not a function.
I can not figure out what is going on, I've been stuck on this for 4 hours.
My code sample :
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const knex = require('knex');
const db = knex({
client:'pg',
connection:{
host:'127.0.0.1',
port:'5432',
user:'postgres',
password:'',
database:'YouList'
}
})
const app = express();
app.use(bodyParser.json());
app.use(cors())
db.select('*').from('users').then(data => {
console.log(data,'oia a data ai');
});
/*testando sem API*/
db('courses')
.return('*')
.insert({
title: "o grande curso",
description : "uma introducao aos ventos do leste",
user_id : 78,
urlimage : "https://i.imgur.com/TiavcG9.jpg",
created : new Date()
})
.then(console.log)
.then(user => {
res.json(user[0]);
})
.catch(err => res.status(400).json('unable to register'))
node.js express knex.js
add a comment |
I am getting the error : TypeError: db(...).return(...).insert is not a function
For some reason the code runs 'db.select('*')'
without a problem but when it gets to
'db('courses')
.return('*')
.insert({'
it gives the error : TypeError: db(...).return(...).insert is not a function.
I can not figure out what is going on, I've been stuck on this for 4 hours.
My code sample :
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const knex = require('knex');
const db = knex({
client:'pg',
connection:{
host:'127.0.0.1',
port:'5432',
user:'postgres',
password:'',
database:'YouList'
}
})
const app = express();
app.use(bodyParser.json());
app.use(cors())
db.select('*').from('users').then(data => {
console.log(data,'oia a data ai');
});
/*testando sem API*/
db('courses')
.return('*')
.insert({
title: "o grande curso",
description : "uma introducao aos ventos do leste",
user_id : 78,
urlimage : "https://i.imgur.com/TiavcG9.jpg",
created : new Date()
})
.then(console.log)
.then(user => {
res.json(user[0]);
})
.catch(err => res.status(400).json('unable to register'))
node.js express knex.js
I am getting the error : TypeError: db(...).return(...).insert is not a function
For some reason the code runs 'db.select('*')'
without a problem but when it gets to
'db('courses')
.return('*')
.insert({'
it gives the error : TypeError: db(...).return(...).insert is not a function.
I can not figure out what is going on, I've been stuck on this for 4 hours.
My code sample :
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const knex = require('knex');
const db = knex({
client:'pg',
connection:{
host:'127.0.0.1',
port:'5432',
user:'postgres',
password:'',
database:'YouList'
}
})
const app = express();
app.use(bodyParser.json());
app.use(cors())
db.select('*').from('users').then(data => {
console.log(data,'oia a data ai');
});
/*testando sem API*/
db('courses')
.return('*')
.insert({
title: "o grande curso",
description : "uma introducao aos ventos do leste",
user_id : 78,
urlimage : "https://i.imgur.com/TiavcG9.jpg",
created : new Date()
})
.then(console.log)
.then(user => {
res.json(user[0]);
})
.catch(err => res.status(400).json('unable to register'))
node.js express knex.js
node.js express knex.js
asked Nov 21 '18 at 23:05
Plínio HelpaPlínio Helpa
535
535
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You are calling return
and not returning
. You should also chain it off of insert
, rather than having it before. Makes it a bit more idiomatic.
So just switch it around...
db('courses')
.insert({
foo: 'bar'
})
.returning('*')
great tip my friend!
– Plínio Helpa
Nov 22 '18 at 18:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421687%2fknex-js-typeerror-db-return-insert-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are calling return
and not returning
. You should also chain it off of insert
, rather than having it before. Makes it a bit more idiomatic.
So just switch it around...
db('courses')
.insert({
foo: 'bar'
})
.returning('*')
great tip my friend!
– Plínio Helpa
Nov 22 '18 at 18:06
add a comment |
You are calling return
and not returning
. You should also chain it off of insert
, rather than having it before. Makes it a bit more idiomatic.
So just switch it around...
db('courses')
.insert({
foo: 'bar'
})
.returning('*')
great tip my friend!
– Plínio Helpa
Nov 22 '18 at 18:06
add a comment |
You are calling return
and not returning
. You should also chain it off of insert
, rather than having it before. Makes it a bit more idiomatic.
So just switch it around...
db('courses')
.insert({
foo: 'bar'
})
.returning('*')
You are calling return
and not returning
. You should also chain it off of insert
, rather than having it before. Makes it a bit more idiomatic.
So just switch it around...
db('courses')
.insert({
foo: 'bar'
})
.returning('*')
answered Nov 21 '18 at 23:31
dvsoukupdvsoukup
1,057923
1,057923
great tip my friend!
– Plínio Helpa
Nov 22 '18 at 18:06
add a comment |
great tip my friend!
– Plínio Helpa
Nov 22 '18 at 18:06
great tip my friend!
– Plínio Helpa
Nov 22 '18 at 18:06
great tip my friend!
– Plínio Helpa
Nov 22 '18 at 18:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421687%2fknex-js-typeerror-db-return-insert-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown