Documentation ¶
Overview ¶
Package postgres implements the github.com/neuronlabs/neuron/repository Factory and Repository interfaces. It allows to query PostgreSQL based databases using github.com/jackc/pgx driver. The repository implements:
- query.FullRepository
- repository.Repository
- repository.Migrator
The repository allows to share single transaction per multiple models - if all are registered within single database.
Index ¶
- Constants
- type Factory
- type Postgres
- func (p *Postgres) Begin(ctx context.Context, tx *query.Transaction) error
- func (p *Postgres) Close(ctx context.Context) (err error)
- func (p *Postgres) Commit(ctx context.Context, tx *query.Transaction) error
- func (p *Postgres) Count(ctx context.Context, s *query.Scope) (int64, error)
- func (p *Postgres) Delete(ctx context.Context, s *query.Scope) (int64, error)
- func (p *Postgres) Dial(ctx context.Context) (err error)
- func (p *Postgres) FactoryName() string
- func (p *Postgres) Find(ctx context.Context, s *query.Scope) error
- func (p *Postgres) HealthCheck(ctx context.Context) (*service.HealthResponse, error)
- func (p *Postgres) ID() string
- func (p *Postgres) Insert(ctx context.Context, s *query.Scope) error
- func (p *Postgres) MigrateModels(ctx context.Context, models ...*mapping.ModelStruct) error
- func (p *Postgres) RegisterModels(models ...*mapping.ModelStruct) error
- func (p *Postgres) Rollback(ctx context.Context, tx *query.Transaction) error
- func (p *Postgres) Update(ctx context.Context, s *query.Scope) (int64, error)
Constants ¶
const FactoryName = "postgres"
FactoryName defines the name of the factory.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Factory ¶
type Factory struct{}
Factory is the pq.Postgres factory.
func (*Factory) DriverName ¶
DriverName gets the Factory repository name. Implements repository.Postgres interface.
type Postgres ¶
type Postgres struct { ConnPool *pgxpool.Pool Config *pgxpool.Config AutoSelectNotNulls bool // PostgresVersion is the numerical version of the postgres server. PostgresVersion int Transactions map[uuid.UUID]pgx.Tx // contains filtered or unexported fields }
Postgres is the neuron repository that allows to query postgres databases. It allows to query PostgreSQL based databases using github.com/jackc/pgx driver. The repository implements:
- query.FullRepository
- repository.Repository
- repository.Migrator
The repository allows to share single transaction per multiple models - if all are registered within single database.
func (*Postgres) Begin ¶
Begin starts a transaction for the given scope. Implements Begin method of the query.Transactioner interface.
func (*Postgres) Commit ¶
Commit commits the scope's transaction Implements Commit method from the query.Commiter interface
func (*Postgres) Delete ¶
Delete deletes all the values that matches scope's filters. Implements repository.Repository interface.
func (*Postgres) Dial ¶
Dial implements repository.Postgres interface. Creates a new Connection Pool for given repository.
func (*Postgres) FactoryName ¶
FactoryName returns the name of the factory for this Postgres. Implements repository.Repository interface.
func (*Postgres) Find ¶
Find lists all the values that matches scope's filters, sorts and pagination. Implements repository.Repository interface.
func (*Postgres) HealthCheck ¶
HealthCheck implements repository.Repository interface. It creates basic queries that checks if the connection is alive and returns given health response. The health response contains also notes with postgres version.
func (*Postgres) Insert ¶
Insert depending on the query efficiently inserts models with related fieldSets. Implements repository.Repository interface.
func (*Postgres) MigrateModels ¶
MigrateModels implements repository.Migrator interface. The method creates models tables if not exists and updates the columns per given model fields.
func (*Postgres) RegisterModels ¶
func (p *Postgres) RegisterModels(models ...*mapping.ModelStruct) error
RegisterModels implements repository.Repository interface.