File tree Expand file tree Collapse file tree 3 files changed +51
-44
lines changed
file_classification_core/src/internal Expand file tree Collapse file tree 3 files changed +51
-44
lines changed Original file line number Diff line number Diff line change @@ -33,21 +33,24 @@ pub fn insert_file(
3333 #[ cfg( feature = "mysql" ) ]
3434 // 对于 MySQL 连接,使用事务方式
3535 AnyConnection :: Mysql ( mysql) => {
36- conn. transaction ( |mysql| {
37- // 执行插入操作
38- diesel:: insert_into ( files:: table)
39- . values ( new_file)
40- . execute ( mysql) ?;
41-
42- // MySQL使用LAST_INSERT_ID()获取最后插入的ID
43- let last_id: i32 = diesel:: select ( diesel:: dsl:: sql :: < diesel:: sql_types:: Integer > ( "LAST_INSERT_ID()" ) )
44- . get_result ( mysql) ?;
45-
46- Ok ( last_id)
47- } )
36+ conn. transaction ( |mysql| {
37+ // 执行插入操作
38+ diesel:: insert_into ( files:: table)
39+ . values ( new_file)
40+ . execute ( mysql) ?;
41+
42+ // MySQL使用LAST_INSERT_ID()获取最后插入的ID
43+ let last_id: i32 = diesel:: select ( diesel:: dsl:: sql :: < diesel:: sql_types:: Integer > ( "LAST_INSERT_ID()" ) )
44+ . get_result ( mysql) ?;
45+
46+ Ok ( last_id)
47+ } )
4848 } ,
49- // 默认情况(如其他数据库类型)使用 returning 子句
50- other_database_type => diesel:: insert_into ( files:: table) . values ( new_file) . returning ( files:: id) . get_result ( other_database_type) ,
49+ #[ cfg( feature = "postgres" ) ]
50+ // 对于 PostgreSQL 连接,使用 returning 子句
51+ AnyConnection :: Postgresql ( postgres) => {
52+ diesel:: insert_into ( files:: table) . values ( new_file) . returning ( files:: id) . get_result ( postgres)
53+ }
5154 }
5255}
5356
Original file line number Diff line number Diff line change @@ -34,22 +34,23 @@ pub fn insert_group(
3434 #[ cfg( feature = "mysql" ) ]
3535 // 对于 MySQL 连接,使用事务方式
3636 AnyConnection :: Mysql ( mysql) => {
37- mysql. transaction ( |mysql| {
38- // 执行插入操作
39- diesel:: insert_into ( groups:: table)
40- . values ( new_group)
41- . execute ( mysql) ?;
42-
43- // MySQL使用LAST_INSERT_ID()获取最后插入的ID
44- let last_id: i32 = diesel:: select ( diesel:: dsl:: sql :: < diesel:: sql_types:: Integer > ( "LAST_INSERT_ID()" ) )
45- . get_result ( mysql) ?;
46-
47- Ok ( last_id)
48- } )
37+ mysql. transaction ( |mysql| {
38+ // 执行插入操作
39+ diesel:: insert_into ( groups:: table)
40+ . values ( new_group)
41+ . execute ( mysql) ?;
42+
43+ // MySQL使用LAST_INSERT_ID()获取最后插入的ID
44+ let last_id: i32 = diesel:: select ( diesel:: dsl:: sql :: < diesel:: sql_types:: Integer > ( "LAST_INSERT_ID()" ) )
45+ . get_result ( mysql) ?;
46+
47+ Ok ( last_id)
48+ } )
4949 } ,
50- // 默认情况(如其他数据库类型)使用 returning 子句
51- other_database_type => {
52- diesel:: insert_into ( groups:: table) . values ( new_group) . returning ( groups:: id) . get_result ( other_database_type)
50+ #[ cfg( feature = "postgres" ) ]
51+ // 对于 PostgreSQL 连接,使用 returning 子句
52+ AnyConnection :: Postgresql ( postgres) => {
53+ diesel:: insert_into ( groups:: table) . values ( new_group) . returning ( groups:: id) . get_result ( postgres)
5354 }
5455 }
5556}
Original file line number Diff line number Diff line change @@ -31,23 +31,26 @@ pub fn insert_tag(
3131 diesel:: insert_into ( tags:: table) . values ( new_tag) . returning ( tags:: id) . get_result ( sqlite)
3232 }
3333 #[ cfg( feature = "mysql" ) ]
34- // 对于 MySQL 连接,使用事务方式(暂时注释掉,因为目前没有启用mysql,注意不要删除以下注释内容,将来会用到)
34+ // 对于 MySQL 连接,使用事务方式
3535 AnyConnection :: Mysql ( mysql) => {
36- mysql. transaction ( |mysql| {
37- // 执行插入操作
38- diesel:: insert_into ( tags:: table)
39- . values ( new_tag)
40- . execute ( mysql) ?;
41-
42- // MySQL使用LAST_INSERT_ID()获取最后插入的ID
43- let last_id: i32 = diesel:: select ( diesel:: dsl:: sql :: < diesel:: sql_types:: Integer > ( "LAST_INSERT_ID()" ) )
44- . get_result ( mysql) ?;
45-
46- Ok ( last_id)
47- } )
36+ mysql. transaction ( |mysql| {
37+ // 执行插入操作
38+ diesel:: insert_into ( tags:: table)
39+ . values ( new_tag)
40+ . execute ( mysql) ?;
41+
42+ // MySQL使用LAST_INSERT_ID()获取最后插入的ID
43+ let last_id: i32 = diesel:: select ( diesel:: dsl:: sql :: < diesel:: sql_types:: Integer > ( "LAST_INSERT_ID()" ) )
44+ . get_result ( mysql) ?;
45+
46+ Ok ( last_id)
47+ } )
4848 } ,
49- // 默认情况(如其他数据库类型)使用 returning 子句
50- other_database_type => diesel:: insert_into ( tags:: table) . values ( new_tag) . returning ( tags:: id) . get_result ( other_database_type) ,
49+ #[ cfg( feature = "postgres" ) ]
50+ // 对于 PostgreSQL 连接,使用 returning 子句
51+ AnyConnection :: Postgresql ( postgres) => {
52+ diesel:: insert_into ( tags:: table) . values ( new_tag) . returning ( tags:: id) . get_result ( postgres)
53+ }
5154 }
5255}
5356
You can’t perform that action at this time.
0 commit comments