Working with the MySQL in GO

MySQL in GO.

Today I want to tell about my little experience with MySQL (although you can use any other database here) in Go.

I found a great way to work with the database from Go and can’t wait to share it.

In general, Go has several important things to do in order to make inquiries. For example, `database/sql` and ``

A typical example looks like this:

And in order to map the query result into a structure, we will use ``.

sqlx is a set of extensions on top of the `database/sql` that allow you to make a minimal “ORM” in Go.

For example, we work with such a model

We have a simple database scheme

The connection to the database will look like this

Sqlx has a bunch of methods, which start with a Must. MustExec, MustBegin. You have to use them with caution because they throw panic and your application can crash when you do not want it :)

CRUDs will look like this

That’s all. Just in case, the complete code:

Custom Software and Mobile App Development.
Application Design Proccess.

Software architecture 101 - introduction to the world...

Software architecture 101 -...

Software architecture 101 - introduction to the world of application design

Hello, everyone!Today, I would like to introduce you to the world of application design.Designing applications can be called a multidisciplinary...

Dec 17, 2020
Mad Devs Internship Program Automation.

Mad Devs internship program automation

Mad Devs internship program automation

Mad Devs internship program automation

Mad Devs has an Internship program for different programming languages. The communication with interns takes place in Telegram messenger. 5...

Jul 17, 2019

Underestimating Go

Underestimating Go

Underestimating Go

Hi, I’m Pavel!I’m a software engineer in Mad Devs. In the past six years, I’ve been working with Ruby and Rails, also I love React and Redux. I was a...

Aug 20, 2019