251 Commits

Author SHA1 Message Date
Ariel Mashraki
d9c8d9545d entc/gen: use NotFoundError when updating non-exist node (#348)
Fixes #341
2020-02-16 13:26:13 +02:00
Ariel Mashraki
9f9596c184 entc/gen: better formatted codegen for predicates (#336) 2020-02-09 11:38:03 +02:00
Ariel Mashraki
b4255998bf entc/gen: change name format for edge fks (#286)
* entc/gen: change name format for edge fks

* dialect/sql/schema: add fixture support for mysql and postgres

* sql/dialect: merge fkcolumn queries to one for the 2 dialects
2020-02-03 15:41:55 +02:00
Alex Snast
e6ba06441b entc/gen: change <E>Err signature to <E>OrErr (#325)
Signed-off-by: Alex Snast <alexsn@fb.com>
2020-01-30 18:56:36 +02:00
Alex Snast
0802e0b4f5 Merge pull request #324 from facebookincubator/nil_before_as
entc/gen: check for nil error before invoking .As
2020-01-30 13:47:17 +01:00
Alex Snast
091f9aba12 entc/gen: check for nil error before invoking .As
Signed-off-by: Alex Snast <alexsn@fb.com>
2020-01-30 13:42:13 +01:00
Alex Snast
112d442dac Merge pull request #323 from facebookincubator/errwrap
entc/gen: add support for wrapped errors
2020-01-30 10:57:08 +01:00
Alex Snast
0428788539 entc/gen: add support for wrapped errors
Signed-off-by: Alex Snast <alexsn@fb.com>
2020-01-30 10:53:58 +01:00
Ariel Mashraki
9e760aae58 entc/gen: change <E>WithError signature to <E>Err (#322)
<E>WithError is too verbose and we like short names
2020-01-30 11:12:53 +02:00
Ariel Mashraki
27935a8c6c entc/gen: add <E>Loaded for <T>Edges (#319)
This helps to determine if the edge was loaded (or requested) in
eager-loading even if it's empty.
2020-01-29 11:39:19 +02:00
Ariel Mashraki
7a480e3943 entc/gen: use more go-ish names for generated error types (#321)
* entc/gen: use more go-ish names for generated error types

* entc/gen: add NotLodedError type for eager-load api
2020-01-28 11:04:27 +02:00
Ariel Mashraki
bc89ed4e0f entc/gen: add type for type edges (#318)
Will be used for adding methods on the struct edges
2020-01-26 12:39:18 +02:00
aca
3ee6223e64 entc/gen: use empty slice instead of nil in sqlAll (#310) 2020-01-23 16:16:21 +02:00
Ariel Mashraki
faf6c2f2f6 ci: initial work for migration-testing (#311)
Also generating new assets for new ci steps.
2020-01-22 21:20:18 +02:00
Harold.Luo
5cb40ff883 entc/gen/eagerloading: ignore loading edges on empty result (#298)
* fix eagerloading

while parent nodes is zero.

* Update entc/gen/template/dialect/sql/query.tmpl

Co-Authored-By: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* Update entc/gen/template/dialect/sql/query.tmpl

Co-Authored-By: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* generate new assets

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
2020-01-20 09:29:01 -05:00
Jeremy
259bf07b5d examples: regenerate examples (#296) 2020-01-19 13:00:17 +02:00
Ariel Mashraki
caf721df47 entc/gen: add eager-loading support (#263)
* entc/gen: add OwnFK indicator for type edges

* entc/gen: add Edges field for generated types

* entc/gen: add With<T> method to query-builder template

* entc/gen: scan and assign foreign-keys on eager-loading

* entc/gen: load fk-relations (wip)

* entc/integration: add o2m/m2o tests for eager-loading

* entc/gen: add m2m support for eager-loading

* entc/gen: add integration tests for m2m and subgraphs

* entc/gen/integration: add tests for o2o eager-loading

* all: generate all assets
2020-01-13 17:21:26 +02:00
Ariel Mashraki
1f2cb87cee examples: regenerate assets
Closes #261
2019-12-25 11:21:04 +02:00
Ariel Mashraki
7fde9b7642 entc/gen: move sql-update-one to sqlgraph 2019-12-22 13:32:51 +02:00
Ariel Mashraki
04e9391c25 entc/gen: move sql-delete to sqlgraph 2019-12-18 15:14:53 +02:00
Ariel Mashraki
0a7608f8bd all: change codegen header 2019-12-18 13:00:25 +02:00
Ariel Mashraki
798d58f02b all: use more go-ish error for constraint failures 2019-12-17 23:17:55 +02:00
Ariel Mashraki
c6800a3869 entc/gen: move node creation to sqlgraph 2019-12-17 22:45:04 +02:00
Ariel Mashraki
0cc74b5297 all: move sqlgraph to its own package 2019-12-17 18:26:09 +02:00
Ariel Mashraki
754a8c9daa examples: regenerate assets 2019-12-09 08:13:34 +02:00
Ariel Mashraki
56335d6e12 ent: regenerate assets
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/197

Reviewed By: aharonnovo

Differential Revision: D18706251

fbshipit-source-id: 1603030671f4541f21a6b34d5ea0b8b7ccbea8da
2019-11-26 05:47:56 -08:00
Ariel Mashraki
c355ed49be entc/gen: move set-neighbors logic from codegen to sqlgraph
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/183

Reviewed By: alexsn

Differential Revision: D18644179

fbshipit-source-id: 2f2b0c03811a09c4c11240e5161187afbb2ac553
2019-11-24 04:16:36 -08:00
Ariel Mashraki
7be1779ad1 entc/gen: add the type name as an index prefix (#171)
Summary:
Pull Request resolved: https://github.com/facebookincubator/ent/pull/171

Note that this is a non backwards compatible change.

I'll add another change (before this) for setting the storage-key of the index, and only after that we can land this.

Reviewed By: alexsn

Differential Revision: D18570445

fbshipit-source-id: e3ffc7b4baa6bc2fcce9e4553e17817091423b1e
2019-11-20 07:08:47 -08:00
Ariel Mashraki
53cfcb6e8b dialect/sql: fix predicate builder on join
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/143

Reviewed By: idoshveki

Differential Revision: D18346652

fbshipit-source-id: e8c5d7eb3cefc16f52090de0d121e82cae058fc2
2019-11-06 05:21:26 -08:00
Ariel Mashraki
930a17b767 dialect/sql: add neighbors function (#140)
Summary:
Pull Request resolved: https://github.com/facebookincubator/ent/pull/140

This part of the effort of moving logic from Go templates to shared packages.
Next diffs will migrate the neighbors-set and predicates as well.

Dedicated tests for `sql/dialect/graph.go` will be added in a follow-up diff.

Reviewed By: alexsn

Differential Revision: D18304531

fbshipit-source-id: 93e9cf2636b5b4525eb27305bd2708122cfd6e40
2019-11-05 13:08:48 -08:00
Ariel Mashraki
c259aee24b entc/gen: generate sql builders with dialect option
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/130

Reviewed By: alexsn

Differential Revision: D18164397

fbshipit-source-id: 2858d69d3ff85c06b51382c01c3d4369ee2c3bdb
2019-10-27 21:53:50 -07:00
Ariel Mashraki
e493574c83 entc: add postgres dialect for sql storage driver options
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/123

Reviewed By: alexsn

Differential Revision: D18117641

fbshipit-source-id: 8e520a1b1f70c7bea70f8a37ac698116e98a804e
2019-10-24 10:49:47 -07:00
Alex Snast
9d9e121dbd ent/entc: .String() now uses ansic time format when formating time fields
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/103

Reviewed By: a8m

Differential Revision: D17978059

fbshipit-source-id: 721014b0bf712943d721c7ff038239cff690b94e
2019-10-17 04:36:04 -07:00
Alex Snast
5d988870bc ent/entc: use select/scan on id query (#1552)
Summary:
Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1552

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

avoids complete ent load on id query

Reviewed By: a8m

Differential Revision: D17906002

fbshipit-source-id: 7749a0d7c707858eab368978a1d220b581ea6dbb
2019-10-14 23:16:14 -07:00
Ariel Mashraki
6f5f42ab3c dialect/sql: dialect based builders (#1550)
Summary:
Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1550

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

This is still WIP and you should ignore this.

Reviewed By: alexsn

Differential Revision: D17854477

fbshipit-source-id: 2d19713c118adb31164b7a2781327e64c87db8d4
2019-10-13 07:03:11 -07:00
Ariel Mashraki
7597f07912 entc: add option to use entc as package
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/72

Reviewed By: alexsn

Differential Revision: D17783580

fbshipit-source-id: 597f124a28415fef66b0b16811ad2acac8df631d
2019-10-07 07:06:32 -07:00
Alex Snast
ac50ea81d4 ent: address several lint errors throughout the project (#1534)
Summary:
Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1534

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

lint errors detected by running `golangci-lint` tool.

Reviewed By: a8m

Differential Revision: D17784980

fbshipit-source-id: f7e8bd99fdf1e018d5672cea1e8d44b67f2a4201
2019-10-06 23:59:12 -07:00
Ariel Mashraki
b64330e475 ent/gen: remove redundant nillable check
Summary: nillable must be optional

Reviewed By: alexsn

Differential Revision: D17763004

fbshipit-source-id: 9c134e1648d1a387d90a5f2353de855a1aa3464f
2019-10-05 11:03:05 -07:00
Ariel Mashraki
8e66691db5 entc: return ErrNotFound on UpdateOne
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/52

Reviewed By: alexsn

Differential Revision: D17737477

fbshipit-source-id: 13890619e0af28a28e3d7bd50d7e4287599eeaf0
2019-10-03 06:25:11 -07:00
Ariel Mashraki
1750d33bd8 all: add support for running examples in playground
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/49

Reviewed By: alexsn

Differential Revision: D17735758

fbshipit-source-id: d4b80631e56870690cc54912528c9950f4e48ccc
2019-10-03 03:05:40 -07:00
Ariel Mashraki
cb1f78f233 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
2019-10-02 01:41:40 -07:00
Alex Snast
dacc568413 ent/entc: corrently reference default value on migrate generation
Summary:
Migration incorrectly generated field default value on storage key inclusion.

Example Field:
```
field.String("tenant").
  StorageKey("organization").
  Default("fb-test"),
```
Generated default of:
```
// DefaultTenant holds the default value on creation for the tenant field.
DefaultTenant = descTenant.Default.(string)
```
But migration references non existent default (storage key is used):
```
{Name: "organization", Type: field.TypeString, Default: user.DefaultOrganization},
```

Reviewed By: a8m

Differential Revision: D17578898

fbshipit-source-id: afca92ac3f34c16100c868a10d0a480139bf4262
2019-09-25 13:51:45 -07:00
Ariel Mashraki
c3955a08f1 schema/field: json type support (#38)
Summary:
Pull Request resolved: https://github.com/facebookincubator/ent/pull/38

Only `IsNil` and `NotNil` predicates are supported this moment

Reviewed By: alexsn

Differential Revision: D17444976

fbshipit-source-id: 37336fa0bc7749af995933baee2e23bb7366dd78
2019-09-19 05:00:11 -07:00
Ariel Mashraki
83d0063437 entc/gen: returns affected rows in delete
Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1455

Reviewed By: alexsn

Differential Revision: D17396880

fbshipit-source-id: 3a3a9849b816777bd0ef94cf55b2291705a37df6
2019-09-16 08:47:42 -07:00
Ariel Mashraki
3fcaf80ca4 entc/migrate: add an option to dump schema changes
Reviewed By: alexsn

Differential Revision: D17253145

fbshipit-source-id: 32640e60a8e149ac8774384db8e2ece29b9fec24
2019-09-08 06:28:58 -07:00
Ariel Mashraki
9ab0a28ffe entc/select: add selection api
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/27

Reviewed By: alexsn

Differential Revision: D17164536

fbshipit-source-id: f5caa80b05aff1ef8ec30d7a53256b00380d018c
2019-09-04 07:14:24 -07:00
Ariel Mashraki
5bc8568069 all: add license reference to README and add copyright headers to gencode
Reviewed By: alexsn

Differential Revision: D17119262

fbshipit-source-id: 046f095ca9432c920778db0edb2158dedb23c0a2
2019-08-30 08:46:03 -07:00
Ariel Mashraki
dc542e46ae entc/gen: add debug option to client
Summary:
It's possible to execute:
```
client.Debug().T.Query().AllX(ctx)
``

Reviewed By: alexsn

Differential Revision: D17092159

fbshipit-source-id: 6d1c56e8e45cfd8e36b2700c9d450f2bd5f66a71
2019-08-28 07:23:28 -07:00
Ariel Mashraki
e7fec6f8f9 entc/gen: change verbose option to debug
Summary: Change the Verbose option to Debug

Reviewed By: alexsn

Differential Revision: D17091911

fbshipit-source-id: c5cf3e1c7f33f607076fe5c7da94e04b9f236218
2019-08-28 06:45:59 -07:00
Alex Snast
4c1f28d58f ent/schema: allow setting collation for string fields
Reviewed By: a8m

Differential Revision: D17090481

fbshipit-source-id: a08768c9bac4318a91bc6a067c85d6eb022c3024
2019-08-28 04:52:32 -07:00