Questions tagged [ent]
18 questions
5
votes
2 answers
How to get the sum of numeric column in Ent
I have two tables: products and baskets, which have the M2M relation and the table name is basket_products. I am trying to get the specific basket-related products total price and quantity, but I am getting stuck again. How can I fix the following…

dsha256
- 230
- 1
- 7
4
votes
2 answers
How to setup pgx to get UTC values from DB?
I'm using Ent with Pgx.
The column created in Postgres is:
used_at timestamp with time zone NOT NULL,
The value in Postgres is saved without timezone (in UTC):
2022-06-30 22:49:03.970913+00
Using this query:
show timezone
I get:
Etc/UTC
But from…

Fred Hors
- 3,258
- 3
- 25
- 71
4
votes
1 answer
Create base entity in go ent framework
I'm new to golang, and am using ent framework as an ORM.
Every schema should have the fields created_at and updated_at, and I want to write it once rather then write it for every schema i.e:
func (User) Fields() []ent.Field {
return…

Avishay28
- 2,288
- 4
- 25
- 47
3
votes
0 answers
What is the difference between database/sql connection & pgx pool on golang?
I'm trying to use ent on golang backed with postgresql DB.
Current legacy code uses pgxpool for connection pool. But ent does not support pgx pool, and only support standard connection pool of database/sql.
What is difference between two? Is it ok…

Hyukjoong Kim
- 81
- 5
2
votes
1 answer
How to make not to generate struct tag `json:"omitempty"`
I am using Go Ent for ORM in my Go server.
The problem is, whenever I generate codes by custom schema, it makes all the fields with omitempty tag.
For example, this is my ent/schema/user.go.
type User struct {
ent.Schema
}
// Fields of the…

Ellisein
- 878
- 6
- 17
1
vote
0 answers
mysql 5.7 decimal precision lost after mysql operator '+'
ddl:
CREATE TABLE `tests` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`num` decimal(40,20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
sql:
query=UPDATE `tests` SET `num` = ? WHERE…

solitary
- 11
- 2
1
vote
1 answer
Nested aggregation in Ent Query
How can I write this simple SQL statement using the code generated by Ent?
select max(t.sum_score) from
(select sum(score) as "sum_score"
from matches
group by…

cimere
- 667
- 1
- 8
- 22
1
vote
0 answers
ENTGQL go generate ./... UUID Error (error calling gqlIDType)
I have a problem. I'm trying to integrate entgo with gqlgen, and my go generate ./... command doesn't work. It throws an error below
running ent codegen: execute template "client": template:
node.tmpl:315:16: executing "client/fields/additional" at…

Nicolas
- 13
- 2
1
vote
1 answer
ent-go o2m upsert duplication
I am trying to upsert table A, with relations to table B - also, upserting via ent-go's framework with Postgres.
CmdbCiServerVmwareVirtualMachine:
…

Rygo
- 159
- 1
- 8
1
vote
1 answer
How to customize the columns corresponding to the foreign keys when they are created in entgo?
Assume the following schema
type Pet struct {
ent.Schema
}
// Fields of the Pet.
func (Pet) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
}
}
// Edges of the Pet.
func (Pet) Edges() []ent.Edge {
return…

Zxilly
- 33
- 5
1
vote
0 answers
How to test error case in golang with "entgo.io/ent"
I am writing go code in a project using ent,
and wondering if there are any ways to test specific error block thrown by Save.
Does anyone know good practice to do this?
test target code example
(from: ent/examples/start/start.go)
func CreateCars(ctx…

a10a
- 211
- 2
- 10
1
vote
0 answers
How to sort by aggregated column in ENT?
I'd like to execute a query like this using ENT:
select
some_column,
count(*)
from some_table
group by some_column
order by count desc
limit 10
I.e. to get the top N of some records using an aggregate. I couldn't figure out how to do the…

psmith
- 2,292
- 1
- 19
- 19
1
vote
0 answers
Getting multiple errors while trying generate grpc files using protoc-gen-entgrpc
Even after installing protoc-gen-entgrpc with this command
go install entgo.io/contrib/entproto/cmd/protoc-gen-entgrpc@latest
still getting multiple errors with protoc-gen-entgrpc
This are the errors I got,
Could not make proto path relative:…

M_x
- 782
- 1
- 8
- 26
1
vote
0 answers
GQLGen related list query limit using entgql
I'm using entgql implementation of gqlgen (https://entgo.io/docs/graphql/) and have run into an issue where after my query reaches a certain size, it starts returning related lists as empty lists.
Rough data as follows
type Partner implements Node…

skeletalmonkey
- 726
- 1
- 10
- 20
1
vote
1 answer
Ent. how to remove a column?
I have already an Ent model in my go project. But I need to remove some columns from the model.
It not works when I update my model. Running migration results runtime error.
How can I remove a column from existing model in Ent. ORM?

S.M.Mousavi
- 5,013
- 7
- 44
- 59