You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Comments in orm expressions will be removed by vfmt
update_expr := {
//name == name_dyn
}
Use Case
#!/usr/bin/env -S v run
import db.sqlite
import time
@[table: 'sys_users']
struct User {
pub:
id string @[primary; sql_type: 'VARCHAR(255)'; unique]
name ?string @[sql_type: 'VARCHAR(255)']
nickname ?string @[sql_type: 'VARCHAR(255)']
mobile ?string @[sql_type: 'VARCHAR(255)']
email ?string @[sql_type: 'VARCHAR(255)']
created_at time.Time @[omitempty; sql_type: 'TIMESTAMP']
updated_at ?time.Time @[default: new; omitempty; sql_type: 'TIMESTAMP']
}
// 查询用户数据
fn query_users(mut db sqlite.DB) ![]User {
users := sql db {
select from User
}!
return users
}
fn main() {
mut db := init_database()!
defer { db.close() or {} }
insert_users(mut db) or { panic(err) }
req := UserReq{
name: 'Jengro'
nickname: 'Woo'
mobile: '535770088'
email: 'admin@admin.com'
}
dynamic_update_users(mut db, req) or { panic(err) }
users := query_users(mut db) or { panic(err) }
dump(users)
}
fn init_database() !&sqlite.DB {
mut db := sqlite.connect(':memory:')!
sql db {
create table User
}!
return &db
}
fn insert_users(mut db sqlite.DB) ! {
users1 := User{
id: '1'
name: 'Jengro'
nickname: 'Woo'
mobile: '535770088'
email: 'admin@admin.com'
created_at: time.now()
updated_at: time.now()
}
users2 := User{
id: '2'
name: 'Dev'
nickname: 'T'
mobile: '15020579521'
email: 'dev@dev.com'
created_at: time.now()
updated_at: time.now()
}
sql db {
insert users1 into User
insert users2 into User
}!
}
struct UserReq {
name ?string @[json: 'name']
nickname ?string @[json: 'nickname']
mobile ?string @[json: 'mobile']
email ?string @[json: 'email']
}
fn dynamic_update_users(mut db sqlite.DB, req UserReq) ! {
name_dyn := 'Avey'
update_expr := {
if m := req.mobile { mobile == m },
//name == name_dyn
}
sql db {
dynamic update User set update_expr where id == '2'
}!
}
v fmt -w test.v
Proposed Solution
Annotated code should be retained, even if it contains valid V syntax. The formatting tool should:
Keep all comments, including those containing code
Do not delete any comment lines
Describe the feature
Comments in orm expressions will be removed by vfmt
Use Case
v fmt -w test.vProposed Solution
Annotated code should be retained, even if it contains valid V syntax. The formatting tool should:
Keep all comments, including those containing code
Do not delete any comment lines
Other Information
No response
Acknowledgements
Version used
V 0.5.1 f34a22f
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.