Skip to content

Instantly share code, notes, and snippets.

View shanev's full-sized avatar
💭
#BUIDL

shane.stars shanev

💭
#BUIDL
View GitHub Profile
msg := curating.NewMsgPost(c.VendorID, postID, creator, creator, body)
account, err := c.GetAccount(creator)
if err != nil {
return err
}
txBytes, err := c.TxBuilder.
WithAccountNumber(account.GetAccountNumber()).
WithSequence(account.GetSequence()).

Postgres Cheat Sheet

psql -h localhost -U postgres -d [db_name]

Disable word wrap PAGER="less -S" psql -h localhost -U postgres -d [db_name]

Connection

Show connection info \conninfo

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
{
"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"
@shanev
shanev / db-1.go
Last active January 22, 2019 09:28
// Client is a Postgres client.
// It wraps a pool of Postgres DB connections.
type Client struct {
*pg.DB
}
// NewDBClient creates a Postgres client
func NewDBClient(addr string, user string, password string, database string) *Client {
db := pg.Connect(&pg.Options{
Addr: addr,
@shanev
shanev / db-3.go
Last active January 22, 2019 04:48
// 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,
})
}
@shanev
shanev / db-7.go
Last active January 21, 2019 19:55
// 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
}
// 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)
// 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
}
// 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()