From ef64024edb38feeb91102e743f4844649b0df7d3 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Thu, 10 Dec 2020 15:06:46 -0500 Subject: [PATCH] Template data (#139) * 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 --- .travis.yml | 12 ++++++------ README.md | 2 +- database/drivers/mysql/parse.go | 2 -- database/drivers/postgres/parse.go | 6 ++---- go.mod | 4 +++- go.sum | 15 +++++++++++++++ run/convert.go | 2 ++ run/data/data.go | 2 ++ run/preview_test.go | 31 +++++++++++++++++++++--------- site/config.toml | 2 +- 10 files changed, 54 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index aa9b46e..d942d04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 7a01c27..f5ab384 100644 --- a/README.md +++ b/README.md @@ -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)

GNORM

diff --git a/database/drivers/mysql/parse.go b/database/drivers/mysql/parse.go index 8b82e0c..655766f 100644 --- a/database/drivers/mysql/parse.go +++ b/database/drivers/mysql/parse.go @@ -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{} diff --git a/database/drivers/postgres/parse.go b/database/drivers/postgres/parse.go index 754845e..fae81eb 100644 --- a/database/drivers/postgres/parse.go +++ b/database/drivers/postgres/parse.go @@ -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{} @@ -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", }) diff --git a/go.mod b/go.mod index 53a8ff6..d477a8c 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 ) diff --git a/go.sum b/go.sum index 25c620b..47e9e61 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/run/convert.go b/run/convert.go index ef63f5f..61e9472 100644 --- a/run/convert.go +++ b/run/convert.go @@ -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)), diff --git a/run/data/data.go b/run/data/data.go index 6add458..48d6625 100644 --- a/run/data/data.go +++ b/run/data/data.go @@ -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 diff --git a/run/preview_test.go b/run/preview_test.go index ab34ea8..00bc2e3 100644 --- a/run/preview_test.go +++ b/run/preview_test.go @@ -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" @@ -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", @@ -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", @@ -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 @@ -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 @@ -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)) } } @@ -403,6 +412,8 @@ var expectJSON = ` "Name": "abc table", "DBName": "table", "Type": "BASE TABLE", + "IsView": false, + "IsInsertable": true, "Comment": "a table", "Columns": [ { @@ -563,7 +574,9 @@ var expectJSON = ` { "Name": "abc tb2", "DBName": "tb2", - "Type": "BASE TABLE", + "Type": "VIEW", + "IsView": true, + "IsInsertable": false, "Comment": "", "Columns": [ { @@ -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)) } } diff --git a/site/config.toml b/site/config.toml index 3a78b83..9149f5f 100644 --- a/site/config.toml +++ b/site/config.toml @@ -1,4 +1,4 @@ -baseURL = "http://gnorm.org/" +baseURL = "https://gnorm.org/" languageCode = "en-us" title = "GNORM" theme = "docdock"