File tree Expand file tree Collapse file tree 3 files changed +8
-50
lines changed Expand file tree Collapse file tree 3 files changed +8
-50
lines changed Original file line number Diff line number Diff line change 1
- # This file is auto-generated by Turbosql.
2
- # It is used to create and apply automatic schema migrations.
3
- # It should be checked into source control.
4
- # Modifying it by hand may be dangerous; see the docs.
5
1
6
- migrations_append_only = [
7
- " CREATE TABLE person (rowid INTEGER PRIMARY KEY) STRICT" ,
8
- " ALTER TABLE person ADD COLUMN name TEXT" ,
9
- " ALTER TABLE person ADD COLUMN age INTEGER" ,
10
- " ALTER TABLE person ADD COLUMN image_jpg BLOB" ,
11
- ]
12
- output_generated_schema_for_your_information_do_not_edit = """
13
- CREATE TABLE _turbosql_migrations (
14
- rowid INTEGER PRIMARY KEY,
15
- migration TEXT NOT NULL
16
- ) STRICT
17
- CREATE TABLE person (
18
- rowid INTEGER PRIMARY KEY,
19
- name TEXT,
20
- age INTEGER,
21
- image_jpg BLOB
22
- ) STRICT
23
- """
24
-
25
- [output_generated_tables_do_not_edit .person ]
26
- name = " person"
27
-
28
- [[output_generated_tables_do_not_edit .person .columns ]]
29
- name = " rowid"
30
- rust_type = " Option < i64 >"
31
- sql_type = " INTEGER PRIMARY KEY"
32
-
33
- [[output_generated_tables_do_not_edit .person .columns ]]
34
- name = " name"
35
- rust_type = " Option < String >"
36
- sql_type = " TEXT"
Original file line number Diff line number Diff line change @@ -5,24 +5,14 @@ use crate::Table;
5
5
pub ( super ) fn delete ( table : & Table ) -> proc_macro2:: TokenStream {
6
6
let sql = makesql_delete ( table) ;
7
7
super :: validate_sql_or_abort ( & sql) ;
8
- let columns = table. columns . iter ( ) . filter ( |c| c. name == "rowid" ) . map ( |c| {
9
- let ident = & c. ident ;
10
- if c. sql_type == "TEXT" && c. rust_type != "Option < String >" {
11
- quote_spanned ! ( c. span => & :: turbosql:: serde_json:: to_string( & self . #ident) ? as & dyn :: turbosql:: ToSql )
12
- } else {
13
- quote_spanned ! ( c. span => & self . #ident as & dyn :: turbosql:: ToSql )
14
- }
15
- } )
16
- . collect :: < Vec < _ > > ( ) ;
17
-
18
8
19
9
quote_spanned ! { table. span =>
20
10
fn delete( & self ) -> Result <usize , :: turbosql:: Error > {
21
11
assert!( self . rowid. is_some( ) ) ;
22
12
:: turbosql:: __TURBOSQL_DB. with( |db| {
23
13
let db = db. borrow_mut( ) ;
24
14
let mut stmt = db. prepare_cached( #sql) ?;
25
- Ok ( stmt. execute( & [ # ( #columns ) , * ] as & [ & dyn :: turbosql :: ToSql ] ) ?)
15
+ Ok ( stmt. execute( [ self . rowid ] ) ?)
26
16
} )
27
17
}
28
18
}
Original file line number Diff line number Diff line change 1
- // cargo test --features test --manifest-path turbosql/Cargo.toml -- --nocapture
1
+ // cargo test --features test --manifest-path turbosql/Cargo.toml -- --nocapture --test-threads=1
2
2
3
3
#![ allow( clippy:: bool_assert_comparison, clippy:: redundant_clone) ]
4
4
@@ -58,13 +58,16 @@ fn integration_test() {
58
58
select!( Vec <String > "field_string FROM personintegrationtest" ) . unwrap( ) ,
59
59
vec![ "Bob" , "Bob" ]
60
60
) ;
61
- let mut r = PersonIntegrationTest {
62
- ..Default :: default ( )
63
- } ;
61
+ let mut r = PersonIntegrationTest :: default ( ) ;
64
62
let id = r. insert ( ) . unwrap ( ) ;
63
+ let id2 = r. insert ( ) . unwrap ( ) ;
65
64
r. rowid = Some ( id) ;
66
65
r. delete ( ) . unwrap ( ) ;
67
66
assert ! ( select!( PersonIntegrationTest "WHERE rowid = ?" , id) . is_err( ) ) ;
67
+ assert ! ( select!( PersonIntegrationTest "WHERE rowid = ?" , id2) . is_ok( ) ) ;
68
+ r. rowid = Some ( id2) ;
69
+ r. delete ( ) . unwrap ( ) ;
70
+ assert ! ( select!( PersonIntegrationTest "WHERE rowid = ?" , id2) . is_err( ) ) ;
68
71
execute ! ( "DELETE FROM personintegrationtest WHERE rowid = 2" ) . unwrap ( ) ;
69
72
assert_eq ! ( select!( i64 "SELECT 1" ) . unwrap( ) , 1 ) ;
70
73
assert_eq ! ( select!( bool "SELECT 1 > ? AS val" , 0 ) . unwrap( ) , true ) ;
You can’t perform that action at this time.
0 commit comments