INSERT
should respect unique indexes (#3092)
This commit is contained in:
parent
3a907813fd
commit
daf02dc4e6
2 changed files with 33 additions and 4 deletions
|
@ -60,10 +60,10 @@ impl<'a> Document<'a> {
|
||||||
self.clean(ctx, opt, txn, stm).await?;
|
self.clean(ctx, opt, txn, stm).await?;
|
||||||
// Check if allowed
|
// Check if allowed
|
||||||
self.allow(ctx, opt, txn, stm).await?;
|
self.allow(ctx, opt, txn, stm).await?;
|
||||||
// Store record data
|
|
||||||
self.store(ctx, opt, txn, stm).await?;
|
|
||||||
// Store index data
|
// Store index data
|
||||||
self.index(ctx, opt, txn, stm).await?;
|
self.index(ctx, opt, txn, stm).await?;
|
||||||
|
// Store record data
|
||||||
|
self.store(ctx, opt, txn, stm).await?;
|
||||||
// Run table queries
|
// Run table queries
|
||||||
self.table(ctx, opt, txn, stm).await?;
|
self.table(ctx, opt, txn, stm).await?;
|
||||||
// Run lives queries
|
// Run lives queries
|
||||||
|
@ -95,10 +95,10 @@ impl<'a> Document<'a> {
|
||||||
self.clean(ctx, opt, txn, stm).await?;
|
self.clean(ctx, opt, txn, stm).await?;
|
||||||
// Check if allowed
|
// Check if allowed
|
||||||
self.allow(ctx, opt, txn, stm).await?;
|
self.allow(ctx, opt, txn, stm).await?;
|
||||||
// Store record data
|
|
||||||
self.store(ctx, opt, txn, stm).await?;
|
|
||||||
// Store index data
|
// Store index data
|
||||||
self.index(ctx, opt, txn, stm).await?;
|
self.index(ctx, opt, txn, stm).await?;
|
||||||
|
// Store record data
|
||||||
|
self.store(ctx, opt, txn, stm).await?;
|
||||||
// Run table queries
|
// Run table queries
|
||||||
self.table(ctx, opt, txn, stm).await?;
|
self.table(ctx, opt, txn, stm).await?;
|
||||||
// Run lives queries
|
// Run lives queries
|
||||||
|
|
|
@ -488,3 +488,32 @@ async fn check_permissions_auth_disabled() {
|
||||||
assert!(res.unwrap() != Value::parse("[]"), "{}", "anonymous user should be able to insert a new record if the table exists and grants full permissions");
|
assert!(res.unwrap() != Value::parse("[]"), "{}", "anonymous user should be able to insert a new record if the table exists and grants full permissions");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn insert_statement_unique_index() -> Result<(), Error> {
|
||||||
|
let sql = "
|
||||||
|
DEFINE INDEX name ON TABLE company COLUMNS name UNIQUE;
|
||||||
|
INSERT INTO company { name: 'SurrealDB' };
|
||||||
|
INSERT INTO company { name: 'SurrealDB' };
|
||||||
|
SELECT count() FROM company GROUP ALL;
|
||||||
|
";
|
||||||
|
let dbs = new_ds().await?;
|
||||||
|
let ses = Session::owner().with_ns("test").with_db("test");
|
||||||
|
let res = &mut dbs.execute(sql, &ses, None).await?;
|
||||||
|
assert_eq!(res.len(), 4);
|
||||||
|
//
|
||||||
|
let tmp = res.remove(0).result;
|
||||||
|
assert!(tmp.is_ok());
|
||||||
|
//
|
||||||
|
let tmp = res.remove(0).result;
|
||||||
|
assert!(tmp.is_ok());
|
||||||
|
//
|
||||||
|
let tmp = res.remove(0).result;
|
||||||
|
assert!(tmp.is_ok());
|
||||||
|
//
|
||||||
|
let tmp = res.remove(0).result?;
|
||||||
|
let val = Value::parse("[ { count: 1 } ]");
|
||||||
|
assert_eq!(tmp, val);
|
||||||
|
//
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue