From f85ba44ec06bcfb3776e4e97c4a5c923a8f3dab7 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 17 Oct 2022 18:35:48 -0400 Subject: [PATCH] update --- .../2022-10-17_comparing-go-gorm-and-sqlx.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/content/blog/2022-10-17_comparing-go-gorm-and-sqlx.rst b/content/blog/2022-10-17_comparing-go-gorm-and-sqlx.rst index fd273b7..d7ea1a6 100644 --- a/content/blog/2022-10-17_comparing-go-gorm-and-sqlx.rst +++ b/content/blog/2022-10-17_comparing-go-gorm-and-sqlx.rst @@ -2,8 +2,8 @@ Comparing Go GORM and SQLX ########################## :author: tyrel :category: Tech -:tags: go, sql, python -:status: draft +:tags: go, sql, python, gorm, sqlx +:status: published Django ORM - My History ~~~~~~~~~~~~~~~~~~~~~~~ @@ -155,7 +155,8 @@ Here is where the main part of GORM/SQLX differ - raw SQL shows up. This will return a slice of Albums - but if you notice on the second line, you have to write your own queries. A little bit more in control of how things happen, with a ``SELECT * ...`` vs the gorm ``DB.Find`` style. -To me this feels more like using ``pymysql``, in fact its a very similar process. +To me this feels more like using ``pymysql``, in fact its a very similar process. +(SEE NOTE BELOW) You use the ``service.connection.Get`` and pass in what you want the output bound to, the string query, and any parameters. This feels kind of backwards to me - I'd much rather have the order be: query, bound, parameters, but thats what they decided for their order. @@ -177,3 +178,12 @@ Repositories * `Go, Gin, Gorm `_ * `Go, Gin, sqlx `_ + +Notes +~~~~~ + +I sent this blog post to my friend `Andrey `_ and he mentioned that I was incorrect with my comparision of sqlx to pymysql. +To put it in a python metaphor, "sqlx is like using urllib3, gorm is like using something that generates a bunch of requests code for you." +Sqlx is more akin to `SqlAlchemy core `_ vs using `SqlAlchemy orm `_. +As the sort of equivalent to ``pymysql`` in Go is ``database/sql`` from the stdlib. +