models

package
v2.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 17 Imported by: 0

README

Test Models

This directory contains SQLBoiler-generated models for integration testing.

Files

  • schema.sql - PostgreSQL schema defining test tables (users, posts)
  • sqlboiler.toml - SQLBoiler configuration for model generation
  • Dockerfile - Docker image with SQLBoiler for model generation
  • *.go - Generated SQLBoiler models (do not edit manually)

Regenerating Models

If you modify schema.sql, regenerate the models:

# From repository root
docker build -t go-paging-sqlboiler -f tests/models/Dockerfile .

# Run SQLBoiler to generate models
docker run --rm \
  --network host \
  -v "$(pwd):/workspace" \
  go-paging-sqlboiler \
  "sqlboiler psql -c tests/models/sqlboiler.toml"
Using Local SQLBoiler
# Install SQLBoiler
go install github.com/aarondl/sqlboiler/v4@latest
go install github.com/aarondl/sqlboiler/v4/drivers/sqlboiler-psql@latest

# Start PostgreSQL (integration tests use testcontainers, so this is just for generation)
# You'll need a local PostgreSQL instance with the schema loaded

# Generate models
sqlboiler psql -c tests/models/sqlboiler.toml

Schema Overview

users Table
  • id (UUID, primary key)
  • name (TEXT)
  • email (TEXT)
  • created_at (TIMESTAMP)
  • updated_at (TIMESTAMP)
posts Table
  • id (UUID, primary key)
  • user_id (UUID, foreign key → users)
  • title (TEXT)
  • content (TEXT)
  • published_at (TIMESTAMP, nullable)
  • created_at (TIMESTAMP)
  • updated_at (TIMESTAMP)

Notes

  • Models are regenerated when schema changes
  • The sqlboiler.toml config outputs to this directory
  • Integration tests use testcontainers, so no local PostgreSQL required for testing
  • The schema is applied automatically by integration tests via migrations

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSyncFail = errors.New("models: failed to synchronize data after insert")

ErrSyncFail occurs during insert when the record could not be retrieved in order to populate default value information. This usually happens when LastInsertId fails or there was a primary key configuration that was not resolvable.

View Source
var PostColumns = struct {
	ID          string
	UserID      string
	Title       string
	Content     string
	ViewCount   string
	PublishedAt string
	CreatedAt   string
	UpdatedAt   string
}{
	ID:          "id",
	UserID:      "user_id",
	Title:       "title",
	Content:     "content",
	ViewCount:   "view_count",
	PublishedAt: "published_at",
	CreatedAt:   "created_at",
	UpdatedAt:   "updated_at",
}
View Source
var PostRels = struct {
	User string
}{
	User: "User",
}

PostRels is where relationship names are stored.

View Source
var PostTableColumns = struct {
	ID          string
	UserID      string
	Title       string
	Content     string
	ViewCount   string
	PublishedAt string
	CreatedAt   string
	UpdatedAt   string
}{
	ID:          "posts.id",
	UserID:      "posts.user_id",
	Title:       "posts.title",
	Content:     "posts.content",
	ViewCount:   "posts.view_count",
	PublishedAt: "posts.published_at",
	CreatedAt:   "posts.created_at",
	UpdatedAt:   "posts.updated_at",
}
View Source
var PostWhere = struct {
	ID          whereHelperstring
	UserID      whereHelperstring
	Title       whereHelperstring
	Content     whereHelpernull_String
	ViewCount   whereHelpernull_Int
	PublishedAt whereHelpernull_Time
	CreatedAt   whereHelpertime_Time
	UpdatedAt   whereHelpertime_Time
}{
	ID:          whereHelperstring{/* contains filtered or unexported fields */},
	UserID:      whereHelperstring{/* contains filtered or unexported fields */},
	Title:       whereHelperstring{/* contains filtered or unexported fields */},
	Content:     whereHelpernull_String{/* contains filtered or unexported fields */},
	ViewCount:   whereHelpernull_Int{/* contains filtered or unexported fields */},
	PublishedAt: whereHelpernull_Time{/* contains filtered or unexported fields */},
	CreatedAt:   whereHelpertime_Time{/* contains filtered or unexported fields */},
	UpdatedAt:   whereHelpertime_Time{/* contains filtered or unexported fields */},
}
View Source
var TableNames = struct {
	Posts string
	Users string
}{
	Posts: "posts",
	Users: "users",
}
View Source
var UserColumns = struct {
	ID        string
	Email     string
	Name      string
	Age       string
	IsActive  string
	CreatedAt string
	UpdatedAt string
}{
	ID:        "id",
	Email:     "email",
	Name:      "name",
	Age:       "age",
	IsActive:  "is_active",
	CreatedAt: "created_at",
	UpdatedAt: "updated_at",
}
View Source
var UserRels = struct {
	Posts string
}{
	Posts: "Posts",
}

UserRels is where relationship names are stored.

View Source
var UserTableColumns = struct {
	ID        string
	Email     string
	Name      string
	Age       string
	IsActive  string
	CreatedAt string
	UpdatedAt string
}{
	ID:        "users.id",
	Email:     "users.email",
	Name:      "users.name",
	Age:       "users.age",
	IsActive:  "users.is_active",
	CreatedAt: "users.created_at",
	UpdatedAt: "users.updated_at",
}
View Source
var UserWhere = struct {
	ID        whereHelperstring
	Email     whereHelperstring
	Name      whereHelperstring
	Age       whereHelpernull_Int
	IsActive  whereHelpernull_Bool
	CreatedAt whereHelpertime_Time
	UpdatedAt whereHelpertime_Time
}{
	ID:        whereHelperstring{/* contains filtered or unexported fields */},
	Email:     whereHelperstring{/* contains filtered or unexported fields */},
	Name:      whereHelperstring{/* contains filtered or unexported fields */},
	Age:       whereHelpernull_Int{/* contains filtered or unexported fields */},
	IsActive:  whereHelpernull_Bool{/* contains filtered or unexported fields */},
	CreatedAt: whereHelpertime_Time{/* contains filtered or unexported fields */},
	UpdatedAt: whereHelpertime_Time{/* contains filtered or unexported fields */},
}
View Source
var ViewNames = struct {
}{}

Functions

func NewQuery

func NewQuery(mods ...qm.QueryMod) *queries.Query

NewQuery initializes a new Query using the passed in QueryMods

func PostExists

func PostExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error)

PostExists checks if the Post row exists.

func Posts

func Posts(mods ...qm.QueryMod) postQuery

Posts retrieves all the records using an executor.

func UserExists

func UserExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error)

UserExists checks if the User row exists.

func Users

func Users(mods ...qm.QueryMod) userQuery

Users retrieves all the records using an executor.

Types

type M

type M map[string]interface{}

M type is for providing columns and column values to UpdateAll.

type Post

type Post struct {
	ID          string      `boil:"id" json:"id" toml:"id" yaml:"id"`
	UserID      string      `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
	Title       string      `boil:"title" json:"title" toml:"title" yaml:"title"`
	Content     null.String `boil:"content" json:"content,omitempty" toml:"content" yaml:"content,omitempty"`
	ViewCount   null.Int    `boil:"view_count" json:"view_count,omitempty" toml:"view_count" yaml:"view_count,omitempty"`
	PublishedAt null.Time   `boil:"published_at" json:"published_at,omitempty" toml:"published_at" yaml:"published_at,omitempty"`
	CreatedAt   time.Time   `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	UpdatedAt   time.Time   `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`

	R *postR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L postL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

Post is an object representing the database table.

func FindPost

func FindPost(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*Post, error)

FindPost retrieves a single record by ID with an executor. If selectCols is empty Find will return all columns.

func (*Post) Delete

func (o *Post) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error)

Delete deletes a single Post record with an executor. Delete will match against the primary key column to find the record to delete.

func (*Post) Exists

func (o *Post) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error)

Exists checks if the Post row exists.

func (*Post) GetUser

func (o *Post) GetUser() *User

func (*Post) Insert

func (o *Post) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error

Insert a single record using an executor. See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.

func (*Post) Reload

func (o *Post) Reload(ctx context.Context, exec boil.ContextExecutor) error

Reload refetches the object from the database using the primary keys with an executor.

func (*Post) SetUser

func (o *Post) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *User) error

SetUser of the post to the related item. Sets o.R.User to related. Adds o to related.R.Posts.

func (*Post) Update

func (o *Post) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error)

Update uses an executor to update the Post. See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates. Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.

func (*Post) Upsert

func (o *Post) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error

Upsert attempts an insert using an executor, and does an update or ignore on conflict. See boil.Columns documentation for how to properly use updateColumns and insertColumns.

func (*Post) User

func (o *Post) User(mods ...qm.QueryMod) userQuery

User pointed to by the foreign key.

type PostSlice

type PostSlice []*Post

PostSlice is an alias for a slice of pointers to Post. This should almost always be used instead of []Post.

func (PostSlice) DeleteAll

func (o PostSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error)

DeleteAll deletes all rows in the slice, using an executor.

func (*PostSlice) ReloadAll

func (o *PostSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error

ReloadAll refetches every row with matching primary key column values and overwrites the original object slice with the newly updated slice.

func (PostSlice) UpdateAll

func (o PostSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error)

UpdateAll updates all rows with the specified column values, using an executor.

type UpsertOptionFunc

type UpsertOptionFunc func(o *UpsertOptions)

func UpsertConflictTarget

func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc

func UpsertUpdateSet

func UpsertUpdateSet(updateSet string) UpsertOptionFunc

type UpsertOptions

type UpsertOptions struct {
	// contains filtered or unexported fields
}

type User

type User struct {
	ID        string    `boil:"id" json:"id" toml:"id" yaml:"id"`
	Email     string    `boil:"email" json:"email" toml:"email" yaml:"email"`
	Name      string    `boil:"name" json:"name" toml:"name" yaml:"name"`
	Age       null.Int  `boil:"age" json:"age,omitempty" toml:"age" yaml:"age,omitempty"`
	IsActive  null.Bool `boil:"is_active" json:"is_active,omitempty" toml:"is_active" yaml:"is_active,omitempty"`
	CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`

	R *userR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L userL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

User is an object representing the database table.

func FindUser

func FindUser(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*User, error)

FindUser retrieves a single record by ID with an executor. If selectCols is empty Find will return all columns.

func (*User) AddPosts

func (o *User) AddPosts(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Post) error

AddPosts adds the given related objects to the existing relationships of the user, optionally inserting them as new records. Appends related to o.R.Posts. Sets related.R.User appropriately.

func (*User) Delete

func (o *User) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error)

Delete deletes a single User record with an executor. Delete will match against the primary key column to find the record to delete.

func (*User) Exists

func (o *User) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error)

Exists checks if the User row exists.

func (*User) GetPosts

func (o *User) GetPosts() PostSlice

func (*User) Insert

func (o *User) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error

Insert a single record using an executor. See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.

func (*User) Posts

func (o *User) Posts(mods ...qm.QueryMod) postQuery

Posts retrieves all the post's Posts with an executor.

func (*User) Reload

func (o *User) Reload(ctx context.Context, exec boil.ContextExecutor) error

Reload refetches the object from the database using the primary keys with an executor.

func (*User) Update

func (o *User) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error)

Update uses an executor to update the User. See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates. Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.

func (*User) Upsert

func (o *User) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error

Upsert attempts an insert using an executor, and does an update or ignore on conflict. See boil.Columns documentation for how to properly use updateColumns and insertColumns.

type UserSlice

type UserSlice []*User

UserSlice is an alias for a slice of pointers to User. This should almost always be used instead of []User.

func (UserSlice) DeleteAll

func (o UserSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error)

DeleteAll deletes all rows in the slice, using an executor.

func (*UserSlice) ReloadAll

func (o *UserSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error

ReloadAll refetches every row with matching primary key column values and overwrites the original object slice with the newly updated slice.

func (UserSlice) UpdateAll

func (o UserSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error)

UpdateAll updates all rows with the specified column values, using an executor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址