postgres

package
v0.0.0-...-2646333 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// VersionTableName is the table name for this model
	VersionTableName = "data_version"
	// VersionFieldName is the name for the version field in Version struct
	VersionFieldName = "version"
	// ServiceFieldName is the name for the service_name field in Version struct
	ServiceFieldName = "service_name"
	// LastUpdatedTsFieldName is the name for last_updated_timestamp field in Version struct
	LastUpdatedTsFieldName = "last_updated_timestamp"
	// ExistsFieldName is the name for exists field in Version struct
	ExistsFieldName = "exists"
)
View Source
const (
	// EventTableBaseName is the type of table this code defines
	EventTableBaseName = "event"
)

Variables

This section is empty.

Functions

func CreateEventTableIndices

func CreateEventTableIndices(tableName string) string

CreateEventTableIndices returns the query to create this table

func CreateEventTableQuery

func CreateEventTableQuery(tableName string) string

CreateEventTableQuery returns the query to create this table

func CreateVersionTableQuery

func CreateVersionTableQuery(tableName string) string

CreateVersionTableQuery returns the query to create this table version and service_name are unique.

Types

type Event

type Event struct {
	EventType       string                 `db:"event_type"`
	EventHash       string                 `db:"hash"`
	ContractAddress string                 `db:"contract_address"`
	ContractName    string                 `db:"contract_name"`
	Timestamp       int64                  `db:"timestamp"`
	RetrievalMethod int                    `db:"retrieval_method"`
	EventPayload    cpostgres.JsonbPayload `db:"payload"`
	LogPayload      cpostgres.JsonbPayload `db:"log_payload"`
}

Event is the model for events table in DB

func NewDbEventFromEvent

func NewDbEventFromEvent(event *model.Event) (*Event, error)

NewDbEventFromEvent constructs an event for DB from a model.event

func (*Event) DBToEventData

func (c *Event) DBToEventData() (*model.Event, error)

DBToEventData converts the db event model to a model. NOTE(IS): because jsonb payloads are stored in DB as a map[string]interface{}, Postgres converts some fields, see notes in function.

func (*Event) DBToEventLogData

func (c *Event) DBToEventLogData() *types.Log

DBToEventLogData converts the DB raw log payload back to types.Log NOTE(IS): because jsonb payloads are stored in DB as a map[string]interface{}, Postgres converts some fields, see notes in function.

func (*Event) EventDataToDB

func (c *Event) EventDataToDB(eventData map[string]interface{}) error

EventDataToDB converts event data payload types so they can be stored in the DB

func (*Event) EventLogDataToDB

func (c *Event) EventLogDataToDB(payload *types.Log)

EventLogDataToDB explicitly converts the raw log data to Postgresql types

type Version

type Version struct {
	Version           *string `db:"version"`
	ServiceName       string  `db:"service_name"`
	LastUpdatedDateTs int64   `db:"last_updated_timestamp"`
	Exists            bool    `db:"exists"`
}

Version is the model for the version table in DB

Jump to

Keyboard shortcuts

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