This commit is contained in:
Tyrel Souza 2022-10-17 18:35:48 -04:00
parent 470b213e29
commit f85ba44ec0
No known key found for this signature in database
GPG Key ID: F6582CF1308A2360

View File

@ -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
~~~~~~~~~~~~~~~~~~~~~~~
@ -156,6 +156,7 @@ This will return a slice of Albums - but if you notice on the second line, you h
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.
(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 <https://gitea.tyrel.dev/tyrel/go-webservice-gin>`_
* `Go, Gin, sqlx <https://gitea.tyrel.dev/tyrel/go-webservice-gin-sqlx>`_
Notes
~~~~~
I sent this blog post to my friend `Andrey <https://shazow.net/>`_ 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 <https://docs.sqlalchemy.org/en/14/core/>`_ vs using `SqlAlchemy orm <https://docs.sqlalchemy.org/en/14/orm/>`_.
As the sort of equivalent to ``pymysql`` in Go is ``database/sql`` from the stdlib.