Skip to content

Commit

Permalink
Cleanup the use of vec! macros
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Feb 3, 2023
1 parent 707e687 commit 5375c34
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion SeaORM/docs/05-basic-crud/03-insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ let orange = fruit::ActiveModel {
..Default::default()
};

let res: InsertResult = Fruit::insert_many(vec![apple, orange]).exec(db).await?;
let res: InsertResult = Fruit::insert_many([apple, orange]).exec(db).await?;
assert_eq!(res.last_insert_id, 30)
```

Expand Down
2 changes: 1 addition & 1 deletion SeaORM/docs/05-basic-crud/07-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let cakes: Vec<serde_json::Value> = Cake::find()

assert_eq!(
cakes,
vec![
[
serde_json::json!({
"id": 2,
"name": "Chocolate Forest"
Expand Down
10 changes: 5 additions & 5 deletions SeaORM/docs/05-basic-crud/08-raw-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let cheese: Option<cake::Model> = cake::Entity::find()
.from_raw_sql(Statement::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "id" = $1"#,
vec![1.into()],
[1.into()],
))
.one(&db)
.await?;
Expand All @@ -26,7 +26,7 @@ pub struct UniqueCake {
let unique: Vec<UniqueCake> = UniqueCake::find_by_statement(Statement::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."name" FROM "cake" GROUP BY "cake"."name"#,
vec![],
[],
))
.all(&db)
.await?;
Expand All @@ -38,7 +38,7 @@ If you do not know what your model looks like beforehand, you can use `JsonValue
let unique: Vec<JsonValue> = JsonValue::find_by_statement(Statement::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."name" FROM "cake" GROUP BY "cake"."name"#,
vec![],
[],
))
.all(&db)
.await?;
Expand All @@ -51,7 +51,7 @@ let mut cake_pages = cake::Entity::find()
.from_raw_sql(Statement::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "id" = $1"#,
vec![1.into()],
[1.into()],
))
.paginate(db, 50);

Expand All @@ -71,7 +71,7 @@ assert_eq!(
cake_filling::Entity::find_by_id((6, 8))
.build(DatabaseBackend::MySql)
.to_string(),
vec![
[
"SELECT `cake_filling`.`cake_id`, `cake_filling`.`filling_id` FROM `cake_filling`",
"WHERE `cake_filling`.`cake_id` = 6 AND `cake_filling`.`filling_id` = 8",
].join(" ")
Expand Down
18 changes: 9 additions & 9 deletions SeaORM/docs/07-write-test/02-mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod tests {
// Return the second query result
assert_eq!(
cake::Entity::find().all(&db).await?,
vec![
[
cake::Model {
id: 1,
name: "New York Cheese".to_owned(),
Expand All @@ -94,7 +94,7 @@ mod tests {
.find_also_related(fruit::Entity)
.all(&db)
.await?,
vec![(
[(
cake::Model {
id: 1,
name: "Apple Cake".to_owned(),
Expand All @@ -110,21 +110,21 @@ mod tests {
// Checking transaction log
assert_eq!(
db.into_transaction_log(),
vec![
[
Transaction::from_sql_and_values(
DatabaseBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake" LIMIT $1"#,
vec![1u64.into()]
[1u64.into()]
),
Transaction::from_sql_and_values(
DatabaseBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake""#,
vec![]
[]
),
Transaction::from_sql_and_values(
DatabaseBackend::Postgres,
r#"SELECT "cake"."id" AS "A_id", "cake"."name" AS "A_name", "fruit"."id" AS "B_id", "fruit"."name" AS "B_name", "fruit"."cake_id" AS "B_cake_id" FROM "cake" LEFT JOIN "fruit" ON "cake"."id" = "fruit"."cake_id""#,
vec![]
[]
),
]
);
Expand Down Expand Up @@ -194,16 +194,16 @@ mod tests {
// Checking transaction log
assert_eq!(
db.into_transaction_log(),
vec![
[
Transaction::from_sql_and_values(
DatabaseBackend::Postgres,
r#"INSERT INTO "cake" ("name") VALUES ($1) RETURNING "id", "name""#,
vec!["Apple Pie".into()]
["Apple Pie".into()]
),
Transaction::from_sql_and_values(
DatabaseBackend::Postgres,
r#"INSERT INTO "cake" ("name") VALUES ($1) RETURNING "id""#,
vec!["Apple Pie".into()]
["Apple Pie".into()]
),
]
);
Expand Down
4 changes: 2 additions & 2 deletions SeaORM/docs/08-advanced-query/01-custom-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ let res: Vec<String> = cake::Entity::find()

assert_eq!(
res,
vec!["Chocolate Forest".to_owned(), "New York Cheese".to_owned()]
["Chocolate Forest".to_owned(), "New York Cheese".to_owned()]
);
```

Expand All @@ -127,7 +127,7 @@ let res: Vec<(String, i64)> = cake::Entity::find()
.all(&db)
.await?;

assert_eq!(res, vec![("Chocolate Forest".to_owned(), 2i64)]);
assert_eq!(res, [("Chocolate Forest".to_owned(), 2i64)]);
```

Instead, the `into_tuple` method can be used to fetch the tuple value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ To further illustrate it, we will show the SQL statement as string below.
db_postgres.build(&schema.create_table_from_entity(CakeFillingPrice)),
Statement::from_string(
db_postgres,
vec![
[
r#"CREATE TABLE "public"."cake_filling_price" ("#,
r#""cake_id" integer NOT NULL,"#,
r#""filling_id" integer NOT NULL,"#,
Expand All @@ -92,7 +92,7 @@ To further illustrate it, we will show the SQL statement as string below.
db_mysql.build(&schema.create_table_from_entity(CakeFillingPrice)),
Statement::from_string(
db_mysql,
vec![
[
"CREATE TABLE `cake_filling_price` (",
"`cake_id` int NOT NULL,",
"`filling_id` int NOT NULL,",
Expand All @@ -117,7 +117,7 @@ To further illustrate it, we will show the SQL statement as string below.
db_sqlite.build(&schema.create_table_from_entity(CakeFillingPrice)),
Statement::from_string(
db_sqlite,
vec![
[
"CREATE TABLE `cake_filling_price` (",
"`cake_id` integer NOT NULL,",
"`filling_id` integer NOT NULL,",
Expand Down
8 changes: 4 additions & 4 deletions SeaORM/docs/09-generate-sea-query-statement/02-create-enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ assert_eq!(
.iter()
.map(|stmt| db_postgres.build(stmt))
.collect::<Vec<_>>(),
vec![Statement::from_string(
[Statement::from_string(
db_postgres,
r#"CREATE TYPE "tea" AS ENUM ('EverydayTea', 'BreakfastTea')"#.to_owned()
),]
Expand All @@ -129,7 +129,7 @@ assert_eq!(
db_postgres.build(&schema.create_table_from_entity(active_enum::Entity)),
Statement::from_string(
db_postgres,
vec![
[
r#"CREATE TABLE "public"."active_enum" ("#,
r#""id" serial NOT NULL PRIMARY KEY,"#,
r#""tea" tea"#,
Expand All @@ -154,7 +154,7 @@ assert_eq!(
db_mysql.build(&schema.create_table_from_entity(active_enum::Entity)),
Statement::from_string(
db_mysql,
vec![
[
"CREATE TABLE `active_enum` (",
"`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,",
"`tea` ENUM('EverydayTea', 'BreakfastTea')",
Expand All @@ -179,7 +179,7 @@ assert_eq!(
db_sqlite.build(&schema.create_enum_from_entity(active_enum::Entity)),
Statement::from_string(
db_sqlite,
vec![
[
"CREATE TABLE `active_enum` (",
"`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,",
"`tea` text",
Expand Down

0 comments on commit 5375c34

Please sign in to comment.