Example #1
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"

	"testing"
)

type TimeTest struct {
	Id       *fat.Field `type:"string uuid"      db:"id UUIDGEN PKEY" rest:" R "`
	Time     *fat.Field `type:"time timestamp"   db:"time"            rest:"CRU"`
	TimeNull *fat.Field `type:"time timestamptz" db:"timenull NULL"   rest:" RU"`
}

var TIME_TEST = fat.Proto(&TimeTest{}).(*TimeTest)
var CRUDTimeTest *CRUD

func init() {
	registry.MustRegisterTable("timetest", TIME_TEST)

	db.Exec("DROP TABLE timetest")

	timeTestTable := registry.TableOf(TIME_TEST)
	_, e := db.Exec(timeTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table timetest: \nError: %s\nSql: %s\n", e.Error(),
			timeTestTable.Create()))
	}

	CRUDTimeTest = NewCRUD(registry, TIME_TEST)
Example #2
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"
	"testing"
)

type BoolsTest struct {
	Id        *fat.Field `type:"string uuid" db:"id UUIDGEN PKEY" rest:" R "`
	Bools     *fat.Field `type:"[]bool"      db:"bools"           rest:"CRU"`
	BoolsNull *fat.Field `type:"[]bool"      db:"boolsnull NULL"  rest:" RU"`
}

var BOOLS_TEST = fat.Proto(&BoolsTest{}).(*BoolsTest)
var CRUDBoolsTest *CRUD

func init() {
	registry.MustRegisterTable("boolstest", BOOLS_TEST)

	db.Exec("DROP TABLE boolstest")

	boolsTestTable := registry.TableOf(BOOLS_TEST)
	_, e := db.Exec(boolsTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table boolstest: \nError: %s\nSql: %s\n", e.Error(),
			boolsTestTable.Create()))
	}

	CRUDBoolsTest = NewCRUD(registry, BOOLS_TEST)
Example #3
0
)

// . "gopkg.in/metakeule/pgsql.v5"

/*
ty := reflect.TypeOf(østruct).Elem()
	return "*" + ty.PkgPath() + "." + ty.Name()
*/

type coop struct {
	Id        *fat.Field `type:"string uuid"        db:"id UUIDGEN PKEY" rest:" R DL"`
	Name      *fat.Field `type:"string varchar(66)" db:"name"            rest:"CRU L"`
	FoundedAt *fat.Field `type:"time date"          db:"founded_at NULL" rest:"CRU L"`
}

var COOP = fat.Proto(&coop{}).(*coop)
var registry = NewRegistries()

func init() {
	registry.MustRegisterTable("co_op", COOP)
	// MustRegisterTable("co_op", COOP)
}

func TestRegistry(t *testing.T) {
	f := registry.FieldOf(COOP.Name)

	if f == nil {
		t.Error("field should not be nil")
	}

	ta := registry.TableOf(COOP)
Example #4
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"

	"testing"
)

type TimesTest struct {
	Id        *fat.Field `type:"string uuid" db:"id UUIDGEN PKEY" rest:" R "`
	Times     *fat.Field `type:"[]time"      db:"times"           rest:"CRU"`
	TimesNull *fat.Field `type:"[]time"      db:"timesnull NULL"  rest:" RU"`
}

var TIMES_TEST = fat.Proto(&TimesTest{}).(*TimesTest)
var CRUDTimesTest *CRUD

func init() {
	registry.MustRegisterTable("timestest", TIMES_TEST)

	db.Exec("DROP TABLE timestest")

	timesTestTable := registry.TableOf(TIMES_TEST)
	_, e := db.Exec(timesTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table timestest: \nError: %s\nSql: %s\n", e.Error(),
			timesTestTable.Create()))
	}

	CRUDTimesTest = NewCRUD(registry, TIMES_TEST)
Example #5
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"
	"testing"
)

type BoolTest struct {
	Id       *fat.Field `type:"string uuid" db:"id UUIDGEN PKEY" rest:" R "`
	Bool     *fat.Field `type:"bool"        db:"bool"            rest:"CRU"`
	BoolNull *fat.Field `type:"bool"        db:"boolnull NULL"   rest:" RU"`
}

var BOOL_TEST = fat.Proto(&BoolTest{}).(*BoolTest)
var CRUDBoolTest *CRUD

func init() {
	registry.MustRegisterTable("booltest", BOOL_TEST)

	db.Exec("DROP TABLE booltest")

	boolTestTable := registry.TableOf(BOOL_TEST)
	_, e := db.Exec(boolTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table booltest: \nError: %s\nSql: %s\n", e.Error(),
			boolTestTable.Create()))
	}

	CRUDBoolTest = NewCRUD(registry, BOOL_TEST)
Example #6
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"

	"testing"
)

type IntsTest struct {
	Id       *fat.Field `type:"string uuid" db:"id UUIDGEN PKEY" rest:" R "`
	Ints     *fat.Field `type:"[]int"       db:"ints"            rest:"CRU"`
	IntsNull *fat.Field `type:"[]int"       db:"intsnull NULL"   rest:" RU"`
}

var INTS_TEST = fat.Proto(&IntsTest{}).(*IntsTest)
var CRUDIntsTest *CRUD

func init() {
	registry.MustRegisterTable("intstest", INTS_TEST)

	db.Exec("DROP TABLE intstest")

	intsTestTable := registry.TableOf(INTS_TEST)
	_, e := db.Exec(intsTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table intstest: \nError: %s\nSql: %s\n", e.Error(),
			intsTestTable.Create()))
	}

	CRUDIntsTest = NewCRUD(registry, INTS_TEST)
Example #7
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"

	"testing"
)

type StringsTest struct {
	Id          *fat.Field `type:"string uuid" db:"id UUIDGEN PKEY"  rest:" R "`
	Strings     *fat.Field `type:"[]string"    db:"strings"          rest:"CRU"`
	StringsNull *fat.Field `type:"[]string"    db:"stringsnull NULL" rest:" RU"`
}

var STRINGS_TEST = fat.Proto(&StringsTest{}).(*StringsTest)
var CRUDStringsTest *CRUD

func init() {
	registry.MustRegisterTable("stringstest", STRINGS_TEST)

	db.Exec("DROP TABLE stringstest")

	stringsTestTable := registry.TableOf(STRINGS_TEST)
	_, e := db.Exec(stringsTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table stringstest: \nError: %s\nSql: %s\n", e.Error(),
			stringsTestTable.Create()))
	}

	CRUDStringsTest = NewCRUD(registry, STRINGS_TEST)
Example #8
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"

	"testing"
)

type FloatsTest struct {
	Id         *fat.Field `type:"string uuid" db:"id UUIDGEN PKEY" rest:" R "`
	Floats     *fat.Field `type:"[]float"     db:"floats"          rest:"CRU"`
	FloatsNull *fat.Field `type:"[]float"     db:"floatsnull NULL" rest:" RU"`
}

var FLOATS_TEST = fat.Proto(&FloatsTest{}).(*FloatsTest)
var CRUDFloatsTest *CRUD

func init() {
	registry.MustRegisterTable("floatstest", FLOATS_TEST)

	db.Exec("DROP TABLE floatstest")

	floatsTestTable := registry.TableOf(FLOATS_TEST)
	_, e := db.Exec(floatsTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table floatstest: \nError: %s\nSql: %s\n", e.Error(),
			floatsTestTable.Create()))
	}

	CRUDFloatsTest = NewCRUD(registry, FLOATS_TEST)
Example #9
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"

	"testing"
)

type StringTest struct {
	Id         *fat.Field `type:"string uuid"         db:"id UUIDGEN PKEY" rest:" R "`
	String     *fat.Field `type:"string varchar(122)" db:"string"          rest:"CRU"`
	StringNull *fat.Field `type:"string text"         db:"stringnull NULL" rest:" RU"`
}

var STRING_TEST = fat.Proto(&StringTest{}).(*StringTest)
var CRUDStringTest *CRUD

func init() {
	registry.MustRegisterTable("stringtest", STRING_TEST)

	db.Exec("DROP TABLE stringtest")

	stringTestTable := registry.TableOf(STRING_TEST)
	_, e := db.Exec(stringTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table stringtest: \nError: %s\nSql: %s\n", e.Error(),
			stringTestTable.Create()))
	}

	CRUDStringTest = NewCRUD(registry, STRING_TEST)
Example #10
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"

	"testing"
)

type FloatTest struct {
	Id        *fat.Field `type:"string uuid" db:"id UUIDGEN PKEY" rest:" R "`
	Float     *fat.Field `type:"float"       db:"float"           rest:"CRU"`
	FloatNull *fat.Field `type:"float"       db:"floatnull NULL"  rest:" RU" `
}

var FLOAT_TEST = fat.Proto(&FloatTest{}).(*FloatTest)
var CRUDFloatTest *CRUD

func init() {
	registry.MustRegisterTable("floattest", FLOAT_TEST)

	db.Exec("DROP TABLE floattest")

	floatTestTable := registry.TableOf(FLOAT_TEST)
	_, e := db.Exec(floatTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table floattest: \nError: %s\nSql: %s\n", e.Error(),
			floatTestTable.Create()))
	}

	CRUDFloatTest = NewCRUD(registry, FLOAT_TEST)
Example #11
0
map[string]int
map[string]string
map[string]bool
map[string]float
map[string]time

*/

type Company struct {
	Id        *fat.Field `type:"string uuid"        db:"id UUIDGEN PKEY" rest:" R DL"`
	Name      *fat.Field `type:"string varchar(66)" db:"name"            rest:"CRU L"`
	Age       *fat.Field `type:"int"                db:"age NULL"        rest:"CRU L"`
	UpdatedAt *fat.Field `type:"time timestamp"     db:"updated_at NULL"      rest:"CRU L"`
}

var COMPANY = fat.Proto(&Company{}).(*Company)
var CRUDCompany *CRUD
var _ = strings.Contains

func makeDB() *sql.DB {
	dbWrap := dbwrap.New(wrapperDriverName, testdb)

	dbWrap.HandlePrepare = func(conn driver.Conn, query string) (driver.Stmt, error) {
		testdb.Query = query
		/*		if strings.Contains(query, "Update") {
				fmt.Printf("-- Prepare --\n%s\n", query)
			}*/
		return conn.Prepare(query)
	}

	dbWrap.HandleExec = func(conn driver.Execer, query string, args []driver.Value) (driver.Result, error) {
Example #12
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"

	"testing"
)

type MapTest struct {
	Id      *fat.Field `type:"int"            db:"id SERIAL PKEY" rest:" R "`
	Map     *fat.Field `type:"[string]string" db:"map"            rest:"CRU"`
	MapNull *fat.Field `type:"[string]int"    db:"mapnull NULL"   rest:" RU"`
}

var MAP_TEST = fat.Proto(&MapTest{}).(*MapTest)
var CRUDMapTest *CRUD

func init() {
	registry.MustRegisterTable("maptest", MAP_TEST)

	db.Exec("DROP TABLE maptest")

	mapTestTable := registry.TableOf(MAP_TEST)
	_, e := db.Exec(mapTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table maptest: \nError: %s\nSql: %s\n", e.Error(),
			mapTestTable.Create()))
	}

	CRUDMapTest = NewCRUD(registry, MAP_TEST)
Example #13
0
import (
	"fmt"
	"gopkg.in/go-on/lib.v3/internal/fat"

	// . "gopkg.in/metakeule/pgsql.v5"

	"testing"
)

type IntTest struct {
	Id      *fat.Field `type:"string uuid" db:"id UUIDGEN PKEY" rest:" R "`
	Int     *fat.Field `type:"int"         db:"int"             rest:"CRU"`
	IntNull *fat.Field `type:"int"         db:"intnull NULL"    rest:" RU"`
}

var INT_TEST = fat.Proto(&IntTest{}).(*IntTest)
var CRUDIntTest *CRUD

func init() {
	registry.MustRegisterTable("inttest", INT_TEST)

	db.Exec("DROP TABLE inttest")

	intTestTable := registry.TableOf(INT_TEST)
	_, e := db.Exec(intTestTable.Create().String())
	if e != nil {
		panic(fmt.Sprintf("Can't create table inttest: \nError: %s\nSql: %s\n", e.Error(),
			intTestTable.Create()))
	}

	CRUDIntTest = NewCRUD(registry, INT_TEST)