Quit all :qa
Go to top of file :gg
Go to bottom of file Shift-g
| 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" |
| // 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 | |
| } |
| // 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 | |
| } |
| // 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() |
| // GenericMutations write to the database | |
| type GenericMutations interface { | |
| Add(model ...interface{}) error | |
| RegisterModel(model interface{}) error | |
| Remove(model interface{}) error | |
| } |
| // Add adds any number of models as a database rows | |
| func (c *Client) Add(model ...interface{}) error { | |
| return c.Insert(model...) | |
| } |
| // 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, | |
| }) | |
| } |