pop: github.com/gobuffalo/pop Index | Files | Directories

package pop

import "github.com/gobuffalo/pop"

Package pop wraps the absolutely amazing https://github.com/jmoiron/sqlx library. It cleans up some of the common patterns and workflows usually associated with dealing with databases in Go.

Pop makes it easy to do CRUD operations, run migrations, and build/execute queries. Is Pop an ORM? I'll leave that up to you, the reader, to decide.

Pop, by default, follows conventions that were defined by the ActiveRecord Ruby gem, http://www.rubyonrails.org. What does this mean?

* Tables must have an "id" column and a corresponding "ID" field on the `struct` being used. * If there is a timestamp column named "created_at", "CreatedAt" on the `struct`, it will be set with the current time when the record is created. * If there is a timestamp column named "updated_at", "UpdatedAt" on the `struct`, it will be set with the current time when the record is updated. * Default databases are lowercase, underscored versions of the `struct` name. Examples: User{} is "users", FooBar{} is "foo_bars", etc...

Index

Package Files

belongs_to.go callbacks.go clause.go commands.go config.go connection.go connection_details.go db.go dialect.go dialect_cockroach.go dialect_mysql.go dialect_postgresql.go dialect_sqlite_shim.go doc.go executors.go executors_eager.go file_migrator.go finders.go group.go having.go join.go logger.go migration.go migration_box.go migration_info.go migrator.go model.go paginator.go pop.go query.go query_groups.go query_having.go query_joins.go schema_migrations.go scopes.go sql_builder.go store.go tx.go validations.go

Variables

var AvailableDialects []string

AvailableDialects lists the available database dialects

var Color = true

Color mode, to toggle colored logs

var ConfigName = "database.yml"

ConfigName is the name of the YAML databases config file

var Connections = map[string]*Connection{}

Connections contains all available connections

var Debug = false

Debug mode, to toggle verbose log traces

var ErrConfigFileNotFound = errors.New("unable to find pop config file")

ErrConfigFileNotFound is returned when the pop config file can't be found, after looking for it.

var Log legacyLogger

Log defines the pop logger. Override it to customize pop logs handling. Deprecated: use SetLogger instead

var PaginatorPageKey = "page"

PaginatorPageKey is the query parameter holding the current page index

var PaginatorPerPageDefault = 20

PaginatorPerPageDefault is the amount of results per page

var PaginatorPerPageKey = "per_page"

PaginatorPerPageKey is the query parameter holding the amount of results per page to override the default one

func AddLookupPaths Uses

func AddLookupPaths(paths ...string) error

AddLookupPaths add paths to the current lookup paths list

func CreateDB Uses

func CreateDB(c *Connection) error

CreateDB creates a database, given a connection definition

func DialectSupported Uses

func DialectSupported(d string) bool

DialectSupported checks support for the given database dialect

func DropDB Uses

func DropDB(c *Connection) error

DropDB drops an existing database, given a connection definition

func IsZeroOfUnderlyingType Uses

func IsZeroOfUnderlyingType(x interface{}) bool

IsZeroOfUnderlyingType will check if the value of anything is the equal to the Zero value of that type.

func LoadConfigFile Uses

func LoadConfigFile() error

LoadConfigFile loads a POP config file from the configured lookup paths

func LoadFrom Uses

func LoadFrom(r io.Reader) error

LoadFrom reads a configuration from the reader and sets up the connections

func LookupPaths Uses

func LookupPaths() []string

LookupPaths returns the current configuration lookup paths

func MigrationCreate Uses

func MigrationCreate(path, name, ext string, up, down []byte) error

MigrationCreate writes contents for a given migration in normalized files

func SetLogger Uses

func SetLogger(l logger)

SetLogger overrides the default logger.

The logger must implement the following interface: type logger func(lvl logging.Level, s string, args ...interface{})

type AfterCreateable Uses

type AfterCreateable interface {
    AfterCreate(*Connection) error
}

AfterCreateable callback will be called after a record is created in the database.

type AfterDestroyable Uses

type AfterDestroyable interface {
    AfterDestroy(*Connection) error
}

AfterDestroyable callback will be called after a record is destroyed in the database.

type AfterFindable Uses

type AfterFindable interface {
    AfterFind(*Connection) error
}

AfterFindable callback will be called after a record, or records, has been retrieved from the database.

type AfterSaveable Uses

type AfterSaveable interface {
    AfterSave(*Connection) error
}

AfterSaveable callback will be called after a record is either created or updated in the database.

type AfterUpdateable Uses

type AfterUpdateable interface {
    AfterUpdate(*Connection) error
}

AfterUpdateable callback will be called after a record is updated in the database.

type BeforeCreateable Uses

type BeforeCreateable interface {
    BeforeCreate(*Connection) error
}

BeforeCreateable callback will be called before a record is created in the database.

type BeforeDestroyable Uses

type BeforeDestroyable interface {
    BeforeDestroy(*Connection) error
}

BeforeDestroyable callback will be called before a record is destroyed in the database.

type BeforeSaveable Uses

type BeforeSaveable interface {
    BeforeSave(*Connection) error
}

BeforeSaveable callback will be called before a record is either created or updated in the database.

type BeforeUpdateable Uses

type BeforeUpdateable interface {
    BeforeUpdate(*Connection) error
}

BeforeUpdateable callback will be called before a record is updated in the database.

type Connection Uses

type Connection struct {
    ID      string
    Store   store
    Dialect dialect
    Elapsed int64
    TX      *Tx
    // contains filtered or unexported fields
}

Connection represents all necessary details to talk with a datastore

func Connect Uses

func Connect(e string) (*Connection, error)

Connect takes the name of a connection, default is "development", and will return that connection from the available `Connections`. If a connection with that name can not be found an error will be returned. If a connection is found, and it has yet to open a connection with its underlying datastore, a connection to that store will be opened.

func NewConnection Uses

func NewConnection(deets *ConnectionDetails) (*Connection, error)

NewConnection creates a new connection, and sets it's `Dialect` appropriately based on the `ConnectionDetails` passed into it.

func (*Connection) All Uses

func (c *Connection) All(models interface{}) error

All retrieves all of the records in the database that match the query.

c.All(&[]User{})

func (*Connection) BelongsTo Uses

func (c *Connection) BelongsTo(model interface{}) *Query

BelongsTo adds a "where" clause based on the "ID" of the "model" passed into it.

func (*Connection) BelongsToAs Uses

func (c *Connection) BelongsToAs(model interface{}, as string) *Query

BelongsToAs adds a "where" clause based on the "ID" of the "model" passed into it using an alias.

func (*Connection) BelongsToThrough Uses

func (c *Connection) BelongsToThrough(bt, thru interface{}) *Query

BelongsToThrough adds a "where" clause that connects the "bt" model through the associated "thru" model.

func (*Connection) Close Uses

func (c *Connection) Close() error

Close destroys an active datasource connection

func (*Connection) Count Uses

func (c *Connection) Count(model interface{}) (int, error)

Count the number of records in the database.

c.Count(&User{})

func (*Connection) Create Uses

func (c *Connection) Create(model interface{}, excludeColumns ...string) error

Create add a new given entry to the database, excluding the given columns. It updates `created_at` and `updated_at` columns automatically.

func (*Connection) Destroy Uses

func (c *Connection) Destroy(model interface{}) error

Destroy deletes a given entry from the database

func (*Connection) Eager Uses

func (c *Connection) Eager(fields ...string) *Connection

Eager will enable associations loading of the model. by defaults loads all the associations on the model, but can take a variadic list of associations to load.

c.Eager().Find(model, 1) // will load all associations for model.
c.Eager("Books").Find(model, 1) // will load only Book association for model.

Eager also enable nested models creation:

model := Parent{Child: Child{}, Parent: &Parent{}}
c.Eager().Create(&model) // will create all associations for model.
c.Eager("Child").Create(&model) // will only create the Child association for model.

func (*Connection) Find Uses

func (c *Connection) Find(model interface{}, id interface{}) error

Find the first record of the model in the database with a particular id.

c.Find(&User{}, 1)

func (*Connection) First Uses

func (c *Connection) First(model interface{}) error

First record of the model in the database that matches the query.

c.First(&User{})

func (*Connection) Last Uses

func (c *Connection) Last(model interface{}) error

Last record of the model in the database that matches the query.

c.Last(&User{})

func (*Connection) Limit Uses

func (c *Connection) Limit(limit int) *Query

Limit will create a query and add a limit clause to it.

c.Limit(10)

func (*Connection) Load Uses

func (c *Connection) Load(model interface{}, fields ...string) error

Load loads all association or the fields specified in params for an already loaded model.

tx.First(&u) tx.Load(&u)

func (*Connection) MigrateDown Uses

func (c *Connection) MigrateDown(path string, step int) error

MigrateDown is deprecated, and will be removed in a future version. Use FileMigrator#Down instead.

func (*Connection) MigrateReset Uses

func (c *Connection) MigrateReset(path string) error

MigrateReset is deprecated, and will be removed in a future version. Use FileMigrator#Reset instead.

func (*Connection) MigrateStatus Uses

func (c *Connection) MigrateStatus(path string) error

MigrateStatus is deprecated, and will be removed in a future version. Use FileMigrator#Status instead.

func (*Connection) MigrateUp Uses

func (c *Connection) MigrateUp(path string) error

MigrateUp is deprecated, and will be removed in a future version. Use FileMigrator#Up instead.

func (*Connection) MigrationTableName Uses

func (c *Connection) MigrationTableName() string

MigrationTableName returns the name of the table to track migrations

func (*Connection) MigrationURL Uses

func (c *Connection) MigrationURL() string

MigrationURL returns the datasource connection string used for running the migrations

func (*Connection) NewTransaction Uses

func (c *Connection) NewTransaction() (*Connection, error)

NewTransaction starts a new transaction on the connection

func (*Connection) Open Uses

func (c *Connection) Open() error

Open creates a new datasource connection

func (*Connection) Order Uses

func (c *Connection) Order(stmt string) *Query

Order will append an order clause to the query.

c.Order("name desc")

func (*Connection) Paginate Uses

func (c *Connection) Paginate(page int, perPage int) *Query

Paginate records returned from the database.

q := c.Paginate(2, 15)
q.All(&[]User{})
q.Paginator

func (*Connection) PaginateFromParams Uses

func (c *Connection) PaginateFromParams(params PaginationParams) *Query

PaginateFromParams paginates records returned from the database.

q := c.PaginateFromParams(req.URL.Query())
q.All(&[]User{})
q.Paginator

func (*Connection) Q Uses

func (c *Connection) Q() *Query

Q creates a new "empty" query for the current connection.

func (*Connection) RawQuery Uses

func (c *Connection) RawQuery(stmt string, args ...interface{}) *Query

RawQuery will override the query building feature of Pop and will use whatever query you want to execute against the `Connection`. You can continue to use the `?` argument syntax.

c.RawQuery("select * from foo where id = ?", 1)

func (*Connection) Reload Uses

func (c *Connection) Reload(model interface{}) error

Reload fetch fresh data for a given model, using its ID.

func (*Connection) Rollback Uses

func (c *Connection) Rollback(fn func(tx *Connection)) error

Rollback will open a new transaction and automatically rollback that transaction when the inner function returns, regardless. This can be useful for tests, etc...

func (*Connection) Save Uses

func (c *Connection) Save(model interface{}, excludeColumns ...string) error

Save wraps the Create and Update methods. It executes a Create if no ID is provided with the entry; or issues an Update otherwise.

func (*Connection) Scope Uses

func (c *Connection) Scope(sf ScopeFunc) *Query

Scope the query by using a `ScopeFunc`

func ByName(name string) ScopeFunc {
	return func(q *Query) *Query {
		return q.Where("name = ?", name)
	}
}

func WithDeleted(q *pop.Query) *pop.Query {
	return q.Where("deleted_at is null")
}

c.Scope(ByName("mark)).Scope(WithDeleted).First(&User{})

func (*Connection) Select Uses

func (c *Connection) Select(fields ...string) *Query

Select allows to query only fields passed as parameter. c.Select("field1", "field2").All(&model) => SELECT field1, field2 FROM models

func (*Connection) String Uses

func (c *Connection) String() string

func (*Connection) Transaction Uses

func (c *Connection) Transaction(fn func(tx *Connection) error) error

Transaction will start a new transaction on the connection. If the inner function returns an error then the transaction will be rolled back, otherwise the transaction will automatically commit at the end.

func (*Connection) TruncateAll Uses

func (c *Connection) TruncateAll() error

TruncateAll truncates all data from the datasource

func (*Connection) URL Uses

func (c *Connection) URL() string

URL returns the datasource connection string

func (*Connection) Update Uses

func (c *Connection) Update(model interface{}, excludeColumns ...string) error

Update writes changes from an entry to the database, excluding the given columns. It updates the `updated_at` column automatically.

func (*Connection) ValidateAndCreate Uses

func (c *Connection) ValidateAndCreate(model interface{}, excludeColumns ...string) (*validate.Errors, error)

ValidateAndCreate applies validation rules on the given entry, then creates it if the validation succeed, excluding the given columns.

func (*Connection) ValidateAndSave Uses

func (c *Connection) ValidateAndSave(model interface{}, excludeColumns ...string) (*validate.Errors, error)

ValidateAndSave applies validation rules on the given entry, then save it if the validation succeed, excluding the given columns.

func (*Connection) ValidateAndUpdate Uses

func (c *Connection) ValidateAndUpdate(model interface{}, excludeColumns ...string) (*validate.Errors, error)

ValidateAndUpdate applies validation rules on the given entry, then update it if the validation succeed, excluding the given columns.

func (*Connection) Where Uses

func (c *Connection) Where(stmt string, args ...interface{}) *Query

Where will append a where clause to the query. You may use `?` in place of arguments.

c.Where("id = ?", 1)
q.Where("id in (?)", 1, 2, 3)

type ConnectionDetails Uses

type ConnectionDetails struct {
    // Example: "postgres" or "sqlite3" or "mysql"
    Dialect string
    // The name of your database. Example: "foo_development"
    Database string
    // The host of your database. Example: "127.0.0.1"
    Host string
    // The port of your database. Example: 1234
    // Will default to the "default" port for each dialect.
    Port string
    // The username of the database user. Example: "root"
    User string
    // The password of the database user. Example: "password"
    Password string
    // The encoding to use to create the database and communicate with it.
    Encoding string
    // Instead of specifying each individual piece of the
    // connection you can instead just specify the URL of the
    // database. Example: "postgres://postgres:postgres@localhost:5432/pop_test?sslmode=disable"
    URL string
    // Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetMaxOpenConns
    Pool int
    // Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns
    IdlePool int
    Options  map[string]string
    // Query string encoded options from URL. Example: "sslmode=disable"
    RawOptions string
}

ConnectionDetails stores the data needed to connect to a datasource

func (*ConnectionDetails) Finalize Uses

func (cd *ConnectionDetails) Finalize() error

Finalize cleans up the connection details by normalizing names, filling in default values, etc...

func (*ConnectionDetails) MigrationTableName Uses

func (cd *ConnectionDetails) MigrationTableName() string

MigrationTableName returns the name of the table to track migrations

func (*ConnectionDetails) OptionsString Uses

func (cd *ConnectionDetails) OptionsString(s string) string

OptionsString returns URL parameter encoded string from options.

func (*ConnectionDetails) Parse Uses

func (cd *ConnectionDetails) Parse(port string) error

Parse cleans up the connection details by normalizing names, filling in default values, etc... Deprecated: use ConnectionDetails.Finalize() instead.

func (*ConnectionDetails) RetryLimit Uses

func (cd *ConnectionDetails) RetryLimit() int

RetryLimit returns the maximum number of accepted connection retries

func (*ConnectionDetails) RetrySleep Uses

func (cd *ConnectionDetails) RetrySleep() time.Duration

RetrySleep returns the amount of time to wait between two connection retries

type FileMigrator Uses

type FileMigrator struct {
    Migrator
    Path string
}

FileMigrator is a migrator for SQL and Fizz files on disk at a specified path.

func NewFileMigrator Uses

func NewFileMigrator(path string, c *Connection) (FileMigrator, error)

NewFileMigrator for a path and a Connection

type GroupClause Uses

type GroupClause struct {
    Field string
}

GroupClause holds the field to apply the GROUP clause on

func (GroupClause) String Uses

func (c GroupClause) String() string

type HavingClause Uses

type HavingClause struct {
    Condition string
    Arguments []interface{}
}

HavingClause defines a condition and its arguments for a HAVING clause

func (HavingClause) String Uses

func (c HavingClause) String() string

type Migration Uses

type Migration struct {
    // Path to the migration (./migrations/123_create_widgets.up.sql)
    Path string
    // Version of the migration (123)
    Version string
    // Name of the migration (create_widgets)
    Name string
    // Direction of the migration (up)
    Direction string
    // Type of migration (sql)
    Type string
    // DB type (all|postgres|mysql...)
    DBType string
    // Runner function to run/execute the migration
    Runner func(Migration, *Connection) error
}

Migration handles the data for a given database migration

func (Migration) Run Uses

func (mf Migration) Run(c *Connection) error

Run the migration. Returns an error if there is no mf.Runner defined.

type MigrationBox Uses

type MigrationBox struct {
    Migrator
    Box packd.Walkable
}

MigrationBox is a wrapper around packr.Box and Migrator. This will allow you to run migrations from a packed box inside of a compiled binary.

func NewMigrationBox Uses

func NewMigrationBox(box packd.Walkable, c *Connection) (MigrationBox, error)

NewMigrationBox from a packr.Box and a Connection.

type Migrations Uses

type Migrations []Migration

Migrations is a collection of Migration

func (Migrations) Len Uses

func (mfs Migrations) Len() int

func (Migrations) Less Uses

func (mfs Migrations) Less(i, j int) bool

func (Migrations) Swap Uses

func (mfs Migrations) Swap(i, j int)

type Migrator Uses

type Migrator struct {
    Connection *Connection
    SchemaPath string
    Migrations map[string]Migrations
}

Migrator forms the basis of all migrations systems. It does the actual heavy lifting of running migrations. When building a new migration system, you should embed this type into your migrator.

func NewMigrator Uses

func NewMigrator(c *Connection) Migrator

NewMigrator returns a new "blank" migrator. It is recommended to use something like MigrationBox or FileMigrator. A "blank" Migrator should only be used as the basis for a new type of migration system.

func (Migrator) CreateSchemaMigrations Uses

func (m Migrator) CreateSchemaMigrations() error

CreateSchemaMigrations sets up a table to track migrations. This is an idempotent operation.

func (Migrator) Down Uses

func (m Migrator) Down(step int) error

Down runs pending "down" migrations and rolls back the database by the specified number of steps.

func (Migrator) DumpMigrationSchema Uses

func (m Migrator) DumpMigrationSchema() error

DumpMigrationSchema will generate a file of the current database schema based on the value of Migrator.SchemaPath

func (Migrator) Reset Uses

func (m Migrator) Reset() error

Reset the database by running the down migrations followed by the up migrations.

func (Migrator) Status Uses

func (m Migrator) Status() error

Status prints out the status of applied/pending migrations.

func (Migrator) Up Uses

func (m Migrator) Up() error

Up runs pending "up" migrations and applies them to the database.

func (Migrator) UpLogOnly Uses

func (m Migrator) UpLogOnly() error

UpLogOnly insert pending "up" migrations logs only, without applying the patch. It's used when loading the schema dump, instead of the migrations.

type Model Uses

type Model struct {
    Value

    As  string
    // contains filtered or unexported fields
}

Model is used throughout Pop to wrap the end user interface that is passed in to many functions.

func (*Model) ID Uses

func (m *Model) ID() interface{}

ID returns the ID of the Model. All models must have an `ID` field this is of type `int`,`int64` or of type `uuid.UUID`.

func (*Model) PrimaryKeyType Uses

func (m *Model) PrimaryKeyType() string

PrimaryKeyType gives the primary key type of the `Model`.

func (*Model) TableName Uses

func (m *Model) TableName() string

TableName returns the corresponding name of the underlying database table for a given `Model`. See also `TableNameAble` to change the default name of the table.

type PaginationParams Uses

type PaginationParams interface {
    Get(key string) string
}

PaginationParams is a parameters provider interface to get the pagination params from

type Paginator Uses

type Paginator struct {
    // Current page you're on
    Page int `json:"page"`
    // Number of results you want per page
    PerPage int `json:"per_page"`
    // Page * PerPage (ex: 2 * 20, Offset == 40)
    Offset int `json:"offset"`
    // Total potential records matching the query
    TotalEntriesSize int `json:"total_entries_size"`
    // Total records returns, will be <= PerPage
    CurrentEntriesSize int `json:"current_entries_size"`
    // Total pages
    TotalPages int `json:"total_pages"`
}

Paginator is a type used to represent the pagination of records from the database.

func NewPaginator Uses

func NewPaginator(page int, perPage int) *Paginator

NewPaginator returns a new `Paginator` value with the appropriate defaults set.

func NewPaginatorFromParams Uses

func NewPaginatorFromParams(params PaginationParams) *Paginator

NewPaginatorFromParams takes an interface of type `PaginationParams`, the `url.Values` type works great with this interface, and returns a new `Paginator` based on the params or `PaginatorPageKey` and `PaginatorPerPageKey`. Defaults are `1` for the page and PaginatorPerPageDefault for the per page value.

func (Paginator) String Uses

func (p Paginator) String() string

type Query Uses

type Query struct {
    RawSQL *clause

    Paginator  *Paginator
    Connection *Connection
    // contains filtered or unexported fields
}

Query is the main value that is used to build up a query to be executed against the `Connection`.

func Q Uses

func Q(c *Connection) *Query

Q will create a new "empty" query from the current connection.

func (*Query) All Uses

func (q *Query) All(models interface{}) error

All retrieves all of the records in the database that match the query.

q.Where("name = ?", "mark").All(&[]User{})

func (*Query) BelongsTo Uses

func (q *Query) BelongsTo(model interface{}) *Query

BelongsTo adds a "where" clause based on the "ID" of the "model" passed into it.

func (*Query) BelongsToAs Uses

func (q *Query) BelongsToAs(model interface{}, as string) *Query

BelongsToAs adds a "where" clause based on the "ID" of the "model" passed into it, using an alias.

func (*Query) BelongsToThrough Uses

func (q *Query) BelongsToThrough(bt, thru interface{}) *Query

BelongsToThrough adds a "where" clause that connects the "bt" model through the associated "thru" model.

func (*Query) Clone Uses

func (q *Query) Clone(targetQ *Query)

Clone will fill targetQ query with the connection used in q, if targetQ is not empty, Clone will override all the fields.

func (Query) Count Uses

func (q Query) Count(model interface{}) (int, error)

Count the number of records in the database.

q.Where("name = ?", "mark").Count(&User{})

func (Query) CountByField Uses

func (q Query) CountByField(model interface{}, field string) (int, error)

CountByField counts the number of records in the database, for a given field.

q.Where("sex = ?", "f").Count(&User{}, "name")

func (*Query) Eager Uses

func (q *Query) Eager(fields ...string) *Query

Eager will enable load associations of the model. by defaults loads all the associations on the model, but can take a variadic list of associations to load.

q.Eager().Find(model, 1) // will load all associations for model.
q.Eager("Books").Find(model, 1) // will load only Book association for model.

func (*Query) Exec Uses

func (q *Query) Exec() error

Exec runs the given query.

func (*Query) ExecWithCount Uses

func (q *Query) ExecWithCount() (int, error)

ExecWithCount runs the given query, and returns the amount of affected rows.

func (*Query) Exists Uses

func (q *Query) Exists(model interface{}) (bool, error)

Exists returns true/false if a record exists in the database that matches the query.

q.Where("name = ?", "mark").Exists(&User{})

func (*Query) Find Uses

func (q *Query) Find(model interface{}, id interface{}) error

Find the first record of the model in the database with a particular id.

q.Find(&User{}, 1)

func (*Query) First Uses

func (q *Query) First(model interface{}) error

First record of the model in the database that matches the query.

q.Where("name = ?", "mark").First(&User{})

func (*Query) GroupBy Uses

func (q *Query) GroupBy(field string, fields ...string) *Query

GroupBy will append a GROUP BY clause to the query

func (*Query) Having Uses

func (q *Query) Having(condition string, args ...interface{}) *Query

Having will append a HAVING clause to the query

func (*Query) InnerJoin Uses

func (q *Query) InnerJoin(table string, on string, args ...interface{}) *Query

InnerJoin will append an INNER JOIN clause to the query

func (*Query) Join Uses

func (q *Query) Join(table string, on string, args ...interface{}) *Query

Join will append a JOIN clause to the query

func (*Query) Last Uses

func (q *Query) Last(model interface{}) error

Last record of the model in the database that matches the query.

q.Where("name = ?", "mark").Last(&User{})

func (*Query) LeftInnerJoin Uses

func (q *Query) LeftInnerJoin(table string, on string, args ...interface{}) *Query

LeftInnerJoin will append an INNER JOIN clause to the query

Deprecated: Use InnerJoin instead

func (*Query) LeftJoin Uses

func (q *Query) LeftJoin(table string, on string, args ...interface{}) *Query

LeftJoin will append a LEFT JOIN clause to the query

func (*Query) LeftOuterJoin Uses

func (q *Query) LeftOuterJoin(table string, on string, args ...interface{}) *Query

LeftOuterJoin will append a LEFT OUTER JOIN clause to the query

func (*Query) Limit Uses

func (q *Query) Limit(limit int) *Query

Limit will add a limit clause to the query.

q.Limit(10)

func (*Query) Order Uses

func (q *Query) Order(stmt string) *Query

Order will append an order clause to the query.

q.Order("name desc")

func (*Query) Paginate Uses

func (q *Query) Paginate(page int, perPage int) *Query

Paginate records returned from the database.

q = q.Paginate(2, 15)
q.All(&[]User{})
q.Paginator

func (*Query) PaginateFromParams Uses

func (q *Query) PaginateFromParams(params PaginationParams) *Query

PaginateFromParams paginates records returned from the database.

q = q.PaginateFromParams(req.URL.Query())
q.All(&[]User{})
q.Paginator

func (*Query) RawQuery Uses

func (q *Query) RawQuery(stmt string, args ...interface{}) *Query

RawQuery will override the query building feature of Pop and will use whatever query you want to execute against the `Connection`. You can continue to use the `?` argument syntax.

q.RawQuery("select * from foo where id = ?", 1)

func (*Query) RightInnerJoin Uses

func (q *Query) RightInnerJoin(table string, on string, args ...interface{}) *Query

RightInnerJoin will append an INNER JOIN clause to the query

Deprecated: Use InnerJoin instead

func (*Query) RightJoin Uses

func (q *Query) RightJoin(table string, on string, args ...interface{}) *Query

RightJoin will append a RIGHT JOIN clause to the query

func (*Query) RightOuterJoin Uses

func (q *Query) RightOuterJoin(table string, on string, args ...interface{}) *Query

RightOuterJoin will append a RIGHT OUTER JOIN clause to the query

func (*Query) Scope Uses

func (q *Query) Scope(sf ScopeFunc) *Query

Scope the query by using a `ScopeFunc`

func ByName(name string) ScopeFunc {
	return func(q *Query) *Query {
		return q.Where("name = ?", name)
	}
}

func WithDeleted(q *pop.Query) *pop.Query {
	return q.Where("deleted_at is null")
}

c.Scope(ByName("mark)).Scope(WithDeleted).First(&User{})

func (*Query) Select Uses

func (q *Query) Select(fields ...string) *Query

Select allows to query only fields passed as parameter. c.Select("field1", "field2").All(&model) => SELECT field1, field2 FROM models

func (Query) ToSQL Uses

func (q Query) ToSQL(model *Model, addColumns ...string) (string, []interface{})

ToSQL will generate SQL and the appropriate arguments for that SQL from the `Model` passed in.

func (*Query) Where Uses

func (q *Query) Where(stmt string, args ...interface{}) *Query

Where will append a where clause to the query. You may use `?` in place of arguments.

q.Where("id = ?", 1)
q.Where("id in (?)", 1, 2, 3)

type ScopeFunc Uses

type ScopeFunc func(q *Query) *Query

ScopeFunc applies a custom operation on a given `Query`

type ServerInfo Uses

type ServerInfo struct {
    VersionString string `db:"version"`
    Product       string `db:"-"`
    License       string `db:"-"`
    Version       string `db:"-"`
    BuildInfo     string `db:"-"`
}

ServerInfo holds informational data about connected database server.

type TableNameAble Uses

type TableNameAble interface {
    TableName() string
}

TableNameAble interface allows for the customize table mapping between a name and the database. For example the value `User{}` will automatically map to "users". Implementing `TableNameAble` would allow this to change to be changed to whatever you would like.

type Tx Uses

type Tx struct {
    ID  int
    *sqlx.Tx
}

Tx stores a transaction with an ID to keep track.

func (*Tx) Close Uses

func (tx *Tx) Close() error

Close does nothing. This is defined so it implements the `Store` interface.

func (*Tx) Transaction Uses

func (tx *Tx) Transaction() (*Tx, error)

Transaction simply returns the current transaction, this is defined so it implements the `Store` interface.

type Value Uses

type Value interface{}

Value is the contents of a `Model`.

Directories

PathSynopsis
associations
columns
fix
genny/config
grifts
logging
nulls
packrdYou can use the "packr2 clean" command to clean up this, and any other packr generated files.
slices
soda
soda/cmd
soda/cmd/generate
soda/cmd/schema

Package pop imports 47 packages (graph) and is imported by 75 packages. Updated 2018-11-19. Refresh now. Tools for package owners.