You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i have created an index DEFINE INDEX unique_username ON user FIELDS username UNIQUE
i'm using surrealdb.js npm package.
Expectation : when i insert duplicate value into username field , proper error message should be thrown
Scenario 0
when i insert duplicate value using below statement
db.query(`create user set username = "${userObj.username}"`).then((data1 : QueryResult<RawQueryResult>[])=>{
console.log("in signupCreateQuery then data ",JSON.stringify(data1))
}).catch((err)=>{
console.log("in signupCreateQuery err ",err);
})
i'm able to receive a proper response.
in signupCreateQuery then data [{"result":"Database index `unique_username` already contains 'cdivine', with record `user:04kjob5s4cdj1e63a9fq`","status":"ERR","time":"281.291µs"}]
i have detailed 2 different scenarios below, it does not return proper response during the above mentioned error scenario.
Scenario 1
when i insert duplicate value using below statement from within a transaction , i receive a very generic response. is it possible to receive a specific response here as it was shown in Scenario 0?
globalThis.DBCONN.query(`
BEGIN TRANSACTION;
LET $ins = (create user set username = "${userObj.username}" );
RETURN $ins;
COMMIT TRANSACTION;
`).then((data1 : QueryResult<RawQueryResult>[])=>{
console.log("in signupCreateQuery then data ",JSON.stringify(data1))
}).catch((err)=>{
console.log("in signupCreateQuery err ",err);
})
response
in signupCreateQuery then data [{"result":"The query was not executed due to a failed transaction","status":"ERR","time":"250ns"}]
Scenario 2
type keyword is allowed here. i tried to use interface as a type, but it gives me an error. is it allowed to use interface as a type ?
Also, when i try to insert duplicate username using below code, the error scenario with below code doesnot show me any proper reason
type Test = {
username: string;
};
globalThis.DBCONN.create<Test>('user',{username: userObj.username }).then((data)=>{
console.log("in then data ",data)
}).catch((err)=>{
console.log("in err ",err)
})
error
in err Error
at <anonymous> (webpack:///node_modules/surrealdb.js/esm/strategies/http.js:200:19)
at Generator.next (<anonymous>)
at asyncGeneratorStep (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:1)
at apply (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:22:1)
at invoke (webpack:///node_modules/zone.js/fesm2015/zone-node.js:368:26)
at run (webpack:///node_modules/zone.js/fesm2015/zone-node.js:129:43)
at apply (webpack:///node_modules/zone.js/fesm2015/zone-node.js:1188:36)
at invokeTask (webpack:///node_modules/zone.js/fesm2015/zone-node.js:402:31)
at runTask (webpack:///node_modules/zone.js/fesm2015/zone-node.js:173:47)
at drainMicroTaskQueue (webpack:///node_modules/zone.js/fesm2015/zone-node.js:581:35)
when i compare Scenario 2 with Scenario 0 and Scenario 1 , Scenario 2 throws error within the catch block , but Scenario 0 and Scenario 1 throws the error within the then block
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
i have created an index
DEFINE INDEX unique_username ON user FIELDS username UNIQUE
i'm using
surrealdb.js
npm package.Expectation : when i insert duplicate value into
username
field ,proper error message should be thrown
Scenario 0
when i insert duplicate value using below statement
i'm able to receive a proper response.
i have detailed 2 different scenarios below, it does not return proper response during the above mentioned error scenario.
Scenario 1
when i insert duplicate value using below statement from within a transaction , i receive a very generic response. is it possible to receive a specific response here as it was shown in
Scenario 0
?response
Scenario 2
type
keyword is allowed here. i tried to useinterface
as a type, but it gives me an error. is it allowed to use interface as atype
?Also, when i try to insert duplicate
username
using below code, the error scenario with below code doesnot show me any proper reasonerror
when i compare
Scenario 2
withScenario 0
andScenario 1
,Scenario 2
throws error within thecatch
block , butScenario 0
andScenario 1
throws the error within thethen
blockPlease clarify
Beta Was this translation helpful? Give feedback.
All reactions