1. 9

Hi, I’m considering using Golang for my main language for web development, I’m trying to see if there is anything resembling Python’s SQLAlchemy - basicly elliminating text query stitching (and to be clear I know SQL itself).

And a web framework that would resemble Pyramid web framework functionally wise.

I’m also trying to wrap my head around the fact that there are tons of db drivers, when I looked last time 2 years ago I was completely unsure which one would be the right to use - are there some “language standards” that are most used and supported well by community?


  2. 8

    Backing up a bit, what kind of web apps are you building, and what makes you interested in using Go for it?

    1. 2

      Apart “standard” CRUD stuff, some of the applications would benefit from first class asynchroneous support and sometimes they do quite a bit of data crunching so the ability to utilize all cores would be a plus. I can sidestep most of the problems of python but a strongly typed and faster language wouldn’t hurt. Although I can see that lack of generics brings its own problems to the table.

      1. 7

        I’ve only worked with Go a bit, and I’m rather skeptical of it’s efficiency for developing CRUD apps. Nothing posted in the rest of this thread so far has inclined me to think otherwise. I could see a couple of ways to go then:

        1. Just implement it all in Python or something, wait and see what parts (if any) are hurting from lack of concurrency, raw computation speed, and strong typing, then convert those bits to Go, and communicate with the web process via whatever makes sense.

        2. Design with a front-end in something more convenient and a computation back-end in Go from the start, thus having the communication designed well from the start and avoiding trying to implement something in Python that probably won’t do the job well enough.

        3. All-in on Go, make it all in Go, whatever warts it may have for CRUD basics.

        If you’re thinking hard about 3, I’d try and pick up whatever frameworks look decent here and build a simple demo CRUD webapp in Go with 1 or 2 models and see how that goes before making the call.

        I also wonder if an all-Go webapp would pair well with a frontend-heavy design with React and Redux. Let the front-end stuff handle the templating and most of the routing, and let the Go code do what it’s best at - slinging JSON and DB queries around and computing business logic.

        1. 3

          Keep in mind that concurrency in Go is very easy to use, but hard to master, as it’s super low-level.

          You might want to take a look at Elixir.

          1. 1

            Elixir ecosystem is a lot smaller than Go I think? Wouldn’t Rust or Kotlin be a better choice?

            1. 3

              Elixir runs on the Erlang VM which is one of the most robust and mature ecosystems of all. If you’re not familiar with Erlang, take a look at the history (it was developed for telecommunications) and then a look at Elixir itself.

              If you want to write web applications, http://phoenixframework.org/ is the web framework in the Elixir world. It’s still quite modular, so it’s easy to start your own project from parts (persistence, webserver, request handling) without using the whole framework.

              1. 1

                I wasn’t aware that Elixir is compatible with existing Erlang (I’m perfectly aware erlang is mature) libraries, I will take a look at that in spare time, thanks.

          2. 2

            If you need asynchronous support to handle a huge amount of concurrent user connections, Go will be valuable. If the async stuff and data crunching you need would work as asynchronous background jobs, then writing the web app in Python, using a job queue, and writing the job runners in Go would be a good move. Or even Python with numpy if applicable, since numpy will be faster and easier than Go at matrix math and the other things it specializes in.

            I personally don’t like Go for web development. It’s a lower level language that’s great for writing network services in general, but slinging HTML is on the tedious side.

            I’m also trying to wrap my head around the fact that there are tons of db drivers, when I looked last time 2 years ago I was completely unsure which one would be the right to use - are there some “language standards” that are most used and supported well by community?

            For what database? For Postgres, github.com/lib/pq is the de facto standard; for MySQL, github.com/go-sql-driver/mysql. They are both used by the Go project for integration tests of database/sql, as described on the github.com/golang/go wiki page here.

        2. 5

          There are various ORMs/mappers, but most advice you’ll find (and what I’ll say, also) is to not use them. Wrap a database connection in a struct that has methods to do what you want. Something I’ve found conditionally useful are generators to write the function to populate a struct from a database row.

          The community will also say to not use web frameworks, and again I’d agree. The stdlib http package provides a stable foundation for what you want to do. You’ll have more luck looking for packages that do what specific thing you want, rather than thinking in terms of frameworks.

          All that said, some coworkers like echo but I can’t for the life of me understand why. Any web-oriented package shouldn’t need to give a shit if it’s hooked up to a tty or not.

          1. 3

            The problem is that when you do search and filtering on various conditions (like in a shop) you don’t want to resort to sql string stitching, I wasn’t able to find anything nice when I looked at the docs, for example in gorm:

            db.Where("name = ? AND age >= ?", "jinzhu", "22") - I expect that when you have 20 conditions with different operators and data types you will end up having a bad time.

            1. 4

              I’m at a small scale but I just write the query entirely and or do string concatenation. I’m having a fine time though. I just use sqlx.

              1. 2


                https://godoc.org/github.com/jmoiron/sqlx#In is pretty useful when you need it.

                1. 3

                  I admit I don’t understand how to use that from the doc string. Could you show a simple example or elaborate?

                  1. 4

                    It’s useful for queries using the IN keyword, like this:

                    query, params, errIn := sqlx.In("SELECT column1 FROM table WHERE something IN (?);", some_slice)
                    // if errIn != nil...
                    rows, errQuery := db.Query(query, params...)
                2. 2

                  We built something in house that is very similar in spirit to sqlx but adds a bunch of helpers.


                3. 4

                  https://github.com/Masterminds/squirrel (which kallax uses) seems somewhat akin to the SQLAlchemy expression API. (And yeah, to me, that’s a great part of SQLAlchemy; I’ve hardly used its ORM in comparison.)

                  I went from Python + heavy use of the SQLAlchemy expression API to Go and got by OK with just stdlib, but part of that was that the work in Go had far less complicated queries most of the time. So, not the best comparison maybe.

                  1. 2

                    I support the advice to not use mappers like ORMs, but I also agree with what you said. The middle ground seems to be query builders.

                    If you use Postgres as your DBMS by any chance, I advise you to make sure that the query abstraction layer of your choice doesn’t do query parameterization by string interleaving but utilizes PQexecParams underneath instead.

                    1. 1

                      I haven’t used it but I think Dropbox built a library for that. https://godoc.org/github.com/dropbox/godropbox/database/sqlbuilder

                  2. 5

                    A bit of shameless self-promotion, but I’m really proud of a library some friends at my company made called DBX: https://github.com/spacemonkeygo/dbx/

                    It’s like SQLAlchemy, but completely type-safe and determined at compile-time. Many other Go ORMs aren’t quite as type-safe and do a lot of runtime reflection. DBX takes a schema upfront and generates multiple database backends and Go code to interact with your database in a type-safe way.

                    It’s neat, check it out!

                    1. 2

                      Just my two cents, but those seem like pretty basic questions for somebody considering a jump to Go as their “main language for web development”.

                      Why not work through some tutorials or create some toy projects first? It would give you an overview of the state of Go web development, and potentially save a lot of time if it doesn’t work out.

                      1. 1

                        I’m not concerned by language syntax for example, I’m more interested in robustness of specific parts of ecosystem, mainly db interaction. I’m sure for toy projects any language would work fine if i’d try to build lets say a blog - I already got a lot of info here that is valuable for me,.

                      2. 2

                        I recently did some due diligence on this. When I was doing go web apps 4 years ago, I did everything by hand. These days there are many more options. I chose kallax for my needs. Here are the three that stood out to me:

                        and somewhat recent discussion here with a few more mentioned: https://www.reddit.com/r/golang/comments/66a9gj/kallax_why_we_built_yet_another_orm_for_go/

                        1. 1

                          No comment on the Go-thing, but it might be interesting to wrap your data logic in stored procedures and work from there.

                          1. -4

                            The language is called Go :)

                            1. 10

                              I have found it useful to use “golang” when doing google searches.

                              1. 13

                                There are two languages called Go as far as I can tell :-) I thought using Golang is nice way to differentiate.

                                1. 2

                                  Rob disagrees :)

                                  1. 9

                                    You make a pedantic comment that ignores the common use of “Golang” to refer to the Go language. Your defense of this comment is the appeal to authority fallacy. None of this has been constructive, insightful, or even particularly correct.

                                    1. 0

                                      Your defense of this comment is the appeal to authority fallacy

                                      Is Rob Pike not a trusted authority with a relevant opinion here?

                                      1. 0

                                        Rob Pike is an authority and his opinion is relevant. But if Rob Pike’s opinion is correct, it is not because he is Rob Pike. Thus, “because Rob Pike said so” is not a winning argument. The fallacy of the appeal to authority is not that authorities aren’t authorities. It’s just that what authorities say, like anything anyone says, must be proven.

                                    2. 13

                                      Rob is wrong.

                                      1. 0

                                        Yeah, some random internet commenter knows better what the name of the language is than its creator.

                                        1. 6

                                          Creating something does not mean that one automatically has a good idea of what a good name, method or workflow is for other people.

                                          1. -3

                                            Creating something most certainly gives you the exclusive right of giving it a name, regardless of what someone else thinks about that name. Otherwise I’m just going to call you Martin Shkreli from now on.