db

package
v0.0.0-...-9e04e3e Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExtraIndex

type ExtraIndex struct {
	IsRoot bool
	Name   string
	Value  string
}

func (*ExtraIndex) NestedPath

func (e *ExtraIndex) NestedPath() string

type MongoDB

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

func NewMongoDB

func NewMongoDB(uri string) (MongoDB, error)

NewMongoDB initializes a new MongoDB connection wrapped in a structure.

func (*MongoDB) AllCompanies

func (m *MongoDB) AllCompanies(ctx context.Context, cursor *string, limit uint32) ([]string, *string, error)

AllCompanies returns a paginated list of CNPJ numbers from the database.

func (*MongoDB) Close

func (m *MongoDB) Close()

Close terminates the connection to MongoDB.

func (*MongoDB) Create

func (m *MongoDB) Create() error

Create creates the required collections.

func (*MongoDB) CreateCompanies

func (m *MongoDB) CreateCompanies(ctx context.Context, batch [][]string) error

CreateCompanies writes a batch of company data to MongoDB

func (*MongoDB) CreateExtraIndexes

func (m *MongoDB) CreateExtraIndexes(idxs []string) error

func (*MongoDB) Drop

func (m *MongoDB) Drop() error

Drop deletes the collectiosn created by `Create`.

func (*MongoDB) GetCompany

func (m *MongoDB) GetCompany(ctx context.Context, id string) (string, error)

func (*MongoDB) MetaRead

func (m *MongoDB) MetaRead(k string) (string, error)

MetaRead reads a key/value pair from the metadata collection.

func (*MongoDB) MetaSave

func (m *MongoDB) MetaSave(k, v string) error

MetaSave inserts if the key doesn't exist, or updates the value if it does.

func (*MongoDB) PostLoad

func (m *MongoDB) PostLoad() error

PostLoad runs after loading data into the database. Removes duplicates and creates indexes.

func (*MongoDB) PreLoad

func (m *MongoDB) PreLoad() error

PreLoad runs before starting to load data into the database.

func (*MongoDB) Search

func (m *MongoDB) Search(ctx context.Context, q *Query) (string, error)

Search returns paginated results with JSON for companies bases on a search query

type PostgreSQL

type PostgreSQL struct {
	CompanyTableName string
	MetaTableName    string
	CursorFieldName  string
	IDFieldName      string
	JSONFieldName    string
	KeyFieldName     string
	ValueFieldName   string
	ExtraIndexes     []ExtraIndex
	// contains filtered or unexported fields
}

PostgreSQL database interface.

func NewPostgreSQL

func NewPostgreSQL(uri, schema string) (PostgreSQL, error)

NewPostgreSQL creates a new PostgreSQL connection and ping it to make sure it works.

func (*PostgreSQL) AllCompanies

func (p *PostgreSQL) AllCompanies(ctx context.Context, cursor *string, limit uint32) ([]string, *string, error)

AllCompanies returns a paginated list of CNPJ numbers from the database.

func (*PostgreSQL) Close

func (p *PostgreSQL) Close()

Close closes the PostgreSQL connection

func (*PostgreSQL) CompanyTableFullName

func (p *PostgreSQL) CompanyTableFullName() string

CompanyTableFullName is the name of the schame and table in dot-notation.

func (*PostgreSQL) Create

func (p *PostgreSQL) Create() error

Create creates the required database table.

func (*PostgreSQL) CreateCompanies

func (p *PostgreSQL) CreateCompanies(ctx context.Context, batch [][]string) error

CreateCompanies performs a copy to create a batch of companies in the database. It expects an array and each item should be another array with only two items: the ID and the JSON field values.

func (*PostgreSQL) CreateExtraIndexes

func (p *PostgreSQL) CreateExtraIndexes(idxs []string) error

CreateExtraIndexes responsible for creating additional indexes in the database

func (*PostgreSQL) Drop

func (p *PostgreSQL) Drop() error

Drop drops the database table created by `Create`.

func (*PostgreSQL) GetCompany

func (p *PostgreSQL) GetCompany(ctx context.Context, id string) (string, error)

GetCompany returns the JSON of a company based on a CNPJ number.

func (*PostgreSQL) MetaRead

func (p *PostgreSQL) MetaRead(k string) (string, error)

MetaRead reads a key/value pair from the metadata table.

func (*PostgreSQL) MetaSave

func (p *PostgreSQL) MetaSave(k, v string) error

MetaSave saves a key/value pair in the metadata table.

func (*PostgreSQL) MetaTableFullName

func (p *PostgreSQL) MetaTableFullName() string

MetaTableFullName is the name of the schame and table in dot-notation.

func (*PostgreSQL) PostLoad

func (p *PostgreSQL) PostLoad() error

PostLoad runs after loading data into the database. Currently it re-enables autovacuum on PostgreSQL.

func (*PostgreSQL) PreLoad

func (p *PostgreSQL) PreLoad() error

PreLoad runs before starting to load data into the database. Currently it disables autovacuum on PostgreSQL.

func (*PostgreSQL) Search

func (p *PostgreSQL) Search(ctx context.Context, q *Query) (string, error)

Search returns paginated results with JSON for companies bases on a search query

type Query

type Query struct {
	CNAE             []uint32
	CNAEFiscal       []uint32
	CNPF             []string // CNPJ or CPF in the QSA
	Municipio        []uint32 // IBGE or SIAFI
	NaturezaJuridica []uint32
	UF               []string
	Cursor           *string
	Limit            uint32
}

func NewQuery

func NewQuery(v url.Values) *Query

func (*Query) CursorAsInt

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

Jump to

Keyboard shortcuts

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