Thank you !!!
This was a big help!!
Thank you !!!
This was a big help!!
I want to use the ID that was generated for one table and insert it into a second table and i am getting an error.
error: "SQL Syntax Error near 'INSERT INTO all_tokens (user_id, device, token)\n" +
" VALUES (LAST_' at line 3",
let sql = `INSERT INTO users (name, nickname, email, password,
last_logged, current_token )
VALUES ('${name}', '${nickname}', '${email}',
'${hachPassword}',now(), '${token}' )
INSERT INTO all_tokens (user_id, device, token)
VALUES (LAST_INSERT_ID(), '1' ,'${token}')`
await cloudbackend.sqlExecuteRawQuery(sql).then(async res => {
let result = await JSON.parse(res);
console.log(result)
if (result.affectedRows == 2 ) {
// do something
}
yes I duplicatedthe function and it is stil not working.
The only thing that works is what i rwote in the past. The try does not responed to the updats i made in the code.
(the api function is a register api.)
Hi!
My try button is not working (it is working in the doc.). olso when i send a request from my front end it returns not fond.
Please help!
@Wassim said in Regster API Function.:
how many rows have been affected in the return of sqlExecuteRawQuery
how do I check it?
Hi!
Thanks for you answer!
I tried setting the email column as unique and this it the error I am getting:
Error: Specified key was too long; max key length is 767 bytes
{"m_MaxCapacity":2147483647,"Capacity":1768,"m_StringValue":"ALTER TABLE my-recipe-app-1fe491
.users
CHANGE COLUMN id
id
int AUTO_INCREMENT COMMENT '::' FIRST ;
ALTER TABLE my-recipe-app-1fe491
.users
CHANGE COLUMN name
name
varchar(255) COMMENT '::' AFTER id
;
ALTER TABLE my-recipe-app-1fe491
.users
CHANGE COLUMN nickname
nickname
varchar(255) COMMENT '::' AFTER name
;
ALTER TABLE my-recipe-app-1fe491
.users
ADD UNIQUE INDEX email_UNIQUE
(email
ASC);
ALTER TABLE my-recipe-app-1fe491
.users
CHANGE COLUMN email
email
varchar(200) COMMENT 'email::' AFTER nickname
;
ALTER TABLE my-recipe-app-1fe491
.users
CHANGE COLUMN password
password
varchar(255) COMMENT 'password::' AFTER email
;
ALTER TABLE my-recipe-app-1fe491
.users
CHANGE COLUMN date_joined
date_joined
date COMMENT '::' AFTER password
;
ALTER TABLE my-recipe-app-1fe491
.users
CHANGE COLUMN active
active
int DEFAULT '0' COMMENT '::' AFTER date_joined
;
ALTER TABLE my-recipe-app-1fe491
.users
CHANGE COLUMN token
token
varchar(255) COMMENT '::' AFTER active
;
","m_currentThread":0}
This function I wrote does not always give me the token. (It does work sometimes)
This is the message I receive:
"errorMessage": "Cannot read property '0' of undefined",
This is the fusction :
const cloudbackend = require('appdrag-cloudbackend');
cloudbackend.init(process.env.APIKEY, process.env.APPID);
const bcrypt = require('bcrypt');
const uuid = require('uuid');
exports.handler = async(event, context, callback) => {
let name = event["POST"]["name"];
let nickname = event["POST"]["nickname"];
let email = event["POST"]["email"];
let password = event["POST"]["password"];
let hachPassword = bcrypt.hashSync(password, 10);
//Check email does not exists.
let finedEmai = `SELECT email FROM users WHERE email = '${email}' `
await cloudbackend.sqlSelect(finedEmai).then(async res => {
let result = JSON.parse(res);
if (result.Table == null) {
// Add user to DB.
let sql = `INSERT INTO users (name, nickname, email, password, date_joined, token) VALUES ('${name}', '${nickname}', '${email}','${hachPassword}', now() , uuid())`;
await cloudbackend.sqlExecuteRawQuery(sql).then(async res => {
// Get current users token
let cotentToken = `SELECT token FROM users WHERE id = LAST_INSERT_ID()`
await cloudbackend.sqlSelect(cotentToken).then(async res => {
let result = await JSON.parse(res);
let token = result.Table[0]
callback(null, token);
});
});
} else {
callback(null, result.Table[0])
}
})
}