package public import ( pubmodel "dorisbot/database/models/public" sq "github.com/elgris/sqrl" ) // CommandImpl - type CommandImpl struct{} // Create - func (c *CommandImpl) Create(cmd *pubmodel.Command) error { query, args, err := sq.Insert(`"public"."command"`). Columns("key", "platform", "binding", "require_manage", "require_init", "value", "ctime", "mtime"). Values(cmd.Key, cmd.Platform, cmd.Binding, cmd.RequireManage, cmd.RequireInit, cmd.Value, sq.Expr("now()"), sq.Expr("now()")). ToSql() if err != nil { return err } query = x.Rebind(query) err = x.Get(cmd, query, args...) if err != nil { return err } return nil } // Delete - func (c *CommandImpl) Delete(key string, platform string, binding string) error { query, args, err := sq.Delete(`"public"."command"`).Where(sq.And{ sq.Eq{"key": key}, sq.Eq{"platform": platform}, sq.Eq{"binding": binding}, }).ToSql() if err != nil { return err } query = x.Rebind(query) _, err = x.Exec(query, args...) if err != nil { return err } return nil } // GetByKey - func (c *CommandImpl) GetByKey(key string) ([]pubmodel.Command, error) { query, args, err := sq.Select("key", "platform", "binding", "require_manage", "require_init", "value", "ctime", "mtime"). From(`"public"."command"`).Where(sq.Eq{"key": key}).ToSql() if err != nil { return nil, err } query = x.Rebind(query) list := make([]pubmodel.Command, 0) err = x.Select(&list, query, args...) if err != nil { return nil, err } return list, nil } // GetByKeyPlatform - func (c *CommandImpl) GetByKeyPlatform(key string, platform string) ([]pubmodel.Command, error) { query, args, err := sq.Select("key", "platform", "binding", "require_manage", "require_init", "value", "ctime", "mtime"). From(`"public"."command"`).Where(sq.And{ sq.Eq{"key": key}, sq.Eq{"platform": platform}, }).ToSql() if err != nil { return nil, err } query = x.Rebind(query) list := make([]pubmodel.Command, 0) err = x.Select(&list, query, args...) if err != nil { return nil, err } return list, nil } // GetByKeyPlatformBinding - func (c *CommandImpl) GetByKeyPlatformBinding(key string, platform string, binding string) ([]pubmodel.Command, error) { query, args, err := sq.Select("key", "platform", "binding", "require_manage", "require_init", "value", "ctime", "mtime"). From(`"public"."command"`).Where(sq.And{ sq.Eq{"key": key}, sq.Eq{"platform": platform}, sq.Eq{"binding": binding}, }).ToSql() if err != nil { return nil, err } query = x.Rebind(query) list := make([]pubmodel.Command, 0) err = x.Select(&list, query, args...) if err != nil { return nil, err } return list, nil } // GetByPlatformBinding - func (c *CommandImpl) GetByPlatformBinding(platform string, binding string) ([]pubmodel.Command, error) { query, args, err := sq.Select("key", "platform", "binding", "require_manage", "require_init", "value", "ctime", "mtime"). From(`"public"."command"`).Where(sq.And{ sq.Eq{"platform": platform}, sq.Eq{"binding": binding}, }).ToSql() if err != nil { return nil, err } query = x.Rebind(query) list := make([]pubmodel.Command, 0) err = x.Select(&list, query, args...) if err != nil { return nil, err } return list, nil } // GetByKeyBinding - func (c *CommandImpl) GetByKeyBinding(key string, binding string) ([]pubmodel.Command, error) { query, args, err := sq.Select("key", "platform", "binding", "require_manage", "require_init", "value", "ctime", "mtime"). From(`"public"."command"`).Where(sq.And{ sq.Eq{"key": key}, sq.Eq{"binding": binding}, }).ToSql() if err != nil { return nil, err } query = x.Rebind(query) list := make([]pubmodel.Command, 0) err = x.Select(&list, query, args...) if err != nil { return nil, err } return list, nil }