FAQ
Hello, everyone.

I recently created a tool that generates code to convert sql.Row(s) into
any structs you define. I've used it for my own small project and it worked
well. I was wondering if I could get some feedback from the community about
his approach of working with databases.

The project is github.com/variadico/scaneo. The readme contains usage info
and a quick tutorial.

Thanks!

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Egon at Jun 1, 2015 at 6:43 am

    On Monday, 1 June 2015 06:35:57 UTC+3, Jaime wrote:
    Hello, everyone.

    I recently created a tool that generates code to convert sql.Row(s) into
    any structs you define. I've used it for my own small project and it worked
    well. I was wondering if I could get some feedback from the community about
    his approach of working with databases.

    The project is github.com/variadico/scaneo. The readme contains usage
    info and a quick tutorial.

    Thanks!
    Maybe name it to something clearer, e.g. "structscanner", "structscan",
    "scanstruct", "dbstruct", that way you can write it's more understandable
    what it does, e.g.

    //go:generate dbstruct -t Post
    type Post struct {
         ID int
         Created time.Time
         Published pq.NullTime
         Draft bool
         Title string
         Body string
    }

    Usually, I don't have a separate "models" package, it slices up the
    architecture the wrong way. I have a package per concept/feature. For
    example https://github.com/egonelbre/event/tree/master/example/guestlist
    there is a package "invitation" that contains model, logic, service
    together.

    Basically, could you add a flag that would allow a type as a parameter. :)

    Anyways... nice work :)

    + Egon

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jaime at Jun 1, 2015 at 5:52 pm
    Thanks, Egon!

    In my particular case, I ended up with a models package because I found
    that I would end up redefining the same structs over again in other
    packages.

    Anyway, I can totally add a flag to filter types. Sounds like a good idea.
    On Sunday, May 31, 2015 at 11:43:38 PM UTC-7, Egon wrote:
    On Monday, 1 June 2015 06:35:57 UTC+3, Jaime wrote:

    Hello, everyone.

    I recently created a tool that generates code to convert sql.Row(s) into
    any structs you define. I've used it for my own small project and it worked
    well. I was wondering if I could get some feedback from the community about
    his approach of working with databases.

    The project is github.com/variadico/scaneo. The readme contains usage
    info and a quick tutorial.

    Thanks!
    Maybe name it to something clearer, e.g. "structscanner", "structscan",
    "scanstruct", "dbstruct", that way you can write it's more understandable
    what it does, e.g.

    //go:generate dbstruct -t Post
    type Post struct {
    ID int
    Created time.Time
    Published pq.NullTime
    Draft bool
    Title string
    Body string
    }

    Usually, I don't have a separate "models" package, it slices up the
    architecture the wrong way. I have a package per concept/feature. For
    example https://github.com/egonelbre/event/tree/master/example/guestlist
    there is a package "invitation" that contains model, logic, service
    together.

    Basically, could you add a flag that would allow a type as a parameter. :)

    Anyways... nice work :)

    + Egon
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Egon at Jun 1, 2015 at 6:07 pm

    On Monday, 1 June 2015 20:52:22 UTC+3, Jaime wrote:
    Thanks, Egon!

    In my particular case, I ended up with a models package because I found
    that I would end up redefining the same structs over again in other
    packages.
    I took a quick look at gradeslast, here's what types I would start with:

    grades.User

    student.Info
    instructor.Info

    course.Info
    course.Roster
    course.Enrollment
    course.Offer

    Here we don't have any duplication, clear distinction of features and
    mental model. Once I've layed those out I start writing some, http.Server
    types where each is mapped to a particular URL e.g.

    admin.Server -> /admin/*
    courses.Server -> /course/*
    public.Server -> /*
    ...

    Of course after laying everything out that way... I may merge things
    together to make it more concise.

    That way the focus will be on the features and the value in the software,
    and not the technology behind it.

    + Egon

    Anyway, I can totally add a flag to filter types. Sounds like a good idea.
    On Sunday, May 31, 2015 at 11:43:38 PM UTC-7, Egon wrote:
    On Monday, 1 June 2015 06:35:57 UTC+3, Jaime wrote:

    Hello, everyone.

    I recently created a tool that generates code to convert sql.Row(s)
    into any structs you define. I've used it for my own small project and it
    worked well. I was wondering if I could get some feedback from the
    community about his approach of working with databases.

    The project is github.com/variadico/scaneo. The readme contains usage
    info and a quick tutorial.

    Thanks!
    Maybe name it to something clearer, e.g. "structscanner", "structscan",
    "scanstruct", "dbstruct", that way you can write it's more understandable
    what it does, e.g.

    //go:generate dbstruct -t Post
    type Post struct {
    ID int
    Created time.Time
    Published pq.NullTime
    Draft bool
    Title string
    Body string
    }

    Usually, I don't have a separate "models" package, it slices up the
    architecture the wrong way. I have a package per concept/feature. For
    example https://github.com/egonelbre/event/tree/master/example/guestlist
    there is a package "invitation" that contains model, logic, service
    together.

    Basically, could you add a flag that would allow a type as a parameter. :)

    Anyways... nice work :)

    + Egon
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jaime at Jun 16, 2015 at 6:35 am
    Hey, Egon.

    Sorry for the late reply. I got hit with a bunch of work recently.

    Anyway, I've added a new flag to Scaneo. With the new -w flag, you can
    specify a whitelist of structs to generate scan functions for. This is
    documented in the usage <https://github.com/variadico/scaneo#usage> now too.

    For example, now you can do stuff like this:
    scaneo -w Post file.go <-- only generate scan func for Post struct in
    file.go
    scaneo -w "Foo,bar" dir/ <-- only generate scan func for Foo and bar
    structs in dir/

    Hopefully, this makes Scaneo a little bit more flexible. I'll probably end
    up adding a blacklist as well some time in the future.

    Also, thank you so much for the feedback on gradeslast! That was a project
    for school! :) Now I finally have time to checkout how you laid out your
    guestlist package.

    Thanks again!
    On Monday, June 1, 2015 at 11:07:41 AM UTC-7, Egon wrote:


    On Monday, 1 June 2015 20:52:22 UTC+3, Jaime wrote:

    Thanks, Egon!

    In my particular case, I ended up with a models package because I found
    that I would end up redefining the same structs over again in other
    packages.
    I took a quick look at gradeslast, here's what types I would start with:

    grades.User

    student.Info
    instructor.Info

    course.Info
    course.Roster
    course.Enrollment
    course.Offer

    Here we don't have any duplication, clear distinction of features and
    mental model. Once I've layed those out I start writing some, http.Server
    types where each is mapped to a particular URL e.g.

    admin.Server -> /admin/*
    courses.Server -> /course/*
    public.Server -> /*
    ...

    Of course after laying everything out that way... I may merge things
    together to make it more concise.

    That way the focus will be on the features and the value in the software,
    and not the technology behind it.

    + Egon

    Anyway, I can totally add a flag to filter types. Sounds like a good idea.
    On Sunday, May 31, 2015 at 11:43:38 PM UTC-7, Egon wrote:
    On Monday, 1 June 2015 06:35:57 UTC+3, Jaime wrote:

    Hello, everyone.

    I recently created a tool that generates code to convert sql.Row(s)
    into any structs you define. I've used it for my own small project and it
    worked well. I was wondering if I could get some feedback from the
    community about his approach of working with databases.

    The project is github.com/variadico/scaneo. The readme contains usage
    info and a quick tutorial.

    Thanks!
    Maybe name it to something clearer, e.g. "structscanner", "structscan",
    "scanstruct", "dbstruct", that way you can write it's more understandable
    what it does, e.g.

    //go:generate dbstruct -t Post
    type Post struct {
    ID int
    Created time.Time
    Published pq.NullTime
    Draft bool
    Title string
    Body string
    }

    Usually, I don't have a separate "models" package, it slices up the
    architecture the wrong way. I have a package per concept/feature. For
    example https://github.com/egonelbre/event/tree/master/example/guestlist
    there is a package "invitation" that contains model, logic, service
    together.

    Basically, could you add a flag that would allow a type as a parameter.
    :)

    Anyways... nice work :)

    + Egon
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Matt Sherman at Jun 17, 2015 at 1:37 am
    Nice! Jaime, if you are interested this would make for a nice "typewriter
    <http://clipperhouse.github.io/gen/typewriters/#>" for gen.

    Slightly nicer because one can simply mark up the struct -- the command
    line won't need arguments. Something like:

    // +gen scaneo
    type Post struct {
         ID int
         Created time.Time
         Published pq.NullTime
         Draft bool
         Title string
         Body string
    }
    On Tuesday, June 16, 2015 at 2:35:10 AM UTC-4, Jaime wrote:

    Hey, Egon.

    Sorry for the late reply. I got hit with a bunch of work recently.

    Anyway, I've added a new flag to Scaneo. With the new -w flag, you can
    specify a whitelist of structs to generate scan functions for. This is
    documented in the usage <https://github.com/variadico/scaneo#usage> now
    too.

    For example, now you can do stuff like this:
    scaneo -w Post file.go <-- only generate scan func for Post struct in
    file.go
    scaneo -w "Foo,bar" dir/ <-- only generate scan func for Foo and bar
    structs in dir/

    Hopefully, this makes Scaneo a little bit more flexible. I'll probably end
    up adding a blacklist as well some time in the future.

    Also, thank you so much for the feedback on gradeslast! That was a project
    for school! :) Now I finally have time to checkout how you laid out your
    guestlist package.

    Thanks again!
    On Monday, June 1, 2015 at 11:07:41 AM UTC-7, Egon wrote:


    On Monday, 1 June 2015 20:52:22 UTC+3, Jaime wrote:

    Thanks, Egon!

    In my particular case, I ended up with a models package because I found
    that I would end up redefining the same structs over again in other
    packages.
    I took a quick look at gradeslast, here's what types I would start with:

    grades.User

    student.Info
    instructor.Info

    course.Info
    course.Roster
    course.Enrollment
    course.Offer

    Here we don't have any duplication, clear distinction of features and
    mental model. Once I've layed those out I start writing some, http.Server
    types where each is mapped to a particular URL e.g.

    admin.Server -> /admin/*
    courses.Server -> /course/*
    public.Server -> /*
    ...

    Of course after laying everything out that way... I may merge things
    together to make it more concise.

    That way the focus will be on the features and the value in the software,
    and not the technology behind it.

    + Egon

    Anyway, I can totally add a flag to filter types. Sounds like a good
    idea.
    On Sunday, May 31, 2015 at 11:43:38 PM UTC-7, Egon wrote:
    On Monday, 1 June 2015 06:35:57 UTC+3, Jaime wrote:

    Hello, everyone.

    I recently created a tool that generates code to convert sql.Row(s)
    into any structs you define. I've used it for my own small project and it
    worked well. I was wondering if I could get some feedback from the
    community about his approach of working with databases.

    The project is github.com/variadico/scaneo. The readme contains usage
    info and a quick tutorial.

    Thanks!
    Maybe name it to something clearer, e.g. "structscanner", "structscan",
    "scanstruct", "dbstruct", that way you can write it's more understandable
    what it does, e.g.

    //go:generate dbstruct -t Post
    type Post struct {
    ID int
    Created time.Time
    Published pq.NullTime
    Draft bool
    Title string
    Body string
    }

    Usually, I don't have a separate "models" package, it slices up the
    architecture the wrong way. I have a package per concept/feature. For
    example
    https://github.com/egonelbre/event/tree/master/example/guestlist there
    is a package "invitation" that contains model, logic, service together.

    Basically, could you add a flag that would allow a type as a parameter.
    :)

    Anyways... nice work :)

    + Egon
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Alfonsodev at Jun 1, 2015 at 3:11 pm
    Hi, Nice work!
    I've been working in the same problem but I took a slightly different
    approach, I would like to know your opinions,
    I created a command line tool that generates structs from tables, with
    additional convenience methods, like Save()
    It's also without reflection and trying to not to be too magic

    http://github.com/alfonsodev/yao
    This is an example of model
    <https://github.com/alfonsodev/yao/blob/master/examples/models/usermanager/users.go> (struct)
    generated by yao command,
    The generated code is very simple, doesn't depend on reflect. There is only
    one additional struct called query.go,
    that allows you to chain And, Or , conditions.
    Although it's functional, is still open for design suggestions, for
    instance I already receive feedback about returning a slice of interfaces
    maybe it's not be the best way.

    // UsersWhere returns a query struct, that can chain additional conditions .And, and Or
    // At the end Get method of query it's executed but it returns a slice of interfaces
    // to be able to work with all tables as it's not posible to know the type you want dynamically
       students, error := UM.UsersWhere("Email", "LIKE", "%.edu").Get()// but it could be rework as the following that would return slice of Users in both cases. students, error := UM.UsersWhere("Email", "LIKE", "%.edu").GetUsers() students, error := UM.UsersWhere("Email", "LIKE", "%.edu").Get("Users")


    For the moment it only has support for postgresql, adding support for mysql
    it's as easy as write the equivalent to the postgres adapter
    <https://github.com/alfonsodev/yao/blob/master/adapter/postgresql/postgresql.go>
    On Monday, June 1, 2015 at 5:35:57 AM UTC+2, Jaime wrote:

    Hello, everyone.

    I recently created a tool that generates code to convert sql.Row(s) into
    any structs you define. I've used it for my own small project and it worked
    well. I was wondering if I could get some feedback from the community about
    his approach of working with databases.

    The project is github.com/variadico/scaneo. The readme contains usage
    info and a quick tutorial.

    Thanks!
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 1, '15 at 3:35a
activeJun 17, '15 at 1:37a
posts7
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase