gorpGo 语言 ORM 框架
一个Go语言的ORM框架,目前支持MySQL、PostgresSQL和SQLite
一个使用示例:
// Define a type for your join // It *must* contain all the columns in your SELECT statement // // The names here should match the aliased column names you specify // in your SQL - no additional binding work required. simple. // type InvoicePersonView struct { InvoiceId int64 PersonId int64 Memo string FName string } // Create some rows p1 := &Person{0, 0, 0, "bob", "smith"} dbmap.Insert(p1) // notice how we can wire up p1.Id to the invoice easily inv1 := &Invoice{0, 0, 0, "xmas order", p1.Id} dbmap.Insert(inv1) // Run your query query := "select i.Id InvoiceId, p.Id PersonId, i.Memo, p.FName " + "from invoice_test i, person_test p " + "where i.PersonId = p.Id" list, err := dbmap.Select(InvoicePersonView{}, query) // this should test true expected := &InvoicePersonView{inv1.Id, p1.Id, inv1.Memo, p1.FName} if reflect.DeepEqual(list[0], expected) { fmt.Println("Woot! My join worked!") }
评论