This is my first post to this mailing list, and wouldn't you know it, I
totally forgot to include the link to the repo. Talk about a bad first
impression! Here it is: https://github.com/jmacwhyte/sqlez
On Saturday, March 4, 2017 at 9:25:29 PM UTC-8, jmacwhyte wrote:
>
> Hello all,
>
> After seeing a need for simplifying SQL databases in Go, I have written a
> new package that makes it very easy to do basic SELECT, INSERT, and UPDATE
> database operations. Essentially you define a struct that corresponds with
> the data in your database, and then you can simply pass that struct to my
> package to insert and retrieve data. I'm now using it in one of my
> projects, and it has reduced database-related code by 60%, making things
> much more readable!
>
> Here's how easy it is to retrieve some info, make some changes, and return
> it to the database:
>
> type SumoWreslter struct {
> Name string `db:"name"`
> Age int `db:"age"`
> Rank string `db:"level"`
> }
>
> func main() {
> db, err := sqlez.Open("databaseDriver", "dataSource")
>
> tooOld := 30
>
> results, err := db.SelectFrom("wrestlers", SumoWreslter{}, sqlez.Params{
> Where: `age < ? AND level = "master"`,
> OrderBy: `age DESC`,
> Limit: 1,
> }, tooOld)
>
> theOne := results[0].(SumoWreslter)
> theOne.Rank = "grand master"
> // Manipulate data further
>
> _, err := db.Update("wrestlers", theOne, sqlez.Params{
> Where: `name = ?`,
> }, theOne.Name)
> }
>
> // Done!
>
> I think it's a very handy tool, especially for getting started quickly. It
> can handle embedded structs, it can store and retrieve Go datatypes like
> structs and maps using JSON, and uses sql.NullString under the hood to
> avoid errors when trying to pull TEXT columns that are NILL.
>
> I would love any feedback or suggestions, both on the code and the
> documentation I've written (which is geared more for people who are new-ish
> to Go).
>
> Thanks!
> James
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.