func (c Check) AsProto() *lokahi.Check {
	return &lokahi.Check{
		Id:          c.UUID,
		Url:         c.URL,
		WebhookUrl:  c.WebhookURL,
		Every:       int32(c.Every),
		PlaybookUrl: c.PlaybookURL,
		State:       lokahi.Check_State(lokahi.Check_State_value[c.State]),
		WebhookResponseTimeNanoseconds: c.WebhookResponseTimeNanoseconds,
	}
}
AsProto converts this to the protobuf representation.
package database
import (
	"context"
	"time"
	"github.com/Xe/ln"
	"github.com/Xe/lokahi/rpc/lokahi"
	"github.com/jmoiron/sqlx"
)
type Checks interface {
	Create(ctx context.Context, c Check) (*Check, error)
	Delete(ctx context.Context, cid string) (*Check, error)
	Get(ctx context.Context, cid string) (*Check, error)
	ListByEveryValue(ctx context.Context, time int) ([]Check, error)
	List(ctx context.Context, count, offset int) ([]Check, error)
	Put(ctx context.Context, c Check) (*Check, error)
}
func ChecksPostgres(db *sqlx.DB) Checks {
	return &checksPostgres{db: db}
}
type checksPostgres struct {
	db *sqlx.DB
}
func (c *checksPostgres) Create(ctx context.Context, ch Check) (*Check, error) {
	_, err := c.db.NamedExec(`INSERT INTO checks(url, webhook_url, playbook_url, every) VALUES (:url, :webhook_url, :playbook_url, :every)`, ch)
	if err != nil {
		return nil, err
	}
	var result Check
	err = c.db.Get(&result, "SELECT * FROM checks WHERE url = $1", ch.URL)
	if err != nil {  
		return nil, err
	}
	return &result, nil
}
func (c *checksPostgres) Get(ctx context.Context, cid string) (*Check, error) {
	var result Check
	err := c.db.Get(&result, "SELECT * FROM checks WHERE uuid = $1", cid)
	if err != nil {
		return nil, err
	}
	return &result, nil
}
func (c *checksPostgres) Delete(ctx context.Context, cid string) (*Check, error) {
	result, err := c.Get(ctx, cid)
	if err != nil {
		return nil, err
	}
	_, err = c.db.Exec(`DELETE FROM checks WHERE uuid = $1`, cid)
	if err != nil {
		return nil, err
	}
	return result, nil
}
func (c *checksPostgres) List(ctx context.Context, count, offset int) ([]Check, error) {
	var result []Check
	err := c.db.Select(&result, `SELECT * FROM checks LIMIT $1 OFFSET $2`, count, offset)
	if err != nil {
		return nil, err
	}
	return result, nil
}
func (c *checksPostgres) Put(ctx context.Context, ch Check) (*Check, error) {
	ch.EditedAt = time.Now()
	_, err := c.db.NamedExec(`UPDATE checks SET edited_at = :edited_at, url = :url, webhook_url = :webhook_url, webhook_response_time_nanoseconds = :webhook_response_time_nanoseconds, every = :every, playbook_url = :playbook_url, state = :state WHERE uuid = :uuid`, ch)
	if err != nil {
		return nil, err
	}
	return c.Get(ctx, ch.UUID)
}
func (c *checksPostgres) ListByEveryValue(ctx context.Context, every int) ([]Check, error) {
	var result []Check
	err := c.db.Select(&result, `SELECT * FROM CHECKS WHERE every = $1`, every)
	if err != nil {
		return nil, err
	}
	return result, nil
}
type Check struct {
	ID   int    `db:"id"`
	UUID string `db:"uuid"`
	CreatedAt time.Time `db:"created_at"`
	EditedAt  time.Time `db:"edited_at"`
	URL string `db:"url"`
	WebhookURL string `db:"webhook_url"`
	WebhookResponseTimeNanoseconds int64 `db:"webhook_response_time_nanoseconds"`
	Every int `db:"every"`
	PlaybookURL string `db:"playbook_url"`
	State string `db:"state"`
}
func (c Check) F() ln.F {
	return ln.F{
		"check_uuid":  c.UUID,
		"check_url":   c.URL,
		"check_every": c.Every,
		"check_state": c.State,
	}
}