mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
ent/doc: crud api
Reviewed By: alexsn Differential Revision: D17094376 fbshipit-source-id: 9b1da24b99bb3ff15382b3a17516904decbca322
This commit is contained in:
committed by
Facebook Github Bot
parent
a6bf47b384
commit
52b268c05c
@@ -39,6 +39,16 @@ You should note, that `goimports` is required for the codegen, and it can be ins
|
||||
go get -u golang.org/x/tools/cmd/goimports
|
||||
```
|
||||
|
||||
The `generate` command generates the following assets for the schemas:
|
||||
|
||||
- `Client` and `Tx` objects used for interacting with the graph.
|
||||
- CRUD builders for each schema type. See [CRUD](crud.md) for more info.
|
||||
- Entity object (Go struct) for each of the schema type.
|
||||
- Package contains constants and predicates used for interacting with the builders.
|
||||
- A `migrate` package, for SQL dialects. See [Migration](migrate.md) for more info.
|
||||
|
||||
## Code Generation Options
|
||||
|
||||
For more info about codegen options, run `entc generate -h`:
|
||||
|
||||
```console
|
||||
|
||||
103
doc/md/crud.md
103
doc/md/crud.md
@@ -2,4 +2,105 @@
|
||||
id: crud
|
||||
title: CRUD API
|
||||
---
|
||||
Lorem ipsum.
|
||||
|
||||
As mentioned in the [introduction](code-gen.md) section, running `entc` on the schemas,
|
||||
will generate the following assets:
|
||||
|
||||
- `Client` and `Tx` objects used for interacting with the graph.
|
||||
- CRUD builders for each schema type. See [CRUD](crud.md) for more info.
|
||||
- Entity object (Go struct) for each of the schema type.
|
||||
- Package contains constants and predicates used for interacting with the builders.
|
||||
- A `migrate` package, for SQL dialects. See [Migration](migrate.md) for more info.
|
||||
|
||||
## Create A New Client
|
||||
|
||||
**MySQL**
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"<project>/ent"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
)
|
||||
|
||||
func main() {
|
||||
drv, err := sql.Open("mysql", "<user>:<pass>@tcp(<host>:<port>)/<database>?parseTime=True")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer drv.Close()
|
||||
client := ent.NewClient(ent.Driver(drv))
|
||||
}
|
||||
```
|
||||
|
||||
**SQLite**
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"<project>/ent"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
)
|
||||
|
||||
func main() {
|
||||
drv, err := sql.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer drv.Close()
|
||||
client := ent.NewClient(ent.Driver(drv))
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
**Gremlin (AWS Neptune)**
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/url"
|
||||
|
||||
"<project>/ent"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/gremlin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c, err := gremlin.NewClient(gremlin.Config{
|
||||
Endpoint: gremlin.Endpoint{
|
||||
URL: &url.URL{
|
||||
Scheme: "http",
|
||||
Host: "localhost:8182",
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
client := ent.NewClient(ent.Driver(gremlin.NewDriver(c)))
|
||||
}
|
||||
```
|
||||
|
||||
## Create An Entity
|
||||
|
||||
## Update An Entity
|
||||
|
||||
## Update Many Entities
|
||||
|
||||
## Query An Entity
|
||||
|
||||
## Delete An Entity
|
||||
|
||||
## Delete Entities
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
id: predicate
|
||||
id: predicates
|
||||
title: Predicates
|
||||
---
|
||||
Lorem ipsum.
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
"Code Generation": [
|
||||
"code-gen",
|
||||
"crud",
|
||||
"predicates",
|
||||
"traversals",
|
||||
"aggregate",
|
||||
"predicates",
|
||||
"transactions"
|
||||
],
|
||||
"Migration": [
|
||||
|
||||
@@ -86,7 +86,6 @@ const siteConfig = {
|
||||
'/js/code-block-buttons.js',
|
||||
'/js/custom.js',
|
||||
],
|
||||
stylesheets: ['/css/code-block-buttons.css'],
|
||||
|
||||
// On page navigation for the current documentation page.
|
||||
onPageNav: 'separate',
|
||||
|
||||
Reference in New Issue
Block a user