예제 #1
0
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
}
예제 #2
0
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
}