Skip to content

Instantly share code, notes, and snippets.

@maxsei
Last active January 8, 2024 16:28
Show Gist options
  • Select an option

  • Save maxsei/28f73ab67a33343a9b14a86a280a7c00 to your computer and use it in GitHub Desktop.

Select an option

Save maxsei/28f73ab67a33343a9b14a86a280a7c00 to your computer and use it in GitHub Desktop.
Query mapper dsl prototype
package q
import (
"sql"
"github.com/google/uuid"
)
func MI(table, col string, ptr any) *MappedIdentifier {
return &MappedIdentifier{table, col, ptr}
}
type MappedIdentifier struct {
table string
col string
ptr any
}
type Node interface {
Gql() string
Db() *MappedIdentifier
Children() []Node
}
type Foo struct {
gql string
db *MappedIdentifier
children []Node
}
func (f *Foo) Gql() string { return f.gql }
func (f *Foo) Db() *MappedIdentifier { return f.db }
func (f *Foo) Children() []Node { return f.children }
type Bar struct {
gql string
db *MappedIdentifier
}
func (f *Bar) Gql() string { return f.gql }
func (f *Bar) Db() *MappedIdentifier { return f.db }
func (f *Bar) Children() []Node { return []Node{} }
var (
datavansRel uuid.NullUUID
datavansName sql.NullString
devicesRel uuid.NullUUID
devicesName sql.NullString
)
var tree Node = &Foo{
"datavans",
MI("datavans", "id", &datavansRel),
[]Node{
&Bar{"id", MI("datavans", "id", &datavansRel)},
&Bar{"name", MI("datavans", "name", &datavansName)},
&Foo{
"devices",
MI("devices", "id", &devicesRel),
[]Node{
&Bar{"id", MI("devices", "id", &devicesRel)},
&Bar{"name", MI("devices", "name", &devicesName)},
},
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment