Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite-support #130

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ go:
- tip
- "1.11"
- "1.10"
- "1.9"
# https://github.com/go-sql-driver/mysql/issues/1040
# go-sql-driver/mysql : Go 1.9 is not supported
# - "1.9"

# don't call go get ./... because this hides when deps are
# not packaged into the vendor directory.
Expand Down
129 changes: 92 additions & 37 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions cli/gnorm.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# ConnStr is the connection string for the database. Any environment variables
# in this string will be expanded, so for example dbname=$MY_DDB will do the
# right thing.
# MySQL example:
# ConnStr = "root:admin@tcp/"
# Postgres example:
# sqlite: ConnStr = "./sqlite.db"
# MySQL: ConnStr = "root:admin@tcp/"
# Postgres: ConnStr = "dbname=mydb host=127.0.0.1 sslmode=disable user=admin"
ConnStr = "dbname=mydb host=127.0.0.1 sslmode=disable user=admin"

# DBType holds the type of db you're connecting to. Possible values are
# "postgres" or "mysql".
# "postgres", "mysql" or "sqlite".
DBType = "postgres"

# Schemas holds the names of schemas to generate code for.
# postgres: "public"
# sqlite: "main"
# Mssql example :
# Schemas = ["dbo"]
Schemas = ["public"]

# PluginDirs a list of paths that will be used for finding plugins. The list
Expand All @@ -37,6 +41,9 @@ IncludeTables = []
# generation. You cannot set ExcludeTables if IncludeTables is set. By
# default, tables will be excluded from all schemas. To specify tables for
# a specific schema only, use the schema.tablenmae format.
# sqlite: ExcludeTables = ["sqlite_sequence", "sqlite_master"]
# Mssql example:
# ExcludeTables = ["sysdiagrams"]
ExcludeTables = ["xyzzx"]

# PostRun is a command with arguments that is run after each file is generated
Expand All @@ -53,7 +60,7 @@ PostRun = ["echo", "$GNORMFILE"]
#
# This defaults to the current working directory i.e the directory in which
# gnorm.toml is found.
OutputDir = "gnorm"
OutputDir = "output"

# StaticDir is the directory relative to the project root (where the
# gnorm.toml file is located) in which all static files , which are
Expand Down Expand Up @@ -119,6 +126,16 @@ NoOverwriteGlobs = ["*.perm.go"]
# not in this mapping, Column.Type will be an empty string. Note that because
# of the way tables in TOML work, TypeMap and NullableTypeMap must be at the end
# of your configuration file.
#
# Example for mapping sqlite types to Go types:
# https://www.sqlite.org/datatype3.html
# [TypeMap]
# "INTEGER" = "int"
# "NUMERIC" = "float64"
# "REAL" = "float64"
# "TEXT" = "string"
# "BLOB" = "byte[]"
#
# Example for mapping postgres types to Go types:
[TypeMap]
"timestamp with time zone" = "time.Time"
Expand Down
6 changes: 6 additions & 0 deletions cli/parse.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli // import "gnorm.org/gnorm/cli"

import (
"gnorm.org/gnorm/database/drivers/mssql"
"io"
"io/ioutil"
"log"
Expand All @@ -14,6 +15,7 @@ import (
"gnorm.org/gnorm/database"
"gnorm.org/gnorm/database/drivers/mysql"
"gnorm.org/gnorm/database/drivers/postgres"
"gnorm.org/gnorm/database/drivers/sqlite"
"gnorm.org/gnorm/environ"
"gnorm.org/gnorm/run"
"gnorm.org/gnorm/run/data"
Expand Down Expand Up @@ -139,6 +141,10 @@ func getDriver(name string) (database.Driver, error) {
return postgres.PG{}, nil
case "mysql":
return mysql.MySQL{}, nil
case "sqlite":
return sqlite.Sqlite{}, nil
case "mssql":
return mssql.Mssql{}, nil
default:
return nil, errors.Errorf("unknown database type: %v", name)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestParseConfig(t *testing.T) {
"numeric": "sql.NullFloat64",
},
PluginDirs: []string{"plugins"},
OutputDir: "gnorm",
OutputDir: "output",
StaticDir: "static",
NoOverwriteGlobs: []string{"*.perm.go"},
}
Expand Down
Loading