Add db.InsertStruct(Table, *interface{}) support #22

Open
opened 2017-02-11 12:59:23 +00:00 by lunny · 2 comments
Owner

Author: @steelbrain

This package is extremely helpful when you want to simplify sql usage in your app without requiring the fullness of xorm so thank you for writing it.

One thing that would make this library a lot more useful is a new func on core.DB, It should allow users to specify the table and provide the struct and automatically generate the required sql for it.

For example

user = User{
    Name:"lunny",
    Title:"test",
    Age: 18,
}
result, err = db.ExecStruct("insert into user (`name`, title, age, alias, nick_name,created) values (?Name,?Title,?Age,?Alias,?NickName,?Created)",
            &user)

would become

user = User{
    Name:"lunny",
    Title:"test",
    Age: 18,
}
result, err = db.InsertStruct("user", &user)

What do you think?

Author: @steelbrain This package is extremely helpful when you want to simplify sql usage in your app without requiring the fullness of xorm so thank you for writing it. One thing that would make this library a lot more useful is a new func on `core.DB`, It should allow users to specify the table and provide the struct and automatically generate the required sql for it. For example ``` user = User{ Name:"lunny", Title:"test", Age: 18, } result, err = db.ExecStruct("insert into user (`name`, title, age, alias, nick_name,created) values (?Name,?Title,?Age,?Alias,?NickName,?Created)", &user) ``` would become ``` user = User{ Name:"lunny", Title:"test", Age: 18, } result, err = db.InsertStruct("user", &user) ``` What do you think?
Author
Owner

Author: @lunny

It has been implemented by XORM I think. And this feature will consider name mapping and different database quotes. So this needs many works I think.

Author: @lunny It has been implemented by XORM I think. And this feature will consider name mapping and different database quotes. So this needs many works I think.
Author
Owner

Author: @steelbrain

@lunny You are correct, a similar solution is available in xorm. The solution present in xorm requires the user to create an engine and go through all that trouble, there are usecases when you just want to execute some raw sql while still having a cleaner way to perform inserts.

But if the request is out of the scope of this package, please do let me know

Author: @steelbrain @lunny You are correct, a similar solution is available in xorm. The solution present in xorm requires the user to create an engine and go through all that trouble, there are usecases when you just want to execute some raw sql while still having a cleaner way to perform inserts. But if the request is out of the scope of this package, please do let me know
This repo is archived. You cannot comment on issues.
No Milestone
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/core#22
No description provided.