tldb

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: GPL-3.0 Imports: 20 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	Open() error
	Close() error
	Create() error
	DBX() sqlx.Ext
	Tx(func(Adapter) error) error
	Sqrl() sq.StatementBuilderType
	Insert(interface{}) (int, error)
	Update(interface{}, ...string) error
	Find(interface{}, ...interface{}) error
	Get(interface{}, string, ...interface{}) error
	Select(interface{}, string, ...interface{}) error
	MultiInsert([]interface{}) ([]int, error)
	CopyInsert([]interface{}) error
}

Adapter provides an interface for connecting to various kinds of database backends.

type PostgresAdapter

type PostgresAdapter struct {
	DBURL string
	// contains filtered or unexported fields
}

PostgresAdapter connects to a Postgres/PostGIS database.

func (*PostgresAdapter) Close

func (adapter *PostgresAdapter) Close() error

Close the adapter.

func (*PostgresAdapter) CopyInsert added in v0.7.1

func (adapter *PostgresAdapter) CopyInsert(ents []interface{}) error

CopyInsert inserts data using COPY.

func (*PostgresAdapter) Create

func (adapter *PostgresAdapter) Create() error

Create an initial database schema.

func (*PostgresAdapter) DBX

func (adapter *PostgresAdapter) DBX() sqlx.Ext

DBX returns sqlx.Ext

func (*PostgresAdapter) Find

func (adapter *PostgresAdapter) Find(dest interface{}, args ...interface{}) error

Find finds a single entity based on the EntityID()

func (*PostgresAdapter) Get

func (adapter *PostgresAdapter) Get(dest interface{}, qstr string, args ...interface{}) error

Get wraps sqlx.Get

func (*PostgresAdapter) Insert

func (adapter *PostgresAdapter) Insert(ent interface{}) (int, error)

Insert builds and executes an insert statement for the given entity.

func (*PostgresAdapter) MultiInsert

func (adapter *PostgresAdapter) MultiInsert(ents []interface{}) ([]int, error)

MultiInsert builds and executes a multi-insert statement for the given entities.

func (*PostgresAdapter) Open

func (adapter *PostgresAdapter) Open() error

Open the adapter.

func (*PostgresAdapter) Select

func (adapter *PostgresAdapter) Select(dest interface{}, qstr string, args ...interface{}) error

Select wraps sqlx.Select

func (*PostgresAdapter) Sqrl

func (adapter *PostgresAdapter) Sqrl() sq.StatementBuilderType

Sqrl returns a properly configured Squirrel StatementBuilder.

func (*PostgresAdapter) Tx

func (adapter *PostgresAdapter) Tx(cb func(Adapter) error) error

Tx runs a callback inside a transaction.

func (*PostgresAdapter) Update

func (adapter *PostgresAdapter) Update(ent interface{}, columns ...string) error

Update a single entity.

type QueryLogger added in v0.7.2

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

QueryLogger wraps sql/sqlx methods with loggers.

func NewQueryLogger added in v0.7.2

func NewQueryLogger(db *sqlx.DB) *QueryLogger

NewQueryLogger returns the db wrapped into a QueryLogger.

func (*QueryLogger) Beginx added in v0.7.2

func (p *QueryLogger) Beginx() (*sqlx.Tx, error)

Beginx .

func (*QueryLogger) Exec added in v0.7.2

func (p *QueryLogger) Exec(query string, args ...interface{}) (sql.Result, error)

Exec .

func (*QueryLogger) Query added in v0.7.2

func (p *QueryLogger) Query(query string, args ...interface{}) (*sql.Rows, error)

Query .

func (*QueryLogger) QueryRow added in v0.7.2

func (p *QueryLogger) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow .

func (*QueryLogger) QueryRowx added in v0.7.2

func (p *QueryLogger) QueryRowx(query string, args ...interface{}) *sqlx.Row

QueryRowx .

func (*QueryLogger) Queryx added in v0.7.2

func (p *QueryLogger) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

Queryx .

type Reader

type Reader struct {
	Adapter        Adapter
	PageSize       int
	FeedVersionIDs []int
}

Reader reads from a database.

func NewReader

func NewReader(dburl string) (*Reader, error)

NewReader returns an initialized Reader based on the provided url string.

func (*Reader) Agencies

func (reader *Reader) Agencies() chan tl.Agency

Agencies sends Agencies.

func (*Reader) CalendarDates

func (reader *Reader) CalendarDates() chan tl.CalendarDate

CalendarDates sends CalendarDates.

func (*Reader) Calendars

func (reader *Reader) Calendars() chan tl.Calendar

Calendars sends Calendars.

func (*Reader) Close

func (reader *Reader) Close() error

Close the database.

func (*Reader) FareAttributes

func (reader *Reader) FareAttributes() chan tl.FareAttribute

FareAttributes sends FareAttributes.

func (*Reader) FareRules

func (reader *Reader) FareRules() chan tl.FareRule

FareRules sends FareRules.

func (*Reader) FeedInfos

func (reader *Reader) FeedInfos() chan tl.FeedInfo

FeedInfos sends FeedInfos.

func (*Reader) Frequencies

func (reader *Reader) Frequencies() chan tl.Frequency

Frequencies sends Frequencies.

func (*Reader) Levels

func (reader *Reader) Levels() chan tl.Level

Levels sends Levels.

func (*Reader) Open

func (reader *Reader) Open() error

Open the database.

func (*Reader) Pathways

func (reader *Reader) Pathways() chan tl.Pathway

Pathways sends Pathways.

func (*Reader) ReadEntities

func (reader *Reader) ReadEntities(c interface{}) error

ReadEntities provides a generic interface for reading entities.

func (*Reader) Routes

func (reader *Reader) Routes() chan tl.Route

Routes sends Routes.

func (*Reader) Shapes

func (reader *Reader) Shapes() chan tl.Shape

Shapes sends Shapes.

func (*Reader) StopTimes

func (reader *Reader) StopTimes() chan tl.StopTime

StopTimes sends StopTimes.

func (*Reader) StopTimesByTripID

func (reader *Reader) StopTimesByTripID(tripIDs ...string) chan []tl.StopTime

StopTimesByTripID sends StopTimes grouped by TripID. Each group is sorted by stop_sequence.

func (*Reader) Stops

func (reader *Reader) Stops() chan tl.Stop

Stops sends Stops.

func (*Reader) Transfers

func (reader *Reader) Transfers() chan tl.Transfer

Transfers sends Transfers.

func (*Reader) Trips

func (reader *Reader) Trips() chan tl.Trip

Trips sends Trips.

func (*Reader) ValidateStructure

func (reader *Reader) ValidateStructure() []error

ValidateStructure returns if all the necessary tables are present. Not implemented.

func (*Reader) Where

func (reader *Reader) Where() sq.SelectBuilder

Where returns a select builder with feed_version_id set

type SQLiteAdapter

type SQLiteAdapter struct {
	DBURL string
	// contains filtered or unexported fields
}

SQLiteAdapter provides support for SQLite.

func (*SQLiteAdapter) Close

func (adapter *SQLiteAdapter) Close() error

Close the database.

func (*SQLiteAdapter) CopyInsert added in v0.7.1

func (adapter *SQLiteAdapter) CopyInsert(ents []interface{}) error

CopyInsert uses MultiInsert.

func (*SQLiteAdapter) Create

func (adapter *SQLiteAdapter) Create() error

Create the database if necessary.

func (*SQLiteAdapter) DBX

func (adapter *SQLiteAdapter) DBX() sqlx.Ext

DBX returns the underlying Sqlx DB or Tx.

func (*SQLiteAdapter) Find

func (adapter *SQLiteAdapter) Find(dest interface{}, args ...interface{}) error

Find finds a single entity based on the EntityID()

func (*SQLiteAdapter) Get

func (adapter *SQLiteAdapter) Get(dest interface{}, qstr string, args ...interface{}) error

Get wraps sqlx.Get

func (*SQLiteAdapter) Insert

func (adapter *SQLiteAdapter) Insert(ent interface{}) (int, error)

Insert builds and executes an insert statement for the given entity.

func (*SQLiteAdapter) MultiInsert added in v0.7.1

func (adapter *SQLiteAdapter) MultiInsert(ents []interface{}) ([]int, error)

MultiInsert inserts multiple entities.

func (*SQLiteAdapter) Open

func (adapter *SQLiteAdapter) Open() error

Open the database.

func (*SQLiteAdapter) Select

func (adapter *SQLiteAdapter) Select(dest interface{}, qstr string, args ...interface{}) error

Select wraps sqlx.Select

func (*SQLiteAdapter) Sqrl

func (adapter *SQLiteAdapter) Sqrl() sq.StatementBuilderType

Sqrl returns a properly configured Squirrel StatementBuilder.

func (*SQLiteAdapter) Tx

func (adapter *SQLiteAdapter) Tx(cb func(Adapter) error) error

Tx runs a callback inside a transaction.

func (*SQLiteAdapter) Update

func (adapter *SQLiteAdapter) Update(ent interface{}, columns ...string) error

Update a single record.

type Writer

type Writer struct {
	FeedVersionID int
	Adapter       Adapter
	// contains filtered or unexported fields
}

Writer takes a Reader and saves it to a database.

func MustGetWriter added in v0.8.0

func MustGetWriter(dburl string, create bool) *Writer

MustGetWriter opens & creates a db writer, panic on failure

func NewWriter

func NewWriter(dburl string) (*Writer, error)

NewWriter returns a Writer appropriate for the given connection url.

func (*Writer) AddEntities

func (writer *Writer) AddEntities(ents []tl.Entity) ([]string, error)

AddEntities writes entities to the database.

func (*Writer) AddEntity

func (writer *Writer) AddEntity(ent tl.Entity) (string, error)

AddEntity writes an entity to the database.

func (*Writer) Close

func (writer *Writer) Close() error

Close the database.

func (*Writer) Create

func (writer *Writer) Create() error

Create the database.

func (*Writer) CreateFeedVersion

func (writer *Writer) CreateFeedVersion(reader tl.Reader) (int, error)

CreateFeedVersion creates a new FeedVersion and inserts into the database.

func (*Writer) Delete

func (writer *Writer) Delete() error

Delete any entities associated with the FeedVersion.

func (*Writer) NewReader

func (writer *Writer) NewReader() (tl.Reader, error)

NewReader returns a new Reader with the same adapter.

func (*Writer) Open

func (writer *Writer) Open() error

Open the database.

Jump to

Keyboard shortcuts

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