Skip to content

Instantly share code, notes, and snippets.

💭
#BUIDL

Shane Vitarana shanev

💭
#BUIDL
Block or report user

Report or block shanev

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View main.go
const (
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Bech32PrefixAccAddr = "tru:"
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
Bech32PrefixAccPub = "tru:pub"
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
Bech32PrefixValAddr = "tru:valoper"
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
Bech32PrefixValPub = "tru:valoperpub"
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
View genesis.json
{
"genesis_time": "2018-11-29T02:28:27.057819Z",
"chain_id": "test-chain-JHrAIn",
"consensus_params": {
"block_size": {
"max_bytes": "22020096",
"max_gas": "-1"
},
"evidence": {
"max_age": "100000"
View db-9.go
// Mutations write to the database
type Mutations interface {
GenericMutations
UpsertProfile(profile *Profile) error
}
// Queries read from the database
type Queries interface {
GenericQueries
ProfileByUsername(username string) (Profile, error)
View db-8.go
// Updates an existing Profile or creates a new one
func (c *Client) UpsertProfile(profile *Profile) error {
_, err := c.Model(profile).
OnConflict("(id) DO UPDATE").
Set("username = EXCLUDED.username").
Insert()
return err
}
View db-7.go
// Finds a Profile by the given username
func (c *Client) ProfileByUsername(username string) (Profile, error) {
profile := new(Profile)
err := c.Model(profile).Where("username = ?", username).Select()
if err != nil {
return *profile, err
}
return *profile, nil
}
View db-6.go
// GenericQueries are generic reads for models
type GenericQueries interface {
Count(model interface{}) (int, error)
Find(model interface{}) error
FindAll(models interface{}) error
}
// Count returns the count of the model
func (c *Client) Count(model interface{}) (count int, err error) {
count, err = c.Model(model).Count()
View db-5.go
// GenericMutations write to the database
type GenericMutations interface {
Add(model ...interface{}) error
RegisterModel(model interface{}) error
Remove(model interface{}) error
}
View db-4.go
// Add adds any number of models as a database rows
func (c *Client) Add(model ...interface{}) error {
return c.Insert(model...)
}
View db-3.go
// RegisterModel creates a table for a type.
// A table is automatically created based on the passed in struct fields.
func (c *Client) RegisterModel(model interface{}) error {
return c.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
IfNotExists: true,
})
}
View db-2.go
// Datastore defines all operations on the DB
// This interface can be mocked out for tests, etc.
type Datastore interface {
Mutations
Queries
}
You can’t perform that action at this time.