mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
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:
committed by
Facebook Github Bot
parent
86a6fbe48e
commit
cb1f78f233
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user