Skip to content
gplusql is a package which provide database operation
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
go.mod
gplusql.go
gplusql_test.go

README.md

gplusql

  • gplusql is a package which provide database operation
  • Support transaction
  • Support Mysql Sqlite3 Postgresql

Usage

  • First you should import your database sqldriver.
  • GqlFindRow to Find a singlerow data from database
  • GqlFindRows to Find rows data from database
package main

import (
     "github.com/taigacute/gplusql"
    _"github.com/go-sql-driver/mysql"
)

func main(){
    databasetype :="mysql"
    dsn :="user:password@tcp(127.0.0.1:3306)/test"
    db :=gplusql.DataFactory(databasetype,dsn)
    err:=db.DataBaseConnection()
    if err!=nil{
        panic(err)
    }
    sql :="SELECT * FROM test"
    rows:=db.GqlFindRows(sql)
    defer rows.Close()
    for rows.Next(){
        //do something
    }
}
  • the insert, update, delete operation based on transaction
  • if the operation failed the data will not insert into you database. it will do tx.Rollback() to Rollback, its very useful when you perform a bulk import to database
package main

import (
     "github.com/taigacute/gplusql"
    _"github.com/go-sql-driver/mysql"
)

func main(){
    databasetype :="mysql"
    dsn :="user:password@tcp(127.0.0.1:3306)/test"
    db :=gplusql.DataFactory(databasetype,dsn)
    err:=db.DataBaseConnection()
    if err!=nil{
        panic(err)
    }
    // you can write Insert Delete Update in this sql
    sql :="INSERT INTO test values(?,?,?)"
    err :=gplusql.GqlExec(sql,value1,value2,value3)
    if err!=nil{
        log.Println(err)
    }
}

ToDo

  • Support Redis MongoDb
  • Support Read and write separation
You can’t perform that action at this time.