node.js - nodejs-cassandra wont insert ints -
ive tried lot of things fixed seems result in 1 or other error.
below code using execute insert query.
req.client.execute("insert users (id,username,email,password,userfolder) values (now(),'"+newuser.username+"','"+newuser.email+"','"+newuser.password+"',"+newuser.userfolder+");",function(err,result){ if(err){ console.log(err.message) }else{ console.log("new user created") } });
the newuser.userfolder defined in array new date().gettime()
ive tried doing parseint(userfolder: new date().gettime());
seems result in either error
also if try number(userfolder :new data().gettime());
not work , results in second error below;
another thing tried typing newuser.userfolder.valueof()
results in second error.
invalid string constant (1443827057269) "userfolder" of type int
or
unable make int '1443827264655'
i have feeling because ' before number causing this. im not sure how remove this.
i tried directly typing number without using array , works fine, variable must causing issue.
im moving mysql cassandra , have deadline project appreciated.
by way im using datastax driver node-js
req.client.execute("insert users (id,username,email,password,userfolder) values (now(), :username, :email, :userfolder)", newuser, {prepare: true }, function(err,result) { if(err){ console.log(err.message) }else{ console.log("new user created") } });
now bit of details:
- instead of creating cql string concatenating values, code above creates parameterized query
the parameters in query retrieved name (for example
username
)newuser
object. names of parameters must same of properties in object.there option use
?
instead positional parameters , can pass values in array:req.client.execute("insert users (id,username,email,password,userfolder) values (now(), ?, ?, ?)", [newuser.username, newuser.password, newuser.userfolder], ...
{prepare: true}
tells client prepare statement if used multiple times optimized both execution , transfer of parameters
last not least, please not store password in clear.
Comments
Post a Comment