Skip to content

srajelli/sgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sgo

sgo provides easy and fun way to interact with sql database

Build Status Go Report Card

Installation

go get github.com/srajelli/sgo

Usage

Open a DB connection

db, err := sgo.Open("mysql", "username:pass@/dbname")

Just define tag names to your fields. Tag names is equal to column names of the table

type User struct {
  Name        string `sql:"name"`
  Email       string `sql:"email"`
  AccessToken string `sql:"accesstoken"`
}
Select
user := User{}
db.Table("user").
  Where("plan = 'basic'").
  And("name = 'John'").
  Or("email = 'john.due@gmail.com'").
  Get(&user)
  
fmt.Println(user)
Insert
user := User{}
user.Name = "John Due"
user.Email = "john.due@gmail.com"
user.Plan = "basic"

db.Table("users").
  Insert(&user)
Update
user := User{}
user.Plan = "pro"

db.Table("users").Table("users").
  Where("email = 'john.due@gmail.com'").
  Update(&user)
Delete
db.Table("users").Table("users").
  Where("email = 'john.due@gmail.com'").
  Delete()

About

SQL query builder for Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages