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 github.com/go-sql-driver/mysql

A typical example looks like this:

And in order to map the query result into a structure, we will use github.com/jmoiron/sqlx.

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.
WebRTC.

What to choose to implement audio/video calls solution...

What to choose to implement...

What to choose to implement audio/video calls solution using WebRTC?

Mad Devs have been working with WebRTC since 2013. We have implemented several projects with video or audio calls enabled. That’s why I want to share...

Yellow Taxi Car.

How we built failover architecture for a taxi service...

How we built failover architecture...

How we built failover architecture for a taxi service part 1 (intro)

This article is the Part 1 of detailed description of my talk at HighLoad++ 2015.Today Namba Taxi is the leading passenger transportation company in...

Uber-like Map with Animated Cars.

How we built a backend system for Uber-like map with...

How we built a backend system for...

How we built a backend system for Uber-like map with animated cars using Go

Hello there. It’s my first blog post in English and I’m going to tell you how we built simple in-memory storage for animated cars. We show animated...