Commit Graph

368 Commits

Author SHA1 Message Date
Ariel Mashraki
a5fea077a9 dialect/sql: use identifier qualifiers for WHERE clause on upsert
Fixed https://github.com/ent/ent/issues/2126
2021-11-12 23:46:46 +02:00
Ariel Mashraki
0dd7b0d7c3 dialect/sql/sqljson: fix sqlite haskey and add docs 2021-11-11 18:58:28 +02:00
Ariel Mashraki
3ba2b4e173 entc/integration/json: add tests for null literals 2021-11-10 17:24:51 +02:00
Ariel Mashraki
0c5398a11d dialect/sql/sqljson: support comparing values with null literal 2021-11-10 17:24:51 +02:00
Ariel Mashraki
dd6c034c2a dialect/sql/schema: support mediumtext field in migration
Fixed https://github.com/ent/ent/issues/2113
2021-11-07 15:37:06 +02:00
Ariel Mashraki
8f88f58713 dialect/sql/sqlgraph: minor refactor changes 2021-11-07 14:01:54 +02:00
Ariel Mashraki
e8e4401d27 dialect/sqltest: use postgres dialect in predicate tests 2021-11-03 13:39:39 +02:00
Ariel Mashraki
02203c3f91 dialect/sqltest: ensure predicates can be reused 2021-11-02 23:01:11 +02:00
Alexander Melentyev
147b1f59ae all: small typo fixes (#2095) 2021-11-01 17:47:06 +02:00
Andrey Elenskiy
62d64f2b78 dialect/sql/sqlgraph: use selector's column instead of table's column in HasNeighbors (#2060)
Allows for HasNeighbors' selector to be a generic selector instead of *SelectTable.
A use case for this is doing HasNeighbors* function on materialized queries instead
of on concrete tables only.
2021-10-25 07:46:54 +03:00
Ariel Mashraki
a1f6de2793 dialect/sql: escape special characters in pattern matching
Resources:
- https://www.postgresql.org/docs/current/functions-matching.html\#FUNCTIONS-LIKE
- https://www.sqlite.org/lang_expr.html\#the_like_glob_regexp_and_match_operators
- https://dev.mysql.com/doc/refman/8.0/en/string-literals.html

Fixed https://github.com/ent/ent/issues/2059
2021-10-24 21:14:26 +03:00
Ariel Mashraki
963bd669fd dialect/sql: add example to SIMILAR TO predicate (#2055) 2021-10-21 12:01:58 +03:00
Ariel Mashraki
3e6c40886d entc/gen: support count with field selection
Fixed https://github.com/ent/ent/issues/2036
2021-10-17 19:03:49 +03:00
Ariel Mashraki
899e9f0e50 dialect/sql: wraps the sql.Rows with ColumnScanner interface 2021-10-14 09:32:30 +03:00
Ariel Mashraki
9e809635b2 entc/gen: ignore immutable fields on Upsert<T>.UpdateNewValues
Also, for some reason, the TimeMixin.UpdateTime was an immutable field,
but this was incorrent, because the codegen just skip generating
update setters to it. Removing the Immutable modifier allows users
to set this field explicitly.
2021-10-08 08:20:05 +03:00
Ariel Mashraki
f30a17edd4 all: fix linting issues before migrating to golangci v1.42 (#2019) 2021-10-07 19:54:43 +03:00
Shen Yang
65cf307b10 dialect/sql/schema: add support for tstzrange and interval and in postgres (#2013)
Fixes #1989
2021-10-06 21:46:34 +03:00
Ariel Mashraki
14cba0abb6 dialect/sql/schema: make Field.Unique and Index.Unique equal (#2004)
This will allow moving from:

	field.String(c).Unique()

To:

	index.Field(c).Unique()

And vice versa
2021-10-03 16:20:28 +03:00
Ariel Mashraki
4306643d16 dialect/sql/sqlgraph: support sql.Scanner types when scanning IDs (#1987)
Fixed https://github.com/ent/ent/issues/1985
2021-09-27 17:49:57 +03:00
Ariel Mashraki
4c2faf2282 entc/gen: allow spaces in enum fields 2021-09-23 23:23:28 +03:00
storyicon
779594f7da dialect/sql/schema: support mysql mediumtext type (#1972)
Signed-off-by: storyicon <yuanchao@bilibili.com>
2021-09-22 15:35:14 +03:00
Ariel Mashraki
5c7c36bf29 dialect/sql/schema: skip parsing expression default for postgres
Fixed https://github.com/ent/ent/issues/1962
2021-09-21 15:59:04 +03:00
Ariel Mashraki
5f31091dcd entc/gen: support de/incrementing values on upsert
Fixed https://github.com/ent/ent/issues/1952.
2021-09-17 14:25:34 +03:00
Ariel Mashraki
912415e1e1 dialect/sql: add Add method to UpdateSet 2021-09-16 23:41:29 +03:00
Ariel Mashraki
3c650e507e dialect/sql: use raw 0 in COALESCE function on Add calls
The second argument for COALESCE function is not a dynamic argument (always 0).
2021-09-16 23:07:45 +03:00
Ariel Mashraki
38925b6134 dialect/sql/schema: revert #1547 for mariadb 2021-09-14 13:07:49 +03:00
Ariel Mashraki
0864659844 dialect/sql/sqlgraph: avoid creating tx blocks for single UPDATE statements
In PostgreSQL, every statement is executed within a transaction. Therefore, we can avoid
creating transaction blocks manually (group of statements surrounded by BEGIN and COMMIT)
for UpdateNodes operation with a single UPDATE statement.

Benchmark for 2000 operations was improved from:

	7.98s      3992160 ns/op    4887 B/op    116 allocs/op

To:

	4.42s      2209659 ns/op    4435 B/op    104 allocs/op

---

MySQL and SQLite share the same behavior. Please see #1858 for more info.
2021-09-11 08:56:37 +03:00
Emmanuel T Odeke
9904bcb8c8 all: add (*testing.B).ReportAllocs() to all benchmarks (#1919)
This allows a full picture when continuous benchmarking
is added to this repository and when any changes are made
to the code in here.

Fixes #1918
2021-09-07 17:04:07 +03:00
Ariel Mashraki
b23a0e8554 dialect/sql/sqlgraph: avoid creating tx blocks for single DELETE statements
In PostgreSQL, every statement is executed within a transaction. Therefore, we can avoid
creating transaction blocks manually (group of statements surrounded by BEGIN and COMMIT)
for DeleteNodes operation as it's implemented with a single statement.

Benchmark for 4000 operations was improved from:

	14.54s      7270455 ns/op    3702 B/op     81 allocs/op

To:

	5.36s      2679935 ns/op    2864 B/op     59 allocs/op

---

MySQL and SQLite share the same behavior. Please see https://github.com/ent/ent/pull/1858
for more info.
2021-08-27 16:02:29 +03:00
dakimura
dac5ccaec9 dialect/sql/schema: fix error message for the missing fk constraints (#1861) 2021-08-22 22:05:40 +03:00
Ariel Mashraki
ea67be12a4 dialect/sql/sqlgraph: avoid creating tx blocks for single statement create operation
For example, in PostgreSQL, every statement is executed within a transaction. Therefore, we can avoid creating transaction
blocks manually (group of statements surrounded by BEGIN and COMMIT) for CreateNode operation with single SQL statement.

Benchmark was improved from:

	(2000 Inserts)   8.41s      4206748 ns/op    4595 B/op    115 allocs/op

To:

	(2000 Inserts)   4.66s      2330222 ns/op    4107 B/op    104 allocs/op
2021-08-20 21:12:24 +03:00
Rotem Tamir
f326c7dfd0 dialect/sql: report explicit error when trying to SELECT .. FOR UPDAT… (#1847)
* dialect/sql: report explicit error when trying to SELECT .. FOR UPDATE with sqlite

* remove redundant assertion
2021-08-17 12:54:23 +03:00
Ariel Mashraki
b8532f87a6 entc/gen: support for upsert with client generated ids
Fixed #1826
2021-08-14 17:44:04 +03:00
Ariel Mashraki
e71ccc6b6e dialect/sql/sqlgraph: fix bug in entql predicate evaluation (#1827) 2021-08-11 21:03:52 +03:00
Ariel Mashraki
397b3e984d dialect/sql/schema: setup tables before execute hooks 2021-08-04 21:43:00 +03:00
Ariel Mashraki
09c4306378 entc/gen: add support for upsert/on-conflict feature-flag 2021-08-04 14:01:31 +03:00
Ariel Mashraki
16c4b3379b sqlgraph: change modifiers to onconflict options 2021-08-01 18:43:59 +03:00
Ariel Mashraki
b19ac669c7 dialect/sql: override column values on Updater.Set
Avoid cases like 'SET a = 1, a = 2'.
2021-08-01 09:53:26 +03:00
Ariel Mashraki
7acf2234b6 dialect/sql/sqlgraph: allow setting stmt modifiers for create-many 2021-07-29 16:33:26 +03:00
Ariel Mashraki
b9fcbff724 dialect/sql/sqlgraph: allow setting stmt modifiers for create-one 2021-07-29 16:33:26 +03:00
Ariel Mashraki
b8f8ea0f06 dialect/sql: move onconflict clause to functional options 2021-07-28 12:49:11 +03:00
Ruben de Vries
1586d50f94 dialect/sql: do not call inner Scan for nil values in sql.NullScanner (#1771) 2021-07-27 12:05:22 +03:00
Ariel Mashraki
9de519d027 dialect/sql: add expression function support 2021-07-27 11:36:56 +03:00
Andrey Elenskiy
20b616768d dialect/sql: return selector's alias as a table name (#1745)
In case selector's from clause has *Selector instead of *SelectTable,
TableName() function (used for column checking) will panic.

Instead, return selector's alias which is useful if the query returns
a table with the same schema as some entity. Essentially, this allows
materialized views to reuse the same entity code as long as columns
are matching.
2021-07-25 22:14:32 +03:00
Khadija Sidhpuri
364ab46333 dialect/sql: append UNION before ORDER BY (#1761)
* fix: builder to append UNION before ORDER_BY

* gofmt builder_test.go
2021-07-22 23:33:34 +03:00
Ariel Mashraki
6a7b3c8e7a entc/gen: add feature-flag and implementation for sql/lock
Fixed #358
2021-07-21 11:50:06 +03:00
Ariel Mashraki
279d6c2a12 dialect/sql/sqlgraph: add support for query modifiers 2021-07-20 13:14:39 +03:00
Tony Griezmann
201c7301aa dialect/sql/schema: support for USING method in create index builder (#1730)
* Support for USING 'method' in create index

* Add USING 'method' in create index support for MySQL

* Fix USING 'method' for MySQL to be a raw string
2021-07-19 15:21:35 +03:00
Ariel Mashraki
79716e47d0 dialect/sql/schema: remove unneeded nolint rule 2021-07-16 14:07:40 +03:00
Ruben de Vries
1ea718f7bf dialect/sql/schema: add support for postgres and mysql numeric and decimal types in migrations (#1721)
* improve error message when failing to generate changeset

* support migrations for postgres and mysql numeric fields
2021-07-16 13:57:53 +03:00