2021-01-16 06:36:44 +00:00
|
|
|
package spec
|
|
|
|
|
2021-01-19 12:26:26 +00:00
|
|
|
import (
|
|
|
|
"github.com/sunboyy/repogen/internal/code"
|
|
|
|
)
|
2021-01-16 06:36:44 +00:00
|
|
|
|
|
|
|
// QueryMode one or many
|
|
|
|
type QueryMode string
|
|
|
|
|
|
|
|
// query mode constants
|
|
|
|
const (
|
|
|
|
QueryModeOne QueryMode = "ONE"
|
|
|
|
QueryModeMany QueryMode = "MANY"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MethodSpec is a method specification inside repository specification
|
|
|
|
type MethodSpec struct {
|
|
|
|
Name string
|
|
|
|
Params []code.Param
|
|
|
|
Returns []code.Type
|
|
|
|
Operation Operation
|
|
|
|
}
|
|
|
|
|
|
|
|
// Operation is an interface for any kind of operation
|
|
|
|
type Operation interface {
|
|
|
|
}
|
|
|
|
|
2021-02-01 14:39:20 +00:00
|
|
|
// InsertOperation is a method specification for insert operations
|
|
|
|
type InsertOperation struct {
|
|
|
|
Mode QueryMode
|
|
|
|
}
|
|
|
|
|
2021-01-16 06:36:44 +00:00
|
|
|
// FindOperation is a method specification for find operations
|
|
|
|
type FindOperation struct {
|
|
|
|
Mode QueryMode
|
2021-01-17 03:29:50 +00:00
|
|
|
Query QuerySpec
|
2021-01-16 06:36:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 12:15:25 +00:00
|
|
|
// UpdateOperation is a method specification for update operations
|
|
|
|
type UpdateOperation struct {
|
|
|
|
Fields []UpdateField
|
|
|
|
Mode QueryMode
|
|
|
|
Query QuerySpec
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateField stores mapping between field name in the model and the parameter index
|
|
|
|
type UpdateField struct {
|
|
|
|
Name string
|
|
|
|
ParamIndex int
|
|
|
|
}
|
|
|
|
|
2021-01-26 13:23:52 +00:00
|
|
|
// DeleteOperation is a method specification for delete operations
|
|
|
|
type DeleteOperation struct {
|
|
|
|
Mode QueryMode
|
|
|
|
Query QuerySpec
|
|
|
|
}
|
|
|
|
|
2021-02-06 11:05:47 +00:00
|
|
|
// CountOperation is a method specification for count operations
|
|
|
|
type CountOperation struct {
|
|
|
|
Query QuerySpec
|
2021-01-16 06:36:44 +00:00
|
|
|
}
|