Skip to content

oussama4/sqlbuilder

Repository files navigation

A simple package for building sql queries in Go.

Go Reference

Usage

Basic queries

Select

// query: SELECT * FROM products
query, _ := sqlbuilder.Select("*").From("products").
		Query()

// query: SELECT id, title FROM products
query, _ := sqlbuilder.Select("id", "title").From("products").
		Query()

Update

// query: UPDATE products SET title = $1
// args: []interface{}{"new title"}
query, args := sqlbuilder.Update("products").
		Set("title", "new title").
		Query()

Insert

// query: INSERT INTO products (title, description)
// 		  VALUES ($1, $2)
// args: []interface{}{"new title", "new description"}
query, args := sqlbuilder.Insert("products").
		Columns("title", "description").
		Values("new title", "new desscription").
		Query()

Delete

// query: DELETE FROM products
query, _ := sqlbuilder.DeleteFrom("products").Query()