Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
G
goqlorm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
Simao Gomes Viana
goqlorm
Commits
351ef802
Commit
351ef802
authored
5 years ago
by
Simao Gomes Viana
Browse files
Options
Downloads
Patches
Plain Diff
Refactor postgres-specific part out of generator
parent
6fb6462b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
database/adapter.go
+7
-0
7 additions, 0 deletions
database/adapter.go
generator/query_resolvers.go
+2
-38
2 additions, 38 deletions
generator/query_resolvers.go
postgres/resolve_adapter.go
+53
-0
53 additions, 0 deletions
postgres/resolve_adapter.go
with
62 additions
and
38 deletions
database/adapter.go
+
7
−
0
View file @
351ef802
package
database
import
(
"reflect"
"github.com/graphql-go/graphql"
)
type
SchemaSyncOptions
struct
{
// Whether to remove columns from the database
// that can't be found in models.
...
...
@@ -19,4 +25,5 @@ type Adapter interface {
Insert
(
obj
interface
{})
error
Update
(
obj
interface
{})
error
Delete
(
obj
interface
{})
error
DataFromDatabaseUsingResolveParams
(
objArr
interface
{},
modelType
reflect
.
Type
,
p
graphql
.
ResolveParams
)
error
}
This diff is collapsed.
Click to expand it.
generator/query_resolvers.go
+
2
−
38
View file @
351ef802
package
generator
import
(
"errors"
"reflect"
"strings"
"gitlab.com/xdevs23/goqlorm/postgres"
"gitlab.com/xdevs23/goqlorm/reflectutil"
"github.com/graphql-go/graphql"
...
...
@@ -24,41 +21,8 @@ func AutoResolve(db database.Adapter, model interface{}, returnList bool) graphq
modelType
:=
*
prepareAutoResolve
(
model
)
return
func
(
p
graphql
.
ResolveParams
)
(
interface
{},
error
)
{
objArr
:=
reflectutil
.
NewFromType
(
reflect
.
SliceOf
(
modelType
))
// TODO: refactor this to use the adapter interface
q
:=
db
.
(
postgres
.
Database
)
.
PgDB
.
Model
(
objArr
)
for
i
:=
0
;
i
<
modelType
.
NumField
();
i
++
{
field
:=
modelType
.
Field
(
i
)
fieldNameLowerCase
:=
strings
.
ToLower
(
field
.
Name
)
if
value
:=
p
.
Args
[
fieldNameLowerCase
];
value
!=
nil
{
switch
field
.
Type
.
Kind
()
{
case
reflect
.
Array
,
reflect
.
Slice
:
q
.
WhereIn
(
fieldNameLowerCase
+
" @> [?]"
,
value
)
case
reflect
.
Complex128
,
reflect
.
Complex64
,
reflect
.
Float64
,
reflect
.
Float32
,
reflect
.
Bool
,
reflect
.
Int8
,
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint64
,
reflect
.
Uint32
,
reflect
.
Int16
,
reflect
.
Int64
,
reflect
.
Int32
,
reflect
.
Int
,
reflect
.
String
:
q
.
Where
(
fieldNameLowerCase
+
" = ?"
,
value
)
case
reflect
.
Map
:
return
nil
,
errors
.
New
(
"maps are not supported yet"
)
}
}
}
if
err
:=
q
.
Select
();
err
!=
nil
{
err
:=
db
.
DataFromDatabaseUsingResolveParams
(
objArr
,
modelType
,
p
)
if
err
!=
nil
{
return
nil
,
err
}
if
returnList
{
...
...
This diff is collapsed.
Click to expand it.
postgres/resolve_adapter.go
0 → 100644
+
53
−
0
View file @
351ef802
package
postgres
import
(
"errors"
"reflect"
"strings"
"github.com/graphql-go/graphql"
)
func
(
db
Database
)
DataFromDatabaseUsingResolveParams
(
objArr
interface
{},
modelType
reflect
.
Type
,
p
graphql
.
ResolveParams
)
error
{
q
:=
db
.
PgDB
.
Model
(
objArr
)
for
i
:=
0
;
i
<
modelType
.
NumField
();
i
++
{
field
:=
modelType
.
Field
(
i
)
fieldNameLowerCase
:=
strings
.
ToLower
(
field
.
Name
)
if
value
:=
p
.
Args
[
fieldNameLowerCase
];
value
!=
nil
{
switch
field
.
Type
.
Kind
()
{
case
reflect
.
Array
,
reflect
.
Slice
:
q
.
WhereIn
(
fieldNameLowerCase
+
" @> [?]"
,
value
)
case
reflect
.
Complex128
,
reflect
.
Complex64
,
reflect
.
Float64
,
reflect
.
Float32
,
reflect
.
Bool
,
reflect
.
Int8
,
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint64
,
reflect
.
Uint32
,
reflect
.
Int16
,
reflect
.
Int64
,
reflect
.
Int32
,
reflect
.
Int
,
reflect
.
String
:
q
.
Where
(
fieldNameLowerCase
+
" = ?"
,
value
)
case
reflect
.
Map
:
return
errors
.
New
(
"maps are not supported yet"
)
}
}
}
if
err
:=
q
.
Select
();
err
!=
nil
{
return
err
}
return
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment