Skip to content

Instantly share code, notes, and snippets.

View rodrwan's full-sized avatar
🇨🇱
cooking amazing code

Rod Fuenzalida rodrwan

🇨🇱
cooking amazing code
View GitHub Profile
docker:
driver: postgres
dsn: postgres://mediumexample:me1234@localhost:5432/example?sslmode=disable
// +build ignore
package main
import "github.com/99designs/gqlgen/cmd"
func main() {
cmd.Execute()
}
package mediumexample
import "time"
// Address hold address information returned by AddressStore
type Address struct {
UserID string `json:"user_id,omitempty" db:"user_id"`
AddressLine string `json:"address_line,omitempty" db:"address_line"`
City string `json:"city,omitempty" db:"city"`
Locality string `json:"locality,omitempty" db:"locality"`
package mediumexample
import (
"errors"
"time"
)
// User hold user information returned by UserService
type User struct {
ID string `json:"id,omitempty" db:"id"`
schema:
- schema.graphql
exec:
filename: graphql/generated.go
resolver:
filename: graphql/resolver.go
type: Resolver
models:
User:
model: github.com/rodrwan/medium-example.User
type User {
id: ID!
email: String!
first_name: String!
last_name: String!
phone: String!
birthdate: Time!
address: Address!
}
package postgres
import (
"crypto/rand"
"database/sql"
"encoding/base64"
"fmt"
"strings"
"time"
package postgres
import (
"unicode"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"github.com/jmoiron/sqlx"
"github.com/lib/pq"
@rodrwan
rodrwan / main.go
Last active October 5, 2018 13:17
func main() {
postgresDSN := flag.String(
"postgres-dsn", "postgres://localhost:5432/graph_test?sslmode=disable", "Postgres DSN")
flag.Parse()
db, err := postgres.New(*postgresDSN)
check(err)
us := &postgres.UserService{
Store: db,
// Address hold adderss information returned by AddressStore
type Address struct {
UserID string `json:"user_id,omitempty" db:"user_id"`
AddressLine string `json:"address_line,omitempty" db:"address_line"`
City string `json:"city,omitempty" db:"city"`
Locality string `json:"locality,omitempty" db:"locality"`
AdministrativeAreaLevel1 string `json:"administrative_area_level_1,omitempty" db:"administrative_area_level_1"`
Country string `json:"country,omitempty" db:"country"`
PostalCode int `json:"postal_code,omitempty" db:"postal_code"`
}