2017-06-13 07:12:58 +00:00
|
|
|
/* WIP Under Construction */
|
|
|
|
package qgen
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
var DB_Registry []DB_Adapter
|
|
|
|
var No_Adapter = errors.New("This adapter doesn't exist")
|
|
|
|
|
2017-06-19 08:06:54 +00:00
|
|
|
type DB_Select struct
|
|
|
|
{
|
|
|
|
Table string
|
|
|
|
Columns string
|
|
|
|
Where string
|
|
|
|
Orderby string
|
|
|
|
Limit string
|
|
|
|
}
|
|
|
|
|
|
|
|
type DB_Join struct
|
|
|
|
{
|
|
|
|
Table1 string
|
|
|
|
Table2 string
|
|
|
|
Columns string
|
|
|
|
Joiners string
|
|
|
|
Where string
|
|
|
|
Orderby string
|
|
|
|
Limit string
|
|
|
|
}
|
|
|
|
|
|
|
|
type DB_Insert struct
|
|
|
|
{
|
|
|
|
Table string
|
|
|
|
Columns string
|
|
|
|
Fields string
|
|
|
|
}
|
|
|
|
|
2017-06-13 07:12:58 +00:00
|
|
|
type DB_Column struct
|
|
|
|
{
|
|
|
|
Table string
|
|
|
|
Left string // Could be a function or a column, so I'm naming this Left
|
|
|
|
Alias string // aka AS Blah, if it's present
|
|
|
|
Type string // function or column
|
|
|
|
}
|
|
|
|
|
|
|
|
type DB_Field struct
|
|
|
|
{
|
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
}
|
|
|
|
|
|
|
|
type DB_Where struct
|
|
|
|
{
|
2017-06-19 08:06:54 +00:00
|
|
|
Expr []DB_Token // Simple expressions, the innards of functions are opaque for now.
|
2017-06-13 07:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DB_Joiner struct
|
|
|
|
{
|
|
|
|
LeftTable string
|
|
|
|
LeftColumn string
|
|
|
|
RightTable string
|
|
|
|
RightColumn string
|
|
|
|
Operator string
|
|
|
|
}
|
|
|
|
|
|
|
|
type DB_Order struct
|
|
|
|
{
|
|
|
|
Column string
|
|
|
|
Order string
|
|
|
|
}
|
|
|
|
|
|
|
|
type DB_Token struct {
|
|
|
|
Contents string
|
|
|
|
Type string // function, operator, column, number, string, substitute
|
|
|
|
}
|
|
|
|
|
|
|
|
type DB_Setter struct {
|
|
|
|
Column string
|
|
|
|
Expr []DB_Token // Simple expressions, the innards of functions are opaque for now.
|
|
|
|
}
|
|
|
|
|
2017-06-15 11:40:35 +00:00
|
|
|
type DB_Limit struct {
|
|
|
|
Offset string // ? or int
|
|
|
|
MaxCount string // ? or int
|
|
|
|
}
|
|
|
|
|
2017-06-13 07:12:58 +00:00
|
|
|
type DB_Adapter interface {
|
|
|
|
GetName() string
|
2017-06-13 08:56:48 +00:00
|
|
|
SimpleInsert(string,string,string,string) (string, error)
|
|
|
|
SimpleReplace(string,string,string,string) (string, error)
|
|
|
|
SimpleUpdate(string,string,string,string) (string, error)
|
|
|
|
SimpleDelete(string,string,string) (string, error)
|
|
|
|
Purge(string,string) (string, error)
|
2017-06-15 11:40:35 +00:00
|
|
|
SimpleSelect(string,string,string,string,string,string) (string, error)
|
|
|
|
SimpleLeftJoin(string,string,string,string,string,string,string,string) (string, error)
|
|
|
|
SimpleInnerJoin(string,string,string,string,string,string,string,string) (string, error)
|
2017-06-19 08:06:54 +00:00
|
|
|
SimpleInsertSelect(string,DB_Insert,DB_Select) (string,error)
|
2017-06-25 09:56:39 +00:00
|
|
|
SimpleInsertLeftJoin(string,DB_Insert,DB_Join) (string,error)
|
2017-06-19 08:06:54 +00:00
|
|
|
SimpleInsertInnerJoin(string,DB_Insert,DB_Join) (string,error)
|
2017-06-15 11:40:35 +00:00
|
|
|
SimpleCount(string,string,string,string) (string, error)
|
2017-06-13 07:12:58 +00:00
|
|
|
Write() error
|
|
|
|
|
|
|
|
// TO-DO: Add a simple query builder
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetAdapter(name string) (adap DB_Adapter, err error) {
|
|
|
|
for _, adapter := range DB_Registry {
|
|
|
|
if adapter.GetName() == name {
|
|
|
|
return adapter, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return adap, No_Adapter
|
|
|
|
}
|