Ejemplo n.º 1
0
func Test_InitDB(t *testing.T) {
	var err error
	db, err = xorm.NewPostgreSQL("postgres://*****:*****@localhost:5432/mblog?sslmode=disable")

	if err != nil {
		t.Fatal(err)
	}

	err = db.SetSqlMapRootDir("./sql/oracle").InitSqlMap()
	if err != nil {
		t.Fatal(err)
	}

	err = db.SetSqlTemplateRootDir("./sql/oracle").InitSqlTemplate(xorm.SqlTemplateOptions{Extension: ".stpl"})
	if err != nil {
		t.Fatal(err)
	}

	err = db.StartFSWatcher()
	if err != nil {
		t.Fatal(err)
	}

	db.ShowSQL(true)
	log.Println(db)
	//	db.NewSession().SqlMapClient().Execute()
}
Ejemplo n.º 2
0
//192.168.0.51:8181/tuser.insertdb?data=helloworld
func main() {
	engine, _ := xorm.NewPostgreSQL("")
	engine.Insert()
	engine.NewSession().Begin()

	var a integer = 1
	if a.Less(2) {
		fmt.Println("2 is bigger then 1")
	}

	var user = new(TUser)
	user.UserCode = "usercode"
	user.UserName = "******"
	user.INSERTDB("golang")
	user.SELECTDB()

	dataConnect = initDbMap()

	dataConnect.Insert(&user)
	dbaTranEx, _ := dataConnect.Begin()
	dbaTranEx.Insert(&user)

	fmt.Println(reflect.TypeOf(dataConnect.Dialect))

	ClasManager = make(map[string]interface{})
	ClasManager["/TUSER"] = user

	var Objt = ClasManager["/TUSER"]
	v := reflect.ValueOf(Objt)
	fmt.Println("type:", v.Type())
	fmt.Println("type.numbmethod:", v.NumMethod())
	m := v.MethodByName("INSERTDB")
	m.Call([]reflect.Value{reflect.ValueOf("true")})
	fmt.Println("kind is float64:", v.Kind() == reflect.Float64)

	http.HandleFunc("/", NetEngineHandle)
	//http.ListenAndServe("192.168.0.51:8181", nil)
	error := http.ListenAndServe("192.168.0.51:8181", nil)
	if error != nil {
		fmt.Println(error)
	}
}