Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions generator/templates/builders_create.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func loadRelation[P any, C any](
scan func(*sql.Rows, *C) error,
childKey func(*C) (string, bool),
assign func(*P, []*C),
params QueryParams,
params QueryParams[C],
) ([]*C, error) {
var parentKeys []any
for _, p := range parents {
Expand All @@ -312,9 +312,9 @@ func loadRelation[P any, C any](
return nil, nil
}

// Prepend parent ID checks to filters using StandardPredicate
allPreds := append([]Predicate{
StandardPredicate{
// Prepend parent ID checks to filters using Predicate[C]
allPreds := append([]PredicateOf[C]{
Predicate[C]{
Data: PredicateData{
Column: fkCol,
Operator: "IN",
Expand Down Expand Up @@ -366,14 +366,14 @@ func loadRelation[P any, C any](
return allChildren, nil
}

func compileRelationSQL(dialect Dialect, table, fkCol string, cols []string, where string, params QueryParams) string {
func compileRelationSQL[M any](dialect Dialect, table, fkCol string, cols []string, where string, params QueryParams[M]) string {
if params.Take != nil || params.Skip != nil {
return compilePartitionedRelationSQL(dialect, table, fkCol, cols, where, params)
}
return compileSimpleRelationSQL(dialect, table, cols, where, params)
}

func compilePartitionedRelationSQL(dialect Dialect, table, fkCol string, cols []string, where string, params QueryParams) string {
func compilePartitionedRelationSQL[M any](dialect Dialect, table, fkCol string, cols []string, where string, params QueryParams[M]) string {
var innerSb strings.Builder
innerSb.WriteString("SELECT ")
for i, col := range cols {
Expand Down Expand Up @@ -424,7 +424,7 @@ func compilePartitionedRelationSQL(dialect Dialect, table, fkCol string, cols []
return outerSb.String()
}

func compileSimpleRelationSQL(dialect Dialect, table string, cols []string, where string, params QueryParams) string {
func compileSimpleRelationSQL[M any](dialect Dialect, table string, cols []string, where string, params QueryParams[M]) string {
var sb strings.Builder
sb.WriteString("SELECT ")
for i, col := range cols {
Expand Down
26 changes: 13 additions & 13 deletions generator/templates/builders_query.gotpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type FindUniqueBuilder[M any, S any, O any] struct {
client *Queries
where UniquePredicate
additional []Predicate
execFunc func(ctx context.Context, where UniquePredicate, additional []Predicate, s *S, o *O) (*M, error)
where UniquePredicate[M]
additional []PredicateOf[M]
execFunc func(ctx context.Context, where UniquePredicate[M], additional []PredicateOf[M], s *S, o *O) (*M, error)
}

func (b *FindUniqueBuilder[M, S, O]) Select(s S) *FindUniqueSelectBuilder[M, S, O] {
Expand Down Expand Up @@ -37,9 +37,9 @@ func (b *FindUniqueOmitBuilder[M, S, O]) Exec(ctx context.Context) (*M, error) {

type FindFirstBuilder[M any, S any, O any] struct {
client *Queries
where []Predicate
where []PredicateOf[M]
skip *int
execFunc func(ctx context.Context, params QueryParams, s *S, o *O) (*M, error)
execFunc func(ctx context.Context, params QueryParams[M], s *S, o *O) (*M, error)
}

func (b *FindFirstBuilder[M, S, O]) Skip(offset int) *FindFirstBuilder[M, S, O] {
Expand All @@ -56,7 +56,7 @@ func (b *FindFirstBuilder[M, S, O]) Omit(o O) *FindFirstOmitBuilder[M, S, O] {
}

func (b *FindFirstBuilder[M, S, O]) Exec(ctx context.Context) (*M, error) {
params := QueryParams{
params := QueryParams[M]{
Where: b.where,
Skip: b.skip,
}
Expand All @@ -69,7 +69,7 @@ type FindFirstSelectBuilder[M any, S any, O any] struct {
}

func (b *FindFirstSelectBuilder[M, S, O]) Exec(ctx context.Context) (*M, error) {
params := QueryParams{
params := QueryParams[M]{
Where: b.builder.where,
Skip: b.builder.skip,
}
Expand All @@ -82,7 +82,7 @@ type FindFirstOmitBuilder[M any, S any, O any] struct {
}

func (b *FindFirstOmitBuilder[M, S, O]) Exec(ctx context.Context) (*M, error) {
params := QueryParams{
params := QueryParams[M]{
Where: b.builder.where,
Skip: b.builder.skip,
}
Expand All @@ -91,10 +91,10 @@ func (b *FindFirstOmitBuilder[M, S, O]) Exec(ctx context.Context) (*M, error) {

type FindManyBuilder[M any, S any, O any] struct {
client *Queries
where []Predicate
where []PredicateOf[M]
take *int
skip *int
execFunc func(ctx context.Context, params QueryParams, s *S, o *O) ([]*M, error)
execFunc func(ctx context.Context, params QueryParams[M], s *S, o *O) ([]*M, error)
}

func (b *FindManyBuilder[M, S, O]) Take(limit int) *FindManyBuilder[M, S, O] {
Expand All @@ -116,7 +116,7 @@ func (b *FindManyBuilder[M, S, O]) Omit(o O) *FindManyOmitBuilder[M, S, O] {
}

func (b *FindManyBuilder[M, S, O]) Exec(ctx context.Context) ([]*M, error) {
params := QueryParams{
params := QueryParams[M]{
Where: b.where,
Take: b.take,
Skip: b.skip,
Expand All @@ -130,7 +130,7 @@ type FindManySelectBuilder[M any, S any, O any] struct {
}

func (b *FindManySelectBuilder[M, S, O]) Exec(ctx context.Context) ([]*M, error) {
params := QueryParams{
params := QueryParams[M]{
Where: b.builder.where,
Take: b.builder.take,
Skip: b.builder.skip,
Expand All @@ -144,7 +144,7 @@ type FindManyOmitBuilder[M any, S any, O any] struct {
}

func (b *FindManyOmitBuilder[M, S, O]) Exec(ctx context.Context) ([]*M, error) {
params := QueryParams{
params := QueryParams[M]{
Where: b.builder.where,
Take: b.builder.take,
Skip: b.builder.skip,
Expand Down
Loading
Loading