-
-
Save maxsei/28f73ab67a33343a9b14a86a280a7c00 to your computer and use it in GitHub Desktop.
Query mapper dsl prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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