Repository navigation
Expand file tree
/
Copy pathinsert_wbtest.mbt
More file actions
55 lines (49 loc) · 1.46 KB
/
Copy pathinsert_wbtest.mbt
File metadata and controls
55 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
///|
struct InsertAutoUser {
id : Int
name : String
active : Bool
} derive(ToJson, FromJson)
///|
pub extend InsertAutoUser with ToJson::{to_json}
///|
pub extend InsertAutoUser with @json.FromJson::{from_json}
///|
impl Entity for InsertAutoUser with fn table(_self) -> Table {
new_table("insert_auto_user", columns=[
{ ..new_column("id", Int), primary_key: true, auto_increment: true, },
{ ..new_column("name", VarChar(255)), nullable: false, },
{ ..new_column("active", Boolean), nullable: false, },
])
}
///|
impl @morm/engine.FromParam for InsertAutoUser with fn from_param(_value) {
raise ParamDecodeError("InsertAutoUser::from_param is unused")
}
///|
test "insert from skips auto increment columns" {
let user = { id: 42, name: "Alice", active: true, }
let (sql, params) = @morm/engine.render_query_sql(
insert_into("insert_auto_user").from(user),
)
inspect(
sql,
content="INSERT INTO insert_auto_user (name, active) VALUES (?, ?)",
)
inspect(params.length(), content="2")
}
///|
test "insert from many skips auto increment columns" {
let users : FixedArray[InsertAutoUser] = [
{ id: 42, name: "Alice", active: true, },
{ id: 43, name: "Bob", active: false, },
]
let (sql, params) = @morm/engine.render_query_sql(
insert_into("insert_auto_user").from_many(users),
)
inspect(
sql,
content="INSERT INTO insert_auto_user (name, active) VALUES (?, ?), (?, ?)",
)
inspect(params.length(), content="4")
}