2017-06-13 07:12:58 +00:00
|
|
|
/* WIP Under Construction */
|
|
|
|
package qgen
|
2017-06-19 08:06:54 +00:00
|
|
|
|
|
|
|
//import "fmt"
|
2017-06-13 08:56:48 +00:00
|
|
|
import "database/sql"
|
2017-06-13 07:12:58 +00:00
|
|
|
|
2017-06-13 08:56:48 +00:00
|
|
|
var Builder *builder
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Builder = &builder{conn:nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A set of wrappers around the generator methods, so that we can use this inline in Gosora
|
|
|
|
type builder struct
|
2017-06-13 07:12:58 +00:00
|
|
|
{
|
2017-06-13 08:56:48 +00:00
|
|
|
conn *sql.DB
|
|
|
|
adapter DB_Adapter
|
|
|
|
}
|
|
|
|
|
|
|
|
func (build *builder) SetConn(conn *sql.DB) {
|
|
|
|
build.conn = conn
|
|
|
|
}
|
|
|
|
|
|
|
|
func (build *builder) SetAdapter(name string) error {
|
|
|
|
adap, err := GetAdapter(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
build.adapter = adap
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-06-15 11:40:35 +00:00
|
|
|
func (build *builder) SimpleSelect(table string, columns string, where string, orderby string, limit string) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.SimpleSelect("_builder", table, columns, where, orderby, limit)
|
2017-06-13 08:56:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
return build.conn.Prepare(res)
|
2017-06-19 08:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (build *builder) SimpleLeftJoin(table1 string, table2 string, columns string, joiners string, where string, orderby string, limit string) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.SimpleLeftJoin("_builder", table1, table2, columns, joiners, where, orderby, limit)
|
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
//fmt.Println("res",res)
|
|
|
|
return build.conn.Prepare(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (build *builder) SimpleInnerJoin(table1 string, table2 string, columns string, joiners string, where string, orderby string, limit string) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.SimpleInnerJoin("_builder", table1, table2, columns, joiners, where, orderby, limit)
|
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
//fmt.Println("res",res)
|
|
|
|
return build.conn.Prepare(res)
|
2017-06-13 07:12:58 +00:00
|
|
|
}
|
2017-06-14 07:09:44 +00:00
|
|
|
|
|
|
|
func (build *builder) SimpleInsert(table string, columns string, fields string) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.SimpleInsert("_builder", table, columns, fields)
|
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
return build.conn.Prepare(res)
|
|
|
|
}
|
|
|
|
|
2017-06-25 09:56:39 +00:00
|
|
|
func (build *builder) SimpleInsertSelect(ins DB_Insert, sel DB_Select) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.SimpleInsertSelect("_builder", ins, sel)
|
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
return build.conn.Prepare(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (build *builder) SimpleInsertLeftJoin(ins DB_Insert, sel DB_Join) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.SimpleInsertLeftJoin("_builder", ins, sel)
|
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
return build.conn.Prepare(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (build *builder) SimpleInsertInnerJoin(ins DB_Insert, sel DB_Join) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.SimpleInsertInnerJoin("_builder", ins, sel)
|
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
return build.conn.Prepare(res)
|
|
|
|
}
|
|
|
|
|
2017-06-14 07:09:44 +00:00
|
|
|
func (build *builder) SimpleUpdate(table string, set string, where string) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.SimpleUpdate("_builder", table, set, where)
|
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
return build.conn.Prepare(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (build *builder) SimpleDelete(table string, where string) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.SimpleDelete("_builder", table, where)
|
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
return build.conn.Prepare(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
// I don't know why you need this, but here it is x.x
|
|
|
|
func (build *builder) Purge(table string) (stmt *sql.Stmt, err error) {
|
|
|
|
res, err := build.adapter.Purge("_builder", table)
|
|
|
|
if err != nil {
|
|
|
|
return stmt, err
|
|
|
|
}
|
|
|
|
return build.conn.Prepare(res)
|
|
|
|
}
|