Skip to content

Instantly share code, notes, and snippets.

@asim
Created November 16, 2020 07:41
Show Gist options
  • Save asim/10b96ed42e300959ec96e963ed4cc6e2 to your computer and use it in GitHub Desktop.
Save asim/10b96ed42e300959ec96e963ed4cc6e2 to your computer and use it in GitHub Desktop.
package handler
import (
"context"
"time"
"github.com/micro/dev/model"
"github.com/micro/go-micro/errors"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/micro/v3/service/store"
proto "posts/proto"
"github.com/gosimple/slug"
)
type Posts struct {
db model.Model
idIndex model.Index
createdIndex model.Index
slugIndex model.Index
}
func NewPosts() *Posts {
createdIndex := model.ByEquality("created")
createdIndex.Order.Type = model.OrderTypeDesc
slugIndex := model.ByEquality("slug")
idIndex := model.ByEquality("id")
idIndex.Order.Type = model.OrderTypeUnordered
return &Posts{
db: model.New(
store.DefaultStore,
"posts",
model.Indexes(slugIndex, createdIndex),
&model.ModelOptions{
IdIndex: idIndex,
},
),
createdIndex: createdIndex,
slugIndex: slugIndex,
idIndex: idIndex,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment