Skip to content

Commit

Permalink
Template data (#139)
Browse files Browse the repository at this point in the history
* add table data to template data
* remove gnorm gen from mage generate
You almost never need to regenerate the gnorm code that gnorm itself uses,
and it requires a local db, so let's not do it automatically anymore.

* make sure base url is https
* update travis
  • Loading branch information
natefinch committed Dec 10, 2020
1 parent 2a56e79 commit ef64024
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 24 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ branches:
# library, I'm not going to worry about older versions for now.
go:
- tip
- "1.11"
- "1.10"
- "1.9"
- "1.15"
- "1.14"
- "1.13"
- "1.12"

# don't call go get ./... because this hides when deps are
# not packaged into the vendor directory.
install: true
env:
- GO111MODULE=on

# don't call go test -v because we want to be able to only show t.Log output when
# a test fails
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/gnormal/gnorm.svg?branch=master)](https://travis-ci.org/gnormal/gnorm)
[![Build Status](https://travis-ci.com/gnormal/gnorm.svg?branch=master)](https://travis-ci.com/gnormal/gnorm)
<h1 align="center">GNORM</h1>

<p align="center"><img src="https://user-images.githubusercontent.com/3185864/29906052-5fd530a2-8de0-11e7-964e-1112fb152ee1.png" /></p>
Expand Down
2 changes: 0 additions & 2 deletions database/drivers/mysql/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"gnorm.org/gnorm/database/drivers/mysql/gnorm/tables"
)

//go:generate gnorm gen

// MySQL implements drivers.Driver interface for MySQL database.
type MySQL struct{}

Expand Down
6 changes: 2 additions & 4 deletions database/drivers/postgres/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"gnorm.org/gnorm/database/drivers/postgres/gnorm/tables"
)

//go:generate gnorm gen

// PG implements drivers.Driver interface for interacting with postgresql
// database.
type PG struct{}
Expand Down Expand Up @@ -53,8 +51,8 @@ func parse(log *log.Logger, conn string, schemaNames []string, filterTables func
}

schemas[t.TableSchema.String] = append(schemas[t.TableSchema.String], &database.Table{
Name: t.TableName.String,
Type: t.TableType.String,
Name: t.TableName.String,
Type: t.TableType.String,
IsView: t.TableType.String == "VIEW",
IsInsertable: t.IsInsertableInto.String == "YES",
})
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.13

require (
github.com/BurntSushi/toml v0.3.0
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
github.com/codemodus/kace v0.5.0
github.com/go-sql-driver/mysql v1.3.0
github.com/google/go-cmp v0.1.0
Expand All @@ -19,8 +20,9 @@ require (
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15
github.com/pkg/errors v0.8.0
github.com/rakyll/statik v0.1.1
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/cobra v0.0.0-20170905172051-b78744579491
github.com/spf13/pflag v1.0.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7
gopkg.in/yaml.v2 v2.2.4
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
github.com/BurntSushi/toml v0.3.0 h1:e1/Ivsx3Z0FVTV0NSOv/aVgbUWyQuzj7DDnFblkRvsY=
github.com/BurntSushi/toml v0.3.0/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/codemodus/kace v0.5.0 h1:okAzgZ+zzRxJvj/0KidA5OA3vgjczpIkSrmHTMBlawc=
github.com/codemodus/kace v0.5.0/go.mod h1:coddaHoX1ku1YFSe4Ip0mL9kQjJvKkzb9CfIdG1YR04=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.3.0 h1:pgwjLi/dvffoP9aabwkT3AKpXQM93QARkjFhDDqC1UE=
github.com/go-sql-driver/mysql v1.3.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/google/go-cmp v0.1.0 h1:9tmYDKxX2N1am4Ooz6a2HC7DfK0CWNuhT8T/Fi/bvtA=
Expand All @@ -14,6 +18,7 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -33,13 +38,23 @@ github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15 h1:mrI+6Ae64Wjt+uahGe5
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rakyll/statik v0.1.1 h1:fCLHsIMajHqD5RKigbFXpvX3dN7c80Pm12+NCrI3kvg=
github.com/rakyll/statik v0.1.1/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/spf13/cobra v0.0.0-20170905172051-b78744579491 h1:XOya2OGpG7Q4gS4MYHRoFSTlBGnZD40X+Kw2ikFQFXE=
github.com/spf13/cobra v0.0.0-20170905172051-b78744579491/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.0 h1:oaPbdDe/x0UncahuwiPxW1GYJyilRAdsPnq3e1yaPcI=
github.com/spf13/pflag v1.0.0/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7 h1:+t9dhfO+GNOIGJof6kPOAenx7YgrZMTdRPV+EsnPabk=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
2 changes: 2 additions & 0 deletions run/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func makeData(log *log.Logger, info *database.Info, cfg *Config) (*data.DBData,
DBName: t.Name,
Type: t.Type,
Comment: t.Comment,
IsView: t.IsView,
IsInsertable: t.IsInsertable,
Schema: sch,
ColumnsByName: make(map[string]*data.Column, len(t.Columns)),
IndexesByName: make(map[string]*data.Index, len(t.Indexes)),
Expand Down
2 changes: 2 additions & 0 deletions run/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Table struct {
Name string // the converted name of the table
DBName string // the original name of the table in the DB
Type string // the table type (e.g. VIEW or BASE TABLE)
IsView bool // true if the table represents a view
IsInsertable bool // true if the table accepts inserts (postgres only)
Comment string // the comment attached to the table
Schema *Schema `yaml:"-" json:"-"` // the schema this table is in
Columns Columns // Database columns
Expand Down
31 changes: 22 additions & 9 deletions run/preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"text/template"

"github.com/andreyvit/diff"
"github.com/google/go-cmp/cmp"
"gnorm.org/gnorm/database"
"gnorm.org/gnorm/environ"
Expand Down Expand Up @@ -51,9 +52,11 @@ func (dummyDriver) Parse(log *log.Logger, conn string, schemaNames []string, fil
Schemas: []*database.Schema{{
Name: "schema",
Tables: []*database.Table{{
Name: "table",
Type: "BASE TABLE",
Comment: "a table",
Name: "table",
Type: "BASE TABLE",
IsView: false,
IsInsertable: true,
Comment: "a table",
Columns: []*database.Column{{
Name: "col1",
Type: "int",
Expand Down Expand Up @@ -83,8 +86,10 @@ func (dummyDriver) Parse(log *log.Logger, conn string, schemaNames []string, fil
}},
}},
}, {
Name: "tb2",
Type: "BASE TABLE",
Name: "tb2",
Type: "VIEW",
IsView: true,
IsInsertable: false,
Columns: []*database.Column{{
Name: "col1",
Type: "int",
Expand Down Expand Up @@ -120,6 +125,8 @@ const expectYaml = `schemas:
- name: abc table
dbname: table
type: BASE TABLE
isview: false
isinsertable: true
comment: a table
columns:
- name: abc col1
Expand Down Expand Up @@ -245,7 +252,9 @@ const expectYaml = `schemas:
refcolumndbname: col1
- name: abc tb2
dbname: tb2
type: BASE TABLE
type: VIEW
isview: true
isinsertable: false
comment: ""
columns:
- name: abc col1
Expand Down Expand Up @@ -388,7 +397,7 @@ func TestPreviewYAML(t *testing.T) {
}
v := out.String()
if v != expectYaml {
t.Errorf(cmp.Diff(expectYaml, v))
t.Errorf(diff.LineDiff(expectYaml, v))
}
}

Expand All @@ -403,6 +412,8 @@ var expectJSON = `
"Name": "abc table",
"DBName": "table",
"Type": "BASE TABLE",
"IsView": false,
"IsInsertable": true,
"Comment": "a table",
"Columns": [
{
Expand Down Expand Up @@ -563,7 +574,9 @@ var expectJSON = `
{
"Name": "abc tb2",
"DBName": "tb2",
"Type": "BASE TABLE",
"Type": "VIEW",
"IsView": true,
"IsInsertable": false,
"Comment": "",
"Columns": [
{
Expand Down Expand Up @@ -689,7 +702,7 @@ func TestPreviewJSON(t *testing.T) {
}
v := out.String()
if v != expectJSON {
t.Errorf(cmp.Diff(expectJSON, v))
t.Error(diff.LineDiff(expectJSON, v))
}
}

Expand Down
2 changes: 1 addition & 1 deletion site/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
baseURL = "http://gnorm.org/"
baseURL = "https://gnorm.org/"
languageCode = "en-us"
title = "GNORM"
theme = "docdock"
Expand Down

0 comments on commit ef64024

Please sign in to comment.