2021-01-16 06:36:44 +00:00
|
|
|
package spec
|
|
|
|
|
|
|
|
import "github.com/sunboyy/repogen/internal/code"
|
|
|
|
|
|
|
|
// QueryMode one or many
|
|
|
|
type QueryMode string
|
|
|
|
|
|
|
|
// query mode constants
|
|
|
|
const (
|
|
|
|
QueryModeOne QueryMode = "ONE"
|
|
|
|
QueryModeMany QueryMode = "MANY"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RepositorySpec is a specification generated from the repository interface
|
|
|
|
type RepositorySpec struct {
|
|
|
|
InterfaceName string
|
|
|
|
Methods []MethodSpec
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-17 03:29:50 +00:00
|
|
|
// QuerySpec is a condition of querying the database
|
|
|
|
type QuerySpec struct {
|
2021-01-16 06:36:44 +00:00
|
|
|
Fields []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NumberOfArguments returns number of arguments required to perform the query
|
2021-01-17 03:29:50 +00:00
|
|
|
func (q QuerySpec) NumberOfArguments() int {
|
2021-01-16 06:36:44 +00:00
|
|
|
return len(q.Fields)
|
|
|
|
}
|