censusgo

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2020 License: MIT Imports: 7 Imported by: 1 module, 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

censusgo

This package is unofficial and is NOT in any way supported by Daybreak Games.

All use of game data and other content must comply with Daybreak Games Intellectual Property policy and Daybreak Game Company's Terms of Service.


censusgo is a library that makes it much easier to use the Census API provided by Daybreak Games Company. It uses dot notation chaining to make it easy to define and maintain queries.

For example, the following code will return all character faction stats saved after lastLoginTime and retrieve them from the API in chunks of 500 at a time.

b := censusgo.NewQueryBuilder("example", "ps2")

q := b.NewQuery("characters_stat_by_faction")
q.SetLimit(500)
q.Where("character_id").Equals("5428010917249639985")
q.ShowFields(
    "character_id",
    "stat_name",
    "profile_id",
    "value_forever_vs",
    "value_forever_nc",
    "value_forever_tr")
q.Where("last_save_date").IsGreaterThanOrEquals(lastLoginTime)

results, err := q.GetResultsBatch()

For a working example check out the examples!

Table of Contents

Installing

To download the censusgo library use

go get github.com/Lampjaw/censusgo
Creating a new query

To start creating queries, first create a QueryBuilder. QueryBuilder is a factory for generating queries that share the same service id and namespace. Using QueryBuilder you can call NewQuery(<collection_name>) to begin building your query definition.

builder := censusgo.NewQueryBuilder("example", "ps2")
query := builder.NewQuery("character")
Returning data from the query

There are two methods of query resolution: GetResults() and GetResultsBatch(). Both methods return type []interface{} as a []byte but execute the query differently.

GetResults() will only return the number of results or less of the limit specified or a single result if no limit is set.

GetResultsBatch() will attempt to return every record in the collection until either an error is thrown or the number of records returns is less than the limit. If no limit is specified it defaults to 500 records per fetch attempt.

results, err := query.GetResults()
Defining a condition
query.Where("name.lower").Equals("lampjaw")

The following operations and their equivalent syntax is below:

  • Equals: =
  • NotEquals: =!
  • IsLessThan: =<
  • IsLessThanOrEquals: =[
  • IsGreaterThan: =>
  • IsGreaterThanOrEquals: =]
  • StartsWith: =^
  • Contains: =*
Setting a language
query.SetLanguageString("en")

OR

query.SetLanguage(censusgo.LangEnglish)

No language is set by default so you will receive all localized strings if available.

Show certain fields
query.ShowFields("character_id"[, "field2", "field3", ...])
Hide certain fields
query.HideFields("currency"[, "field2", "field3", ...])
Set a limit for number of rows to return
query.SetLimit(10)
Set the starting row
query.SetStart(100)
Add a resolve
query.AddResolve("world"[, "resolve2", "resolve3", ...])
Join to another service
worldJoin := query.JoinCollection("characters_world")

Join objects have the following methods:

  • IsList(bool)
  • IsOuterJoin(bool)
  • ShowFields(...string): See the 'Show certain fields' section above
  • HideFields(...string): See the 'Hide certain fields' section above
  • OnField(string)
  • ToField(string)
  • WithInjectAt(string)
  • Where(string): See the 'Defining a condition' section above
  • JoinCollection(string): Returns another join object for sub joining
Tree results on a field
vehicleTree := query.TreeField("type_id")

Tree objects have the following methods:

  • IsList(bool)
  • GroupPrefix(string)
  • StartField(string)
  • TreeField(string): Returns another tree object for sub grouping
Getting the url of the query
url := query.GetURL()

Documentation

Index

Constants

View Source
const VERSION = "1.2.0"

VERSION for semver

Variables

This section is empty.

Functions

This section is empty.

Types

type CensusClient

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

CensusClient is an object that retains a client and census configuration states between generated queries

func NewCensusClient

func NewCensusClient(serviceID string, collectionNamespace string) *CensusClient

NewCensusClient creates a CensusClient object

type CensusLanguage

type CensusLanguage int
const (
	LangEnglish CensusLanguage = iota
	LangGerman
	LangSpanish
	LangFrench
	LangItalian
	LangTurkish
)

type Query added in v1.1.0

type Query struct {
	Collection string

	ExactMatchFirst bool         `queryProp:"exactMatchFirst"`
	Timing          bool         `queryProp:"timing"`
	IncludeNull     bool         `queryProp:"includeNull"`
	CaseSensitive   bool         `queryProp:"case,default=true"`
	Retry           bool         `queryProp:"retry,default=true"`
	Limit           int          `queryProp:"limit,default=-1"`
	LimitPerDB      int          `queryProp:"limitPerDB,default=-1"`
	Start           int          `queryProp:"start,default=-1"`
	Show            []string     `queryProp:"show"`
	Hide            []string     `queryProp:"hide"`
	Sort            []string     `queryProp:"sort"`
	Has             []string     `queryProp:"has"`
	Resolve         []string     `queryProp:"resolve"`
	Join            []*queryJoin `queryProp:"join"`
	Tree            []*queryTree `queryProp:"tree"`
	Distinct        string       `queryProp:"distinct"`
	Language        string       `queryProp:"lang"`
	// contains filtered or unexported fields
}

Query is the expression root for a census query

func NewQuery added in v1.1.0

func NewQuery(collection string, censusClient *CensusClient) *Query

NewQuery creates a new Query object

func (*Query) AddResolve added in v1.1.0

func (q *Query) AddResolve(resolves ...string) *Query

AddResolve adds resolution effects to the query

func (*Query) GetResults added in v1.1.0

func (q *Query) GetResults() ([]byte, error)

GetResults returns the records from the census API as stated in the query expression

func (*Query) GetResultsBatch added in v1.1.0

func (q *Query) GetResultsBatch() ([]byte, error)

GetResultsBatch returns ALL records from the census API as stated in the query expression in batches

func (*Query) GetURL added in v1.1.0

func (q *Query) GetURL() string

GetURL returns the URL equivalent of the query expression

func (*Query) HideFields added in v1.1.0

func (q *Query) HideFields(fields ...string) *Query

HideFields lists the specific fields to exclude from each record

func (*Query) JoinCollection added in v1.1.0

func (q *Query) JoinCollection(collection string) *queryJoin

JoinCollection joins the query with another collection

func (*Query) SetLanguage added in v1.1.0

func (q *Query) SetLanguage(language CensusLanguage) *Query

SetLanguage sets the localization string set to only return a specific language

func (*Query) SetLanguageString added in v1.1.0

func (q *Query) SetLanguageString(language string) *Query

SetLanguageString sets the localization string set to only return a specific language

func (*Query) SetLimit added in v1.1.0

func (q *Query) SetLimit(limit int) *Query

SetLimit sets the maximum number of records to return

func (*Query) SetStart added in v1.1.0

func (q *Query) SetStart(start int) *Query

SetStart sets the record to begin the query from if the collection isn't stored in a cluster

func (*Query) ShowFields added in v1.1.0

func (q *Query) ShowFields(fields ...string) *Query

ShowFields lists the specific fields to include from each record

func (*Query) String added in v1.1.0

func (q *Query) String() string

func (*Query) TreeField added in v1.1.0

func (q *Query) TreeField(field string) *queryTree

TreeField creates a tree with a specific field

func (*Query) Where added in v1.1.0

func (q *Query) Where(field string) *queryOperand

Where begins an argument expression with a field designation

type QueryBuilder

type QueryBuilder struct {
	CensusClient *CensusClient
}

QueryBuilder is a factory used to generate census queries that share the same census service ID and collection namespace

func NewQueryBuilder

func NewQueryBuilder(serviceID string, collectionNamespace string) *QueryBuilder

NewQueryBuilder returns a new QueryBuilder object

func (*QueryBuilder) NewQuery

func (b *QueryBuilder) NewQuery(collection string) *Query

NewQuery creates a new census query expression

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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