in database/sql rows.Scan(…) can only copy values to seperate variables, the 
style is not comfortable ,I want use a struct as database row.

I want to use unexported database/sql.convertAssign,

        type Test struct {
                Name  string
                Age   int
                Email string
        }

        var tests []Test
        var count int

        b := NewSqlBuilder()
        b.Sql(`select * from test where name = ?;
         select count(*) from test;`, "ybj")
        fmt.Println(b.String())
        fmt.Println(b.Params())

        QueryObjects(db, b.String(), b.Params(), []func(r *Record){

                func(r *Record) {
                        var t Test = Test{}
                        r.ConvertAssign(0, &t.Name)
                        r.ConvertAssignByName("age", &t.Age)
                        r.ConvertAssignByName("Email", &t.Email)

                        tests = append(tests, t)
                },
                func(r *Record) {
                        r.ConvertAssign(0, &count)
                },
        })

        fmt.Println(tests)
        fmt.Println(count)

The methods r.ConvertAssign and r.ConvertAssignByName should work keep the same 
with database.sql.ConvertAssign





> On Nov 20, 2018, at 04:41, Ian Lance Taylor <i...@golang.org> wrote:
> 
> On Mon, Nov 19, 2018 at 2:11 AM, iamybj via golang-nuts
> <golang-nuts@googlegroups.com> wrote:
>> 
>> I am dong a simple sql library, but i need access some unexpected members in
>> the std lib.
>> I find this project https://github.com/alangpierce/go-forceexport
>> but it is out of date.\
>> 
>> The authors of golang are some old programmer, but programming language
>> processing for several ten years.
>> golang must borrow new features from c# and java.
>> 
>> reflection should be completely support package, it is not enough  now.
>> 
>> And also, in java and c#, user defined types are the same as runtime types
>> for example these 2 languages can use for..each for user defined types.
>> but in go, for...range can only be applied in system types.
>> 
>> A lot of thing should be done, go process too slow...
> 
> Thanks for the note, but you didn't show us any code.  What do you
> actually want?
> 
> To the best of my knowledge the reflect package lets you do anything
> that you can do in the language itself, except for some very special
> cases like creating a new interface type.
> 
> Ian
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to