postgres

package
v5.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package postgres contains generated code for schema 'public'.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(s string, v ...interface{})

Errorf logs an error message using the package error logger.

func Logf

func Logf(s string, v ...interface{})

Logf logs a message using the package logger.

func SayHello

func SayHello(ctx context.Context, db DB, name string) (string, error)

SayHello calls the stored function 'public.say_hello(character varying) character varying' on db.

func SetErrorLogger

func SetErrorLogger(logger interface{})

SetErrorLogger sets the package error logger. Valid logger types:

io.Writer
func(string, ...interface{}) (int, error) // fmt.Printf
func(string, ...interface{}) // log.Printf

func SetLogger

func SetLogger(logger interface{})

SetLogger sets the package logger. Valid logger types:

io.Writer
func(string, ...interface{}) (int, error) // fmt.Printf
func(string, ...interface{}) // log.Printf

Types

type Author

type Author struct {
	AuthorID int    `json:"author_id"` // author_id
	Name     string `json:"name"`      // name
	// contains filtered or unexported fields
}

Author represents a row from 'public.authors'.

func AuthorByAuthorID

func AuthorByAuthorID(ctx context.Context, db DB, authorID int) (*Author, error)

AuthorByAuthorID retrieves a row from 'public.authors' as a Author.

Generated from index 'authors_pkey'.

func AuthorsByName

func AuthorsByName(ctx context.Context, db DB, name string) ([]*Author, error)

AuthorsByName retrieves a row from 'public.authors' as a Author.

Generated from index 'authors_name_idx'.

func (*Author) Delete

func (a *Author) Delete(ctx context.Context, db DB) error

Delete deletes the Author from the database.

func (*Author) Deleted

func (a *Author) Deleted() bool

Deleted returns true when the Author has been marked for deletion from the database.

func (*Author) Exists

func (a *Author) Exists() bool

Exists returns true when the Author exists in the database.

func (*Author) Insert

func (a *Author) Insert(ctx context.Context, db DB) error

Insert inserts the Author to the database.

func (*Author) Save

func (a *Author) Save(ctx context.Context, db DB) error

Save saves the Author to the database.

func (*Author) Update

func (a *Author) Update(ctx context.Context, db DB) error

Update updates a Author in the database.

func (*Author) Upsert

func (a *Author) Upsert(ctx context.Context, db DB) error

Upsert performs an upsert for Author.

type AuthorBookResult

type AuthorBookResult struct {
	AuthorID   int            `json:"author_id"`   // author_id
	AuthorName string         `json:"author_name"` // author_name
	BookID     int            `json:"book_id"`     // book_id
	BookISBN   string         `json:"book_isbn"`   // book_isbn
	BookTitle  string         `json:"book_title"`  // book_title
	BookTags   pq.StringArray `json:"book_tags"`   // book_tags
}

AuthorBookResult is the result of a search.

func AuthorBookResultsByTags

func AuthorBookResultsByTags(ctx context.Context, db DB, tags pq.StringArray) ([]*AuthorBookResult, error)

AuthorBookResultsByTags runs a custom query, returning results as AuthorBookResult.

type Book

type Book struct {
	BookID      int            `json:"book_id"`     // book_id
	AuthorID    int            `json:"author_id"`   // author_id
	ISBN        string         `json:"isbn"`        // isbn
	BookType    BookType       `json:"book_type"`   // book_type
	Title       string         `json:"title"`       // title
	Year        int            `json:"year"`        // year
	Available   time.Time      `json:"available"`   // available
	Description string         `json:"description"` // description
	Tags        pq.StringArray `json:"tags"`        // tags
	// contains filtered or unexported fields
}

Book represents a row from 'public.books'.

func BookByBookID

func BookByBookID(ctx context.Context, db DB, bookID int) (*Book, error)

BookByBookID retrieves a row from 'public.books' as a Book.

Generated from index 'books_pkey'.

func BookByISBN

func BookByISBN(ctx context.Context, db DB, isbn string) (*Book, error)

BookByISBN retrieves a row from 'public.books' as a Book.

Generated from index 'books_isbn_key'.

func BooksByTitleYear

func BooksByTitleYear(ctx context.Context, db DB, title string, year int) ([]*Book, error)

BooksByTitleYear retrieves a row from 'public.books' as a Book.

Generated from index 'books_title_idx'.

func (*Book) Author

func (b *Book) Author(ctx context.Context, db DB) (*Author, error)

Author returns the Author associated with the Book's (AuthorID).

Generated from foreign key 'books_author_id_fkey'.

func (*Book) Delete

func (b *Book) Delete(ctx context.Context, db DB) error

Delete deletes the Book from the database.

func (*Book) Deleted

func (b *Book) Deleted() bool

Deleted returns true when the Book has been marked for deletion from the database.

func (*Book) Exists

func (b *Book) Exists() bool

Exists returns true when the Book exists in the database.

func (*Book) Insert

func (b *Book) Insert(ctx context.Context, db DB) error

Insert inserts the Book to the database.

func (*Book) Save

func (b *Book) Save(ctx context.Context, db DB) error

Save saves the Book to the database.

func (*Book) Update

func (b *Book) Update(ctx context.Context, db DB) error

Update updates a Book in the database.

func (*Book) Upsert

func (b *Book) Upsert(ctx context.Context, db DB) error

Upsert performs an upsert for Book.

type BookType

type BookType uint16

BookType is the 'book_type' enum type from schema 'public'.

const (
	// BookTypeFiction is the 'FICTION' book_type.
	BookTypeFiction BookType = 1
	// BookTypeNonfiction is the 'NONFICTION' book_type.
	BookTypeNonfiction BookType = 2
)

BookType values.

func (BookType) MarshalText

func (bt BookType) MarshalText() ([]byte, error)

MarshalText marshals BookType into text.

func (*BookType) Scan

func (bt *BookType) Scan(v interface{}) error

Scan satisfies the sql.Scanner interface.

func (BookType) String

func (bt BookType) String() string

String satisfies the fmt.Stringer interface.

func (*BookType) UnmarshalText

func (bt *BookType) UnmarshalText(buf []byte) error

UnmarshalText unmarshals BookType from text.

func (BookType) Value

func (bt BookType) Value() (driver.Value, error)

Value satisfies the driver.Valuer interface.

type DB

type DB interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

DB is the common interface for database operations that can be used with types from schema 'public'.

This works with both database/sql.DB and database/sql.Tx.

type ErrInsertFailed

type ErrInsertFailed struct {
	Err error
}

ErrInsertFailed is the insert failed error.

func (*ErrInsertFailed) Error

func (err *ErrInsertFailed) Error() string

Error satisfies the error interface.

func (*ErrInsertFailed) Unwrap

func (err *ErrInsertFailed) Unwrap() error

Unwrap satisfies the unwrap interface.

type ErrInvalidBookType

type ErrInvalidBookType string

ErrInvalidBookType is the invalid BookType error.

func (ErrInvalidBookType) Error

func (err ErrInvalidBookType) Error() string

Error satisfies the error interface.

type ErrUpdateFailed

type ErrUpdateFailed struct {
	Err error
}

ErrUpdateFailed is the update failed error.

func (*ErrUpdateFailed) Error

func (err *ErrUpdateFailed) Error() string

Error satisfies the error interface.

func (*ErrUpdateFailed) Unwrap

func (err *ErrUpdateFailed) Unwrap() error

Unwrap satisfies the unwrap interface.

type ErrUpsertFailed

type ErrUpsertFailed struct {
	Err error
}

ErrUpsertFailed is the upsert failed error.

func (*ErrUpsertFailed) Error

func (err *ErrUpsertFailed) Error() string

Error satisfies the error interface.

func (*ErrUpsertFailed) Unwrap

func (err *ErrUpsertFailed) Unwrap() error

Unwrap satisfies the unwrap interface.

type Error

type Error string

Error is an error.

const (
	// ErrAlreadyExists is the already exists error.
	ErrAlreadyExists Error = "already exists"
	// ErrDoesNotExist is the does not exist error.
	ErrDoesNotExist Error = "does not exist"
	// ErrMarkedForDeletion is the marked for deletion error.
	ErrMarkedForDeletion Error = "marked for deletion"
)

Error values.

func (Error) Error

func (err Error) Error() string

Error satisfies the error interface.

type NullBookType

type NullBookType struct {
	BookType BookType
	// Valid is true if BookType is not null.
	Valid bool
}

NullBookType represents a null 'book_type' enum for schema 'public'.

func (*NullBookType) Scan

func (nbt *NullBookType) Scan(v interface{}) error

Scan satisfies the sql.Scanner interface.

func (NullBookType) Value

func (nbt NullBookType) Value() (driver.Value, error)

Value satisfies the driver.Valuer interface.

Jump to

Keyboard shortcuts

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