sqlite3

package
v0.0.0-...-de94dfd Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sqlite3 contains generated code for schema 'booktest.db'.

Index

Constants

This section is empty.

Variables

View Source
var TimestampFormats = []string{

	"2006-01-02 15:04:05.999999999-07:00",
	"2006-01-02T15:04:05.999999999-07:00",
	"2006-01-02 15:04:05.999999999",
	"2006-01-02T15:04:05.999999999",
	"2006-01-02 15:04:05",
	"2006-01-02T15:04:05",
	"2006-01-02 15:04",
	"2006-01-02T15:04",
	"2006-01-02",
}

TimestampFormats are the timestamp formats used by SQLite3 database drivers to store a time.Time in SQLite3.

The first format in the slice will be used when saving time values into the database. When parsing a string from a timestamp or datetime column, the formats are tried in order.

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 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 'authors'.

func AuthorByAuthorID

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

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

Generated from index 'authors_author_id_pkey'.

func AuthorsByName

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

AuthorsByName retrieves a row from '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   string `json:"book_tags"`   // book_tags
}

AuthorBookResult is the result of a search.

func AuthorBookResultsByTag

func AuthorBookResultsByTag(ctx context.Context, db DB, tag string) ([]*AuthorBookResult, error)

AuthorBookResultsByTag 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
	Title       string `json:"title"`       // title
	Year        int    `json:"year"`        // year
	Available   Time   `json:"available"`   // available
	Description string `json:"description"` // description
	Tags        string `json:"tags"`        // tags
	// contains filtered or unexported fields
}

Book represents a row from 'books'.

func BookByBookID

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

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

Generated from index 'books_book_id_pkey'.

func BookByISBN

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

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

Generated from index 'sqlite_autoindex_books_1'.

func BooksByTitleYear

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

BooksByTitleYear retrieves a row from '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 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 'booktest.db'.

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 ErrInvalidTime

type ErrInvalidTime string

ErrInvalidTime is the invalid Time error.

func (ErrInvalidTime) Error

func (err ErrInvalidTime) 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 Time

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

Time is a SQLite3 Time that scans for the various timestamps values used by SQLite3 database drivers to store time.Time values.

func NewTime

func NewTime(t time.Time) Time

NewTime creates a time.

func (Time) Format

func (t Time) Format(layout string) string

Format formats the time.

func (*Time) Parse

func (t *Time) Parse(s string) error

Parse attempts to Parse string s to t.

func (*Time) Scan

func (t *Time) Scan(v interface{}) error

Scan satisfies the sql.Scanner interface.

func (Time) String

func (t Time) String() string

String satisfies the fmt.Stringer interface.

func (Time) Time

func (t Time) Time() time.Time

Time returns a time.Time.

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value satisfies the sql/driver.Valuer interface.

Jump to

Keyboard shortcuts

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