Skip to content

Commit

Permalink
add view data to tables and switch to modules
Browse files Browse the repository at this point in the history
  • Loading branch information
natefinch committed Dec 10, 2020
1 parent c8ccca9 commit ce094a7
Show file tree
Hide file tree
Showing 349 changed files with 126 additions and 72,217 deletions.
153 changes: 0 additions & 153 deletions Gopkg.lock

This file was deleted.

26 changes: 0 additions & 26 deletions Gopkg.toml

This file was deleted.

2 changes: 0 additions & 2 deletions cli/docs_make.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/pkg/errors"
"github.com/rakyll/statik/fs"
"github.com/spf13/cobra"

_ "gnorm.org/gnorm/cli/statik"
"gnorm.org/gnorm/environ"
)

Expand Down
1 change: 1 addition & 0 deletions database/drivers/mysql/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func parse(log *log.Logger, conn string, schemaNames []string, filterTables func
Name: t.TableName,
Type: t.TableType,
Comment: t.TableComment,
IsView: t.TableType == "VIEW",
})
}

Expand Down
3 changes: 3 additions & 0 deletions database/drivers/postgres/001_first.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ CREATE TABLE books (

CREATE INDEX books_title_idx ON books(author_id, title);




---- create above / drop below ----

DROP TABLE IF EXISTS books CASCADE;
Expand Down
16 changes: 16 additions & 0 deletions database/drivers/postgres/002_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Write your migrate up statements here

CREATE VIEW view_book_title_author as
SELECT
authors.name,
books.title
FROM
books
INNER JOIN authors ON authors.id = books.author_id;

---- create above / drop below ----

DROP VIEW IF EXISTS view_book_title_author

-- Write your migrate down statements here. If this migration is irreversible
-- Then delete the separator line above.
2 changes: 2 additions & 0 deletions database/drivers/postgres/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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,
IsView: t.TableType.String == "VIEW",
IsInsertable: t.IsInsertableInto.String == "YES",
})
}

Expand Down
10 changes: 6 additions & 4 deletions database/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ type EnumValue struct {

// Table contains the definition of a database table.
type Table struct {
Name string // the original name of the table in the DB
Name string // the original name of the table in the DB
Type string // the table type (e.g. VIEW or BASE TABLE)
Comment string // the comment attached to the table
Columns []*Column // ordered list of columns in this table
Indexes []*Index // list of indexes in this table
Comment string // the comment attached to the table
IsView bool // true if the table is actually a view
IsInsertable bool // true if the table accepts inserts
Columns []*Column // ordered list of columns in this table
Indexes []*Index // list of indexes in this table
}

// Index contains the definition of a database index.
Expand Down
26 changes: 26 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module gnorm.org/gnorm

go 1.13

require (
github.com/BurntSushi/toml v0.3.0
github.com/codemodus/kace v0.5.0
github.com/go-sql-driver/mysql v1.3.0
github.com/google/go-cmp v0.1.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jessevdk/go-flags v1.4.0 // indirect
github.com/jinzhu/inflection v1.0.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/lib/pq v0.0.0-20170810061220-e42267488fe3
github.com/magefile/mage v1.10.0
github.com/mattn/go-runewidth v0.0.2 // indirect
github.com/natefinch/gocog v0.0.0-20170818170132-3af1fb832aae // indirect
github.com/olekukonko/tablewriter v0.0.0-20170719101040-be5337e7b39e
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/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
)
45 changes: 45 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
github.com/BurntSushi/toml v0.3.0 h1:e1/Ivsx3Z0FVTV0NSOv/aVgbUWyQuzj7DDnFblkRvsY=
github.com/BurntSushi/toml v0.3.0/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/codemodus/kace v0.5.0 h1:okAzgZ+zzRxJvj/0KidA5OA3vgjczpIkSrmHTMBlawc=
github.com/codemodus/kace v0.5.0/go.mod h1:coddaHoX1ku1YFSe4Ip0mL9kQjJvKkzb9CfIdG1YR04=
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=
github.com/google/go-cmp v0.1.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
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.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=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v0.0.0-20170810061220-e42267488fe3 h1:2Fs7SMFLrtkGta5HodD3MRV3nIzv+6I90eSfqwPklbo=
github.com/lib/pq v0.0.0-20170810061220-e42267488fe3/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/natefinch/gocog v0.0.0-20170818170132-3af1fb832aae h1:Z3R+4/DSiF444iRM83qqnr1JLk5xx8TDzoqkREQ7CUE=
github.com/natefinch/gocog v0.0.0-20170818170132-3af1fb832aae/go.mod h1:Gw45Xz09BU+HPrJZURrGezG/RV8mICxEiRWEkjyuFO4=
github.com/olekukonko/tablewriter v0.0.0-20170719101040-be5337e7b39e h1:TXm3cxcAmTO1Gp9W7QK0DeczE8vgXJDUyPPjEXViZ3Y=
github.com/olekukonko/tablewriter v0.0.0-20170719101040-be5337e7b39e/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15 h1:mrI+6Ae64Wjt+uahGe5we/sPS1sXjvfT3YjtawAVgps=
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/rakyll/statik v0.1.1 h1:fCLHsIMajHqD5RKigbFXpvX3dN7c80Pm12+NCrI3kvg=
github.com/rakyll/statik v0.1.1/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
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=
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=
2 changes: 0 additions & 2 deletions mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import (
"os"
"regexp"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)

// Runs go install for gnorm. This generates the embedded docs and the version
// info into the binary.
func Build() error {
mg.Deps(Generate)
if err := genSite(); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions site/content/templates/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ Strings is a list of string values with the following methods (not avaialable wi
| Name | string | the converted name of the table
| DBName | string | the original name of the table in the DB
| Comment | string | the comment attached to the table
| IsView | bool | true if the table is actually a view
| IsInsertable | bool | true if the table accepts inserts (postgres only)
| Schema | [Schema](#schema) | the schema this table is in
| Columns | [Columns](#columns) | ordered list of Database columns
| ColumnsByName | map[string][Column](#column) | map of column dbname to column
Expand Down
Loading

0 comments on commit ce094a7

Please sign in to comment.