entc/gen: add open func for creating client

Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/44

Reviewed By: alexsn

Differential Revision: D17657719

fbshipit-source-id: 9bbe18dc0e9c553f8a2df81018d7db06f38f5e0e
This commit is contained in:
Ariel Mashraki
2019-10-02 01:39:14 -07:00
committed by Facebook Github Bot
parent 86a6fbe48e
commit cb1f78f233
35 changed files with 525 additions and 70 deletions

View File

@@ -14,17 +14,15 @@ import (
"github.com/facebookincubator/ent/examples/m2m2types/ent"
"github.com/facebookincubator/ent/examples/m2m2types/ent/group"
"github.com/facebookincubator/ent/dialect/sql"
_ "github.com/mattn/go-sqlite3"
)
func main() {
db, err := sql.Open("sqlite3", "file:o2o2types?mode=memory&cache=shared&_fk=1")
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)
}
defer db.Close()
client := ent.NewClient(ent.Driver(db))
defer client.Close()
ctx := context.Background()
// run the auto migration tool.
if err := client.Schema.Create(ctx); err != nil {