Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crossworth/enthstore
Postgres Hstore type for Ent
https://github.com/crossworth/enthstore
ent gqlgen graphql postgresql
Last synced: 13 days ago
JSON representation
Postgres Hstore type for Ent
- Host: GitHub
- URL: https://github.com/crossworth/enthstore
- Owner: crossworth
- Created: 2022-02-03T02:28:35.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-03T03:54:53.000Z (almost 3 years ago)
- Last Synced: 2023-07-27T22:02:04.567Z (over 1 year ago)
- Topics: ent, gqlgen, graphql, postgresql
- Language: Go
- Homepage:
- Size: 65.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Hstore type and predicates for Ent.
This package defines the [`Postgres hstore`](https://www.postgresql.org/docs/9/hstore.html) type
to be used with [`ent`](https://github.com/ent/ent) and a few predicates.### Using the type:
```go
func (User) Fields() []ent.Field {
return []ent.Field{
field.Other("attributes", enthstore.Hstore{}).
SchemaType(enthstore.Hstore{}.SchemaType()).
Default(func() enthstore.Hstore {
return enthstore.Hstore{}
}),
}
}
```### Using the predicates:
```go
users, err := client.User.Query().Where(func(selector *sql.Selector) {
selector.Where(enthstore.HasKey(user.FieldAttributes, "a"))
}).All(context.Background)
```#### List of predicates:
- HasKey
- HasAllKeys
- ValueIsNull
- ValueEQ
- ValueNEQ
- ValueGT
- ValueGTE
- ValueLT
- ValueLTE
- ValueContains
- ValueHasPrefix
- ValueHasSuffix### Using with [GQLGen](https://github.com/99designs/gqlgen):
Define a [custom scalar](https://gqlgen.com/reference/scalars/):
```graphql
scalar Hstore
```And declare the type mapping on `gqlgen.yml`:
```yaml
models:
Hstore:
model: github.com/crossworth/enthstore.Hstore
```