func PrintTable(orm beedb.Model) {
	var users []User

	if err := orm.FindAll(&users); err != nil {
		panic(err)
	}

	fmt.Printf("%+v,", users)
	for _, user := range users {
		fmt.Printf("%+v,", user)
	}
	fmt.Println()
}
Esempio n. 2
0
File: test.go Progetto: roca/GO
func QueryRows2(db *sql.DB) {

	var orm beedb.Model

	var allCommands []Command

	beedb.PluralizeTableNames = true

	orm = beedb.New(db, "pg")
	beedb.OnDebug = true

	err := orm.FindAll(&allCommands)
	if err != nil {
		panic(err)
	}

	for i, command := range allCommands {
		fmt.Printf("row %d : %s %s\n", i, command.Path, command.Dir)
	}
}
Esempio n. 3
0
File: test.go Progetto: roca/GO
func QueryRows2(db *sql.DB) {

	var orm beedb.Model

	var allclones []Clone

	beedb.PluralizeTableNames = true

	orm = beedb.New(db, "pg")
	beedb.OnDebug = true

	err := orm.FindAll(&allclones)
	if err != nil {
		panic(err)
	}

	for i, clone := range allclones {
		fmt.Printf("row %d : %s %s\n", i, clone.Name, clone.Seq)
	}
}
func main() {
	var (
		orm beedb.Model
	)

	orm = SetupDb()

	//START SETUP OMIT
	orm.SetTable("users").Insert(map[string]interface{}{
		"id":         1,
		"first_name": "John",
		"last_name":  "Doe",
		"age":        24,
	})
	orm.SetTable("users").Insert(map[string]interface{}{
		"id":         2,
		"first_name": "Jane",
		"last_name":  "Doe",
		"age":        52,
	})
	orm.SetTable("users").Insert(map[string]interface{}{
		"id":         1,
		"first_name": "Joe",
		"last_name":  "Shmoe",
		"age":        10,
	})
	//END SETUP OMIT

	//START CODE OMIT

	var users []User
	orm.Where("last_name = ? OR age < ?", "Doe", 12).Limit(2).OrderBy("age").FindAll(&users)
	for _, user := range users {
		fmt.Printf("%+v,", user)
	}
	fmt.Println()

	//END CODE OMIT
}
func main() {
	var (
		orm  beedb.Model
		user *User
	)

	user = new(User)

	orm = SetupDb()

	//START CODE OMIT
	orm.SetTable("users").Insert(map[string]interface{}{"id": 1, "first_name": "John", "last_name": "Doe", "age": 25})
	PrintTable(orm)

	orm.Where(1).Find(user)

	user.FirstName = "James"
	orm.Save(user)
	PrintTable(orm)

	orm.Delete(user)
	PrintTable(orm)
	//END CODE OMIT
}
Esempio n. 6
0
func insertUser(orm *beedb.Model, user *UserInfo) {
	orm.Save(user)
}