mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
examples: make examples testable
This commit is contained in:
@@ -8,3 +8,9 @@ Each user can **have many** friends. If user A becomes a friend of B, B is also
|
||||
```console
|
||||
go generate ./...
|
||||
```
|
||||
|
||||
### Run Example
|
||||
|
||||
```console
|
||||
go test
|
||||
```
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
func Example_M2MBidi() {
|
||||
client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
|
||||
if err != nil {
|
||||
log.Fatalf("failed opening connection to sqlite: %v", err)
|
||||
@@ -29,6 +29,10 @@ func main() {
|
||||
if err := Do(ctx, client); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// Output:
|
||||
// [User(id=1, age=30, name=a8m)]
|
||||
// [User(id=2, age=28, name=nati)]
|
||||
// [User(id=1, age=30, name=a8m) User(id=2, age=28, name=nati)]
|
||||
}
|
||||
|
||||
func Do(ctx context.Context, client *ent.Client) error {
|
||||
Reference in New Issue
Block a user