Add generated Bob database integration
This commit is contained in:
parent
8203c50b08
commit
7c4a181cdf
32 changed files with 5128 additions and 2 deletions
67
models/bob_loaders.bob.go
Normal file
67
models/bob_loaders.bob.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
)
|
||||
|
||||
var Preload = getPreloaders()
|
||||
|
||||
type preloaders struct {
|
||||
Organization organizationPreloader
|
||||
User userPreloader
|
||||
}
|
||||
|
||||
func getPreloaders() preloaders {
|
||||
return preloaders{
|
||||
Organization: buildOrganizationPreloader(),
|
||||
User: buildUserPreloader(),
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
SelectThenLoad = getThenLoaders[*dialect.SelectQuery]()
|
||||
InsertThenLoad = getThenLoaders[*dialect.InsertQuery]()
|
||||
UpdateThenLoad = getThenLoaders[*dialect.UpdateQuery]()
|
||||
)
|
||||
|
||||
type thenLoaders[Q orm.Loadable] struct {
|
||||
Organization organizationThenLoader[Q]
|
||||
User userThenLoader[Q]
|
||||
}
|
||||
|
||||
func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
||||
return thenLoaders[Q]{
|
||||
Organization: buildOrganizationThenLoader[Q](),
|
||||
User: buildUserThenLoader[Q](),
|
||||
}
|
||||
}
|
||||
|
||||
func thenLoadBuilder[Q orm.Loadable, T any](name string, f func(context.Context, bob.Executor, T, ...bob.Mod[*dialect.SelectQuery]) error) func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] {
|
||||
return func(queryMods ...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] {
|
||||
return func(ctx context.Context, exec bob.Executor, retrieved any) error {
|
||||
loader, isLoader := retrieved.(T)
|
||||
if !isLoader {
|
||||
return fmt.Errorf("object %T cannot load %q", retrieved, name)
|
||||
}
|
||||
|
||||
err := f(ctx, exec, loader, queryMods...)
|
||||
|
||||
// Don't cause an issue due to missing relationships
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue