geostore

package module
v1.14.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Geo Store

tests Go Report Card PkgGoDev

Usage:

store, err := NewStore(NewStoreOptions{
  DB:                 db,
  CountryTableName:   "geo_country",
  StateTableName:     "geo_state",
  TimezoneTableName:  "geo_timezone",
  AutomigrateEnabled: true,
})

if err != nil {
  t.Fatal("unexpected error:", err)
}

if store == nil {
  t.Fatal("unexpected nil store")
}

country, errFind := store.CountryFindByIso2("BG")

if errFind != nil {
  t.Fatal("unexpected error:", errFind)
}

if country == nil {
  t.Fatal("Country MUST NOT be nil")
}

log.Print(country.Name()) // Prints the name of the country

Documentation

Index

Constants

View Source
const COLUMN_CONTINENT = "continent"
View Source
const COLUMN_COUNTRY_CODE = "country_code"
View Source
const COLUMN_CREATED_AT = "created_at"
View Source
const COLUMN_GLOBAL_NAME = "global_name"
View Source
const COLUMN_ID = "id"
View Source
const COLUMN_ISO2_CODE = "iso2_code"
View Source
const COLUMN_ISO3_CODE = "iso3_code"
View Source
const COLUMN_NAME = "name"
View Source
const COLUMN_OFFSET = "offset"
View Source
const COLUMN_PHONE_PREFIX = "phone_prefix"
View Source
const COLUMN_SOFT_DELETED_AT = "soft_deleted_at"
View Source
const COLUMN_STATE_CODE = "state_code"
View Source
const COLUMN_STATUS = "status"
View Source
const COLUMN_TIMEZONE = "timezone"
View Source
const COLUMN_UPDATED_AT = "updated_at"
View Source
const COLUMN_ZONE_NAME = "zone_name"
View Source
const COUNTRY_STATUS_ACTIVE = "active"
View Source
const COUNTRY_STATUS_INACTIVE = "inactive"
View Source
const MAX_DATETIME = "9999-12-31 23:59:59"

MAX_DATETIME is a far-future datetime used as the default soft-delete sentinel.

View Source
const STATE_STATUS_ACTIVE = "active"
View Source
const STATE_STATUS_INACTIVE = "inactive"
View Source
const TIMEZONE_STATUS_ACTIVE = "active"
View Source
const TIMEZONE_STATUS_INACTIVE = "inactive"

Variables

This section is empty.

Functions

This section is empty.

Types

type Country

type Country struct {
	orm.StringID

	StatusField      string `db:"status"`
	Iso2CodeField    string `db:"iso2_code"`
	Iso3CodeField    string `db:"iso3_code"`
	NameField        string `db:"name"`
	ContinentField   string `db:"continent"`
	PhonePrefixField string `db:"phone_prefix"`

	CreatedAtField orm.CreatedAt
	UpdatedAtField orm.UpdatedAt
	soft_delete.SoftDeletesMaxDate
	// contains filtered or unexported fields
}

func NewCountry

func NewCountry() *Country

func NewCountryFromExistingData

func NewCountryFromExistingData(data map[string]string) *Country

func (*Country) Continent

func (o *Country) Continent() string

func (*Country) CreatedAt

func (o *Country) CreatedAt() string

func (*Country) CreatedAtCarbon added in v1.5.0

func (o *Country) CreatedAtCarbon() *carbon.Carbon

func (*Country) Data added in v1.5.0

func (o *Country) Data() map[string]string

func (*Country) GetSoftDeletedAt added in v1.5.0

func (o *Country) GetSoftDeletedAt() string

func (*Country) GetSoftDeletedAtCarbon added in v1.5.0

func (o *Country) GetSoftDeletedAtCarbon() *carbon.Carbon

func (*Country) ID added in v1.5.0

func (o *Country) ID() string

func (*Country) IsoCode2

func (o *Country) IsoCode2() string

func (*Country) IsoCode3

func (o *Country) IsoCode3() string

func (*Country) MarkAsNotDirty added in v1.5.0

func (o *Country) MarkAsNotDirty(columns ...string)

func (*Country) Name

func (o *Country) Name() string

func (*Country) PhonePrefix

func (o *Country) PhonePrefix() string

func (*Country) SetContinent

func (o *Country) SetContinent(continent string) *Country

func (*Country) SetCreatedAt

func (o *Country) SetCreatedAt(createdAt string) *Country

func (*Country) SetID added in v1.5.0

func (o *Country) SetID(id string) *Country

func (*Country) SetIsoCode2

func (o *Country) SetIsoCode2(isoCode2 string) *Country

func (*Country) SetIsoCode3

func (o *Country) SetIsoCode3(isoCode3 string) *Country

func (*Country) SetName

func (o *Country) SetName(name string) *Country

func (*Country) SetPhonePrefix

func (o *Country) SetPhonePrefix(phonePrefix string) *Country

func (*Country) SetSoftDeletedAt added in v1.5.0

func (o *Country) SetSoftDeletedAt(softDeletedAt string) *Country

func (*Country) SetStatus

func (o *Country) SetStatus(status string) *Country

func (*Country) SetUpdatedAt

func (o *Country) SetUpdatedAt(updatedAt string) *Country

func (*Country) Status

func (o *Country) Status() string

func (*Country) UpdatedAt

func (o *Country) UpdatedAt() string

func (*Country) UpdatedAtCarbon added in v1.5.0

func (o *Country) UpdatedAtCarbon() *carbon.Carbon

type CountryQueryOptions

type CountryQueryOptions struct {
	ID          string
	IDIn        []string
	Status      string
	StatusIn    []string
	Iso2        string
	Iso3        string
	Offset      int
	Limit       int
	SortOrder   string
	OrderBy     string
	CountOnly   bool
	WithDeleted bool
}

type NewStoreOptions

type NewStoreOptions struct {
	CountryTableName   string
	StateTableName     string
	TimezoneTableName  string
	DB                 *sql.DB
	AutomigrateEnabled bool
	AutoseedEnabled    bool
}

NewStoreOptions define the options for creating a new geostore

type State

type State struct {
	orm.StringID

	StatusField      string `db:"status"`
	CountryCodeField string `db:"country_code"`
	StateCodeField   string `db:"state_code"`
	NameField        string `db:"name"`

	CreatedAtField orm.CreatedAt
	UpdatedAtField orm.UpdatedAt
	soft_delete.SoftDeletesMaxDate
	// contains filtered or unexported fields
}

func NewState

func NewState() *State

func NewStateFromExistingData

func NewStateFromExistingData(data map[string]string) *State

func (*State) CountryCode

func (o *State) CountryCode() string

func (*State) CreatedAt

func (o *State) CreatedAt() string

func (*State) CreatedAtCarbon added in v1.5.0

func (o *State) CreatedAtCarbon() *carbon.Carbon

func (*State) Data added in v1.5.0

func (o *State) Data() map[string]string

func (*State) GetSoftDeletedAt added in v1.5.0

func (o *State) GetSoftDeletedAt() string

func (*State) GetSoftDeletedAtCarbon added in v1.5.0

func (o *State) GetSoftDeletedAtCarbon() *carbon.Carbon

func (*State) ID added in v1.5.0

func (o *State) ID() string

func (*State) MarkAsNotDirty added in v1.5.0

func (o *State) MarkAsNotDirty(columns ...string)

func (*State) Name

func (o *State) Name() string

func (*State) SetCountryCode

func (o *State) SetCountryCode(countryCodeIso2 string) *State

func (*State) SetCreatedAt

func (o *State) SetCreatedAt(createdAt string) *State

func (*State) SetID added in v1.5.0

func (o *State) SetID(id string) *State

func (*State) SetName

func (o *State) SetName(name string) *State

func (*State) SetSoftDeletedAt added in v1.5.0

func (o *State) SetSoftDeletedAt(softDeletedAt string) *State

func (*State) SetStateCode

func (o *State) SetStateCode(stateCode string) *State

func (*State) SetStatus

func (o *State) SetStatus(status string) *State

func (*State) SetUpdatedAt

func (o *State) SetUpdatedAt(updatedAt string) *State

func (*State) StateCode

func (o *State) StateCode() string

func (*State) Status

func (o *State) Status() string

func (*State) UpdatedAt

func (o *State) UpdatedAt() string

func (*State) UpdatedAtCarbon added in v1.5.0

func (o *State) UpdatedAtCarbon() *carbon.Carbon

type StateQueryOptions

type StateQueryOptions struct {
	ID          string
	Status      string
	StatusIn    []string
	CountryCode string
	StateCode   string
	Offset      int
	Limit       int
	SortOrder   string
	OrderBy     string
	CountOnly   bool
	WithDeleted bool
}

type StoreInterface

type StoreInterface interface {
	// GetCountryTableName returns the country table name
	GetCountryTableName() string
	// SetCountryTableName sets the country table name
	SetCountryTableName(countryTableName string)

	// GetStateTableName returns the state table name
	GetStateTableName() string
	// SetStateTableName sets the state table name
	SetStateTableName(stateTableName string)

	// GetTimezoneTableName returns the timezone table name
	GetTimezoneTableName() string
	// SetTimezoneTableName sets the timezone table name
	SetTimezoneTableName(timezoneTableName string)

	// MigrateUp creates all database tables
	MigrateUp(ctx context.Context, tx ...*sql.Tx) error

	// MigrateDown drops all database tables
	MigrateDown(ctx context.Context, tx ...*sql.Tx) error

	// Seed populates all tables with initial data
	Seed(ctx context.Context, tx ...*sql.Tx) error

	EnableDebug(debug bool)

	CountryCreate(ctx context.Context, country *Country) error
	CountryDelete(ctx context.Context, country *Country) error
	CountryDeleteByID(ctx context.Context, countryID string) error
	CountryFindByID(ctx context.Context, countryID string) (*Country, error)
	CountryFindByIso2(ctx context.Context, iso2Code string) (*Country, error)
	CountryList(ctx context.Context, options CountryQueryOptions) ([]Country, error)
	CountrySoftDelete(ctx context.Context, country *Country) error
	CountrySoftDeleteByID(ctx context.Context, countryID string) error
	CountryUpdate(ctx context.Context, country *Country) error

	StateCreate(ctx context.Context, state *State) error
	StatesCreate(ctx context.Context, states []*State) error
	StateList(ctx context.Context, options StateQueryOptions) ([]State, error)

	TimezoneCreate(ctx context.Context, timezone *Timezone) error
	TimezoneList(ctx context.Context, options TimezoneQueryOptions) ([]Timezone, error)
}

func NewStore

func NewStore(opts NewStoreOptions) (StoreInterface, error)

NewStore creates a new geostore

type Timezone

type Timezone struct {
	orm.StringID

	StatusField      string `db:"status"`
	TimezoneField    string `db:"timezone"`
	ZoneNameField    string `db:"zone_name"`
	GlobalNameField  string `db:"global_name"`
	CountryCodeField string `db:"country_code"`
	OffsetField      string `db:"offset"`

	CreatedAtField orm.CreatedAt
	UpdatedAtField orm.UpdatedAt
	soft_delete.SoftDeletesMaxDate
	// contains filtered or unexported fields
}

func NewTimezone

func NewTimezone() *Timezone

func NewTimezoneFromExistingData

func NewTimezoneFromExistingData(data map[string]string) *Timezone

func (*Timezone) CountryCode

func (o *Timezone) CountryCode() string

func (*Timezone) CreatedAt

func (o *Timezone) CreatedAt() string

func (*Timezone) CreatedAtCarbon

func (o *Timezone) CreatedAtCarbon() *carbon.Carbon

func (*Timezone) Data added in v1.5.0

func (o *Timezone) Data() map[string]string

func (*Timezone) GetSoftDeletedAt added in v1.5.0

func (o *Timezone) GetSoftDeletedAt() string

func (*Timezone) GetSoftDeletedAtCarbon added in v1.5.0

func (o *Timezone) GetSoftDeletedAtCarbon() *carbon.Carbon

func (*Timezone) GlobalName

func (o *Timezone) GlobalName() string

func (*Timezone) ID added in v1.5.0

func (o *Timezone) ID() string

func (*Timezone) MarkAsNotDirty added in v1.5.0

func (o *Timezone) MarkAsNotDirty(columns ...string)

func (*Timezone) Offset

func (o *Timezone) Offset() string

func (*Timezone) SetCountryCode

func (o *Timezone) SetCountryCode(countryCode string) *Timezone

func (*Timezone) SetCreatedAt

func (o *Timezone) SetCreatedAt(createdAt string) *Timezone

func (*Timezone) SetGlobalName

func (o *Timezone) SetGlobalName(globalName string) *Timezone

func (*Timezone) SetID added in v1.5.0

func (o *Timezone) SetID(id string) *Timezone

func (*Timezone) SetOffset

func (o *Timezone) SetOffset(offset string) *Timezone

func (*Timezone) SetSoftDeletedAt added in v1.5.0

func (o *Timezone) SetSoftDeletedAt(softDeletedAt string) *Timezone

func (*Timezone) SetStatus

func (o *Timezone) SetStatus(status string) *Timezone

func (*Timezone) SetTimezone

func (o *Timezone) SetTimezone(timezone string) *Timezone

func (*Timezone) SetUpdatedAt

func (o *Timezone) SetUpdatedAt(updatedAt string) *Timezone

func (*Timezone) SetZoneName

func (o *Timezone) SetZoneName(zoneName string) *Timezone

func (*Timezone) Status

func (o *Timezone) Status() string

func (*Timezone) Timezone

func (o *Timezone) Timezone() string

func (*Timezone) UpdatedAt

func (o *Timezone) UpdatedAt() string

func (*Timezone) UpdatedAtCarbon

func (o *Timezone) UpdatedAtCarbon() *carbon.Carbon

func (*Timezone) ZoneName

func (o *Timezone) ZoneName() string

type TimezoneQueryOptions

type TimezoneQueryOptions struct {
	ID          string
	Status      string
	StatusIn    []string
	CountryCode string
	Timezone    string
	Offset      int
	Limit       int
	SortOrder   string
	OrderBy     string
	CountOnly   bool
	WithDeleted bool
}

Jump to

Keyboard shortcuts

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