mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
fmt: fix alignment of struct init fields (#22025)
This commit is contained in:
parent
99da5726db
commit
c51d30bf53
671 changed files with 18817 additions and 18787 deletions
|
@ -43,7 +43,7 @@ import db.mysql
|
|||
// Create connection
|
||||
mut connection := mysql.Connection{
|
||||
username: 'root'
|
||||
dbname: 'mysql'
|
||||
dbname: 'mysql'
|
||||
}
|
||||
// Connect to server
|
||||
connection.connect()?
|
||||
|
@ -60,4 +60,4 @@ for user in get_users_query_result.maps() {
|
|||
get_users_query_result.free()
|
||||
// Close the connection if needed
|
||||
connection.close()
|
||||
```
|
||||
```
|
|
@ -384,7 +384,7 @@ pub fn (db &DB) prepare(query string) !StmtHandle {
|
|||
|
||||
return StmtHandle{
|
||||
stmt: stmt
|
||||
db: DB{
|
||||
db: DB{
|
||||
conn: db.conn
|
||||
}
|
||||
}
|
||||
|
@ -398,10 +398,10 @@ pub fn (stmt &StmtHandle) execute(params []string) ![]Row {
|
|||
mut bind_params := []C.MYSQL_BIND{}
|
||||
for param in params {
|
||||
bind := C.MYSQL_BIND{
|
||||
buffer_type: mysql_type_string
|
||||
buffer: param.str
|
||||
buffer_type: mysql_type_string
|
||||
buffer: param.str
|
||||
buffer_length: u32(param.len)
|
||||
length: 0
|
||||
length: 0
|
||||
}
|
||||
bind_params << bind
|
||||
}
|
||||
|
@ -428,10 +428,10 @@ pub fn (stmt &StmtHandle) execute(params []string) ![]Row {
|
|||
mut binds := []C.MYSQL_BIND{}
|
||||
for i in 0 .. num_cols {
|
||||
bind := C.MYSQL_BIND{
|
||||
buffer_type: mysql_type_string
|
||||
buffer: 0
|
||||
buffer_type: mysql_type_string
|
||||
buffer: 0
|
||||
buffer_length: 0
|
||||
length: unsafe { &length[i] }
|
||||
length: unsafe { &length[i] }
|
||||
}
|
||||
binds << bind
|
||||
}
|
||||
|
|
|
@ -42,58 +42,58 @@ fn test_mysql_orm() {
|
|||
return
|
||||
}
|
||||
mut db := mysql.connect(
|
||||
host: '127.0.0.1'
|
||||
port: 3306
|
||||
host: '127.0.0.1'
|
||||
port: 3306
|
||||
username: 'root'
|
||||
password: ''
|
||||
dbname: 'mysql'
|
||||
dbname: 'mysql'
|
||||
)!
|
||||
defer {
|
||||
db.close()
|
||||
}
|
||||
db.create('Test', [
|
||||
orm.TableField{
|
||||
name: 'id'
|
||||
typ: typeof[int]().idx
|
||||
name: 'id'
|
||||
typ: typeof[int]().idx
|
||||
attrs: [
|
||||
VAttribute{
|
||||
name: 'primary'
|
||||
},
|
||||
VAttribute{
|
||||
name: 'sql'
|
||||
name: 'sql'
|
||||
has_arg: true
|
||||
kind: .plain
|
||||
arg: 'serial'
|
||||
kind: .plain
|
||||
arg: 'serial'
|
||||
},
|
||||
]
|
||||
},
|
||||
orm.TableField{
|
||||
name: 'name'
|
||||
typ: typeof[string]().idx
|
||||
name: 'name'
|
||||
typ: typeof[string]().idx
|
||||
attrs: []
|
||||
},
|
||||
orm.TableField{
|
||||
name: 'age'
|
||||
typ: typeof[int]().idx
|
||||
typ: typeof[int]().idx
|
||||
},
|
||||
]) or { panic(err) }
|
||||
|
||||
db.insert('Test', orm.QueryData{
|
||||
fields: ['name', 'age']
|
||||
data: [orm.string_to_primitive('Louis'), orm.int_to_primitive(101)]
|
||||
data: [orm.string_to_primitive('Louis'), orm.int_to_primitive(101)]
|
||||
}) or { panic(err) }
|
||||
|
||||
res := db.@select(orm.SelectConfig{
|
||||
table: 'Test'
|
||||
table: 'Test'
|
||||
has_where: true
|
||||
fields: ['id', 'name', 'age']
|
||||
types: [typeof[int]().idx, typeof[string]().idx, typeof[i64]().idx]
|
||||
fields: ['id', 'name', 'age']
|
||||
types: [typeof[int]().idx, typeof[string]().idx, typeof[i64]().idx]
|
||||
}, orm.QueryData{}, orm.QueryData{
|
||||
fields: ['name', 'age']
|
||||
data: [orm.Primitive('Louis'), i64(101)]
|
||||
types: [typeof[string]().idx, typeof[i64]().idx]
|
||||
data: [orm.Primitive('Louis'), i64(101)]
|
||||
types: [typeof[string]().idx, typeof[i64]().idx]
|
||||
is_and: [true, true]
|
||||
kinds: [.eq, .eq]
|
||||
kinds: [.eq, .eq]
|
||||
}) or { panic(err) }
|
||||
|
||||
id := res[0][0]
|
||||
|
@ -179,7 +179,7 @@ fn test_mysql_orm() {
|
|||
}
|
||||
|
||||
model := TestTimeType{
|
||||
username: 'hitalo'
|
||||
username: 'hitalo'
|
||||
created_at: today
|
||||
updated_at: today.str()
|
||||
deleted_at: today
|
||||
|
|
|
@ -7,11 +7,11 @@ fn test_mysql() {
|
|||
return
|
||||
}
|
||||
config := mysql.Config{
|
||||
host: '127.0.0.1'
|
||||
port: 3306
|
||||
host: '127.0.0.1'
|
||||
port: 3306
|
||||
username: 'root'
|
||||
password: ''
|
||||
dbname: 'mysql'
|
||||
dbname: 'mysql'
|
||||
}
|
||||
|
||||
db := mysql.connect(config)!
|
||||
|
|
|
@ -133,9 +133,9 @@ pub fn (db DB) insert(table string, data orm.QueryData) ! {
|
|||
|
||||
converted_primitive_data := orm.QueryData{
|
||||
fields: data.fields
|
||||
data: converted_primitive_array
|
||||
types: []
|
||||
kinds: []
|
||||
data: converted_primitive_array
|
||||
types: []
|
||||
kinds: []
|
||||
is_and: []
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,11 @@ fn test_prep() {
|
|||
return
|
||||
}
|
||||
config := mysql.Config{
|
||||
host: '127.0.0.1'
|
||||
port: 3306
|
||||
host: '127.0.0.1'
|
||||
port: 3306
|
||||
username: 'root'
|
||||
password: ''
|
||||
dbname: 'mysql'
|
||||
dbname: 'mysql'
|
||||
}
|
||||
|
||||
db := mysql.connect(config)!
|
||||
|
|
|
@ -93,26 +93,26 @@ pub fn (r Result) fields() []Field {
|
|||
for i in 0 .. nr_cols {
|
||||
unsafe {
|
||||
fields << Field{
|
||||
name: mystring(orig_fields[i].name)
|
||||
org_name: mystring(orig_fields[i].org_name)
|
||||
table: mystring(orig_fields[i].table)
|
||||
org_table: mystring(orig_fields[i].org_table)
|
||||
db: mystring(orig_fields[i].db)
|
||||
catalog: mystring(orig_fields[i].catalog)
|
||||
def: resolve_nil_str(orig_fields[i].def)
|
||||
length: orig_fields.length
|
||||
max_length: orig_fields.max_length
|
||||
name_length: orig_fields.name_length
|
||||
org_name_length: orig_fields.org_name_length
|
||||
table_length: orig_fields.table_length
|
||||
name: mystring(orig_fields[i].name)
|
||||
org_name: mystring(orig_fields[i].org_name)
|
||||
table: mystring(orig_fields[i].table)
|
||||
org_table: mystring(orig_fields[i].org_table)
|
||||
db: mystring(orig_fields[i].db)
|
||||
catalog: mystring(orig_fields[i].catalog)
|
||||
def: resolve_nil_str(orig_fields[i].def)
|
||||
length: orig_fields.length
|
||||
max_length: orig_fields.max_length
|
||||
name_length: orig_fields.name_length
|
||||
org_name_length: orig_fields.org_name_length
|
||||
table_length: orig_fields.table_length
|
||||
org_table_length: orig_fields.org_table_length
|
||||
db_length: orig_fields.db_length
|
||||
catalog_length: orig_fields.catalog_length
|
||||
def_length: orig_fields.def_length
|
||||
flags: orig_fields.flags
|
||||
decimals: orig_fields.decimals
|
||||
charsetnr: orig_fields.charsetnr
|
||||
type_: FieldType(orig_fields.@type)
|
||||
db_length: orig_fields.db_length
|
||||
catalog_length: orig_fields.catalog_length
|
||||
def_length: orig_fields.def_length
|
||||
flags: orig_fields.flags
|
||||
decimals: orig_fields.decimals
|
||||
charsetnr: orig_fields.charsetnr
|
||||
type_: FieldType(orig_fields.@type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ pub fn (s &Stmt) str() string {
|
|||
// init_stmt creates a new statement, given the `query`.
|
||||
pub fn (db DB) init_stmt(query string) Stmt {
|
||||
return Stmt{
|
||||
stmt: C.mysql_stmt_init(db.conn)
|
||||
stmt: C.mysql_stmt_init(db.conn)
|
||||
query: query
|
||||
binds: []C.MYSQL_BIND{}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ pub fn (stmt Stmt) error(code int) IError {
|
|||
msg := stmt.get_error_msg()
|
||||
|
||||
return &SQLError{
|
||||
msg: '${msg} (${code}) (${stmt.query})'
|
||||
msg: '${msg} (${code}) (${stmt.query})'
|
||||
code: code
|
||||
}
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ pub fn (mut stmt Stmt) bind_text(b string) {
|
|||
pub fn (mut stmt Stmt) bind_null() {
|
||||
stmt.binds << C.MYSQL_BIND{
|
||||
buffer_type: mysql.mysql_type_null
|
||||
length: 0
|
||||
length: 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,10 +257,10 @@ pub fn (mut stmt Stmt) bind_null() {
|
|||
// Note: it is more convenient to use one of the other bind_XYZ methods.
|
||||
pub fn (mut stmt Stmt) bind(typ int, buffer voidptr, buf_len u32) {
|
||||
stmt.binds << C.MYSQL_BIND{
|
||||
buffer_type: typ
|
||||
buffer: buffer
|
||||
buffer_type: typ
|
||||
buffer: buffer
|
||||
buffer_length: buf_len
|
||||
length: 0
|
||||
length: 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,8 +269,8 @@ pub fn (mut stmt Stmt) bind_res(fields &C.MYSQL_FIELD, dataptr []&u8, lengths []
|
|||
for i in 0 .. num_fields {
|
||||
stmt.res << C.MYSQL_BIND{
|
||||
buffer_type: unsafe { fields[i].@type }
|
||||
buffer: dataptr[i]
|
||||
length: &lengths[i]
|
||||
buffer: dataptr[i]
|
||||
length: &lengths[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue