Let's make a Query builder using Go

Factory pattern?

Factory pattern is a creational pattern that provides one of the best way to create object. In this case, you don’t have to take panic about how the object created, what is going on underneath. Learn more about it here…

Singleton pattern?

In singleton pattern ensure a class can only one object is created. If you want to create another instance from that particular class it will provide you the previously created object. Read more about it here…

Builder pattern?

The builder pattern is a design pattern designed to provide a flexible solution to various object creation problems in object-oriented programming. The intent of the Builder design pattern is to separate the construction of a complex object from its representation

Let's build a fake Query builder to simulate the factory + singleton pattern

Make a querybuilder directory inside $GOPATH/src/ and create these files.

Directory Structure
db.go
mysql.go
sqlite.go
mongodb.go
main.db

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Saddam H

Saddam H

Software Engineer, Pathao Inc | Open Source Enthusiast | Love to write elegant code | Gopher by passion | https://thedevsaddam.github.io