From 24f14bc8b634e48937b6158e7224112fd324e312 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Fri, 2 Jun 2017 10:26:12 -0400 Subject: [PATCH] Cleanup (#174) * renamed the examples folder to integration-tests, since that is what it actually is * removed the dependency on the nulls package * cleaned up some unnecessary assignments in the UnmarshalJSON method for Coverage * documented the Formatter interface --- Gopkg.lock | 8 +- Makefile | 10 +- examples/clover.xml | 447 ------------------ examples/cobertura/coverage.xml | 97 ---- examples/jacoco.xml | 52 -- examples/javascript/coverage.json | 1 - examples/javascript/lcov-report/base.css | 213 --------- examples/javascript/lcov-report/index.html | 93 ---- .../javascript-test-reporter/ci_info.js.html | 311 ------------ .../formatter.js.html | 377 --------------- .../javascript-test-reporter/git_info.js.html | 272 ----------- .../gocover_parse.js.html | 215 --------- .../javascript-test-reporter/index.html | 132 ------ examples/javascript/lcov-report/prettify.css | 1 - examples/javascript/lcov-report/prettify.js | 1 - .../lcov-report/sort-arrow-sprite.png | Bin 209 -> 0 bytes examples/javascript/lcov-report/sorter.js | 158 ------- examples/javascript/lcov.info | 268 ----------- formatters/clover/clover.go | 5 +- formatters/coverage.go | 18 +- formatters/coveragepy/coveragepy.go | 5 +- formatters/formatter.go | 8 + formatters/gcov/parse.go | 7 +- formatters/gocov/gocov.go | 5 +- formatters/lcov/lcov.go | 5 +- formatters/null_int.go | 49 ++ formatters/report_test.go | 13 +- formatters/source_file.go | 3 +- formatters/source_file_test.go | 13 +- {examples => integration-tests}/.coverage | 0 .../clover/Dockerfile | 0 .../codeclimate.0.json | 0 .../codeclimate.1.json | 0 .../codeclimate.2.json | 0 .../codeclimate.3.json | 0 .../codeclimate.json | 0 .../coverage_py/Dockerfile | 0 .../gcov/Dockerfile | 0 .../gocov/Dockerfile | 0 .../lcov/Dockerfile | 0 .../simplecov/Dockerfile | 0 upload/test_report_test.go | 2 +- vendor/github.com/markbates/pop/.gitignore | 31 -- vendor/github.com/markbates/pop/.travis.yml | 40 -- vendor/github.com/markbates/pop/CHANGELOG.md | 260 ---------- vendor/github.com/markbates/pop/Dockerfile | 8 - vendor/github.com/markbates/pop/LICENSE.txt | 22 - vendor/github.com/markbates/pop/README.md | 222 --------- vendor/github.com/markbates/pop/belongs_to.go | 33 -- .../markbates/pop/belongs_to_test.go | 30 -- vendor/github.com/markbates/pop/bench.sh | 14 - .../markbates/pop/benchmarks_test.go | 115 ----- vendor/github.com/markbates/pop/clause.go | 56 --- .../markbates/pop/columns/column.go | 20 - .../markbates/pop/columns/column_test.go | 14 - .../markbates/pop/columns/columns.go | 107 ----- .../pop/columns/columns_for_struct.go | 52 -- .../markbates/pop/columns/columns_test.go | 62 --- .../markbates/pop/columns/readable_columns.go | 19 - .../pop/columns/readable_columns_test.go | 35 -- .../pop/columns/writeable_columns.go | 19 - .../pop/columns/writeable_columns_test.go | 35 -- vendor/github.com/markbates/pop/commands.go | 25 - vendor/github.com/markbates/pop/config.go | 102 ---- .../github.com/markbates/pop/config_test.go | 21 - vendor/github.com/markbates/pop/connection.go | 175 ------- .../markbates/pop/connection_details.go | 95 ---- .../markbates/pop/connection_details_test.go | 51 -- .../markbates/pop/connection_test.go | 1 - vendor/github.com/markbates/pop/database.yml | 23 - vendor/github.com/markbates/pop/db.go | 19 - vendor/github.com/markbates/pop/dialect.go | 103 ---- vendor/github.com/markbates/pop/doc.go | 13 - vendor/github.com/markbates/pop/executors.go | 107 ----- .../markbates/pop/executors_test.go | 286 ----------- vendor/github.com/markbates/pop/finders.go | 141 ------ .../github.com/markbates/pop/finders_test.go | 183 ------- .../github.com/markbates/pop/fizz/README.md | 121 ----- .../github.com/markbates/pop/fizz/bubbler.go | 54 --- .../markbates/pop/fizz/bubbler_test.go | 1 - .../github.com/markbates/pop/fizz/columns.go | 62 --- vendor/github.com/markbates/pop/fizz/fizz.go | 34 -- vendor/github.com/markbates/pop/fizz/index.go | 65 --- .../github.com/markbates/pop/fizz/raw_sql.go | 7 - .../github.com/markbates/pop/fizz/tables.go | 78 --- .../markbates/pop/fizz/translator.go | 13 - .../markbates/pop/fizz/translators/mysql.go | 168 ------- .../pop/fizz/translators/mysql_meta.go | 111 ----- .../pop/fizz/translators/mysql_test.go | 194 -------- .../pop/fizz/translators/postgres.go | 150 ------ .../pop/fizz/translators/postgres_test.go | 162 ------- .../markbates/pop/fizz/translators/schema.go | 8 - .../markbates/pop/fizz/translators/sqlite.go | 319 ------------- .../pop/fizz/translators/sqlite_meta.go | 169 ------- .../pop/fizz/translators/sqlite_test.go | 230 --------- .../pop/fizz/translators/translators_test.go | 31 -- .../markbates/pop/grifts/release.go | 139 ------ vendor/github.com/markbates/pop/migration.go | 201 -------- .../markbates/pop/migration_file.go | 76 --- .../20160808213308_setup_tests.down.fizz | 4 - .../20160808213308_setup_tests.up.fizz | 21 - .../20160808213308_setup_tests2.down.fizz | 4 - .../20160808213310_setup_tests2.up.fizz | 12 - vendor/github.com/markbates/pop/model.go | 186 -------- vendor/github.com/markbates/pop/model_test.go | 52 -- vendor/github.com/markbates/pop/mysql.go | 169 ------- .../github.com/markbates/pop/nulls/README.md | 24 - vendor/github.com/markbates/pop/nulls/bool.go | 78 --- .../markbates/pop/nulls/byte_slice.go | 72 --- .../github.com/markbates/pop/nulls/float32.go | 76 --- .../github.com/markbates/pop/nulls/float64.go | 72 --- vendor/github.com/markbates/pop/nulls/int.go | 76 --- .../github.com/markbates/pop/nulls/int32.go | 76 --- .../github.com/markbates/pop/nulls/int64.go | 72 --- .../github.com/markbates/pop/nulls/schema.go | 59 --- .../github.com/markbates/pop/nulls/string.go | 76 --- vendor/github.com/markbates/pop/nulls/time.go | 73 --- .../markbates/pop/nulls/types_test.go | 190 -------- .../github.com/markbates/pop/nulls/uint32.go | 76 --- .../markbates/pop/pagination_test.go | 72 --- vendor/github.com/markbates/pop/paginator.go | 106 ----- vendor/github.com/markbates/pop/pop.go | 34 -- vendor/github.com/markbates/pop/pop_test.go | 145 ------ vendor/github.com/markbates/pop/postgresql.go | 216 --------- vendor/github.com/markbates/pop/query.go | 97 ---- vendor/github.com/markbates/pop/query_test.go | 104 ---- vendor/github.com/markbates/pop/scopes.go | 29 -- .../github.com/markbates/pop/scopes_test.go | 26 - .../github.com/markbates/pop/slices/float.go | 53 --- vendor/github.com/markbates/pop/slices/int.go | 53 --- vendor/github.com/markbates/pop/slices/map.go | 30 -- .../github.com/markbates/pop/slices/string.go | 40 -- .../github.com/markbates/pop/slices_test.go | 63 --- .../github.com/markbates/pop/soda/.gitignore | 4 - .../markbates/pop/soda/cmd/create.go | 30 -- .../github.com/markbates/pop/soda/cmd/drop.go | 27 -- .../markbates/pop/soda/cmd/generate.go | 19 - .../markbates/pop/soda/cmd/generate/config.go | 57 --- .../pop/soda/cmd/generate/config_templates.go | 50 -- .../pop/soda/cmd/generate/fizz_migration.go | 23 - .../markbates/pop/soda/cmd/generate/model.go | 212 --------- .../pop/soda/cmd/generate/model_templates.go | 69 --- .../pop/soda/cmd/generate/model_test.go | 67 --- .../pop/soda/cmd/generate/sql_migration.go | 22 - .../markbates/pop/soda/cmd/migrate.go | 28 -- .../markbates/pop/soda/cmd/migrate_create.go | 32 -- .../markbates/pop/soda/cmd/migrate_down.go | 19 - .../markbates/pop/soda/cmd/migrate_reset.go | 16 - .../markbates/pop/soda/cmd/migrate_up.go | 16 - .../github.com/markbates/pop/soda/cmd/root.go | 67 --- .../markbates/pop/soda/cmd/schema.go | 18 - .../markbates/pop/soda/cmd/schema/dump.go | 49 -- .../markbates/pop/soda/cmd/schema/load.go | 40 -- .../markbates/pop/soda/cmd/version.go | 3 - vendor/github.com/markbates/pop/soda/main.go | 7 - .../github.com/markbates/pop/sql_builder.go | 156 ------ vendor/github.com/markbates/pop/sqlite.go | 185 -------- vendor/github.com/markbates/pop/store.go | 21 - vendor/github.com/markbates/pop/test.sh | 34 -- vendor/github.com/markbates/pop/tx.go | 37 -- 160 files changed, 97 insertions(+), 11468 deletions(-) delete mode 100644 examples/clover.xml delete mode 100644 examples/cobertura/coverage.xml delete mode 100644 examples/jacoco.xml delete mode 100644 examples/javascript/coverage.json delete mode 100644 examples/javascript/lcov-report/base.css delete mode 100644 examples/javascript/lcov-report/index.html delete mode 100644 examples/javascript/lcov-report/javascript-test-reporter/ci_info.js.html delete mode 100644 examples/javascript/lcov-report/javascript-test-reporter/formatter.js.html delete mode 100644 examples/javascript/lcov-report/javascript-test-reporter/git_info.js.html delete mode 100644 examples/javascript/lcov-report/javascript-test-reporter/gocover_parse.js.html delete mode 100644 examples/javascript/lcov-report/javascript-test-reporter/index.html delete mode 100644 examples/javascript/lcov-report/prettify.css delete mode 100644 examples/javascript/lcov-report/prettify.js delete mode 100644 examples/javascript/lcov-report/sort-arrow-sprite.png delete mode 100644 examples/javascript/lcov-report/sorter.js delete mode 100644 examples/javascript/lcov.info create mode 100644 formatters/null_int.go rename {examples => integration-tests}/.coverage (100%) rename {examples => integration-tests}/clover/Dockerfile (100%) rename {examples => integration-tests}/codeclimate.0.json (100%) rename {examples => integration-tests}/codeclimate.1.json (100%) rename {examples => integration-tests}/codeclimate.2.json (100%) rename {examples => integration-tests}/codeclimate.3.json (100%) rename {examples => integration-tests}/codeclimate.json (100%) rename {examples => integration-tests}/coverage_py/Dockerfile (100%) rename {examples => integration-tests}/gcov/Dockerfile (100%) rename {examples => integration-tests}/gocov/Dockerfile (100%) rename {examples => integration-tests}/lcov/Dockerfile (100%) rename {examples => integration-tests}/simplecov/Dockerfile (100%) delete mode 100644 vendor/github.com/markbates/pop/.gitignore delete mode 100644 vendor/github.com/markbates/pop/.travis.yml delete mode 100644 vendor/github.com/markbates/pop/CHANGELOG.md delete mode 100644 vendor/github.com/markbates/pop/Dockerfile delete mode 100644 vendor/github.com/markbates/pop/LICENSE.txt delete mode 100644 vendor/github.com/markbates/pop/README.md delete mode 100644 vendor/github.com/markbates/pop/belongs_to.go delete mode 100644 vendor/github.com/markbates/pop/belongs_to_test.go delete mode 100755 vendor/github.com/markbates/pop/bench.sh delete mode 100644 vendor/github.com/markbates/pop/benchmarks_test.go delete mode 100644 vendor/github.com/markbates/pop/clause.go delete mode 100644 vendor/github.com/markbates/pop/columns/column.go delete mode 100644 vendor/github.com/markbates/pop/columns/column_test.go delete mode 100644 vendor/github.com/markbates/pop/columns/columns.go delete mode 100644 vendor/github.com/markbates/pop/columns/columns_for_struct.go delete mode 100644 vendor/github.com/markbates/pop/columns/columns_test.go delete mode 100644 vendor/github.com/markbates/pop/columns/readable_columns.go delete mode 100644 vendor/github.com/markbates/pop/columns/readable_columns_test.go delete mode 100644 vendor/github.com/markbates/pop/columns/writeable_columns.go delete mode 100644 vendor/github.com/markbates/pop/columns/writeable_columns_test.go delete mode 100644 vendor/github.com/markbates/pop/commands.go delete mode 100644 vendor/github.com/markbates/pop/config.go delete mode 100644 vendor/github.com/markbates/pop/config_test.go delete mode 100644 vendor/github.com/markbates/pop/connection.go delete mode 100644 vendor/github.com/markbates/pop/connection_details.go delete mode 100644 vendor/github.com/markbates/pop/connection_details_test.go delete mode 100644 vendor/github.com/markbates/pop/connection_test.go delete mode 100644 vendor/github.com/markbates/pop/database.yml delete mode 100644 vendor/github.com/markbates/pop/db.go delete mode 100644 vendor/github.com/markbates/pop/dialect.go delete mode 100644 vendor/github.com/markbates/pop/doc.go delete mode 100644 vendor/github.com/markbates/pop/executors.go delete mode 100644 vendor/github.com/markbates/pop/executors_test.go delete mode 100644 vendor/github.com/markbates/pop/finders.go delete mode 100644 vendor/github.com/markbates/pop/finders_test.go delete mode 100644 vendor/github.com/markbates/pop/fizz/README.md delete mode 100644 vendor/github.com/markbates/pop/fizz/bubbler.go delete mode 100644 vendor/github.com/markbates/pop/fizz/bubbler_test.go delete mode 100644 vendor/github.com/markbates/pop/fizz/columns.go delete mode 100644 vendor/github.com/markbates/pop/fizz/fizz.go delete mode 100644 vendor/github.com/markbates/pop/fizz/index.go delete mode 100644 vendor/github.com/markbates/pop/fizz/raw_sql.go delete mode 100644 vendor/github.com/markbates/pop/fizz/tables.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translator.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/mysql.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/mysql_meta.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/mysql_test.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/postgres.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/postgres_test.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/schema.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/sqlite.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/sqlite_meta.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/sqlite_test.go delete mode 100644 vendor/github.com/markbates/pop/fizz/translators/translators_test.go delete mode 100644 vendor/github.com/markbates/pop/grifts/release.go delete mode 100644 vendor/github.com/markbates/pop/migration.go delete mode 100644 vendor/github.com/markbates/pop/migration_file.go delete mode 100644 vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests.down.fizz delete mode 100644 vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests.up.fizz delete mode 100644 vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests2.down.fizz delete mode 100644 vendor/github.com/markbates/pop/migrations/20160808213310_setup_tests2.up.fizz delete mode 100644 vendor/github.com/markbates/pop/model.go delete mode 100644 vendor/github.com/markbates/pop/model_test.go delete mode 100644 vendor/github.com/markbates/pop/mysql.go delete mode 100644 vendor/github.com/markbates/pop/nulls/README.md delete mode 100644 vendor/github.com/markbates/pop/nulls/bool.go delete mode 100644 vendor/github.com/markbates/pop/nulls/byte_slice.go delete mode 100644 vendor/github.com/markbates/pop/nulls/float32.go delete mode 100644 vendor/github.com/markbates/pop/nulls/float64.go delete mode 100644 vendor/github.com/markbates/pop/nulls/int.go delete mode 100644 vendor/github.com/markbates/pop/nulls/int32.go delete mode 100644 vendor/github.com/markbates/pop/nulls/int64.go delete mode 100644 vendor/github.com/markbates/pop/nulls/schema.go delete mode 100644 vendor/github.com/markbates/pop/nulls/string.go delete mode 100644 vendor/github.com/markbates/pop/nulls/time.go delete mode 100644 vendor/github.com/markbates/pop/nulls/types_test.go delete mode 100644 vendor/github.com/markbates/pop/nulls/uint32.go delete mode 100644 vendor/github.com/markbates/pop/pagination_test.go delete mode 100644 vendor/github.com/markbates/pop/paginator.go delete mode 100644 vendor/github.com/markbates/pop/pop.go delete mode 100644 vendor/github.com/markbates/pop/pop_test.go delete mode 100644 vendor/github.com/markbates/pop/postgresql.go delete mode 100644 vendor/github.com/markbates/pop/query.go delete mode 100644 vendor/github.com/markbates/pop/query_test.go delete mode 100644 vendor/github.com/markbates/pop/scopes.go delete mode 100644 vendor/github.com/markbates/pop/scopes_test.go delete mode 100644 vendor/github.com/markbates/pop/slices/float.go delete mode 100644 vendor/github.com/markbates/pop/slices/int.go delete mode 100644 vendor/github.com/markbates/pop/slices/map.go delete mode 100644 vendor/github.com/markbates/pop/slices/string.go delete mode 100644 vendor/github.com/markbates/pop/slices_test.go delete mode 100644 vendor/github.com/markbates/pop/soda/.gitignore delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/create.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/drop.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/generate.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/generate/config.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/generate/config_templates.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/generate/fizz_migration.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/generate/model.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/generate/model_templates.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/generate/model_test.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/generate/sql_migration.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/migrate.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/migrate_create.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/migrate_down.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/migrate_reset.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/migrate_up.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/root.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/schema.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/schema/dump.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/schema/load.go delete mode 100644 vendor/github.com/markbates/pop/soda/cmd/version.go delete mode 100644 vendor/github.com/markbates/pop/soda/main.go delete mode 100644 vendor/github.com/markbates/pop/sql_builder.go delete mode 100644 vendor/github.com/markbates/pop/sqlite.go delete mode 100644 vendor/github.com/markbates/pop/store.go delete mode 100755 vendor/github.com/markbates/pop/test.sh delete mode 100644 vendor/github.com/markbates/pop/tx.go diff --git a/Gopkg.lock b/Gopkg.lock index 6cede6e4..ce374499 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,4 +1,4 @@ -memo = "073ef4b1edd95b4c45b942591c63e2edcdcc966401055a0e8ce092a8ed0cfb65" +memo = "c273f8dfebad140999110b446f841504fba353d31f116e66b36fa6b81fee7596" [[projects]] name = "github.com/Sirupsen/logrus" @@ -30,12 +30,6 @@ memo = "073ef4b1edd95b4c45b942591c63e2edcdcc966401055a0e8ce092a8ed0cfb65" packages = ["."] revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" -[[projects]] - name = "github.com/markbates/pop" - packages = ["nulls"] - revision = "6e0f5604b25bec1533b35c584fa7c19a67e8ca1b" - version = "v3.18.0" - [[projects]] branch = "master" name = "github.com/mitchellh/go-homedir" diff --git a/Makefile b/Makefile index d60b89a2..79fa9962 100644 --- a/Makefile +++ b/Makefile @@ -53,19 +53,19 @@ build-docker: golang:1.8 make build test-simplecov: - docker build -f examples/simplecov/Dockerfile . + docker build -f integration-tests/simplecov/Dockerfile . test-lcov: - docker build -f examples/lcov/Dockerfile . + docker build -f integration-tests/lcov/Dockerfile . test-covpy: - docker build -f examples/coverage_py/Dockerfile . + docker build -f integration-tests/coverage_py/Dockerfile . test-gocov: - docker build -f examples/gocov/Dockerfile . + docker build -f integration-tests/gocov/Dockerfile . test-clover: - docker build -f examples/clover/Dockerfile . + docker build -f integration-tests/clover/Dockerfile . publish-head: $(AWS) s3 cp \ diff --git a/examples/clover.xml b/examples/clover.xml deleted file mode 100644 index be89be7e..00000000 --- a/examples/clover.xml +++ /dev/null @@ -1,447 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/cobertura/coverage.xml b/examples/cobertura/coverage.xml deleted file mode 100644 index 7393fd8c..00000000 --- a/examples/cobertura/coverage.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - /Users/GordonDiggs/git_repos/cobertura/src/main/java - --source - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/jacoco.xml b/examples/jacoco.xml deleted file mode 100644 index 6e1f26c3..00000000 --- a/examples/jacoco.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/javascript/coverage.json b/examples/javascript/coverage.json deleted file mode 100644 index 40640d8d..00000000 --- a/examples/javascript/coverage.json +++ /dev/null @@ -1 +0,0 @@ -{"/Users/GordonDiggs/cc/javascript-test-reporter/formatter.js":{"path":"/Users/GordonDiggs/cc/javascript-test-reporter/formatter.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":1,"11":1,"12":5,"13":1,"14":2,"15":1,"16":1,"17":1,"18":0,"19":1,"20":2,"21":2,"22":2,"23":0,"24":2,"25":2,"26":2,"27":0,"28":2,"29":2,"30":1,"31":2,"32":2,"33":2,"34":5,"35":5,"36":5,"37":5,"38":5,"39":5,"40":0,"41":5,"42":5,"43":5,"44":5,"45":5,"46":817,"47":5,"48":5,"49":0,"50":5,"51":2,"52":1},"b":{"1":[1,0],"2":[5,0],"3":[1,1],"4":[1,0],"5":[0,2],"6":[0,2],"7":[5,0],"8":[0,5]},"f":{"1":1,"2":5,"3":2,"4":2,"5":2,"6":2,"7":2,"8":5,"9":5,"10":817},"fnMap":{"1":{"name":"Formatter","line":10,"loc":{"start":{"line":10,"column":0},"end":{"line":10,"column":28}}},"2":{"name":"(anonymous_2)","line":14,"loc":{"start":{"line":14,"column":36},"end":{"line":14,"column":47}}},"3":{"name":"(anonymous_3)","line":18,"loc":{"start":{"line":18,"column":28},"end":{"line":18,"column":53}}},"4":{"name":"(anonymous_4)","line":28,"loc":{"start":{"line":28,"column":29},"end":{"line":28,"column":62}}},"5":{"name":"(anonymous_5)","line":31,"loc":{"start":{"line":31,"column":27},"end":{"line":31,"column":54}}},"6":{"name":"(anonymous_6)","line":51,"loc":{"start":{"line":51,"column":4},"end":{"line":51,"column":27}}},"7":{"name":"(anonymous_7)","line":65,"loc":{"start":{"line":65,"column":34},"end":{"line":65,"column":49}}},"8":{"name":"(anonymous_8)","line":68,"loc":{"start":{"line":68,"column":15},"end":{"line":68,"column":37}}},"9":{"name":"(anonymous_9)","line":83,"loc":{"start":{"line":83,"column":21},"end":{"line":83,"column":48}}},"10":{"name":"(anonymous_10)","line":86,"loc":{"start":{"line":86,"column":31},"end":{"line":86,"column":52}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":23}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":38}},"5":{"start":{"line":5,"column":0},"end":{"line":5,"column":33}},"6":{"start":{"line":6,"column":0},"end":{"line":6,"column":31}},"7":{"start":{"line":7,"column":0},"end":{"line":7,"column":29}},"8":{"start":{"line":8,"column":0},"end":{"line":8,"column":46}},"9":{"start":{"line":10,"column":0},"end":{"line":12,"column":1}},"10":{"start":{"line":11,"column":2},"end":{"line":11,"column":31}},"11":{"start":{"line":14,"column":0},"end":{"line":16,"column":2}},"12":{"start":{"line":15,"column":2},"end":{"line":15,"column":53}},"13":{"start":{"line":18,"column":0},"end":{"line":26,"column":1}},"14":{"start":{"line":19,"column":4},"end":{"line":25,"column":5}},"15":{"start":{"line":20,"column":8},"end":{"line":20,"column":34}},"16":{"start":{"line":21,"column":11},"end":{"line":25,"column":5}},"17":{"start":{"line":22,"column":8},"end":{"line":22,"column":37}},"18":{"start":{"line":24,"column":8},"end":{"line":24,"column":56}},"19":{"start":{"line":28,"column":0},"end":{"line":63,"column":2}},"20":{"start":{"line":29,"column":2},"end":{"line":29,"column":18}},"21":{"start":{"line":31,"column":2},"end":{"line":62,"column":5}},"22":{"start":{"line":32,"column":4},"end":{"line":34,"column":5}},"23":{"start":{"line":33,"column":6},"end":{"line":33,"column":23}},"24":{"start":{"line":36,"column":4},"end":{"line":45,"column":6}},"25":{"start":{"line":46,"column":4},"end":{"line":61,"column":7}},"26":{"start":{"line":52,"column":6},"end":{"line":54,"column":7}},"27":{"start":{"line":53,"column":8},"end":{"line":53,"column":35}},"28":{"start":{"line":55,"column":6},"end":{"line":59,"column":8}},"29":{"start":{"line":60,"column":6},"end":{"line":60,"column":42}},"30":{"start":{"line":65,"column":0},"end":{"line":102,"column":2}},"31":{"start":{"line":66,"column":2},"end":{"line":66,"column":24}},"32":{"start":{"line":67,"column":2},"end":{"line":67,"column":18}},"33":{"start":{"line":68,"column":2},"end":{"line":100,"column":5}},"34":{"start":{"line":69,"column":4},"end":{"line":69,"column":16}},"35":{"start":{"line":70,"column":4},"end":{"line":79,"column":5}},"36":{"start":{"line":71,"column":6},"end":{"line":71,"column":54}},"37":{"start":{"line":73,"column":6},"end":{"line":78,"column":7}},"38":{"start":{"line":74,"column":8},"end":{"line":74,"column":86}},"39":{"start":{"line":75,"column":8},"end":{"line":75,"column":21}},"40":{"start":{"line":77,"column":8},"end":{"line":77,"column":16}},"41":{"start":{"line":80,"column":4},"end":{"line":80,"column":44}},"42":{"start":{"line":82,"column":4},"end":{"line":82,"column":39}},"43":{"start":{"line":83,"column":4},"end":{"line":85,"column":7}},"44":{"start":{"line":84,"column":6},"end":{"line":84,"column":24}},"45":{"start":{"line":86,"column":4},"end":{"line":88,"column":7}},"46":{"start":{"line":87,"column":6},"end":{"line":87,"column":53}},"47":{"start":{"line":90,"column":4},"end":{"line":90,"column":66}},"48":{"start":{"line":91,"column":4},"end":{"line":93,"column":5}},"49":{"start":{"line":92,"column":6},"end":{"line":92,"column":52}},"50":{"start":{"line":95,"column":4},"end":{"line":99,"column":7}},"51":{"start":{"line":101,"column":2},"end":{"line":101,"column":22}},"52":{"start":{"line":104,"column":0},"end":{"line":104,"column":27}}},"branchMap":{"1":{"line":11,"type":"binary-expr","locations":[{"start":{"line":11,"column":17},"end":{"line":11,"column":24}},{"start":{"line":11,"column":28},"end":{"line":11,"column":30}}]},"2":{"line":15,"type":"binary-expr","locations":[{"start":{"line":15,"column":9},"end":{"line":15,"column":35}},{"start":{"line":15,"column":39},"end":{"line":15,"column":52}}]},"3":{"line":19,"type":"if","locations":[{"start":{"line":19,"column":4},"end":{"line":19,"column":4}},{"start":{"line":19,"column":4},"end":{"line":19,"column":4}}]},"4":{"line":21,"type":"if","locations":[{"start":{"line":21,"column":11},"end":{"line":21,"column":11}},{"start":{"line":21,"column":11},"end":{"line":21,"column":11}}]},"5":{"line":32,"type":"if","locations":[{"start":{"line":32,"column":4},"end":{"line":32,"column":4}},{"start":{"line":32,"column":4},"end":{"line":32,"column":4}}]},"6":{"line":52,"type":"if","locations":[{"start":{"line":52,"column":6},"end":{"line":52,"column":6}},{"start":{"line":52,"column":6},"end":{"line":52,"column":6}}]},"7":{"line":73,"type":"if","locations":[{"start":{"line":73,"column":6},"end":{"line":73,"column":6}},{"start":{"line":73,"column":6},"end":{"line":73,"column":6}}]},"8":{"line":91,"type":"if","locations":[{"start":{"line":91,"column":4},"end":{"line":91,"column":4}},{"start":{"line":91,"column":4},"end":{"line":91,"column":4}}]}}},"/Users/GordonDiggs/cc/javascript-test-reporter/git_info.js":{"path":"/Users/GordonDiggs/cc/javascript-test-reporter/git_info.js","s":{"1":1,"2":1,"3":1,"4":5,"5":5,"6":5,"7":5,"8":5,"9":1,"10":2,"11":2,"12":2,"13":2,"14":2,"15":2,"16":2,"17":2,"18":2,"19":2,"20":2,"21":2,"22":2,"23":2,"24":2,"25":4,"26":2,"27":2,"28":2,"29":2,"30":5,"31":5,"32":5,"33":5,"34":0,"35":5,"36":5},"b":{"1":[2,0],"2":[2,0],"3":[2,2],"4":[2,0],"5":[2,2],"6":[2,0],"7":[0,5]},"f":{"1":5,"2":2,"3":2,"4":2,"5":2,"6":2,"7":2,"8":4,"9":5},"fnMap":{"1":{"name":"calculateBlobId","line":4,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":34}}},"2":{"name":"(anonymous_2)","line":14,"loc":{"start":{"line":14,"column":8},"end":{"line":14,"column":21}}},"3":{"name":"(anonymous_3)","line":15,"loc":{"start":{"line":15,"column":55},"end":{"line":15,"column":88}}},"4":{"name":"(anonymous_4)","line":20,"loc":{"start":{"line":20,"column":15},"end":{"line":20,"column":28}}},"5":{"name":"(anonymous_5)","line":21,"loc":{"start":{"line":21,"column":56},"end":{"line":21,"column":89}}},"6":{"name":"(anonymous_6)","line":34,"loc":{"start":{"line":34,"column":10},"end":{"line":34,"column":23}}},"7":{"name":"(anonymous_7)","line":35,"loc":{"start":{"line":35,"column":36},"end":{"line":35,"column":69}}},"8":{"name":"(anonymous_8)","line":39,"loc":{"start":{"line":39,"column":25},"end":{"line":39,"column":39}}},"9":{"name":"(anonymous_9)","line":54,"loc":{"start":{"line":54,"column":10},"end":{"line":54,"column":34}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":44}},"3":{"start":{"line":4,"column":0},"end":{"line":10,"column":1}},"4":{"start":{"line":5,"column":2},"end":{"line":5,"column":48}},"5":{"start":{"line":6,"column":2},"end":{"line":6,"column":33}},"6":{"start":{"line":7,"column":2},"end":{"line":7,"column":42}},"7":{"start":{"line":8,"column":2},"end":{"line":8,"column":23}},"8":{"start":{"line":9,"column":2},"end":{"line":9,"column":30}},"9":{"start":{"line":12,"column":0},"end":{"line":69,"column":2}},"10":{"start":{"line":15,"column":4},"end":{"line":17,"column":7}},"11":{"start":{"line":16,"column":6},"end":{"line":16,"column":31}},"12":{"start":{"line":21,"column":4},"end":{"line":31,"column":7}},"13":{"start":{"line":22,"column":6},"end":{"line":22,"column":24}},"14":{"start":{"line":23,"column":6},"end":{"line":23,"column":27}},"15":{"start":{"line":24,"column":6},"end":{"line":29,"column":7}},"16":{"start":{"line":25,"column":8},"end":{"line":25,"column":41}},"17":{"start":{"line":26,"column":8},"end":{"line":28,"column":9}},"18":{"start":{"line":27,"column":10},"end":{"line":27,"column":29}},"19":{"start":{"line":30,"column":6},"end":{"line":30,"column":31}},"20":{"start":{"line":35,"column":4},"end":{"line":49,"column":7}},"21":{"start":{"line":36,"column":6},"end":{"line":36,"column":30}},"22":{"start":{"line":37,"column":6},"end":{"line":47,"column":7}},"23":{"start":{"line":38,"column":8},"end":{"line":38,"column":42}},"24":{"start":{"line":39,"column":8},"end":{"line":43,"column":11}},"25":{"start":{"line":40,"column":10},"end":{"line":42,"column":11}},"26":{"start":{"line":41,"column":12},"end":{"line":41,"column":31}},"27":{"start":{"line":44,"column":8},"end":{"line":46,"column":9}},"28":{"start":{"line":45,"column":10},"end":{"line":45,"column":56}},"29":{"start":{"line":48,"column":6},"end":{"line":48,"column":37}},"30":{"start":{"line":55,"column":4},"end":{"line":55,"column":36}},"31":{"start":{"line":57,"column":4},"end":{"line":59,"column":19}},"32":{"start":{"line":58,"column":6},"end":{"line":58,"column":98}},"33":{"start":{"line":61,"column":4},"end":{"line":65,"column":5}},"34":{"start":{"line":62,"column":6},"end":{"line":62,"column":46}},"35":{"start":{"line":64,"column":6},"end":{"line":64,"column":46}},"36":{"start":{"line":67,"column":4},"end":{"line":67,"column":24}}},"branchMap":{"1":{"line":24,"type":"if","locations":[{"start":{"line":24,"column":6},"end":{"line":24,"column":6}},{"start":{"line":24,"column":6},"end":{"line":24,"column":6}}]},"2":{"line":26,"type":"if","locations":[{"start":{"line":26,"column":8},"end":{"line":26,"column":8}},{"start":{"line":26,"column":8},"end":{"line":26,"column":8}}]},"3":{"line":26,"type":"binary-expr","locations":[{"start":{"line":26,"column":12},"end":{"line":26,"column":29}},{"start":{"line":26,"column":33},"end":{"line":26,"column":48}}]},"4":{"line":37,"type":"if","locations":[{"start":{"line":37,"column":6},"end":{"line":37,"column":6}},{"start":{"line":37,"column":6},"end":{"line":37,"column":6}}]},"5":{"line":40,"type":"if","locations":[{"start":{"line":40,"column":10},"end":{"line":40,"column":10}},{"start":{"line":40,"column":10},"end":{"line":40,"column":10}}]},"6":{"line":44,"type":"if","locations":[{"start":{"line":44,"column":8},"end":{"line":44,"column":8}},{"start":{"line":44,"column":8},"end":{"line":44,"column":8}}]},"7":{"line":61,"type":"if","locations":[{"start":{"line":61,"column":4},"end":{"line":61,"column":4}},{"start":{"line":61,"column":4},"end":{"line":61,"column":4}}]}}},"/Users/GordonDiggs/cc/javascript-test-reporter/ci_info.js":{"path":"/Users/GordonDiggs/cc/javascript-test-reporter/ci_info.js","s":{"1":1,"2":6,"3":6,"4":1,"5":5,"6":0,"7":5,"8":0,"9":5,"10":0,"11":5,"12":0,"13":5,"14":0,"15":5,"16":0,"17":5,"18":1,"19":4,"20":1,"21":3,"22":1,"23":2},"b":{"1":[1,5],"2":[0,5],"3":[0,5],"4":[0,5],"5":[0,5],"6":[0,5],"7":[0,5],"8":[5,0],"9":[1,4],"10":[1,3],"11":[1,2]},"f":{"1":6},"fnMap":{"1":{"name":"(anonymous_1)","line":2,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":22}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":82,"column":2}},"2":{"start":{"line":3,"column":4},"end":{"line":3,"column":26}},"3":{"start":{"line":5,"column":4},"end":{"line":80,"column":5}},"4":{"start":{"line":6,"column":6},"end":{"line":11,"column":8}},"5":{"start":{"line":12,"column":11},"end":{"line":80,"column":5}},"6":{"start":{"line":13,"column":6},"end":{"line":18,"column":8}},"7":{"start":{"line":19,"column":11},"end":{"line":80,"column":5}},"8":{"start":{"line":20,"column":6},"end":{"line":24,"column":8}},"9":{"start":{"line":25,"column":11},"end":{"line":80,"column":5}},"10":{"start":{"line":26,"column":6},"end":{"line":32,"column":8}},"11":{"start":{"line":33,"column":11},"end":{"line":80,"column":5}},"12":{"start":{"line":34,"column":6},"end":{"line":38,"column":8}},"13":{"start":{"line":39,"column":11},"end":{"line":80,"column":5}},"14":{"start":{"line":40,"column":6},"end":{"line":46,"column":8}},"15":{"start":{"line":47,"column":11},"end":{"line":80,"column":5}},"16":{"start":{"line":48,"column":6},"end":{"line":54,"column":8}},"17":{"start":{"line":55,"column":11},"end":{"line":80,"column":5}},"18":{"start":{"line":56,"column":6},"end":{"line":62,"column":8}},"19":{"start":{"line":63,"column":11},"end":{"line":80,"column":5}},"20":{"start":{"line":64,"column":6},"end":{"line":70,"column":8}},"21":{"start":{"line":71,"column":11},"end":{"line":80,"column":5}},"22":{"start":{"line":72,"column":6},"end":{"line":77,"column":8}},"23":{"start":{"line":79,"column":6},"end":{"line":79,"column":16}}},"branchMap":{"1":{"line":5,"type":"if","locations":[{"start":{"line":5,"column":4},"end":{"line":5,"column":4}},{"start":{"line":5,"column":4},"end":{"line":5,"column":4}}]},"2":{"line":12,"type":"if","locations":[{"start":{"line":12,"column":11},"end":{"line":12,"column":11}},{"start":{"line":12,"column":11},"end":{"line":12,"column":11}}]},"3":{"line":19,"type":"if","locations":[{"start":{"line":19,"column":11},"end":{"line":19,"column":11}},{"start":{"line":19,"column":11},"end":{"line":19,"column":11}}]},"4":{"line":25,"type":"if","locations":[{"start":{"line":25,"column":11},"end":{"line":25,"column":11}},{"start":{"line":25,"column":11},"end":{"line":25,"column":11}}]},"5":{"line":33,"type":"if","locations":[{"start":{"line":33,"column":11},"end":{"line":33,"column":11}},{"start":{"line":33,"column":11},"end":{"line":33,"column":11}}]},"6":{"line":39,"type":"if","locations":[{"start":{"line":39,"column":11},"end":{"line":39,"column":11}},{"start":{"line":39,"column":11},"end":{"line":39,"column":11}}]},"7":{"line":47,"type":"if","locations":[{"start":{"line":47,"column":11},"end":{"line":47,"column":11}},{"start":{"line":47,"column":11},"end":{"line":47,"column":11}}]},"8":{"line":47,"type":"binary-expr","locations":[{"start":{"line":47,"column":15},"end":{"line":47,"column":26}},{"start":{"line":47,"column":30},"end":{"line":47,"column":60}}]},"9":{"line":55,"type":"if","locations":[{"start":{"line":55,"column":11},"end":{"line":55,"column":11}},{"start":{"line":55,"column":11},"end":{"line":55,"column":11}}]},"10":{"line":63,"type":"if","locations":[{"start":{"line":63,"column":11},"end":{"line":63,"column":11}},{"start":{"line":63,"column":11},"end":{"line":63,"column":11}}]},"11":{"line":71,"type":"if","locations":[{"start":{"line":71,"column":11},"end":{"line":71,"column":11}},{"start":{"line":71,"column":11},"end":{"line":71,"column":11}}]}}},"/Users/GordonDiggs/cc/javascript-test-reporter/gocover_parse.js":{"path":"/Users/GordonDiggs/cc/javascript-test-reporter/gocover_parse.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":272,"8":272,"9":1,"10":271,"11":271,"12":271,"13":271,"14":271,"15":3,"16":3,"17":271,"18":271,"19":271,"20":795,"21":1},"b":{"1":[1,271],"2":[3,268]},"f":{"1":1,"2":272},"fnMap":{"1":{"name":"(anonymous_1)","line":3,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":36}}},"2":{"name":"(anonymous_2)","line":12,"loc":{"start":{"line":12,"column":16},"end":{"line":12,"column":31}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":49,"column":1}},"2":{"start":{"line":4,"column":2},"end":{"line":4,"column":16}},"3":{"start":{"line":5,"column":2},"end":{"line":5,"column":22}},"4":{"start":{"line":7,"column":2},"end":{"line":7,"column":31}},"5":{"start":{"line":10,"column":2},"end":{"line":10,"column":16}},"6":{"start":{"line":12,"column":2},"end":{"line":46,"column":5}},"7":{"start":{"line":15,"column":4},"end":{"line":15,"column":65}},"8":{"start":{"line":16,"column":4},"end":{"line":18,"column":5}},"9":{"start":{"line":17,"column":6},"end":{"line":17,"column":13}},"10":{"start":{"line":22,"column":4},"end":{"line":22,"column":58}},"11":{"start":{"line":23,"column":4},"end":{"line":23,"column":28}},"12":{"start":{"line":24,"column":4},"end":{"line":24,"column":26}},"13":{"start":{"line":25,"column":4},"end":{"line":25,"column":27}},"14":{"start":{"line":27,"column":4},"end":{"line":35,"column":5}},"15":{"start":{"line":28,"column":6},"end":{"line":33,"column":7}},"16":{"start":{"line":34,"column":6},"end":{"line":34,"column":37}},"17":{"start":{"line":37,"column":4},"end":{"line":37,"column":40}},"18":{"start":{"line":39,"column":4},"end":{"line":39,"column":22}},"19":{"start":{"line":40,"column":4},"end":{"line":45,"column":5}},"20":{"start":{"line":41,"column":6},"end":{"line":44,"column":8}},"21":{"start":{"line":48,"column":2},"end":{"line":48,"column":23}}},"branchMap":{"1":{"line":16,"type":"if","locations":[{"start":{"line":16,"column":4},"end":{"line":16,"column":4}},{"start":{"line":16,"column":4},"end":{"line":16,"column":4}}]},"2":{"line":27,"type":"if","locations":[{"start":{"line":27,"column":4},"end":{"line":27,"column":4}},{"start":{"line":27,"column":4},"end":{"line":27,"column":4}}]}}}} \ No newline at end of file diff --git a/examples/javascript/lcov-report/base.css b/examples/javascript/lcov-report/base.css deleted file mode 100644 index 29737bcb..00000000 --- a/examples/javascript/lcov-report/base.css +++ /dev/null @@ -1,213 +0,0 @@ -body, html { - margin:0; padding: 0; - height: 100%; -} -body { - font-family: Helvetica Neue, Helvetica, Arial; - font-size: 14px; - color:#333; -} -.small { font-size: 12px; } -*, *:after, *:before { - -webkit-box-sizing:border-box; - -moz-box-sizing:border-box; - box-sizing:border-box; - } -h1 { font-size: 20px; margin: 0;} -h2 { font-size: 14px; } -pre { - font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; - margin: 0; - padding: 0; - -moz-tab-size: 2; - -o-tab-size: 2; - tab-size: 2; -} -a { color:#0074D9; text-decoration:none; } -a:hover { text-decoration:underline; } -.strong { font-weight: bold; } -.space-top1 { padding: 10px 0 0 0; } -.pad2y { padding: 20px 0; } -.pad1y { padding: 10px 0; } -.pad2x { padding: 0 20px; } -.pad2 { padding: 20px; } -.pad1 { padding: 10px; } -.space-left2 { padding-left:55px; } -.space-right2 { padding-right:20px; } -.center { text-align:center; } -.clearfix { display:block; } -.clearfix:after { - content:''; - display:block; - height:0; - clear:both; - visibility:hidden; - } -.fl { float: left; } -@media only screen and (max-width:640px) { - .col3 { width:100%; max-width:100%; } - .hide-mobile { display:none!important; } -} - -.quiet { - color: #7f7f7f; - color: rgba(0,0,0,0.5); -} -.quiet a { opacity: 0.7; } - -.fraction { - font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; - font-size: 10px; - color: #555; - background: #E8E8E8; - padding: 4px 5px; - border-radius: 3px; - vertical-align: middle; -} - -div.path a:link, div.path a:visited { color: #333; } -table.coverage { - border-collapse: collapse; - margin: 10px 0 0 0; - padding: 0; -} - -table.coverage td { - margin: 0; - padding: 0; - vertical-align: top; -} -table.coverage td.line-count { - text-align: right; - padding: 0 5px 0 20px; -} -table.coverage td.line-coverage { - text-align: right; - padding-right: 10px; - min-width:20px; -} - -table.coverage td span.cline-any { - display: inline-block; - padding: 0 5px; - width: 100%; -} -.missing-if-branch { - display: inline-block; - margin-right: 5px; - border-radius: 3px; - position: relative; - padding: 0 4px; - background: #333; - color: yellow; -} - -.skip-if-branch { - display: none; - margin-right: 10px; - position: relative; - padding: 0 4px; - background: #ccc; - color: white; -} -.missing-if-branch .typ, .skip-if-branch .typ { - color: inherit !important; -} -.coverage-summary { - border-collapse: collapse; - width: 100%; -} -.coverage-summary tr { border-bottom: 1px solid #bbb; } -.keyline-all { border: 1px solid #ddd; } -.coverage-summary td, .coverage-summary th { padding: 10px; } -.coverage-summary tbody { border: 1px solid #bbb; } -.coverage-summary td { border-right: 1px solid #bbb; } -.coverage-summary td:last-child { border-right: none; } -.coverage-summary th { - text-align: left; - font-weight: normal; - white-space: nowrap; -} -.coverage-summary th.file { border-right: none !important; } -.coverage-summary th.pct { } -.coverage-summary th.pic, -.coverage-summary th.abs, -.coverage-summary td.pct, -.coverage-summary td.abs { text-align: right; } -.coverage-summary td.file { white-space: nowrap; } -.coverage-summary td.pic { min-width: 120px !important; } -.coverage-summary tfoot td { } - -.coverage-summary .sorter { - height: 10px; - width: 7px; - display: inline-block; - margin-left: 0.5em; - background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; -} -.coverage-summary .sorted .sorter { - background-position: 0 -20px; -} -.coverage-summary .sorted-desc .sorter { - background-position: 0 -10px; -} -.status-line { height: 10px; } -/* dark red */ -.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } -.low .chart { border:1px solid #C21F39 } -/* medium red */ -.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } -/* light red */ -.low, .cline-no { background:#FCE1E5 } -/* light green */ -.high, .cline-yes { background:rgb(230,245,208) } -/* medium green */ -.cstat-yes { background:rgb(161,215,106) } -/* dark green */ -.status-line.high, .high .cover-fill { background:rgb(77,146,33) } -.high .chart { border:1px solid rgb(77,146,33) } -/* dark yellow (gold) */ -.medium .chart { border:1px solid #f9cd0b; } -.status-line.medium, .medium .cover-fill { background: #f9cd0b; } -/* light yellow */ -.medium { background: #fff4c2; } -/* light gray */ -span.cline-neutral { background: #eaeaea; } - -.cbranch-no { background: yellow !important; color: #111; } - -.cstat-skip { background: #ddd; color: #111; } -.fstat-skip { background: #ddd; color: #111 !important; } -.cbranch-skip { background: #ddd !important; color: #111; } - - -.cover-fill, .cover-empty { - display:inline-block; - height: 12px; -} -.chart { - line-height: 0; -} -.cover-empty { - background: white; -} -.cover-full { - border-right: none !important; -} -pre.prettyprint { - border: none !important; - padding: 0 !important; - margin: 0 !important; -} -.com { color: #999 !important; } -.ignore-none { color: #999; font-weight: normal; } - -.wrapper { - min-height: 100%; - height: auto !important; - height: 100%; - margin: 0 auto -48px; -} -.footer, .push { - height: 48px; -} diff --git a/examples/javascript/lcov-report/index.html b/examples/javascript/lcov-report/index.html deleted file mode 100644 index f3e4a09c..00000000 --- a/examples/javascript/lcov-report/index.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - Code coverage report for All files - - - - - - - -
-
-

- / -

-
-
- 90.91% - Statements - 120/132 -
-
- 66.07% - Branches - 37/56 -
-
- 100% - Functions - 22/22 -
-
- 90.91% - Lines - 120/132 -
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
javascript-test-reporter/
90.91%120/13266.07%37/56100%22/2290.91%120/132
-
-
- - - - - - - diff --git a/examples/javascript/lcov-report/javascript-test-reporter/ci_info.js.html b/examples/javascript/lcov-report/javascript-test-reporter/ci_info.js.html deleted file mode 100644 index 6d1bc115..00000000 --- a/examples/javascript/lcov-report/javascript-test-reporter/ci_info.js.html +++ /dev/null @@ -1,311 +0,0 @@ - - - - Code coverage report for javascript-test-reporter/ci_info.js - - - - - - - -
-
-

- all files / javascript-test-reporter/ ci_info.js -

-
-
- 73.91% - Statements - 17/23 -
-
- 68.18% - Branches - 15/22 -
-
- 100% - Functions - 1/1 -
-
- 73.91% - Lines - 17/23 -
-
-
-
-

-
-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -831× -  -6× -  -6× -1× -  -  -  -  -  -5× -  -  -  -  -  -  -5× -  -  -  -  -  -5× -  -  -  -  -  -  -  -5× -  -  -  -  -  -5× -  -  -  -  -  -  -  -5× -  -  -  -  -  -  -  -5× -1× -  -  -  -  -  -  -4× -1× -  -  -  -  -  -  -3× -1× -  -  -  -  -  -  -2× -  -  -  - 
module.exports = {
-  getInfo: function() {
-    var env = process.env;
- 
-    if (env.TRAVIS) {
-      return {
-        name: "travis-ci",
-        branch: env.TRAVIS_BRANCH,
-        build_identifier: env.TRAVIS_JOB_ID,
-        pull_request: env.TRAVIS_PULL_REQUEST
-      };
-    } else Iif (env.CIRCLECI) {
-      return {
-        name:             "circleci",
-        build_identifier: env.CIRCLE_BUILD_NUM,
-        branch:           env.CIRCLE_BRANCH,
-        commit_sha:       env.CIRCLE_SHA1
-      };
-    } else Iif (env.SEMAPHORE) {
-      return {
-        name:             "semaphore",
-        branch:           env.BRANCH_NAME,
-        build_identifier: env.SEMAPHORE_BUILD_NUMBER
-      };
-    } else Iif (env.JENKINS_URL) {
-      return {
-        name:             "jenkins",
-        build_identifier: env.BUILD_NUMBER,
-        build_url:        env.BUILD_URL,
-        branch:           env.GIT_BRANCH,
-        commit_sha:       env.GIT_COMMIT
-      };
-    } else Iif (env.TDDIUM) {
-      return {
-        name:             "tddium",
-        build_identifier: env.TDDIUM_SESSION_ID,
-        worker_id:        env.TDDIUM_TID
-      };
-    } else Iif (env.WERCKER) {
-      return {
-        name:               "wercker",
-        build_identifier:   env.WERCKER_BUILD_ID,
-        build_url:          env.WERCKER_BUILD_URL,
-        branch:             env.WERCKER_GIT_BRANCH,
-        commit_sha:         env.WERCKER_GIT_COMMIT
-      };
-    } else Iif (env.CI_NAME && env.CI_NAME.match(/codeship/i)) {
-      return {
-        name:             "codeship",
-        build_identifier: env.CI_BUILD_NUMBER,
-        build_url:        env.CI_BUILD_URL,
-        branch:           env.CI_BRANCH,
-        commit_sha:       env.CI_COMMIT_ID
-      };
-    } else if (env.APPVEYOR) {
-      return {
-        name:             "appveyor",
-        build_identifier: env.APPVEYOR_BUILD_NUMBER,
-        branch:           env.APPVEYOR_REPO_BRANCH,
-        commit_sha:       env.APPVEYOR_REPO_COMMIT,
-        pull_request:     env.APPVEYOR_PULL_REQUEST_NUMBER
-      };
-    } else if (env.BUILDKITE) {
-      return {
-        name:             "buildkite",
-        build_identifier: env.BUILDKITE_BUILD_ID,
-        build_url:        env.BUILDKITE_BUILD_URL,
-        branch:           env.BUILDKITE_BRANCH,
-        commit_sha:       env.BUILDKITE_COMMIT
-      };
-    } else if (env.GITLAB_CI) {
-      return {
-        name:             "gitlab-ci",
-        build_identifier: env.CI_BUILD_ID,
-        branch:           env.CI_BUILD_REF_NAME,
-        commit_sha:       env.CI_BUILD_REF
-      };
-    } else {
-      return {};
-    }
-  }
-};
- 
-
-
- - - - - - - diff --git a/examples/javascript/lcov-report/javascript-test-reporter/formatter.js.html b/examples/javascript/lcov-report/javascript-test-reporter/formatter.js.html deleted file mode 100644 index 2bb7c39d..00000000 --- a/examples/javascript/lcov-report/javascript-test-reporter/formatter.js.html +++ /dev/null @@ -1,377 +0,0 @@ - - - - Code coverage report for javascript-test-reporter/formatter.js - - - - - - - -
-
-

- all files / javascript-test-reporter/ formatter.js -

-
-
- 90.38% - Statements - 47/52 -
-
- 56.25% - Branches - 9/16 -
-
- 100% - Functions - 10/10 -
-
- 90.38% - Lines - 47/52 -
-
-
-
-

-
-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -1051× -1× -1× -1× -1× -1× -1× -1× -  -1× -1× -  -  -1× -5× -  -  -1× -2× -1× -1× -1× -  -  -  -  -  -1× -2× -  -2× -2× -  -  -  -2× -  -  -  -  -  -  -  -  -  -2× -  -  -  -  -  -2× -  -  -2× -  -  -  -  -2× -  -  -  -  -1× -2× -2× -2× -5× -5× -5× -  -5× -5× -5× -  -  -  -  -5× -  -5× -5× -5× -  -5× -817× -  -  -5× -5× -  -  -  -5× -  -  -  -  -  -2× -  -  -1× - 
var lcovParse = require('lcov-parse');
-var path = require('path');
-var fs = require('fs');
-var pjson = require('./package.json');
-var git  = require("./git_info");
-var ci  = require("./ci_info");
-var async = require("async");
-var gocoverParse = require('./gocover_parse');
- 
-function Formatter(options) {
-  this.options = options || {};
-}
- 
-Formatter.prototype.rootDirectory = function() {
-  return this.options.rootDirectory || process.cwd();
-};
- 
-Formatter.prototype.parse = function(data, callback) {
-    if (/^SF:/m.test(data)) {
-        lcovParse(data, callback);
-    } else Eif (/^mode:/.test(data)) {
-        gocoverParse(data, callback);
-    } else {
-        callback("Unknown input coverage format", null);
-    }
-}
- 
-Formatter.prototype.format = function(coverageData, callback) {
-  var self = this;
- 
-  self.parse(coverageData, function(parseError, data) {
-    Iif (parseError) {
-      throw parseError;
-    }
- 
-    var result = {
-      source_files: self.sourceFiles(data),
-      run_at: Date.now(),
-      partial: false,
-      environment: {
-        pwd: process.cwd().split(path.sep).join('/'),
-        package_version: pjson.version
-      },
-      ci_service: ci.getInfo()
-    };
-    async.parallel({
-      head: git.head,
-      branch: git.branch,
-      committed_at: git.committedAt
-    },
-    function(err, results) {
-      Iif (err) {
-        console.error(err.message);
-      }
-      result.git = {
-        head: results.head,
-        branch: results.branch,
-        committed_at: results.committed_at
-      };
-      return callback(parseError, result);
-    });
-  });
-};
- 
-Formatter.prototype.sourceFiles = function(data) {
-  var source_files = [];
-  var self = this;
-  data.forEach(function(elem, index) {
-    var content;
-    try {
-      content = fs.readFileSync(elem.file).toString();
-    } catch (e) {
-      Eif (e.code === 'ENOENT') {
-        console.log('The file ' + elem.file + ' does not exist and will be skipped.');
-        content = '';
-      } else {
-        throw e;
-      }
-    }
-    var numLines = content.split("\n").size;
- 
-    var coverage = new Array(numLines);
-    coverage.forEach(function(elem, index, arr) {
-      arr[index] = null;
-    });
-    elem.lines.details.forEach(function(lineDetail) {
-      coverage[lineDetail.line - 1] = lineDetail.hit;
-    });
- 
-    var fileName = path.relative(self.rootDirectory(), elem.file);
-    Iif (path.sep !== '/') {
-      fileName = fileName.split(path.sep).join('/');
-    }
- 
-    source_files.push({
-      name: fileName,
-      blob_id: git.blobId(elem.file, content),
-      coverage: JSON.stringify(coverage)
-    });
-  });
-  return source_files;
-};
- 
-module.exports = Formatter;
- 
-
-
- - - - - - - diff --git a/examples/javascript/lcov-report/javascript-test-reporter/git_info.js.html b/examples/javascript/lcov-report/javascript-test-reporter/git_info.js.html deleted file mode 100644 index 913e07c2..00000000 --- a/examples/javascript/lcov-report/javascript-test-reporter/git_info.js.html +++ /dev/null @@ -1,272 +0,0 @@ - - - - Code coverage report for javascript-test-reporter/git_info.js - - - - - - - -
-
-

- all files / javascript-test-reporter/ git_info.js -

-
-
- 97.22% - Statements - 35/36 -
-
- 64.29% - Branches - 9/14 -
-
- 100% - Functions - 9/9 -
-
- 97.22% - Lines - 35/36 -
-
-
-
-

-
-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -701× -1× -  -1× -5× -5× -5× -5× -5× -  -  -1× -  -  -2× -2× -  -  -  -  -2× -2× -2× -2× -2× -2× -2× -  -  -2× -  -  -  -  -2× -2× -2× -2× -2× -4× -2× -  -  -2× -2× -  -  -2× -  -  -  -  -  -  -5× -  -5× -5× -  -  -5× -  -  -5× -  -  -5× -  -  - 
var crypto = require('crypto');
-var childProcess = require('child_process');
- 
-function calculateBlobId(content) {
-  var header  = 'blob ' + content.length + '\0';
-  var store   = header + content;
-  var shasum  = crypto.createHash('sha1');
-  shasum.update(store);
-  return shasum.digest("hex");
-}
- 
-module.exports = {
- 
-  head: function(cb) {
-    childProcess.exec("git log -1 --pretty=format:%H", function (error, stdout, stderr) {
-      return cb(error, stdout);
-    });
-  },
- 
-  committedAt: function(cb) {
-    childProcess.exec("git log -1 --pretty=format:%ct", function (error, stdout, stderr) {
-      var result = null;
-      var timestamp = null;
-      Eif (stdout) {
-        timestamp = parseInt(stdout, 10);
-        Eif (!isNaN(timestamp) && timestamp !== 0) {
-          result = timestamp;
-        }
-      }
-      return cb(error, result);
-    });
-  },
- 
-  branch: function(cb) {
-    childProcess.exec("git branch", function (error, stdout, stderr) {
-      var returnBranch = null;
-      Eif (stdout) {
-        var branches = stdout.split("\n");
-        branches.forEach(function(val) {
-          if(val.charAt(0) === "*") {
-            returnBranch = val;
-          }
-        });
-        Eif (returnBranch) {
-          returnBranch = returnBranch.replace("* ", "");
-        }
-      }
-      return cb(error, returnBranch);
-    });
-  },
- 
-  calculateBlobId: calculateBlobId,
- 
-  blobId: function(path, content) {
-    var stdout, returnBlobId = null;
- 
-    try {
-      stdout = childProcess.execSync("git hash-object " + path, { stdio: [0, "pipe", "ignore"] });
-    } catch (e) { }
- 
-    Iif (stdout) {
-      returnBlobId = stdout.toString().trim();
-    } else {
-      returnBlobId = calculateBlobId(content);
-    }
- 
-    return returnBlobId;
-  }
-};
- 
-
-
- - - - - - - diff --git a/examples/javascript/lcov-report/javascript-test-reporter/gocover_parse.js.html b/examples/javascript/lcov-report/javascript-test-reporter/gocover_parse.js.html deleted file mode 100644 index a2be6f7e..00000000 --- a/examples/javascript/lcov-report/javascript-test-reporter/gocover_parse.js.html +++ /dev/null @@ -1,215 +0,0 @@ - - - - Code coverage report for javascript-test-reporter/gocover_parse.js - - - - - - - -
-
-

- all files / javascript-test-reporter/ gocover_parse.js -

-
-
- 100% - Statements - 21/21 -
-
- 100% - Branches - 4/4 -
-
- 100% - Functions - 2/2 -
-
- 100% - Lines - 21/21 -
-
-
-
-

-
-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51  -  -1× -1× -1× -  -1× -  -  -1× -  -1× -  -  -272× -272× -1× -  -  -  -  -271× -271× -271× -271× -  -271× -3× -  -  -  -  -  -3× -  -  -271× -  -271× -271× -795× -  -  -  -  -  -  -1× -  -  - 
'use strict'
- 
-module.exports = function(data, cb) {
-  var memo = {};
-  var parsedData = [];
- 
-  var lines = data.split('\n');
- 
-  // Skip mode line
-  lines.shift();
- 
-  lines.forEach(function(line) {
-    // coverage line syntax:
-    // Filename:<start line>.<start column>,<end line>.<end column>.<# of statements>.<hit count>
-    var data = line.match(/(.*?):(\d+).\d+,(\d+).\d+ \d+ (\d+)/);
-    if (!data) {
-      return;
-    }
- 
-    // filename is given relative to $GOPATH/src, so tack $GOPATH/src on the
-    // front. Converting it to a relative filenae is handled by the formatter.
-    var filename = process.env.GOPATH + '/src/' + data[1];
-    var startLine = data[2];
-    var endLine = data[3];
-    var hitCount = data[4];
- 
-    if (!memo[filename]) {
-      memo[filename] = {
-        file: filename,
-        lines: {
-          details: []
-        }
-      }
-      parsedData.push(memo[filename])
-    }
- 
-    var lineData = memo[filename].lines;
- 
-    var i = startLine;
-    for(var i = startLine; i <= endLine; i++) {
-      lineData.details.push({
-        line: i*1,
-        hit: hitCount*1
-      })
-    }
-  });
- 
-  cb(null, parsedData);
-}
- 
- 
-
-
- - - - - - - diff --git a/examples/javascript/lcov-report/javascript-test-reporter/index.html b/examples/javascript/lcov-report/javascript-test-reporter/index.html deleted file mode 100644 index 67837608..00000000 --- a/examples/javascript/lcov-report/javascript-test-reporter/index.html +++ /dev/null @@ -1,132 +0,0 @@ - - - - Code coverage report for javascript-test-reporter/ - - - - - - - -
-
-

- all files javascript-test-reporter/ -

-
-
- 90.91% - Statements - 120/132 -
-
- 66.07% - Branches - 37/56 -
-
- 100% - Functions - 22/22 -
-
- 90.91% - Lines - 120/132 -
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
ci_info.js
73.91%17/2368.18%15/22100%1/173.91%17/23
formatter.js
90.38%47/5256.25%9/16100%10/1090.38%47/52
git_info.js
97.22%35/3664.29%9/14100%9/997.22%35/36
gocover_parse.js
100%21/21100%4/4100%2/2100%21/21
-
-
- - - - - - - diff --git a/examples/javascript/lcov-report/prettify.css b/examples/javascript/lcov-report/prettify.css deleted file mode 100644 index b317a7cd..00000000 --- a/examples/javascript/lcov-report/prettify.css +++ /dev/null @@ -1 +0,0 @@ -.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} diff --git a/examples/javascript/lcov-report/prettify.js b/examples/javascript/lcov-report/prettify.js deleted file mode 100644 index ef51e038..00000000 --- a/examples/javascript/lcov-report/prettify.js +++ /dev/null @@ -1 +0,0 @@ -window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); diff --git a/examples/javascript/lcov-report/sort-arrow-sprite.png b/examples/javascript/lcov-report/sort-arrow-sprite.png deleted file mode 100644 index 03f704a609c6fd0dbfdac63466a7d7c958b5cbf3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^>_9Bd!3HEZxJ@+%Qj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>Jii$m5978H@?Fn+^JD|Y9yzj{W`447Gxa{7*dM7nnnD-Lb z6^}Hx2)'; - } - } - return cols; - } - // attaches a data attribute to every tr element with an object - // of data values keyed by column name - function loadRowData(tableRow) { - var tableCols = tableRow.querySelectorAll('td'), - colNode, - col, - data = {}, - i, - val; - for (i = 0; i < tableCols.length; i += 1) { - colNode = tableCols[i]; - col = cols[i]; - val = colNode.getAttribute('data-value'); - if (col.type === 'number') { - val = Number(val); - } - data[col.key] = val; - } - return data; - } - // loads all row data - function loadData() { - var rows = getTableBody().querySelectorAll('tr'), - i; - - for (i = 0; i < rows.length; i += 1) { - rows[i].data = loadRowData(rows[i]); - } - } - // sorts the table using the data for the ith column - function sortByIndex(index, desc) { - var key = cols[index].key, - sorter = function (a, b) { - a = a.data[key]; - b = b.data[key]; - return a < b ? -1 : a > b ? 1 : 0; - }, - finalSorter = sorter, - tableBody = document.querySelector('.coverage-summary tbody'), - rowNodes = tableBody.querySelectorAll('tr'), - rows = [], - i; - - if (desc) { - finalSorter = function (a, b) { - return -1 * sorter(a, b); - }; - } - - for (i = 0; i < rowNodes.length; i += 1) { - rows.push(rowNodes[i]); - tableBody.removeChild(rowNodes[i]); - } - - rows.sort(finalSorter); - - for (i = 0; i < rows.length; i += 1) { - tableBody.appendChild(rows[i]); - } - } - // removes sort indicators for current column being sorted - function removeSortIndicators() { - var col = getNthColumn(currentSort.index), - cls = col.className; - - cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); - col.className = cls; - } - // adds sort indicators for current column being sorted - function addSortIndicators() { - getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted'; - } - // adds event listeners for all sorter widgets - function enableUI() { - var i, - el, - ithSorter = function ithSorter(i) { - var col = cols[i]; - - return function () { - var desc = col.defaultDescSort; - - if (currentSort.index === i) { - desc = !currentSort.desc; - } - sortByIndex(i, desc); - removeSortIndicators(); - currentSort.index = i; - currentSort.desc = desc; - addSortIndicators(); - }; - }; - for (i =0 ; i < cols.length; i += 1) { - if (cols[i].sortable) { - // add the click event handler on the th so users - // dont have to click on those tiny arrows - el = getNthColumn(i).querySelector('.sorter').parentElement; - if (el.addEventListener) { - el.addEventListener('click', ithSorter(i)); - } else { - el.attachEvent('onclick', ithSorter(i)); - } - } - } - } - // adds sorting functionality to the UI - return function () { - if (!getTable()) { - return; - } - cols = loadColumns(); - loadData(cols); - addSortIndicators(); - enableUI(); - }; -})(); - -window.addEventListener('load', addSorting); diff --git a/examples/javascript/lcov.info b/examples/javascript/lcov.info deleted file mode 100644 index 70c22f01..00000000 --- a/examples/javascript/lcov.info +++ /dev/null @@ -1,268 +0,0 @@ -TN: -SF:/Users/GordonDiggs/cc/javascript-test-reporter/formatter.js -FN:10,Formatter -FN:14,(anonymous_2) -FN:18,(anonymous_3) -FN:28,(anonymous_4) -FN:31,(anonymous_5) -FN:51,(anonymous_6) -FN:65,(anonymous_7) -FN:68,(anonymous_8) -FN:83,(anonymous_9) -FN:86,(anonymous_10) -FNF:10 -FNH:10 -FNDA:1,Formatter -FNDA:5,(anonymous_2) -FNDA:2,(anonymous_3) -FNDA:2,(anonymous_4) -FNDA:2,(anonymous_5) -FNDA:2,(anonymous_6) -FNDA:2,(anonymous_7) -FNDA:5,(anonymous_8) -FNDA:5,(anonymous_9) -FNDA:817,(anonymous_10) -DA:1,1 -DA:2,1 -DA:3,1 -DA:4,1 -DA:5,1 -DA:6,1 -DA:7,1 -DA:8,1 -DA:10,1 -DA:11,1 -DA:14,1 -DA:15,5 -DA:18,1 -DA:19,2 -DA:20,1 -DA:21,1 -DA:22,1 -DA:24,0 -DA:28,1 -DA:29,2 -DA:31,2 -DA:32,2 -DA:33,0 -DA:36,2 -DA:46,2 -DA:52,2 -DA:53,0 -DA:55,2 -DA:60,2 -DA:65,1 -DA:66,2 -DA:67,2 -DA:68,2 -DA:69,5 -DA:70,5 -DA:71,5 -DA:73,5 -DA:74,5 -DA:75,5 -DA:77,0 -DA:80,5 -DA:82,5 -DA:83,5 -DA:84,5 -DA:86,5 -DA:87,817 -DA:90,5 -DA:91,5 -DA:92,0 -DA:95,5 -DA:101,2 -DA:104,1 -LF:52 -LH:47 -BRDA:11,1,0,1 -BRDA:11,1,1,0 -BRDA:15,2,0,5 -BRDA:15,2,1,0 -BRDA:19,3,0,1 -BRDA:19,3,1,1 -BRDA:21,4,0,1 -BRDA:21,4,1,0 -BRDA:32,5,0,0 -BRDA:32,5,1,2 -BRDA:52,6,0,0 -BRDA:52,6,1,2 -BRDA:73,7,0,5 -BRDA:73,7,1,0 -BRDA:91,8,0,0 -BRDA:91,8,1,5 -BRF:16 -BRH:9 -end_of_record -TN: -SF:/Users/GordonDiggs/cc/javascript-test-reporter/git_info.js -FN:4,calculateBlobId -FN:14,(anonymous_2) -FN:15,(anonymous_3) -FN:20,(anonymous_4) -FN:21,(anonymous_5) -FN:34,(anonymous_6) -FN:35,(anonymous_7) -FN:39,(anonymous_8) -FN:54,(anonymous_9) -FNF:9 -FNH:9 -FNDA:5,calculateBlobId -FNDA:2,(anonymous_2) -FNDA:2,(anonymous_3) -FNDA:2,(anonymous_4) -FNDA:2,(anonymous_5) -FNDA:2,(anonymous_6) -FNDA:2,(anonymous_7) -FNDA:4,(anonymous_8) -FNDA:5,(anonymous_9) -DA:1,1 -DA:2,1 -DA:4,1 -DA:5,5 -DA:6,5 -DA:7,5 -DA:8,5 -DA:9,5 -DA:12,1 -DA:15,2 -DA:16,2 -DA:21,2 -DA:22,2 -DA:23,2 -DA:24,2 -DA:25,2 -DA:26,2 -DA:27,2 -DA:30,2 -DA:35,2 -DA:36,2 -DA:37,2 -DA:38,2 -DA:39,2 -DA:40,4 -DA:41,2 -DA:44,2 -DA:45,2 -DA:48,2 -DA:55,5 -DA:57,5 -DA:58,5 -DA:61,5 -DA:62,0 -DA:64,5 -DA:67,5 -LF:36 -LH:35 -BRDA:24,1,0,2 -BRDA:24,1,1,0 -BRDA:26,2,0,2 -BRDA:26,2,1,0 -BRDA:26,3,0,2 -BRDA:26,3,1,2 -BRDA:37,4,0,2 -BRDA:37,4,1,0 -BRDA:40,5,0,2 -BRDA:40,5,1,2 -BRDA:44,6,0,2 -BRDA:44,6,1,0 -BRDA:61,7,0,0 -BRDA:61,7,1,5 -BRF:14 -BRH:9 -end_of_record -TN: -SF:/Users/GordonDiggs/cc/javascript-test-reporter/ci_info.js -FN:2,(anonymous_1) -FNF:1 -FNH:1 -FNDA:6,(anonymous_1) -DA:1,1 -DA:3,6 -DA:5,6 -DA:6,1 -DA:12,5 -DA:13,0 -DA:19,5 -DA:20,0 -DA:25,5 -DA:26,0 -DA:33,5 -DA:34,0 -DA:39,5 -DA:40,0 -DA:47,5 -DA:48,0 -DA:55,5 -DA:56,1 -DA:63,4 -DA:64,1 -DA:71,3 -DA:72,1 -DA:79,2 -LF:23 -LH:17 -BRDA:5,1,0,1 -BRDA:5,1,1,5 -BRDA:12,2,0,0 -BRDA:12,2,1,5 -BRDA:19,3,0,0 -BRDA:19,3,1,5 -BRDA:25,4,0,0 -BRDA:25,4,1,5 -BRDA:33,5,0,0 -BRDA:33,5,1,5 -BRDA:39,6,0,0 -BRDA:39,6,1,5 -BRDA:47,7,0,0 -BRDA:47,7,1,5 -BRDA:47,8,0,5 -BRDA:47,8,1,0 -BRDA:55,9,0,1 -BRDA:55,9,1,4 -BRDA:63,10,0,1 -BRDA:63,10,1,3 -BRDA:71,11,0,1 -BRDA:71,11,1,2 -BRF:22 -BRH:15 -end_of_record -TN: -SF:/Users/GordonDiggs/cc/javascript-test-reporter/gocover_parse.js -FN:3,(anonymous_1) -FN:12,(anonymous_2) -FNF:2 -FNH:2 -FNDA:1,(anonymous_1) -FNDA:272,(anonymous_2) -DA:3,1 -DA:4,1 -DA:5,1 -DA:7,1 -DA:10,1 -DA:12,1 -DA:15,272 -DA:16,272 -DA:17,1 -DA:22,271 -DA:23,271 -DA:24,271 -DA:25,271 -DA:27,271 -DA:28,3 -DA:34,3 -DA:37,271 -DA:39,271 -DA:40,271 -DA:41,795 -DA:48,1 -LF:21 -LH:21 -BRDA:16,1,0,1 -BRDA:16,1,1,271 -BRDA:27,2,0,3 -BRDA:27,2,1,268 -BRF:4 -BRH:4 -end_of_record diff --git a/formatters/clover/clover.go b/formatters/clover/clover.go index 3d302a50..f45ebc9b 100644 --- a/formatters/clover/clover.go +++ b/formatters/clover/clover.go @@ -8,7 +8,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/codeclimate/test-reporter/env" "github.com/codeclimate/test-reporter/formatters" - "github.com/markbates/pop/nulls" "github.com/pkg/errors" ) @@ -54,10 +53,10 @@ func (f *Formatter) Parse() error { } for _, l := range pf.Lines { for num < l.Num { - sf.Coverage = append(sf.Coverage, nulls.Int{}) + sf.Coverage = append(sf.Coverage, formatters.NullInt{}) num++ } - ni := nulls.NewInt(l.Count) + ni := formatters.NewNullInt(l.Count) sf.Coverage = append(sf.Coverage, ni) num++ } diff --git a/formatters/coverage.go b/formatters/coverage.go index d31e64ba..b6b72923 100644 --- a/formatters/coverage.go +++ b/formatters/coverage.go @@ -3,14 +3,12 @@ package formatters import ( "bytes" "encoding/json" - "fmt" "strings" - "github.com/markbates/pop/nulls" "github.com/pkg/errors" ) -type Coverage []nulls.Int +type Coverage []NullInt // MarshalJSON marshals the coverage into JSON. Since the Code Climate // API requires this as a string "[1,2,null]" and not just a straight @@ -28,22 +26,24 @@ func (c Coverage) MarshalJSON() ([]byte, error) { b, err := json.Marshal(strings.TrimSpace(bb.String())) if err != nil { - fmt.Printf("### err -> %+v\n", err) return b, errors.WithStack(err) } return b, nil } +var cwp = []byte("\"") +var cws = []byte("\"") + func (c *Coverage) UnmarshalJSON(text []byte) error { - q := []byte("\"") - text = bytes.TrimPrefix(text, q) - text = bytes.TrimSuffix(text, q) - cc := []nulls.Int{} + text = bytes.TrimPrefix(text, cwp) + text = bytes.TrimSuffix(text, cws) + cc := make([]NullInt, 0, 1024) + err := json.Unmarshal(text, &cc) if err != nil { return err } - *c = append(*c, cc...) + *c = cc return nil } diff --git a/formatters/coveragepy/coveragepy.go b/formatters/coveragepy/coveragepy.go index a54a51c9..02c4f75f 100644 --- a/formatters/coveragepy/coveragepy.go +++ b/formatters/coveragepy/coveragepy.go @@ -8,7 +8,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/codeclimate/test-reporter/env" "github.com/codeclimate/test-reporter/formatters" - "github.com/markbates/pop/nulls" "github.com/pkg/errors" ) @@ -54,10 +53,10 @@ func (f *Formatter) Parse() error { num := 1 for _, l := range cc.Lines { for num < l.Number { - sf.Coverage = append(sf.Coverage, nulls.Int{}) + sf.Coverage = append(sf.Coverage, formatters.NullInt{}) num++ } - ni := nulls.NewInt(l.Hits) + ni := formatters.NewNullInt(l.Hits) sf.Coverage = append(sf.Coverage, ni) num++ } diff --git a/formatters/formatter.go b/formatters/formatter.go index 169c1a86..60c54399 100644 --- a/formatters/formatter.go +++ b/formatters/formatter.go @@ -1,7 +1,15 @@ package formatters +// Formatter needs to be implemented for each new test system type Formatter interface { + // Search for the both the "standard" paths for the formatter, + // plus any additional paths, for a file that can be parsed + // by the formatter. Search(...string) (string, error) + // Parse the file found by the Search method. Returns an error + // if there was a problem parsing the file. Parse() error + // Format the information for Parse into a standardized "Report". + // Returns an error if there was a problem formatting the results. Format() (Report, error) } diff --git a/formatters/gcov/parse.go b/formatters/gcov/parse.go index d91125b6..3cf0df8f 100644 --- a/formatters/gcov/parse.go +++ b/formatters/gcov/parse.go @@ -12,7 +12,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/codeclimate/test-reporter/env" "github.com/codeclimate/test-reporter/formatters" - "github.com/markbates/pop/nulls" "github.com/pkg/errors" ) @@ -97,15 +96,15 @@ func parseSourceFile(fileName string) (*formatters.SourceFile, error) { switch coverage { case "-": - sf.Coverage = append(sf.Coverage, nulls.Int{}) + sf.Coverage = append(sf.Coverage, formatters.NullInt{}) case "#####": - sf.Coverage = append(sf.Coverage, nulls.NewInt(0)) + sf.Coverage = append(sf.Coverage, formatters.NewNullInt(0)) default: // coverage is number of hits num, err := strconv.Atoi(coverage) if err != nil { return nil, errors.WithStack(err) } - sf.Coverage = append(sf.Coverage, nulls.NewInt(num)) + sf.Coverage = append(sf.Coverage, formatters.NewNullInt(num)) } } diff --git a/formatters/gocov/gocov.go b/formatters/gocov/gocov.go index 343687f9..95238cb0 100644 --- a/formatters/gocov/gocov.go +++ b/formatters/gocov/gocov.go @@ -11,7 +11,6 @@ import ( "github.com/codeclimate/test-reporter/env" "github.com/codeclimate/test-reporter/formatters" "github.com/gobuffalo/envy" - "github.com/markbates/pop/nulls" "github.com/pkg/errors" ) @@ -60,11 +59,11 @@ func (f *Formatter) Parse() error { num := 0 for _, b := range p.Blocks { for num < b.StartLine { - sf.Coverage = append(sf.Coverage, nulls.Int{}) + sf.Coverage = append(sf.Coverage, formatters.NullInt{}) num++ } for i := 0; i < b.NumStmt; i++ { - sf.Coverage = append(sf.Coverage, nulls.NewInt(b.Count)) + sf.Coverage = append(sf.Coverage, formatters.NewNullInt(b.Count)) num++ } } diff --git a/formatters/lcov/lcov.go b/formatters/lcov/lcov.go index 60827c33..8bb03dd7 100644 --- a/formatters/lcov/lcov.go +++ b/formatters/lcov/lcov.go @@ -10,7 +10,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/codeclimate/test-reporter/env" "github.com/codeclimate/test-reporter/formatters" - "github.com/markbates/pop/nulls" "github.com/pkg/errors" ) @@ -60,7 +59,7 @@ func (f *Formatter) Parse() error { return errors.WithStack(err) } for ln-curLine >= 1 { - sf.Coverage = append(sf.Coverage, nulls.Int{}) + sf.Coverage = append(sf.Coverage, formatters.NullInt{}) sf.CalcLineCounts() curLine++ } @@ -68,7 +67,7 @@ func (f *Formatter) Parse() error { if err != nil { return errors.WithStack(err) } - sf.Coverage = append(sf.Coverage, nulls.NewInt(lh)) + sf.Coverage = append(sf.Coverage, formatters.NewNullInt(lh)) curLine++ continue } diff --git a/formatters/null_int.go b/formatters/null_int.go new file mode 100644 index 00000000..0a453fea --- /dev/null +++ b/formatters/null_int.go @@ -0,0 +1,49 @@ +package formatters + +import ( + "encoding/json" + "strconv" +) + +// NullInt adds an implementation for int +// that supports proper JSON encoding/decoding. +type NullInt struct { + Int int + Valid bool // Valid is true if Int is not NULL +} + +func (ns NullInt) Interface() interface{} { + if !ns.Valid { + return nil + } + return ns.Int +} + +// NewNullInt returns a new, properly instantiated +// Int object. +func NewNullInt(i int) NullInt { + return NullInt{Int: i, Valid: true} +} + +// MarshalJSON marshals the underlying value to a +// proper JSON representation. +func (ns NullInt) MarshalJSON() ([]byte, error) { + if ns.Valid { + return json.Marshal(ns.Int) + } + return json.Marshal(nil) +} + +// UnmarshalJSON will unmarshal a JSON value into +// the propert representation of that value. +func (ns *NullInt) UnmarshalJSON(text []byte) error { + if i, err := strconv.ParseInt(string(text), 10, strconv.IntSize); err == nil { + ns.Valid = true + ns.Int = int(i) + } + return nil +} + +func (ns *NullInt) UnmarshalText(text []byte) error { + return ns.UnmarshalJSON(text) +} diff --git a/formatters/report_test.go b/formatters/report_test.go index 1ff887ef..896afba5 100644 --- a/formatters/report_test.go +++ b/formatters/report_test.go @@ -6,7 +6,6 @@ import ( "os" "testing" - "github.com/markbates/pop/nulls" "github.com/stretchr/testify/require" ) @@ -36,7 +35,7 @@ func Test_Report_Merge_MismatchedCoverageLength(t *testing.T) { SourceFiles: SourceFiles{ "a.go": { Name: "a.go", - Coverage: Coverage{nulls.NewInt(1)}, + Coverage: Coverage{NewNullInt(1)}, }, }, } @@ -47,7 +46,7 @@ func Test_Report_Merge_MismatchedCoverageLength(t *testing.T) { SourceFiles: SourceFiles{ "a.go": { Name: "a.go", - Coverage: Coverage{nulls.NewInt(1), nulls.NewInt(2)}, + Coverage: Coverage{NewNullInt(1), NewNullInt(2)}, }, }, } @@ -63,7 +62,7 @@ func Test_Report_Merge(t *testing.T) { rep, err := NewReport() r.NoError(err) - f, err := os.Open(fmt.Sprintf("../examples/codeclimate.%d.json", i)) + f, err := os.Open(fmt.Sprintf("../integration-tests/codeclimate.%d.json", i)) r.NoError(err) err = json.NewDecoder(f).Decode(&rep) r.NoError(err) @@ -91,7 +90,7 @@ func Test_Report_Merge(t *testing.T) { func Test_Report_JSON_Unmarshal(t *testing.T) { r := require.New(t) - f, err := os.Open("../examples/codeclimate.json") + f, err := os.Open("../integration-tests/codeclimate.json") r.NoError(err) rep, err := NewReport() @@ -121,7 +120,7 @@ func Test_Merge_Issue_103(t *testing.T) { sf := SourceFile{ Name: "app/jobs/initialize_account_seats.rb", CoveredPercent: 100, - Coverage: Coverage{nulls.NewInt(1), nulls.NewInt(1), nulls.NewInt(15), nulls.Int{}, nulls.Int{}, nulls.NewInt(1), nulls.NewInt(3), nulls.Int{}, nulls.Int{}, nulls.NewInt(1), nulls.Int{}, nulls.NewInt(1), nulls.NewInt(3), nulls.Int{}, nulls.Int{}}, + Coverage: Coverage{NewNullInt(1), NewNullInt(1), NewNullInt(15), NullInt{}, NullInt{}, NewNullInt(1), NewNullInt(3), NullInt{}, NullInt{}, NewNullInt(1), NullInt{}, NewNullInt(1), NewNullInt(3), NullInt{}, NullInt{}}, LineCounts: LineCounts{ Missed: 0, Covered: 8, @@ -136,7 +135,7 @@ func Test_Merge_Issue_103(t *testing.T) { sf2 := SourceFile{ Name: "app/jobs/initialize_account_seats.rb", CoveredPercent: 62.5, - Coverage: Coverage{nulls.NewInt(1), nulls.NewInt(1), nulls.NewInt(0), nulls.Int{}, nulls.Int{}, nulls.NewInt(1), nulls.NewInt(0), nulls.Int{}, nulls.Int{}, nulls.NewInt(1), nulls.Int{}, nulls.NewInt(1), nulls.NewInt(0), nulls.Int{}, nulls.Int{}}, + Coverage: Coverage{NewNullInt(1), NewNullInt(1), NewNullInt(0), NullInt{}, NullInt{}, NewNullInt(1), NewNullInt(0), NullInt{}, NullInt{}, NewNullInt(1), NullInt{}, NewNullInt(1), NewNullInt(0), NullInt{}, NullInt{}}, LineCounts: LineCounts{ Missed: 3, Covered: 5, diff --git a/formatters/source_file.go b/formatters/source_file.go index dbdb7c59..f698016d 100644 --- a/formatters/source_file.go +++ b/formatters/source_file.go @@ -11,7 +11,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/codeclimate/test-reporter/env" "github.com/gobuffalo/envy" - "github.com/markbates/pop/nulls" "github.com/pkg/errors" ) @@ -33,7 +32,7 @@ func (a SourceFile) Merge(b SourceFile) (SourceFile, error) { ac := a.Coverage[i] if ac.Valid && bc.Valid { // they're both valid numbers so add them: - a.Coverage[i] = nulls.NewInt(ac.Int + bc.Int) + a.Coverage[i] = NewNullInt(ac.Int + bc.Int) continue } diff --git a/formatters/source_file_test.go b/formatters/source_file_test.go index cc3f008d..b9ed2307 100644 --- a/formatters/source_file_test.go +++ b/formatters/source_file_test.go @@ -3,7 +3,6 @@ package formatters import ( "testing" - "github.com/markbates/pop/nulls" "github.com/stretchr/testify/require" ) @@ -11,18 +10,18 @@ func Test_SourceFile_Merge_With_Numbers(t *testing.T) { r := require.New(t) a := SourceFile{ BlobID: "a", - Coverage: Coverage{nulls.NewInt(0), nulls.NewInt(2), nulls.NewInt(3), nulls.NewInt(0)}, + Coverage: Coverage{NewNullInt(0), NewNullInt(2), NewNullInt(3), NewNullInt(0)}, } b := SourceFile{ BlobID: "b", - Coverage: Coverage{nulls.NewInt(1), nulls.NewInt(0), nulls.NewInt(1), nulls.NewInt(0)}, + Coverage: Coverage{NewNullInt(1), NewNullInt(0), NewNullInt(1), NewNullInt(0)}, } c, err := a.Merge(b) r.NoError(err) r.Equal("a", c.BlobID) r.Equal(4, len(c.Coverage)) - r.Equal(Coverage{nulls.NewInt(1), nulls.NewInt(2), nulls.NewInt(4), nulls.NewInt(0)}, c.Coverage) + r.Equal(Coverage{NewNullInt(1), NewNullInt(2), NewNullInt(4), NewNullInt(0)}, c.Coverage) r.InDelta(75.0, c.CoveredPercent, 1) r.InDelta(2.2, c.CoveredStrength, 1) r.Equal(LineCounts{Total: 4, Missed: 1, Covered: 3, Strength: 7}, c.LineCounts) @@ -32,18 +31,18 @@ func Test_SourceFile_Merge_With_Nulls(t *testing.T) { r := require.New(t) a := SourceFile{ BlobID: "a", - Coverage: Coverage{nulls.Int{}, nulls.NewInt(2), nulls.NewInt(3), nulls.NewInt(0)}, + Coverage: Coverage{NullInt{}, NewNullInt(2), NewNullInt(3), NewNullInt(0)}, } b := SourceFile{ BlobID: "b", - Coverage: Coverage{nulls.NewInt(1), nulls.Int{}, nulls.NewInt(3), nulls.NewInt(3)}, + Coverage: Coverage{NewNullInt(1), NullInt{}, NewNullInt(3), NewNullInt(3)}, } c, err := a.Merge(b) r.NoError(err) r.Equal("a", c.BlobID) r.Equal(4, len(c.Coverage)) - r.Equal(Coverage{nulls.Int{}, nulls.Int{}, nulls.NewInt(6), nulls.NewInt(3)}, c.Coverage) + r.Equal(Coverage{NullInt{}, NullInt{}, NewNullInt(6), NewNullInt(3)}, c.Coverage) r.InDelta(100.0, c.CoveredPercent, 1) r.InDelta(4.5, c.CoveredStrength, 1) r.Equal(LineCounts{Total: 2, Missed: 0, Covered: 2, Strength: 9}, c.LineCounts) diff --git a/examples/.coverage b/integration-tests/.coverage similarity index 100% rename from examples/.coverage rename to integration-tests/.coverage diff --git a/examples/clover/Dockerfile b/integration-tests/clover/Dockerfile similarity index 100% rename from examples/clover/Dockerfile rename to integration-tests/clover/Dockerfile diff --git a/examples/codeclimate.0.json b/integration-tests/codeclimate.0.json similarity index 100% rename from examples/codeclimate.0.json rename to integration-tests/codeclimate.0.json diff --git a/examples/codeclimate.1.json b/integration-tests/codeclimate.1.json similarity index 100% rename from examples/codeclimate.1.json rename to integration-tests/codeclimate.1.json diff --git a/examples/codeclimate.2.json b/integration-tests/codeclimate.2.json similarity index 100% rename from examples/codeclimate.2.json rename to integration-tests/codeclimate.2.json diff --git a/examples/codeclimate.3.json b/integration-tests/codeclimate.3.json similarity index 100% rename from examples/codeclimate.3.json rename to integration-tests/codeclimate.3.json diff --git a/examples/codeclimate.json b/integration-tests/codeclimate.json similarity index 100% rename from examples/codeclimate.json rename to integration-tests/codeclimate.json diff --git a/examples/coverage_py/Dockerfile b/integration-tests/coverage_py/Dockerfile similarity index 100% rename from examples/coverage_py/Dockerfile rename to integration-tests/coverage_py/Dockerfile diff --git a/examples/gcov/Dockerfile b/integration-tests/gcov/Dockerfile similarity index 100% rename from examples/gcov/Dockerfile rename to integration-tests/gcov/Dockerfile diff --git a/examples/gocov/Dockerfile b/integration-tests/gocov/Dockerfile similarity index 100% rename from examples/gocov/Dockerfile rename to integration-tests/gocov/Dockerfile diff --git a/examples/lcov/Dockerfile b/integration-tests/lcov/Dockerfile similarity index 100% rename from examples/lcov/Dockerfile rename to integration-tests/lcov/Dockerfile diff --git a/examples/simplecov/Dockerfile b/integration-tests/simplecov/Dockerfile similarity index 100% rename from examples/simplecov/Dockerfile rename to integration-tests/simplecov/Dockerfile diff --git a/upload/test_report_test.go b/upload/test_report_test.go index 96dea9fd..3d32b85b 100644 --- a/upload/test_report_test.go +++ b/upload/test_report_test.go @@ -12,7 +12,7 @@ import ( func exampleReport() (formatters.Report, error) { rep := formatters.Report{} - f, err := os.Open("../examples/codeclimate.json") + f, err := os.Open("../integration-tests/codeclimate.json") if err != nil { return rep, errors.WithStack(err) } diff --git a/vendor/github.com/markbates/pop/.gitignore b/vendor/github.com/markbates/pop/.gitignore deleted file mode 100644 index 4766eae4..00000000 --- a/vendor/github.com/markbates/pop/.gitignore +++ /dev/null @@ -1,31 +0,0 @@ -*.log -.DS_Store -doc -tmp -pkg -*.gem -*.pid -coverage -coverage.data -build/* -*.pbxuser -*.mode1v3 -.svn -profile -.console_history -.sass-cache/* -.rake_tasks~ -*.log.lck -solr/ -.jhw-cache/ -jhw.* -*.sublime* -node_modules/ -dist/ -generated/ -.vendor/ -bin/* -gin-bin -*.sqlite -vendor/ -tsoda diff --git a/vendor/github.com/markbates/pop/.travis.yml b/vendor/github.com/markbates/pop/.travis.yml deleted file mode 100644 index b9b4e518..00000000 --- a/vendor/github.com/markbates/pop/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: go - -sudo: false - -go: - - 1.7 - - 1.8 - - tip - -install: - - go get -t -v ./... - -before_script: - - go build -o tsoda ./soda - # travis hangs when trying to create mysql db using soda. not sure why - - mysql -e 'create database pop_test;' - - ./tsoda create -e "postgres" - - ./tsoda create -e "sqlite" - - ./tsoda migrate -e "mysql_travis" - - ./tsoda migrate -e "postgres" - - ./tsoda migrate -e "sqlite" - -script: go test ./... -v - -global_env: - - MYSQL_USER="travis" - - MYSQL_PASSWORD="" - - POSTGRES_PASSWORD="" - -env: - - SODA_DIALECT="postgres" - - SODA_DIALECT="mysql_travis" - - SODA_DIALECT="sqlite" - -addons: - postgresql: "9.3" - -matrix: - allow_failures: - - go: 'tip' diff --git a/vendor/github.com/markbates/pop/CHANGELOG.md b/vendor/github.com/markbates/pop/CHANGELOG.md deleted file mode 100644 index 32b9e418..00000000 --- a/vendor/github.com/markbates/pop/CHANGELOG.md +++ /dev/null @@ -1,260 +0,0 @@ -# Change Log - -## [v3.17.0](https://github.com/markbates/pop/tree/v3.17.0) (2017-04-11) -[Full Changelog](https://github.com/markbates/pop/compare/v3.16.0...v3.17.0) - -## [v3.16.0](https://github.com/markbates/pop/tree/v3.16.0) (2017-04-11) -[Full Changelog](https://github.com/markbates/pop/compare/v3.15.0...v3.16.0) - -**Closed issues:** - -- Address struct will become addres table name [\#61](https://github.com/markbates/pop/issues/61) - -## [v3.15.0](https://github.com/markbates/pop/tree/v3.15.0) (2017-04-11) -[Full Changelog](https://github.com/markbates/pop/compare/v3.14.1...v3.15.0) - -## [v3.14.1](https://github.com/markbates/pop/tree/v3.14.1) (2017-04-10) -[Full Changelog](https://github.com/markbates/pop/compare/v3.14.0...v3.14.1) - -## [v3.14.0](https://github.com/markbates/pop/tree/v3.14.0) (2017-04-10) -[Full Changelog](https://github.com/markbates/pop/compare/v3.13.7...v3.14.0) - -**Closed issues:** - -- Cannot generate a config and cannot update pop [\#60](https://github.com/markbates/pop/issues/60) -- How can I exec a raw sql query? [\#59](https://github.com/markbates/pop/issues/59) - -## [v3.13.7](https://github.com/markbates/pop/tree/v3.13.7) (2017-04-04) -[Full Changelog](https://github.com/markbates/pop/compare/v3.13.6...v3.13.7) - -**Closed issues:** - -- count is currently taking order sql [\#56](https://github.com/markbates/pop/issues/56) -- Add model generation example [\#19](https://github.com/markbates/pop/issues/19) - -## [v3.13.6](https://github.com/markbates/pop/tree/v3.13.6) (2017-03-29) -[Full Changelog](https://github.com/markbates/pop/compare/v3.13.5...v3.13.6) - -**Closed issues:** - -- allow raw sql for default value [\#53](https://github.com/markbates/pop/issues/53) -- Generated model with an already plural name fails to compile [\#37](https://github.com/markbates/pop/issues/37) -- model generation fails to compile [\#32](https://github.com/markbates/pop/issues/32) - -## [v3.13.5](https://github.com/markbates/pop/tree/v3.13.5) (2017-03-28) -[Full Changelog](https://github.com/markbates/pop/compare/v3.13.4...v3.13.5) - -**Merged pull requests:** - -- fix migrate down to correctly step down [\#54](https://github.com/markbates/pop/pull/54) ([u007](https://github.com/u007)) - -## [v3.13.4](https://github.com/markbates/pop/tree/v3.13.4) (2017-03-27) -[Full Changelog](https://github.com/markbates/pop/compare/v3.13.3...v3.13.4) - -**Closed issues:** - -- migration down roll back all? [\#47](https://github.com/markbates/pop/issues/47) - -**Merged pull requests:** - -- add uuid support for sqlite [\#52](https://github.com/markbates/pop/pull/52) ([u007](https://github.com/u007)) - -## [v3.13.3](https://github.com/markbates/pop/tree/v3.13.3) (2017-03-24) -[Full Changelog](https://github.com/markbates/pop/compare/v3.13.2...v3.13.3) - -## [v3.13.2](https://github.com/markbates/pop/tree/v3.13.2) (2017-03-21) -[Full Changelog](https://github.com/markbates/pop/compare/v3.13.1...v3.13.2) - -**Closed issues:** - -- transaction with destroy: error committing or rolling back transaction: sql: Transaction has already been committed or rolled back [\#48](https://github.com/markbates/pop/issues/48) - -**Merged pull requests:** - -- Changed config templates to use env in test case [\#51](https://github.com/markbates/pop/pull/51) ([stanislas-m](https://github.com/stanislas-m)) - -## [v3.13.1](https://github.com/markbates/pop/tree/v3.13.1) (2017-03-19) -[Full Changelog](https://github.com/markbates/pop/compare/v3.13.0...v3.13.1) - -## [v3.13.0](https://github.com/markbates/pop/tree/v3.13.0) (2017-03-19) -[Full Changelog](https://github.com/markbates/pop/compare/v3.12.1...v3.13.0) - -## [v3.12.1](https://github.com/markbates/pop/tree/v3.12.1) (2017-03-17) -[Full Changelog](https://github.com/markbates/pop/compare/v3.11.7...v3.12.1) - -**Merged pull requests:** - -- Dump load [\#50](https://github.com/markbates/pop/pull/50) ([markbates](https://github.com/markbates)) - -## [v3.11.7](https://github.com/markbates/pop/tree/v3.11.7) (2017-03-17) -[Full Changelog](https://github.com/markbates/pop/compare/v3.11.6...v3.11.7) - -**Closed issues:** - -- reflect: call of reflect.Value.Elem on struct Value [\#45](https://github.com/markbates/pop/issues/45) - -**Merged pull requests:** - -- set default migrate down to run only single migration. [\#49](https://github.com/markbates/pop/pull/49) ([u007](https://github.com/u007)) - -## [v3.11.6](https://github.com/markbates/pop/tree/v3.11.6) (2017-03-06) -[Full Changelog](https://github.com/markbates/pop/compare/v3.11.5...v3.11.6) - -## [v3.11.5](https://github.com/markbates/pop/tree/v3.11.5) (2017-03-06) -[Full Changelog](https://github.com/markbates/pop/compare/v3.12.0...v3.11.5) - -**Closed issues:** - -- Panic running soda config [\#44](https://github.com/markbates/pop/issues/44) - -## [v3.12.0](https://github.com/markbates/pop/tree/v3.12.0) (2017-03-01) -[Full Changelog](https://github.com/markbates/pop/compare/v3.11.4...v3.12.0) - -**Merged pull requests:** - -- Xela rellum xela rellum/remove connections singleton 2 [\#42](https://github.com/markbates/pop/pull/42) ([markbates](https://github.com/markbates)) - -## [v3.11.4](https://github.com/markbates/pop/tree/v3.11.4) (2017-03-01) -[Full Changelog](https://github.com/markbates/pop/compare/v3.11.3...v3.11.4) - -**Closed issues:** - -- Generated model with a name beginning with "b" fails to compile [\#38](https://github.com/markbates/pop/issues/38) - -**Merged pull requests:** - -- Fixed issue \#38. [\#39](https://github.com/markbates/pop/pull/39) ([stanislas-m](https://github.com/stanislas-m)) -- Fix model.PrimaryKeyType returning invalid type if ID column not found [\#36](https://github.com/markbates/pop/pull/36) ([SheepGoesBaa](https://github.com/SheepGoesBaa)) -- Typo fixes in README [\#30](https://github.com/markbates/pop/pull/30) ([srt32](https://github.com/srt32)) - -## [v3.11.3](https://github.com/markbates/pop/tree/v3.11.3) (2017-02-04) -[Full Changelog](https://github.com/markbates/pop/compare/v3.11.2...v3.11.3) - -**Merged pull requests:** - -- Avoid wrapping mysql table names in strings [\#29](https://github.com/markbates/pop/pull/29) ([r-butler](https://github.com/r-butler)) - -## [v3.11.2](https://github.com/markbates/pop/tree/v3.11.2) (2017-02-03) -[Full Changelog](https://github.com/markbates/pop/compare/v3.11.1...v3.11.2) - -## [v3.11.1](https://github.com/markbates/pop/tree/v3.11.1) (2017-02-02) -[Full Changelog](https://github.com/markbates/pop/compare/v3.11.0...v3.11.1) - -**Closed issues:** - -- Transaction wrapper for tests ignores Rollback result [\#26](https://github.com/markbates/pop/issues/26) - -**Merged pull requests:** - -- Distinguish between empty strings and NULL \(?\) [\#28](https://github.com/markbates/pop/pull/28) ([hyPiRion](https://github.com/hyPiRion)) -- Mem patch 3 [\#24](https://github.com/markbates/pop/pull/24) ([markbates](https://github.com/markbates)) -- Update import path for nulls [\#23](https://github.com/markbates/pop/pull/23) ([mem](https://github.com/mem)) -- Add soda generate model documentation to README.md [\#22](https://github.com/markbates/pop/pull/22) ([mem](https://github.com/mem)) -- Escape . in nrx regexp [\#21](https://github.com/markbates/pop/pull/21) ([mem](https://github.com/mem)) - -## [v3.11.0](https://github.com/markbates/pop/tree/v3.11.0) (2017-01-13) -[Full Changelog](https://github.com/markbates/pop/compare/v3.10.1...v3.11.0) - -**Merged pull requests:** - -- UUID [\#18](https://github.com/markbates/pop/pull/18) ([markbates](https://github.com/markbates)) - -## [v3.10.1](https://github.com/markbates/pop/tree/v3.10.1) (2017-01-10) -[Full Changelog](https://github.com/markbates/pop/compare/v3.10.0...v3.10.1) - -**Closed issues:** - -- mysql dialect doesn't respect port and host parameters [\#15](https://github.com/markbates/pop/issues/15) -- sqlite example incorrect? [\#13](https://github.com/markbates/pop/issues/13) -- Add "Generated by ..." comment to top of generated files [\#9](https://github.com/markbates/pop/issues/9) - -**Merged pull requests:** - -- break on first error in db create [\#17](https://github.com/markbates/pop/pull/17) ([lumost](https://github.com/lumost)) -- specify host and port for mysql dialect creation and drop [\#16](https://github.com/markbates/pop/pull/16) ([slashk](https://github.com/slashk)) -- Fix sqlite example in README [\#14](https://github.com/markbates/pop/pull/14) ([slava-vishnyakov](https://github.com/slava-vishnyakov)) - -## [v3.10.0](https://github.com/markbates/pop/tree/v3.10.0) (2017-01-05) -[Full Changelog](https://github.com/markbates/pop/compare/3.9.9...v3.10.0) - -## [3.9.9](https://github.com/markbates/pop/tree/3.9.9) (2017-01-04) -[Full Changelog](https://github.com/markbates/pop/compare/3.9.8...3.9.9) - -## [3.9.8](https://github.com/markbates/pop/tree/3.9.8) (2016-12-30) -[Full Changelog](https://github.com/markbates/pop/compare/3.9.2...3.9.8) - -**Closed issues:** - -- Inconsistency in README.md [\#12](https://github.com/markbates/pop/issues/12) -- Documentation on `default databases` clarification [\#10](https://github.com/markbates/pop/issues/10) -- Vendoring strategy for pop/sqlx [\#7](https://github.com/markbates/pop/issues/7) - -**Merged pull requests:** - -- Update README.md [\#11](https://github.com/markbates/pop/pull/11) ([webRat](https://github.com/webRat)) - -## [3.9.2](https://github.com/markbates/pop/tree/3.9.2) (2016-11-27) -[Full Changelog](https://github.com/markbates/pop/compare/v3.8.0...3.9.2) - -**Closed issues:** - -- Roadmap or feature-complete? [\#8](https://github.com/markbates/pop/issues/8) - -## [v3.8.0](https://github.com/markbates/pop/tree/v3.8.0) (2016-08-30) -[Full Changelog](https://github.com/markbates/pop/compare/v3.7.2...v3.8.0) - -## [v3.7.2](https://github.com/markbates/pop/tree/v3.7.2) (2016-08-26) -[Full Changelog](https://github.com/markbates/pop/compare/v3.7.1...v3.7.2) - -## [v3.7.1](https://github.com/markbates/pop/tree/v3.7.1) (2016-08-26) -[Full Changelog](https://github.com/markbates/pop/compare/v3.7.0...v3.7.1) - -## [v3.7.0](https://github.com/markbates/pop/tree/v3.7.0) (2016-08-26) -[Full Changelog](https://github.com/markbates/pop/compare/v3.6.2...v3.7.0) - -## [v3.6.2](https://github.com/markbates/pop/tree/v3.6.2) (2016-08-26) -[Full Changelog](https://github.com/markbates/pop/compare/v3.6.1...v3.6.2) - -## [v3.6.1](https://github.com/markbates/pop/tree/v3.6.1) (2016-08-26) -[Full Changelog](https://github.com/markbates/pop/compare/v3.6.0...v3.6.1) - -## [v3.6.0](https://github.com/markbates/pop/tree/v3.6.0) (2016-08-26) -[Full Changelog](https://github.com/markbates/pop/compare/v3.5.1.1...v3.6.0) - -## [v3.5.1.1](https://github.com/markbates/pop/tree/v3.5.1.1) (2016-08-26) -[Full Changelog](https://github.com/markbates/pop/compare/v3.5.2...v3.5.1.1) - -## [v3.5.2](https://github.com/markbates/pop/tree/v3.5.2) (2016-08-26) -[Full Changelog](https://github.com/markbates/pop/compare/v3.5.1...v3.5.2) - -## [v3.5.1](https://github.com/markbates/pop/tree/v3.5.1) (2016-08-26) -[Full Changelog](https://github.com/markbates/pop/compare/v3.5.0...v3.5.1) - -## [v3.5.0](https://github.com/markbates/pop/tree/v3.5.0) (2016-08-25) -[Full Changelog](https://github.com/markbates/pop/compare/v3.4.1...v3.5.0) - -## [v3.4.1](https://github.com/markbates/pop/tree/v3.4.1) (2016-08-25) -[Full Changelog](https://github.com/markbates/pop/compare/v3.4.0...v3.4.1) - -## [v3.4.0](https://github.com/markbates/pop/tree/v3.4.0) (2016-08-25) -[Full Changelog](https://github.com/markbates/pop/compare/v3.3.1...v3.4.0) - -## [v3.3.1](https://github.com/markbates/pop/tree/v3.3.1) (2016-08-23) -[Full Changelog](https://github.com/markbates/pop/compare/v3.3.0...v3.3.1) - -## [v3.3.0](https://github.com/markbates/pop/tree/v3.3.0) (2016-08-19) -**Closed issues:** - -- Add dialect detection via the Parse function [\#1](https://github.com/markbates/pop/issues/1) - -**Merged pull requests:** - -- Fizz [\#6](https://github.com/markbates/pop/pull/6) ([markbates](https://github.com/markbates)) -- Remove unused column cache [\#5](https://github.com/markbates/pop/pull/5) ([timraymond](https://github.com/timraymond)) -- Sqlite [\#4](https://github.com/markbates/pop/pull/4) ([markbates](https://github.com/markbates)) -- Thread Safety Dance [\#3](https://github.com/markbates/pop/pull/3) ([timraymond](https://github.com/timraymond)) -- Use url scheme as ConnectionDetails' dialect [\#2](https://github.com/markbates/pop/pull/2) ([jboursiquot](https://github.com/jboursiquot)) - - - -\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file diff --git a/vendor/github.com/markbates/pop/Dockerfile b/vendor/github.com/markbates/pop/Dockerfile deleted file mode 100644 index d6d0b03d..00000000 --- a/vendor/github.com/markbates/pop/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -from golang:1.7 - -RUN echo $GOPATH -RUN mkdir -p $GOPATH/src/github.com/markbates/pop -WORKDIR $GOPATH/src/github.com/markbates/pop -ADD . . -RUN go get -t -v ./... -RUN SODA_DIALECT=sqlite go test ./... diff --git a/vendor/github.com/markbates/pop/LICENSE.txt b/vendor/github.com/markbates/pop/LICENSE.txt deleted file mode 100644 index 36df95c0..00000000 --- a/vendor/github.com/markbates/pop/LICENSE.txt +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015 Mark Bates - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/markbates/pop/README.md b/vendor/github.com/markbates/pop/README.md deleted file mode 100644 index c1a7408b..00000000 --- a/vendor/github.com/markbates/pop/README.md +++ /dev/null @@ -1,222 +0,0 @@ -# POP [![GoDoc](https://godoc.org/github.com/markbates/pop?status.svg)](https://godoc.org/github.com/markbates/pop) [![Build Status](https://travis-ci.org/markbates/pop.svg)](https://travis-ci.org/markbates/pop) - -## A Tasty Treat For All Your Database Needs - -So what does Pop do exactly? Well, it wraps the absolutely amazing [https://github.com/jmoiron/sqlx](https://github.com/jmoiron/sqlx) library. It cleans up some of the common patterns and workflows usually associated with dealing with databases in Go. - -Pop makes it easy to do CRUD operations, run migrations, and build/execute queries. Is Pop an ORM? I'll leave that up to you, the reader, to decide. - -Pop, by default, follows conventions that were defined by the ActiveRecord Ruby gem, http://www.rubyonrails.org. What does this mean? - -* Tables must have an "id" column and a corresponding "ID" field on the `struct` being used. -* If there is a timestamp column named "created_at", "CreatedAt" on the `struct`, it will be set with the current time when the record is created. -* If there is a timestamp column named "updated_at", "UpdatedAt" on the `struct`, it will be set with the current time when the record is updated. -* Default database table names are lowercase, plural, and underscored versions of the `struct` name. Examples: User{} is "users", FooBar{} is "foo_bars", etc... - -## Supported Databases - -* PostgreSQL (>= 9.3) -* MySQL (>= 5.7) -* SQLite (>= 3.x) - -## Connecting to Databases - -Pop is easily configured using a YAML file. The configuration file should be stored in `config/database.yml` or `database.yml`. - -#### Example Configuration File - -```yaml -development: - dialect: "postgres" - database: "your_db_development" - host: "localhost" - port: "5432" - user: "postgres" - password: "postgres" - -test: - dialect: "mysql" - database: "your_db_test" - host: "localhost" - port: "3306" - user: "root" - password: "root" - -staging: - dialect: "sqlite3" - database: "./staging.sqlite" - -production: - dialect: "postgres" - url: {{ env "DATABASE_URL" }} -``` - -Note that the `database.yml` file is also a Go template, so you can use Go template syntax. There are two special functions that are included, `env` and `envOr`. - -* `env` - This function will look for the named environment variable and insert it into your file. This is useful for configuring production databases without having to store secret information in your repository. `{{ env "DATABASE_URL" }}` -* `envOr` - This function will look for the named environment variable and use it. If the variable can not be found a default value will be used. `{{ envOr "MYSQL_HOST" "localhost" }}` - -You can generate a default configuration file using the `init` command: - -``` -$ soda g config -``` - -The default will generate a `database.yml` file in the current directory for a PostgreSQL database. You can override the type of database using the `-t` flag and passing in any of the supported database types: `postgres`, `mysql`, or `sqlite3`. - -### In your code - -Once you have a configuration file defined you can easily connect to one of these connections in your application. - -```go -db, err := pop.Connect("development") -if err != nil { - log.Panic(err) -} -``` - -Now that you have your connection to the database you can start executing queries against it. - -## CLI Support - -Pop features CLI support via the `soda` command for the following operations: - -* creating databases -* dropping databases -* migrating databases - -### Installing CLI Support - -```bash -$ go get github.com/markbates/pop/... -$ go install github.com/markbates/pop/soda -``` - -### Creating Databases - -Assuming you defined a configuration file like that described in the above section you can automatically create those databases using the `soda` command: - -#### Create All Databases - -```bash -$ soda create -a -``` - -#### Create a Specific Database - -```bash -$ soda create -e development -``` - -### Dropping Databases - -Assuming you defined a configuration file like that described in the above section you can automatically drop those databases using the `soda` command: - -#### Drop All Databases - -```bash -$ soda drop -a -``` - -#### Drop a Specific Database - -```bash -$ soda drop -e development -``` - -### Models - -The `soda` command supports the generation of models. - -A full list of commands available for model generation can be found by asking for help: - -```bash -$ soda generate help -``` - -#### Generate Models - -The `soda` command will generate Go models and, optionally, the associated migrations for you. - -```bash -$ soda generate model user name:text email:text -``` - -Running this command with generate the following files: - -```text -models/user.go -models/user_test.go -migrations/20170115024143_create_users.up.fizz -migrations/20170115024143_create_users.down.fizz -``` - -The `models/user.go` file contains a structure named `User` with fields `ID`, `CreatedAt`, `UpdatedAt`, `Name`, and `Email`. The first three correspond to the columns commonly found in ActiveRecord models as mentioned before, and the last two correspond to the additional fields specified on the command line. The known types are: - -* `text` (`string` in Go) -* `time` or `timestamp` (`time.Time`) -* `nulls.Text` (`nulls.String`) which corresponds to a nullifyable string, which can be distinguished from an empty string -* `uuid` (`uuid.UUID`) -* Other types are passed thru and are used as [Fizz](./fizz/README.md) types. - -The `models/user_test.go` contains tests for the User model and they must be implemented by you. - -The other two files correspond to the migrations as explained below. - -### Migrations - -The `soda` command supports the creation and running of migrations. - -A full list of commands available for migration can be found by asking for help: - -```bash -$ soda migrate help -``` - -#### Create Migrations - -The `soda` command will generate SQL migrations (both the up and down) files for you. - -```bash -$ soda migrate create name_of_migration -``` - -Running this command with generate the following files: - -```text -./migrations/20160815134952_name_of_migration.up.fizz -./migrations/20160815134952_name_of_migration.down.fizz -``` - -The generated files are `fizz` files. [Fizz](./fizz/README.md) lets you use a common DSL for generating migrations. This means the same `.fizz` file can be run against any of the supported dialects of Pop! Find out more about [Fizz](./fizz/README.md) - -If you want to generate old fashion `.sql` files you can use the `-t` flag for that: - -```bash -$ soda migrate create name_of_migration -t sql -``` - -Running this command with generate the following files: - -```text -./migrations/20160815134952_name_of_migration.up.sql -./migrations/20160815134952_name_of_migration.down.sql -``` - -The `soda migrate` command supports both `.fizz` and `.sql` files, so you can mix and match them to suit your needs. - -#### Running Migrations - -The `soda` command will run the migrations using the following command: - -```bash -$ soda migrate up -``` - -Migrations will be run in sequential order. The previously run migrations will be kept track of in a table named `schema_migrations` in the database. - -Migrations can also be run in reverse to rollback the schema. - -```bash -$ soda migrate down -``` diff --git a/vendor/github.com/markbates/pop/belongs_to.go b/vendor/github.com/markbates/pop/belongs_to.go deleted file mode 100644 index de247ef4..00000000 --- a/vendor/github.com/markbates/pop/belongs_to.go +++ /dev/null @@ -1,33 +0,0 @@ -package pop - -import "fmt" - -// BelongsTo adds a "where" clause based on the "ID" of the -// "model" passed into it. -func (c *Connection) BelongsTo(model interface{}) *Query { - return Q(c).BelongsTo(model) -} - -// BelongsTo adds a "where" clause based on the "ID" of the -// "model" passed into it. -func (q *Query) BelongsTo(model interface{}) *Query { - m := &Model{Value: model} - q.Where(fmt.Sprintf("%s = ?", m.associationName()), m.ID()) - return q -} - -// BelongsToThrough adds a "where" clause that connects the "bt" model -// through the associated "thru" model. -func (c *Connection) BelongsToThrough(bt, thru interface{}) *Query { - return Q(c).BelongsToThrough(bt, thru) -} - -// BelongsToThrough adds a "where" clause that connects the "bt" model -// through the associated "thru" model. -func (q *Query) BelongsToThrough(bt, thru interface{}) *Query { - q.belongsToThroughClauses = append(q.belongsToThroughClauses, belongsToThroughClause{ - BelongsTo: &Model{Value: bt}, - Through: &Model{Value: thru}, - }) - return q -} diff --git a/vendor/github.com/markbates/pop/belongs_to_test.go b/vendor/github.com/markbates/pop/belongs_to_test.go deleted file mode 100644 index 181f7dfc..00000000 --- a/vendor/github.com/markbates/pop/belongs_to_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package pop_test - -import ( - "testing" - - "github.com/markbates/pop" - "github.com/stretchr/testify/require" -) - -func Test_BelongsTo(t *testing.T) { - r := require.New(t) - - q := PDB.BelongsTo(&User{ID: 1}) - - m := &pop.Model{Value: &Enemy{}} - - sql, _ := q.ToSQL(m) - r.Equal(ts("SELECT enemies.A FROM enemies AS enemies WHERE user_id = ?"), sql) -} - -func Test_BelongsToThrough(t *testing.T) { - r := require.New(t) - - q := PDB.BelongsToThrough(&User{ID: 1}, &Friend{}) - qs := "SELECT enemies.A FROM enemies AS enemies, good_friends AS good_friends WHERE good_friends.user_id = ? AND enemies.id = good_friends.enemy_id" - - m := &pop.Model{Value: &Enemy{}} - sql, _ := q.ToSQL(m) - r.Equal(ts(qs), sql) -} diff --git a/vendor/github.com/markbates/pop/bench.sh b/vendor/github.com/markbates/pop/bench.sh deleted file mode 100755 index e5e92b82..00000000 --- a/vendor/github.com/markbates/pop/bench.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -set +e - -clear - -echo "postgres" -SODA_DIALECT=postgres go test -bench=. -echo "--------------------" -echo "mysql" -SODA_DIALECT=mysql go test -bench=. -echo "--------------------" -echo "sqlite" -SODA_DIALECT=sqlite go test -bench=. diff --git a/vendor/github.com/markbates/pop/benchmarks_test.go b/vendor/github.com/markbates/pop/benchmarks_test.go deleted file mode 100644 index 7173c43d..00000000 --- a/vendor/github.com/markbates/pop/benchmarks_test.go +++ /dev/null @@ -1,115 +0,0 @@ -package pop_test - -import ( - "fmt" - "strconv" - "testing" - - "github.com/markbates/pop" - "github.com/markbates/pop/nulls" -) - -func Benchmark_Create_Pop(b *testing.B) { - transaction(func(tx *pop.Connection) { - for n := 0; n < b.N; n++ { - u := &User{ - Name: nulls.NewString("Mark Bates"), - } - tx.Create(u) - } - }) -} - -func Benchmark_Create_Raw(b *testing.B) { - transaction(func(tx *pop.Connection) { - for n := 0; n < b.N; n++ { - u := &User{ - Name: nulls.NewString("Mark Bates"), - } - q := "INSERT INTO users (alive, bio, birth_date, created_at, name, price, updated_at) VALUES (:alive, :bio, :birth_date, :created_at, :name, :price, :updated_at)" - tx.Store.NamedExec(q, u) - } - }) -} - -func Benchmark_Update(b *testing.B) { - transaction(func(tx *pop.Connection) { - u := &User{ - Name: nulls.NewString("Mark Bates"), - } - tx.Create(u) - for n := 0; n < b.N; n++ { - tx.Update(u) - } - }) -} - -func Benchmark_Find_Pop(b *testing.B) { - transaction(func(tx *pop.Connection) { - u := &User{ - Name: nulls.NewString("Mark Bates"), - } - tx.Create(u) - for n := 0; n < b.N; n++ { - tx.Find(u, u.ID) - } - }) -} - -func Benchmark_Find_Raw(b *testing.B) { - transaction(func(tx *pop.Connection) { - u := &User{ - Name: nulls.NewString("Mark Bates"), - } - tx.Create(u) - for n := 0; n < b.N; n++ { - tx.Store.Get(u, "select * from users where id = ?", u.ID) - } - }) -} - -func Benchmark_translateOne(b *testing.B) { - q := "select * from users where id = ? and name = ? and email = ? and a = ? and b = ? and c = ? and d = ? and e = ? and f = ?" - for n := 0; n < b.N; n++ { - translateOne(q) - } -} - -func Benchmark_translateTwo(b *testing.B) { - q := "select * from users where id = ? and name = ? and email = ? and a = ? and b = ? and c = ? and d = ? and e = ? and f = ?" - for n := 0; n < b.N; n++ { - translateTwo(q) - } -} - -func translateOne(sql string) string { - curr := 1 - out := make([]byte, 0, len(sql)) - for i := 0; i < len(sql); i++ { - if sql[i] == '?' { - str := "$" + strconv.Itoa(curr) - for _, char := range str { - out = append(out, byte(char)) - } - curr += 1 - } else { - out = append(out, sql[i]) - } - } - return string(out) -} - -func translateTwo(sql string) string { - curr := 1 - csql := "" - for i := 0; i < len(sql); i++ { - x := sql[i] - if x == '?' { - csql = fmt.Sprintf("%s$%d", csql, curr) - curr++ - } else { - csql += string(x) - } - } - return csql -} diff --git a/vendor/github.com/markbates/pop/clause.go b/vendor/github.com/markbates/pop/clause.go deleted file mode 100644 index b87638d4..00000000 --- a/vendor/github.com/markbates/pop/clause.go +++ /dev/null @@ -1,56 +0,0 @@ -package pop - -import ( - "fmt" - "strings" -) - -type clause struct { - Fragment string - Arguments []interface{} -} - -type clauses []clause - -func (c clauses) Join(sep string) string { - out := make([]string, 0, len(c)) - for _, clause := range c { - out = append(out, clause.Fragment) - } - return strings.Join(out, sep) -} - -func (c clauses) Args() (args []interface{}) { - for _, clause := range c { - for _, arg := range clause.Arguments { - args = append(args, arg) - } - } - return -} - -type fromClause struct { - From string - As string -} - -type fromClauses []fromClause - -func (c fromClause) String() string { - return fmt.Sprintf("%s AS %s", c.From, c.As) -} - -func (c fromClauses) String() string { - cs := []string{} - for _, cl := range c { - cs = append(cs, cl.String()) - } - return strings.Join(cs, ", ") -} - -type belongsToThroughClause struct { - BelongsTo *Model - Through *Model -} - -type belongsToThroughClauses []belongsToThroughClause diff --git a/vendor/github.com/markbates/pop/columns/column.go b/vendor/github.com/markbates/pop/columns/column.go deleted file mode 100644 index 63eb5370..00000000 --- a/vendor/github.com/markbates/pop/columns/column.go +++ /dev/null @@ -1,20 +0,0 @@ -package columns - -import "fmt" - -type Column struct { - Name string - Writeable bool - Readable bool - SelectSQL string -} - -func (c Column) UpdateString() string { - return fmt.Sprintf("%s = :%s", c.Name, c.Name) -} - -func (c *Column) SetSelectSQL(s string) { - c.SelectSQL = s - c.Writeable = false - c.Readable = true -} diff --git a/vendor/github.com/markbates/pop/columns/column_test.go b/vendor/github.com/markbates/pop/columns/column_test.go deleted file mode 100644 index 892bd23b..00000000 --- a/vendor/github.com/markbates/pop/columns/column_test.go +++ /dev/null @@ -1,14 +0,0 @@ -package columns_test - -import ( - "testing" - - "github.com/markbates/pop/columns" - "github.com/stretchr/testify/require" -) - -func Test_Column_UpdateString(t *testing.T) { - r := require.New(t) - c := columns.Column{Name: "foo"} - r.Equal(c.UpdateString(), "foo = :foo") -} diff --git a/vendor/github.com/markbates/pop/columns/columns.go b/vendor/github.com/markbates/pop/columns/columns.go deleted file mode 100644 index f1bf6e7b..00000000 --- a/vendor/github.com/markbates/pop/columns/columns.go +++ /dev/null @@ -1,107 +0,0 @@ -package columns - -import ( - "fmt" - "sort" - "strings" - "sync" -) - -type Columns struct { - Cols map[string]*Column - lock *sync.RWMutex - TableName string -} - -// Add a column to the list. -func (c *Columns) Add(names ...string) []*Column { - ret := []*Column{} - c.lock.Lock() - for _, name := range names { - xs := strings.Split(name, ",") - col := c.Cols[xs[0]] - if col == nil { - ss := xs[0] - if c.TableName != "" { - ss = fmt.Sprintf("%s.%s", c.TableName, ss) - } - col = &Column{ - Name: xs[0], - SelectSQL: ss, - Readable: true, - Writeable: true, - } - - if len(xs) > 1 { - if xs[1] == "r" { - col.Writeable = false - } - if xs[1] == "w" { - col.Readable = false - } - } else if col.Name == "id" { - col.Writeable = false - } - - c.Cols[col.Name] = col - } - ret = append(ret, col) - } - c.lock.Unlock() - return ret -} - -// Remove a column from the list. -func (c *Columns) Remove(names ...string) { - for _, name := range names { - xs := strings.Split(name, ",") - name = xs[0] - delete(c.Cols, name) - } -} - -func (c Columns) Writeable() *WriteableColumns { - w := &WriteableColumns{NewColumns(c.TableName)} - for _, col := range c.Cols { - if col.Writeable { - w.Cols[col.Name] = col - } - } - return w -} - -func (c Columns) Readable() *ReadableColumns { - w := &ReadableColumns{NewColumns(c.TableName)} - for _, col := range c.Cols { - if col.Readable { - w.Cols[col.Name] = col - } - } - return w -} - -func (c Columns) String() string { - xs := []string{} - for _, t := range c.Cols { - xs = append(xs, t.Name) - } - sort.Strings(xs) - return strings.Join(xs, ", ") -} - -func (c Columns) SymbolizedString() string { - xs := []string{} - for _, t := range c.Cols { - xs = append(xs, ":"+t.Name) - } - sort.Strings(xs) - return strings.Join(xs, ", ") -} - -func NewColumns(tableName string) Columns { - return Columns{ - lock: &sync.RWMutex{}, - Cols: map[string]*Column{}, - TableName: tableName, - } -} diff --git a/vendor/github.com/markbates/pop/columns/columns_for_struct.go b/vendor/github.com/markbates/pop/columns/columns_for_struct.go deleted file mode 100644 index d4bc72a1..00000000 --- a/vendor/github.com/markbates/pop/columns/columns_for_struct.go +++ /dev/null @@ -1,52 +0,0 @@ -package columns - -import "reflect" - -// ColumnsForStruct returns a Columns instance for -// the struct passed in. -func ColumnsForStruct(s interface{}, tableName string) (columns Columns) { - columns = NewColumns(tableName) - defer func() { - if r := recover(); r != nil { - columns = NewColumns(tableName) - columns.Add("*") - } - }() - st := reflect.TypeOf(s) - if st.Kind() == reflect.Ptr { - st = reflect.ValueOf(s).Elem().Type() - } - if st.Kind() == reflect.Slice { - v := reflect.ValueOf(s) - t := v.Type() - x := t.Elem().Elem() - - n := reflect.New(x) - return ColumnsForStruct(n.Interface(), tableName) - } - - field_count := st.NumField() - - for i := 0; i < field_count; i++ { - field := st.Field(i) - tag := field.Tag.Get("db") - if tag == "" { - tag = field.Name - } - - if tag != "-" { - rw := field.Tag.Get("rw") - if rw != "" { - tag = tag + "," + rw - } - cs := columns.Add(tag) - c := cs[0] - tag = field.Tag.Get("select") - if tag != "" { - c.SetSelectSQL(tag) - } - } - } - - return columns -} diff --git a/vendor/github.com/markbates/pop/columns/columns_test.go b/vendor/github.com/markbates/pop/columns/columns_test.go deleted file mode 100644 index a26d8590..00000000 --- a/vendor/github.com/markbates/pop/columns/columns_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package columns_test - -import ( - "testing" - - "github.com/markbates/pop/columns" - "github.com/stretchr/testify/require" -) - -type foo struct { - FirstName string `db:"first_name" select:"first_name as f"` - LastName string - Unwanted string `db:"-"` - ReadOnly string `db:"read" rw:"r"` - WriteOnly string `db:"write" rw:"w"` -} - -type foos []foo - -func Test_Column_MapsSlice(t *testing.T) { - r := require.New(t) - - c1 := columns.ColumnsForStruct(&foo{}, "foo") - c2 := columns.ColumnsForStruct(&foos{}, "foo") - r.Equal(c1.String(), c2.String()) -} - -func Test_Columns_Basics(t *testing.T) { - r := require.New(t) - - for _, f := range []interface{}{foo{}, &foo{}} { - c := columns.ColumnsForStruct(f, "foo") - r.Equal(len(c.Cols), 4) - r.Equal(c.Cols["first_name"], &columns.Column{Name: "first_name", Writeable: false, Readable: true, SelectSQL: "first_name as f"}) - r.Equal(c.Cols["LastName"], &columns.Column{Name: "LastName", Writeable: true, Readable: true, SelectSQL: "foo.LastName"}) - r.Equal(c.Cols["read"], &columns.Column{Name: "read", Writeable: false, Readable: true, SelectSQL: "foo.read"}) - r.Equal(c.Cols["write"], &columns.Column{Name: "write", Writeable: true, Readable: false, SelectSQL: "foo.write"}) - } -} - -func Test_Columns_Add(t *testing.T) { - r := require.New(t) - - for _, f := range []interface{}{foo{}, &foo{}} { - c := columns.ColumnsForStruct(f, "foo") - r.Equal(len(c.Cols), 4) - c.Add("foo", "first_name") - r.Equal(len(c.Cols), 5) - r.Equal(c.Cols["foo"], &columns.Column{Name: "foo", Writeable: true, Readable: true, SelectSQL: "foo.foo"}) - } -} - -func Test_Columns_Remove(t *testing.T) { - r := require.New(t) - - for _, f := range []interface{}{foo{}, &foo{}} { - c := columns.ColumnsForStruct(f, "foo") - r.Equal(len(c.Cols), 4) - c.Remove("foo", "first_name") - r.Equal(len(c.Cols), 3) - } -} diff --git a/vendor/github.com/markbates/pop/columns/readable_columns.go b/vendor/github.com/markbates/pop/columns/readable_columns.go deleted file mode 100644 index f71fae74..00000000 --- a/vendor/github.com/markbates/pop/columns/readable_columns.go +++ /dev/null @@ -1,19 +0,0 @@ -package columns - -import ( - "sort" - "strings" -) - -type ReadableColumns struct { - Columns -} - -func (c ReadableColumns) SelectString() string { - xs := []string{} - for _, t := range c.Cols { - xs = append(xs, t.SelectSQL) - } - sort.Strings(xs) - return strings.Join(xs, ", ") -} diff --git a/vendor/github.com/markbates/pop/columns/readable_columns_test.go b/vendor/github.com/markbates/pop/columns/readable_columns_test.go deleted file mode 100644 index 38347104..00000000 --- a/vendor/github.com/markbates/pop/columns/readable_columns_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package columns_test - -import ( - "testing" - - "github.com/markbates/pop/columns" - "github.com/stretchr/testify/require" -) - -func Test_Columns_ReadableString(t *testing.T) { - r := require.New(t) - for _, f := range []interface{}{foo{}, &foo{}} { - c := columns.ColumnsForStruct(f, "foo") - u := c.Readable().String() - r.Equal(u, "LastName, first_name, read") - } -} - -func Test_Columns_Readable_SelectString(t *testing.T) { - r := require.New(t) - for _, f := range []interface{}{foo{}, &foo{}} { - c := columns.ColumnsForStruct(f, "foo") - u := c.Readable().SelectString() - r.Equal(u, "first_name as f, foo.LastName, foo.read") - } -} - -func Test_Columns_ReadableString_Symbolized(t *testing.T) { - r := require.New(t) - for _, f := range []interface{}{foo{}, &foo{}} { - c := columns.ColumnsForStruct(f, "foo") - u := c.Readable().SymbolizedString() - r.Equal(u, ":LastName, :first_name, :read") - } -} diff --git a/vendor/github.com/markbates/pop/columns/writeable_columns.go b/vendor/github.com/markbates/pop/columns/writeable_columns.go deleted file mode 100644 index 593df655..00000000 --- a/vendor/github.com/markbates/pop/columns/writeable_columns.go +++ /dev/null @@ -1,19 +0,0 @@ -package columns - -import ( - "sort" - "strings" -) - -type WriteableColumns struct { - Columns -} - -func (c WriteableColumns) UpdateString() string { - xs := []string{} - for _, t := range c.Cols { - xs = append(xs, t.UpdateString()) - } - sort.Strings(xs) - return strings.Join(xs, ", ") -} diff --git a/vendor/github.com/markbates/pop/columns/writeable_columns_test.go b/vendor/github.com/markbates/pop/columns/writeable_columns_test.go deleted file mode 100644 index ed6a47b3..00000000 --- a/vendor/github.com/markbates/pop/columns/writeable_columns_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package columns_test - -import ( - "testing" - - "github.com/markbates/pop/columns" - "github.com/stretchr/testify/require" -) - -func Test_Columns_WriteableString_Symbolized(t *testing.T) { - r := require.New(t) - for _, f := range []interface{}{foo{}, &foo{}} { - c := columns.ColumnsForStruct(f, "foo") - u := c.Writeable().SymbolizedString() - r.Equal(u, ":LastName, :write") - } -} - -func Test_Columns_UpdateString(t *testing.T) { - r := require.New(t) - for _, f := range []interface{}{foo{}, &foo{}} { - c := columns.ColumnsForStruct(f, "foo") - u := c.Writeable().UpdateString() - r.Equal(u, "LastName = :LastName, write = :write") - } -} - -func Test_Columns_WriteableString(t *testing.T) { - r := require.New(t) - for _, f := range []interface{}{foo{}, &foo{}} { - c := columns.ColumnsForStruct(f, "foo") - u := c.Writeable().String() - r.Equal(u, "LastName, write") - } -} diff --git a/vendor/github.com/markbates/pop/commands.go b/vendor/github.com/markbates/pop/commands.go deleted file mode 100644 index b18cde8f..00000000 --- a/vendor/github.com/markbates/pop/commands.go +++ /dev/null @@ -1,25 +0,0 @@ -package pop - -import ( - "fmt" - - "github.com/pkg/errors" -) - -func CreateDB(c *Connection) error { - deets := c.Dialect.Details() - if deets.Database != "" { - Log(fmt.Sprintf("Create %s (%s)", deets.Database, c.URL())) - return errors.Wrapf(c.Dialect.CreateDB(), "couldn't create database %s", deets.Database) - } - return nil -} - -func DropDB(c *Connection) error { - deets := c.Dialect.Details() - if deets.Database != "" { - Log(fmt.Sprintf("Drop %s (%s)", deets.Database, c.URL())) - return errors.Wrapf(c.Dialect.DropDB(), "couldn't drop database %s", deets.Database) - } - return nil -} diff --git a/vendor/github.com/markbates/pop/config.go b/vendor/github.com/markbates/pop/config.go deleted file mode 100644 index 2762ffd5..00000000 --- a/vendor/github.com/markbates/pop/config.go +++ /dev/null @@ -1,102 +0,0 @@ -package pop - -import ( - "bytes" - "fmt" - "html/template" - "io/ioutil" - "os" - "path/filepath" - - "github.com/pkg/errors" - - "github.com/markbates/going/defaults" - "gopkg.in/yaml.v2" -) - -var lookupPaths = []string{"", "./config", "/config", "../", "../config", "../..", "../../config"} -var ConfigName = "database.yml" - -func init() { - ap := os.Getenv("APP_PATH") - if ap != "" { - AddLookupPaths(ap) - } - ap = os.Getenv("POP_PATH") - if ap != "" { - AddLookupPaths(ap) - } - LoadConfig() -} - -func LoadConfig() error { - path, err := findConfigPath() - if err != nil { - return errors.WithStack(err) - } - Connections = map[string]*Connection{} - return loadConfig(path) -} - -func LookupPaths() []string { - return lookupPaths -} - -func AddLookupPaths(paths ...string) error { - lookupPaths = append(paths, lookupPaths...) - return LoadConfig() -} - -func findConfigPath() (string, error) { - for _, p := range LookupPaths() { - path, _ := filepath.Abs(filepath.Join(p, ConfigName)) - if _, err := os.Stat(path); err == nil { - return path, err - } - } - return "", errors.New("[POP]: Tried to load configuration file, but couldn't find it.") -} - -func loadConfig(path string) error { - if Debug { - fmt.Printf("[POP]: Loading config file from %s\n", path) - } - b, err := ioutil.ReadFile(path) - if err != nil { - return errors.Wrapf(err, "couldn't read file %s", path) - } - - tmpl := template.New("test") - tmpl.Funcs(map[string]interface{}{ - "envOr": func(s1, s2 string) string { - return defaults.String(os.Getenv(s1), s2) - }, - "env": func(s1 string) string { - return os.Getenv(s1) - }, - }) - t, err := tmpl.Parse(string(b)) - if err != nil { - return errors.Wrap(err, "couldn't parse config template") - } - - var bb bytes.Buffer - err = t.Execute(&bb, nil) - if err != nil { - return errors.Wrap(err, "couldn't execute config template") - } - - deets := map[string]*ConnectionDetails{} - err = yaml.Unmarshal(bb.Bytes(), &deets) - if err != nil { - return errors.Wrap(err, "couldn't unmarshal config to yaml") - } - for n, d := range deets { - con, err := NewConnection(d) - if err != nil { - return err - } - Connections[n] = con - } - return nil -} diff --git a/vendor/github.com/markbates/pop/config_test.go b/vendor/github.com/markbates/pop/config_test.go deleted file mode 100644 index a93d0afa..00000000 --- a/vendor/github.com/markbates/pop/config_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package pop_test - -import ( - "testing" - - "github.com/markbates/pop" - "github.com/stretchr/testify/require" -) - -func Test_LoadsConnectionsFromConfig(t *testing.T) { - r := require.New(t) - - conns := pop.Connections - r.Equal(4, len(conns)) -} - -func Test_AddLookupPaths(t *testing.T) { - r := require.New(t) - pop.AddLookupPaths("./foo") - r.Contains(pop.LookupPaths(), "./foo") -} diff --git a/vendor/github.com/markbates/pop/connection.go b/vendor/github.com/markbates/pop/connection.go deleted file mode 100644 index 0d21bc95..00000000 --- a/vendor/github.com/markbates/pop/connection.go +++ /dev/null @@ -1,175 +0,0 @@ -package pop - -import ( - "sync/atomic" - "time" - - "github.com/jmoiron/sqlx" - "github.com/markbates/going/defaults" - "github.com/markbates/going/randx" - "github.com/pkg/errors" -) - -// Connections contains all of the available connections -var Connections = map[string]*Connection{} - -// Connection represents all of the necessary details for -// talking with a datastore -type Connection struct { - ID string - Store store - Dialect dialect - Elapsed int64 - TX *tX -} - -func (c *Connection) String() string { - return c.URL() -} - -func (c *Connection) URL() string { - return c.Dialect.URL() -} - -func (c *Connection) MigrationURL() string { - return c.Dialect.MigrationURL() -} - -// NewConnection creates a new connection, and sets it's `Dialect` -// appropriately based on the `ConnectionDetails` passed into it. -func NewConnection(deets *ConnectionDetails) (*Connection, error) { - err := deets.Finalize() - if err != nil { - return nil, errors.Wrap(err, "could not create a new connection") - } - c := &Connection{ - ID: randx.String(30), - } - switch deets.Dialect { - case "postgres": - c.Dialect = newPostgreSQL(deets) - case "mysql": - c.Dialect = newMySQL(deets) - case "sqlite3": - c.Dialect = newSQLite(deets) - } - return c, nil -} - -// Connect takes the name of a connection, default is "development", and will -// return that connection from the available `Connections`. If a connection with -// that name can not be found an error will be returned. If a connection is -// found, and it has yet to open a connection with its underlying datastore, -// a connection to that store will be opened. -func Connect(e string) (*Connection, error) { - if len(Connections) == 0 { - err := LoadConfig() - if err != nil { - return nil, errors.WithStack(err) - } - } - e = defaults.String(e, "development") - c := Connections[e] - if c == nil { - return c, errors.Errorf("Could not find connection named %s!", e) - } - err := c.Open() - return c, errors.Wrapf(err, "couldn't open connection for %s", e) -} - -func (c *Connection) Open() error { - if c.Store != nil { - return nil - } - db, err := sqlx.Open(c.Dialect.Details().Dialect, c.Dialect.URL()) - db.SetMaxOpenConns(c.Dialect.Details().Pool) - if err == nil { - c.Store = &dB{db} - } - return errors.Wrap(err, "coudn't connection to database") -} - -func (c *Connection) Close() error { - return errors.Wrap(c.Store.Close(), "couldn't close connection") -} - -// Transaction will start a new transaction on the connection. If the inner function -// returns an error then the transaction will be rolled back, otherwise the transaction -// will automatically commit at the end. -func (c *Connection) Transaction(fn func(tx *Connection) error) error { - return c.Dialect.Lock(func() error { - var dberr error - cn, err := c.NewTransaction() - if err != nil { - return err - } - err = fn(cn) - if err != nil { - dberr = cn.TX.Rollback() - } else { - dberr = cn.TX.Commit() - } - if err != nil { - return errors.Wrap(err, "error inside of calling function") - } - return errors.Wrap(dberr, "error committing or rolling back transaction") - }) - -} - -func (c *Connection) NewTransaction() (*Connection, error) { - var cn *Connection - if c.TX == nil { - tx, err := c.Store.Transaction() - if err != nil { - return cn, errors.Wrap(err, "couldn't start a new transaction") - } - cn = &Connection{ - ID: randx.String(30), - Store: tx, - Dialect: c.Dialect, - TX: tx, - } - } else { - cn = c - } - return cn, nil -} - -// Rollback will open a new transaction and automatically rollback that transaction -// when the inner function returns, regardless. This can be useful for tests, etc... -func (c *Connection) Rollback(fn func(tx *Connection)) error { - var cn *Connection - if c.TX == nil { - tx, err := c.Store.Transaction() - if err != nil { - return errors.Wrap(err, "couldn't start a new transaction") - } - cn = &Connection{ - ID: randx.String(30), - Store: tx, - Dialect: c.Dialect, - TX: tx, - } - } else { - cn = c - } - fn(cn) - return cn.TX.Rollback() -} - -// Q creates a new "empty" query for the current connection. -func (c *Connection) Q() *Query { - return Q(c) -} - -func (c *Connection) TruncateAll() error { - return c.Dialect.TruncateAll(c) -} - -func (c *Connection) timeFunc(name string, fn func() error) error { - now := time.Now() - err := fn() - atomic.AddInt64(&c.Elapsed, int64(time.Now().Sub(now))) - return errors.Wrap(err, "error inside of calling function") -} diff --git a/vendor/github.com/markbates/pop/connection_details.go b/vendor/github.com/markbates/pop/connection_details.go deleted file mode 100644 index ef4d60c9..00000000 --- a/vendor/github.com/markbates/pop/connection_details.go +++ /dev/null @@ -1,95 +0,0 @@ -package pop - -import ( - "fmt" - "net/url" - "strconv" - "strings" - "time" - - "github.com/markbates/going/defaults" - "github.com/pkg/errors" -) - -type ConnectionDetails struct { - // Example: "postgres" or "sqlite3" or "mysql" - Dialect string - // The name of your database. Example: "foo_development" - Database string - // The host of your database. Example: "127.0.0.1" - Host string - // The port of your database. Example: 1234 - // Will default to the "default" port for each dialect. - Port string - // The username of the database user. Example: "root" - User string - // The password of the database user. Example: "password" - Password string - // Instead of specifying each individual piece of the - // connection you can instead just specify the URL of the - // database. Example: "postgres://postgres:postgres@localhost:5432/pop_test?sslmode=disable" - URL string - // Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetMaxOpenConns - Pool int - Options map[string]string -} - -// Finalize cleans up the connection details by normalizing names, -// filling in default values, etc... -func (cd *ConnectionDetails) Finalize() error { - if cd.URL != "" { - u, err := url.Parse(cd.URL) - if err != nil { - return errors.Wrapf(err, "couldn't parse %s", cd.URL) - } - cd.Dialect = u.Scheme - cd.Database = u.Path - - hp := strings.Split(u.Host, ":") - cd.Host = hp[0] - if len(hp) > 1 { - cd.Port = hp[1] - } - - if u.User != nil { - cd.User = u.User.Username() - cd.Password, _ = u.User.Password() - } - } - switch strings.ToLower(cd.Dialect) { - case "postgres", "postgresql", "pg": - cd.Dialect = "postgres" - cd.Port = defaults.String(cd.Port, "5432") - cd.Database = strings.TrimPrefix(cd.Database, "/") - case "mysql": - cd.Port = defaults.String(cd.Port, "3006") - cd.Database = strings.TrimPrefix(cd.Database, "/") - case "sqlite", "sqlite3": - cd.Dialect = "sqlite3" - default: - return errors.Errorf("Unknown dialect %s!", cd.Dialect) - } - return nil -} - -// Parse is deprecated! Please use `ConnectionDetails.Finalize()` instead! -func (cd *ConnectionDetails) Parse(port string) error { - fmt.Println("[POP] ConnectionDetails#Parse(port string) has been deprecated!") - return cd.Finalize() -} - -func (cd *ConnectionDetails) RetrySleep() time.Duration { - d, err := time.ParseDuration(defaults.String(cd.Options["retry_sleep"], "1ms")) - if err != nil { - return 1 * time.Millisecond - } - return d -} - -func (cd *ConnectionDetails) RetryLimit() int { - i, err := strconv.Atoi(defaults.String(cd.Options["retry_limit"], "1000")) - if err != nil { - return 100 - } - return i -} diff --git a/vendor/github.com/markbates/pop/connection_details_test.go b/vendor/github.com/markbates/pop/connection_details_test.go deleted file mode 100644 index f94d5501..00000000 --- a/vendor/github.com/markbates/pop/connection_details_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package pop_test - -import ( - "testing" - - "github.com/markbates/pop" - "github.com/stretchr/testify/require" -) - -func Test_ConnectionDetails_Finalize(t *testing.T) { - r := require.New(t) - - cd := &pop.ConnectionDetails{ - URL: "postgres://user:pass@host:port/database", - } - err := cd.Finalize() - r.NoError(err) - - r.Equal(cd.Database, "database") - r.Equal(cd.Dialect, "postgres") - r.Equal(cd.Host, "host") - r.Equal(cd.Password, "pass") - r.Equal(cd.Port, "port") - r.Equal(cd.User, "user") -} - -func Test_ConnectionDetails_Finalize_UnknownDialect(t *testing.T) { - r := require.New(t) - cd := &pop.ConnectionDetails{ - URL: "unknown://user:pass@host:port/database", - } - err := cd.Finalize() - r.Error(err) -} - -func Test_ConnectionDetails_Finalize_SQLite(t *testing.T) { - r := require.New(t) - - cd := &pop.ConnectionDetails{ - URL: "sqlite3:///tmp/foo.db", - } - err := cd.Finalize() - r.NoError(err) - - r.Equal(cd.Database, "/tmp/foo.db") - r.Equal(cd.Dialect, "sqlite3") - r.Equal(cd.Host, "") - r.Equal(cd.Password, "") - r.Equal(cd.Port, "") - r.Equal(cd.User, "") -} diff --git a/vendor/github.com/markbates/pop/connection_test.go b/vendor/github.com/markbates/pop/connection_test.go deleted file mode 100644 index 090cda41..00000000 --- a/vendor/github.com/markbates/pop/connection_test.go +++ /dev/null @@ -1 +0,0 @@ -package pop_test diff --git a/vendor/github.com/markbates/pop/database.yml b/vendor/github.com/markbates/pop/database.yml deleted file mode 100644 index 316a0d2a..00000000 --- a/vendor/github.com/markbates/pop/database.yml +++ /dev/null @@ -1,23 +0,0 @@ -mysql: - dialect: "mysql" - database: "pop_test" - host: {{ envOr "MYSQL_HOST" "localhost" }} - port: {{ envOr "MYSQL_PORT" "3306" }} - user: {{ envOr "MYSQL_USER" "root" }} - password: {{ envOr "MYSQL_PASSWORD" "root" }} - -mysql_travis: - dialect: "mysql" - database: "pop_test" - host: {{ envOr "MYSQL_HOST" "localhost" }} - port: {{ envOr "MYSQL_PORT" "3306" }} - user: {{ envOr "MYSQL_USER" "root" }} - password: {{ envOr "MYSQL_PASSWORD" "" }} - -postgres: - url: "postgres://postgres:postgres@localhost:5432/pop_test?sslmode=disable" - pool: 25 - -sqlite: - dialect: "sqlite3" - database: "./sql_scripts/sqlite/test.sqlite" diff --git a/vendor/github.com/markbates/pop/db.go b/vendor/github.com/markbates/pop/db.go deleted file mode 100644 index 88e8f7bb..00000000 --- a/vendor/github.com/markbates/pop/db.go +++ /dev/null @@ -1,19 +0,0 @@ -package pop - -import "github.com/jmoiron/sqlx" - -type dB struct { - *sqlx.DB -} - -func (db *dB) Transaction() (*tX, error) { - return newTX(db) -} - -func (db *dB) Rollback() error { - return nil -} - -func (db *dB) Commit() error { - return nil -} diff --git a/vendor/github.com/markbates/pop/dialect.go b/vendor/github.com/markbates/pop/dialect.go deleted file mode 100644 index 0da26786..00000000 --- a/vendor/github.com/markbates/pop/dialect.go +++ /dev/null @@ -1,103 +0,0 @@ -package pop - -import ( - "encoding/gob" - "fmt" - "io" - - . "github.com/markbates/pop/columns" - "github.com/markbates/pop/fizz" - "github.com/pkg/errors" - uuid "github.com/satori/go.uuid" -) - -func init() { - gob.Register(uuid.UUID{}) -} - -type dialect interface { - URL() string - MigrationURL() string - Details() *ConnectionDetails - TranslateSQL(string) string - Create(store, *Model, Columns) error - Update(store, *Model, Columns) error - Destroy(store, *Model) error - SelectOne(store, *Model, Query) error - SelectMany(store, *Model, Query) error - CreateDB() error - DropDB() error - DumpSchema(io.Writer) error - LoadSchema(io.Reader) error - FizzTranslator() fizz.Translator - Lock(func() error) error - TruncateAll(*Connection) error -} - -func genericCreate(s store, model *Model, cols Columns) error { - keyType := model.PrimaryKeyType() - switch keyType { - case "int": - var id int64 - w := cols.Writeable() - query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", model.TableName(), w.String(), w.SymbolizedString()) - Log(query) - res, err := s.NamedExec(query, model.Value) - if err != nil { - return errors.Wrapf(err, "create: couldn't execute named statement %s", query) - } - id, err = res.LastInsertId() - if err == nil { - model.setID(int(id)) - } - return errors.Wrap(err, "couldn't get the last inserted id") - case "UUID": - model.setID(uuid.NewV4()) - w := cols.Writeable() - w.Add("id") - query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", model.TableName(), w.String(), w.SymbolizedString()) - Log(query) - stmt, err := s.PrepareNamed(query) - if err != nil { - return errors.WithStack(err) - } - _, err = stmt.Exec(model.Value) - return err - } - return errors.Errorf("can not use %s as a primary key type!", keyType) -} - -func genericUpdate(s store, model *Model, cols Columns) error { - stmt := fmt.Sprintf("UPDATE %s SET %s where %s", model.TableName(), cols.Writeable().UpdateString(), model.whereID()) - Log(stmt) - _, err := s.NamedExec(stmt, model.Value) - return errors.Wrapf(err, "update: couldn't execute named statement %s", stmt) -} - -func genericDestroy(s store, model *Model) error { - stmt := fmt.Sprintf("DELETE FROM %s WHERE %s", model.TableName(), model.whereID()) - return errors.Wrapf(genericExec(s, stmt), "destroy: couldn't execute named statement %s", stmt) -} - -func genericExec(s store, stmt string) error { - Log(stmt) - _, err := s.Exec(stmt) - return errors.Wrapf(err, "couldn't execute statement %s", stmt) -} - -func genericSelectOne(s store, model *Model, query Query) error { - sql, args := query.ToSQL(model) - Log(sql, args...) - err := s.Get(model.Value, sql, args...) - return errors.Wrapf(err, "couldn't select one %s %+v", sql, args) -} - -func genericSelectMany(s store, models *Model, query Query) error { - sql, args := query.ToSQL(models) - Log(sql, args...) - err := s.Select(models.Value, sql, args...) - if err != nil { - return errors.Wrapf(err, "couldn't select many %s %+v", sql, args) - } - return nil -} diff --git a/vendor/github.com/markbates/pop/doc.go b/vendor/github.com/markbates/pop/doc.go deleted file mode 100644 index 35ef81ad..00000000 --- a/vendor/github.com/markbates/pop/doc.go +++ /dev/null @@ -1,13 +0,0 @@ -/* -So what does Pop do exactly? Well, it wraps the absolutely amazing https://github.com/jmoiron/sqlx library. It cleans up some of the common patterns and workflows usually associated with dealing with databases in Go. - -Pop makes it easy to do CRUD operations, run migrations, and build/execute queries. Is Pop an ORM? I'll leave that up to you, the reader, to decide. - -Pop, by default, follows conventions that were defined by the ActiveRecord Ruby gem, http://www.rubyonrails.org. What does this mean? - -* Tables must have an "id" column and a corresponding "ID" field on the `struct` being used. -* If there is a timestamp column named "created_at", "CreatedAt" on the `struct`, it will be set with the current time when the record is created. -* If there is a timestamp column named "updated_at", "UpdatedAt" on the `struct`, it will be set with the current time when the record is updated. -* Default databases are lowercase, underscored versions of the `struct` name. Examples: User{} is "users", FooBar{} is "foo_bars", etc... -*/ -package pop diff --git a/vendor/github.com/markbates/pop/executors.go b/vendor/github.com/markbates/pop/executors.go deleted file mode 100644 index d1d1d669..00000000 --- a/vendor/github.com/markbates/pop/executors.go +++ /dev/null @@ -1,107 +0,0 @@ -package pop - -import ( - "fmt" - - . "github.com/markbates/pop/columns" - "github.com/markbates/validate" - uuid "github.com/satori/go.uuid" -) - -func (c *Connection) Reload(model interface{}) error { - sm := Model{Value: model} - return c.Find(model, sm.ID()) -} - -func (q *Query) Exec() error { - return q.Connection.timeFunc("Exec", func() error { - sql, args := q.ToSQL(nil) - Log(sql, args...) - _, err := q.Connection.Store.Exec(sql, args...) - return err - }) -} - -func (c *Connection) ValidateAndSave(model interface{}, excludeColumns ...string) (*validate.Errors, error) { - sm := &Model{Value: model} - verrs, err := sm.validateSave(c) - if err != nil { - return verrs, err - } - if verrs.HasAny() { - return verrs, nil - } - return verrs, c.Save(model, excludeColumns...) -} - -var emptyUUID = uuid.Nil.String() - -func (c *Connection) Save(model interface{}, excludeColumns ...string) error { - sm := &Model{Value: model} - id := sm.ID() - if id == 0 || (fmt.Sprint(id) == emptyUUID) { - return c.Create(model, excludeColumns...) - } else { - return c.Update(model, excludeColumns...) - } -} - -func (c *Connection) ValidateAndCreate(model interface{}, excludeColumns ...string) (*validate.Errors, error) { - sm := &Model{Value: model} - verrs, err := sm.validateCreate(c) - if err != nil { - return verrs, err - } - if verrs.HasAny() { - return verrs, nil - } - return verrs, c.Create(model, excludeColumns...) -} - -func (c *Connection) Create(model interface{}, excludeColumns ...string) error { - return c.timeFunc("Create", func() error { - sm := &Model{Value: model} - - cols := ColumnsForStruct(model, sm.TableName()) - cols.Remove(excludeColumns...) - - sm.touchCreatedAt() - sm.touchUpdatedAt() - - return c.Dialect.Create(c.Store, sm, cols) - }) -} - -func (c *Connection) ValidateAndUpdate(model interface{}, excludeColumns ...string) (*validate.Errors, error) { - sm := &Model{Value: model} - verrs, err := sm.validateUpdate(c) - if err != nil { - return verrs, err - } - if verrs.HasAny() { - return verrs, nil - } - return verrs, c.Update(model, excludeColumns...) -} - -func (c *Connection) Update(model interface{}, excludeColumns ...string) error { - return c.timeFunc("Update", func() error { - sm := &Model{Value: model} - - cols := ColumnsForStruct(model, sm.TableName()) - cols.Remove("id", "created_at") - cols.Remove(excludeColumns...) - - sm.touchUpdatedAt() - - return c.Dialect.Update(c.Store, sm, cols) - }) -} - -func (c *Connection) Destroy(model interface{}) error { - return c.timeFunc("Destroy", func() error { - sm := &Model{Value: model} - - return c.Dialect.Destroy(c.Store, sm) - }) -} diff --git a/vendor/github.com/markbates/pop/executors_test.go b/vendor/github.com/markbates/pop/executors_test.go deleted file mode 100644 index c3f217d3..00000000 --- a/vendor/github.com/markbates/pop/executors_test.go +++ /dev/null @@ -1,286 +0,0 @@ -package pop_test - -import ( - "testing" - - "github.com/markbates/pop" - "github.com/markbates/pop/nulls" - "github.com/stretchr/testify/require" -) - -func Test_ValidateAndSave(t *testing.T) { - r := require.New(t) - validationLogs = []string{} - transaction(func(tx *pop.Connection) { - car := &ValidatableCar{Name: "VW"} - verrs, err := tx.ValidateAndSave(car) - r.NoError(err) - r.False(verrs.HasAny()) - r.Len(validationLogs, 2) - r.Equal([]string{"Validate", "ValidateSave"}, validationLogs) - r.NotZero(car.ID) - r.NotZero(car.CreatedAt) - - validationLogs = []string{} - car = &ValidatableCar{Name: ""} - verrs, err = tx.ValidateAndSave(car) - r.NoError(err) - r.True(verrs.HasAny()) - r.Len(validationLogs, 1) - errs := verrs.Get("name") - r.Len(errs, 1) - - validationLogs = []string{} - ncar := &NotValidatableCar{Name: ""} - verrs, err = tx.ValidateAndSave(ncar) - r.NoError(err) - r.False(verrs.HasAny()) - r.Len(validationLogs, 0) - }) -} - -func Test_ValidateAndCreate(t *testing.T) { - r := require.New(t) - validationLogs = []string{} - transaction(func(tx *pop.Connection) { - car := &ValidatableCar{Name: "VW"} - verrs, err := tx.ValidateAndCreate(car) - r.NoError(err) - r.False(verrs.HasAny()) - r.Len(validationLogs, 2) - r.Equal([]string{"Validate", "ValidateCreate"}, validationLogs) - r.NotZero(car.ID) - r.NotZero(car.CreatedAt) - - validationLogs = []string{} - car = &ValidatableCar{Name: ""} - verrs, err = tx.ValidateAndSave(car) - r.NoError(err) - r.True(verrs.HasAny()) - r.Len(validationLogs, 1) - errs := verrs.Get("name") - r.Len(errs, 1) - - validationLogs = []string{} - ncar := &NotValidatableCar{Name: ""} - verrs, err = tx.ValidateAndCreate(ncar) - r.NoError(err) - r.False(verrs.HasAny()) - r.Len(validationLogs, 0) - }) -} - -func Test_ValidateAndUpdate(t *testing.T) { - r := require.New(t) - validationLogs = []string{} - transaction(func(tx *pop.Connection) { - car := &ValidatableCar{Name: "VW"} - verrs, err := tx.ValidateAndCreate(car) - r.NoError(err) - r.False(verrs.HasAny()) - r.Len(validationLogs, 2) - r.Equal([]string{"Validate", "ValidateCreate"}, validationLogs) - r.NotZero(car.ID) - r.NotZero(car.CreatedAt) - - validationLogs = []string{} - car.Name = "" - verrs, err = tx.ValidateAndUpdate(car) - r.NoError(err) - r.True(verrs.HasAny()) - r.Len(validationLogs, 1) - errs := verrs.Get("name") - r.Len(errs, 1) - - validationLogs = []string{} - ncar := &NotValidatableCar{Name: ""} - verrs, err = tx.ValidateAndCreate(ncar) - r.NoError(err) - r.False(verrs.HasAny()) - r.Len(validationLogs, 0) - - validationLogs = []string{} - ncar.Name = "" - verrs, err = tx.ValidateAndUpdate(ncar) - r.NoError(err) - r.False(verrs.HasAny()) - r.Len(validationLogs, 0) - }) -} - -func Test_Exec(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - user := User{Name: nulls.NewString("Mark 'Awesome' Bates")} - tx.Create(&user) - - ctx, _ := tx.Count(user) - a.Equal(1, ctx) - - q := tx.RawQuery("delete from users where id = ?", user.ID) - err := q.Exec() - a.NoError(err) - - ctx, _ = tx.Count(user) - a.Equal(0, ctx) - }) -} - -func Test_Save(t *testing.T) { - r := require.New(t) - transaction(func(tx *pop.Connection) { - u := &User{Name: nulls.NewString("Mark")} - r.Zero(u.ID) - tx.Save(u) - r.NotZero(u.ID) - - uat := u.UpdatedAt.UnixNano() - - tx.Save(u) - r.NotEqual(uat, u.UpdatedAt.UnixNano()) - }) -} - -func Test_Create(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - count, _ := tx.Count(&User{}) - user := User{Name: nulls.NewString("Mark 'Awesome' Bates")} - err := tx.Create(&user) - a.NoError(err) - a.NotEqual(user.ID, 0) - - ctx, _ := tx.Count(&User{}) - a.Equal(count+1, ctx) - - u := User{} - q := tx.Where("name = ?", "Mark 'Awesome' Bates") - err = q.First(&u) - a.NoError(err) - a.Equal(user.Name.String, "Mark 'Awesome' Bates") - }) -} - -func Test_Create_UUID(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - count, _ := tx.Count(&Song{}) - song := Song{Title: "Automatic Buffalo"} - err := tx.Create(&song) - a.NoError(err) - a.NotZero(song.ID) - - ctx, _ := tx.Count(&Song{}) - a.Equal(count+1, ctx) - - u := Song{} - q := tx.Where("title = ?", "Automatic Buffalo") - err = q.First(&u) - a.NoError(err) - }) -} - -func Test_Create_Timestamps(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - user := User{Name: nulls.NewString("Mark 'Awesome' Bates")} - a.Zero(user.CreatedAt) - a.Zero(user.UpdatedAt) - - err := tx.Create(&user) - a.NoError(err) - - a.NotZero(user.CreatedAt) - a.NotZero(user.UpdatedAt) - - friend := Friend{FirstName: "Ross", LastName: "Gellar"} - err = tx.Create(&friend) - a.NoError(err) - }) -} - -func Test_Update(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - user := User{Name: nulls.NewString("Mark")} - tx.Create(&user) - - a.NotZero(user.CreatedAt) - a.NotZero(user.UpdatedAt) - - user.Name.String = "Marky" - err := tx.Update(&user) - a.NoError(err) - - tx.Reload(&user) - a.Equal(user.Name.String, "Marky") - }) -} - -func Test_Update_UUID(t *testing.T) { - transaction(func(tx *pop.Connection) { - r := require.New(t) - - song := Song{Title: "Automatic Buffalo"} - err := tx.Create(&song) - r.NoError(err) - - r.NotZero(song.CreatedAt) - r.NotZero(song.UpdatedAt) - - song.Title = "Hum" - err = tx.Update(&song) - r.NoError(err) - - err = tx.Reload(&song) - r.NoError(err) - r.Equal("Hum", song.Title) - }) -} - -func Test_Destroy(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - count, err := tx.Count("users") - user := User{Name: nulls.NewString("Mark")} - err = tx.Create(&user) - a.NoError(err) - a.NotEqual(user.ID, 0) - - ctx, err := tx.Count("users") - a.Equal(count+1, ctx) - - err = tx.Destroy(&user) - a.NoError(err) - - ctx, _ = tx.Count("users") - a.Equal(count, ctx) - }) -} - -func Test_Destroy_UUID(t *testing.T) { - transaction(func(tx *pop.Connection) { - r := require.New(t) - - count, err := tx.Count("songs") - song := Song{Title: "Automatic Buffalo"} - err = tx.Create(&song) - r.NoError(err) - r.NotZero(song.ID) - - ctx, err := tx.Count("songs") - r.Equal(count+1, ctx) - - err = tx.Destroy(&song) - r.NoError(err) - - ctx, _ = tx.Count("songs") - r.Equal(count, ctx) - }) -} diff --git a/vendor/github.com/markbates/pop/finders.go b/vendor/github.com/markbates/pop/finders.go deleted file mode 100644 index 84a555e7..00000000 --- a/vendor/github.com/markbates/pop/finders.go +++ /dev/null @@ -1,141 +0,0 @@ -package pop - -import ( - "fmt" - "reflect" - "strconv" - - "github.com/satori/go.uuid" -) - -// Find the first record of the model in the database with a particular id. -// -// c.Find(&User{}, 1) -func (c *Connection) Find(model interface{}, id interface{}) error { - return Q(c).Find(model, id) -} - -// Find the first record of the model in the database with a particular id. -// -// q.Find(&User{}, 1) -func (q *Query) Find(model interface{}, id interface{}) error { - m := &Model{Value: model} - idq := fmt.Sprintf("%s.id = ?", m.TableName()) - var idi int - switch t := id.(type) { - case int: - idi = t - case uuid.UUID: - return q.Where(idq, t.String()).First(model) - case string: - var err error - idi, err = strconv.Atoi(t) - if err != nil { - return q.Where(idq, t).First(model) - } - } - return q.Where(idq, idi).First(model) -} - -// First record of the model in the database that matches the query. -// -// c.First(&User{}) -func (c *Connection) First(model interface{}) error { - return Q(c).First(model) -} - -// First record of the model in the database that matches the query. -// -// q.Where("name = ?", "mark").First(&User{}) -func (q *Query) First(model interface{}) error { - return q.Connection.timeFunc("First", func() error { - q.Limit(1) - m := &Model{Value: model} - return q.Connection.Dialect.SelectOne(q.Connection.Store, m, *q) - }) -} - -// Last record of the model in the database that matches the query. -// -// c.Last(&User{}) -func (c *Connection) Last(model interface{}) error { - return Q(c).Last(model) -} - -// Last record of the model in the database that matches the query. -// -// q.Where("name = ?", "mark").Last(&User{}) -func (q *Query) Last(model interface{}) error { - return q.Connection.timeFunc("Last", func() error { - q.Limit(1) - q.Order("id desc") - m := &Model{Value: model} - return q.Connection.Dialect.SelectOne(q.Connection.Store, m, *q) - }) -} - -// All retrieves all of the records in the database that match the query. -// -// c.All(&[]User{}) -func (c *Connection) All(models interface{}) error { - return Q(c).All(models) -} - -// All retrieves all of the records in the database that match the query. -// -// q.Where("name = ?", "mark").All(&[]User{}) -func (q *Query) All(models interface{}) error { - return q.Connection.timeFunc("All", func() error { - m := &Model{Value: models} - err := q.Connection.Dialect.SelectMany(q.Connection.Store, m, *q) - if err == nil && q.Paginator != nil { - ct, err := q.Count(models) - if err == nil { - q.Paginator.TotalEntriesSize = ct - st := reflect.ValueOf(models).Elem() - q.Paginator.CurrentEntriesSize = st.Len() - q.Paginator.TotalPages = (q.Paginator.TotalEntriesSize / q.Paginator.PerPage) - if q.Paginator.TotalEntriesSize%q.Paginator.PerPage > 0 { - q.Paginator.TotalPages = q.Paginator.TotalPages + 1 - } - } - } - return err - }) -} - -// Exists returns true/false if a record exists in the database that matches -// the query. -// -// q.Where("name = ?", "mark").Exists(&User{}) -func (q *Query) Exists(model interface{}) (bool, error) { - i, err := q.Count(model) - return i != 0, err -} - -// Count the number of records in the database. -// -// c.Count(&User{}) -func (c *Connection) Count(model interface{}) (int, error) { - return Q(c).Count(model) -} - -// Count the number of records in the database. -// -// q.Where("name = ?", "mark").Count(&User{}) -func (q Query) Count(model interface{}) (int, error) { - res := &rowCount{} - err := q.Connection.timeFunc("Count", func() error { - q.Paginator = nil - col := "count(*) as row_count" - q.orderClauses = clauses{} - query, args := q.ToSQL(&Model{Value: model}, col) - Log(query, args...) - return q.Connection.Store.Get(res, query, args...) - }) - return res.Count, err -} - -type rowCount struct { - Count int `db:"row_count"` -} diff --git a/vendor/github.com/markbates/pop/finders_test.go b/vendor/github.com/markbates/pop/finders_test.go deleted file mode 100644 index 1218455d..00000000 --- a/vendor/github.com/markbates/pop/finders_test.go +++ /dev/null @@ -1,183 +0,0 @@ -package pop_test - -import ( - "testing" - - "github.com/markbates/pop" - "github.com/markbates/pop/nulls" - "github.com/stretchr/testify/require" -) - -func Test_Find(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - user := User{Name: nulls.NewString("Mark")} - err := tx.Create(&user) - a.NoError(err) - - u := User{} - err = tx.Find(&u, user.ID) - a.NoError(err) - - a.NotEqual(u.ID, 0) - a.Equal(u.Name.String, "Mark") - }) -} - -func Test_First(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - first := User{Name: nulls.NewString("Mark")} - err := tx.Create(&first) - a.NoError(err) - - last := User{Name: nulls.NewString("Mark")} - err = tx.Create(&last) - a.NoError(err) - - u := User{} - err = tx.Where("name = 'Mark'").First(&u) - a.NoError(err) - - a.Equal(first.ID, u.ID) - }) -} - -func Test_Last(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - first := User{Name: nulls.NewString("Mark")} - err := tx.Create(&first) - a.NoError(err) - - last := User{Name: nulls.NewString("Mark")} - err = tx.Create(&last) - a.NoError(err) - - u := User{} - err = tx.Where("name = 'Mark'").Last(&u) - a.NoError(err) - - a.Equal(last.ID, u.ID) - }) -} - -func Test_All(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - for _, name := range []string{"Mark", "Joe", "Jane"} { - user := User{Name: nulls.NewString(name)} - err := tx.Create(&user) - a.NoError(err) - } - - u := Users{} - err := tx.All(&u) - a.NoError(err) - a.Equal(len(u), 3) - - u = Users{} - err = tx.Where("name = 'Mark'").All(&u) - a.NoError(err) - a.Equal(len(u), 1) - }) -} - -func Test_Count(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - user := User{Name: nulls.NewString("Mark")} - err := tx.Create(&user) - a.NoError(err) - c, err := tx.Count(&user) - a.NoError(err) - a.Equal(c, 1) - // should ignore order in count - - c, err = tx.Order("id desc").Count(&user) - a.NoError(err) - a.Equal(c, 1) - }) -} - -func Test_Count_Disregards_Pagination(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - names := []string{ - "Jack", - "Hurley", - "Charlie", - "Desmond", - "Juliet", - "Locke", - "Sawyer", - "Kate", - "Benjamin Linus", - } - - for _, name := range names { - user := User{Name: nulls.NewString(name)} - err := tx.Create(&user) - a.NoError(err) - } - - first_users := Users{} - second_users := Users{} - - q := tx.Paginate(1, 3) - q.All(&first_users) - - a.Equal(3, len(first_users)) - totalFirstPage := q.Paginator.TotalPages - - q = tx.Paginate(2, 3) - q.All(&second_users) - - a.Equal(3, len(second_users)) - totalSecondPage := q.Paginator.TotalPages - - a.NotEqual(0, totalFirstPage) - a.NotEqual(0, totalSecondPage) - a.Equal(totalFirstPage, totalSecondPage) - }) -} - -func Test_Count_RawQuery(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - user := User{Name: nulls.NewString("Mark")} - err := tx.Create(&user) - a.NoError(err) - - c, err := tx.RawQuery("select count(*) as row_count from users as users").Count(nil) - a.NoError(err) - a.Equal(c, 1) - - c, err = tx.RawQuery("select count(*) as row_count from users as users where id = -1").Count(nil) - a.NoError(err) - a.Equal(c, 0) - }) -} - -func Test_Exists(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - t, _ := tx.Where("id = ?", 0).Exists("users") - a.False(t) - - user := User{Name: nulls.NewString("Mark")} - err := tx.Create(&user) - a.NoError(err) - - t, _ = tx.Where("id = ?", user.ID).Exists("users") - a.True(t) - }) -} diff --git a/vendor/github.com/markbates/pop/fizz/README.md b/vendor/github.com/markbates/pop/fizz/README.md deleted file mode 100644 index c32bc1c5..00000000 --- a/vendor/github.com/markbates/pop/fizz/README.md +++ /dev/null @@ -1,121 +0,0 @@ -# Fizz - -## A Common DSL for Migrating Databases - -## Create a Table - -``` javascript -create_table("users", func(t) { - t.Column("email", "string", {}) - t.Column("twitter_handle", "string", {"size": 50}) - t.Column("age", "integer", {"default": 0}) - t.Column("admin", "boolean", {"default": false}) - t.Column("company_id", "uuid", {"default_raw": "uuid_generate_v1()"}) - t.Column("bio", "text", {"null": true}) - t.Column("joined_at", "timestamp", {}) -}) -``` - -The `create_table` function will also generate an `id` column of type `integer` that will auto-increment. It will also generate two `timestamp` columns; `created_at` and `updated_at`. - -Columns all have the same syntax. First is the name of the column. Second is the type of the field. Third is any options you want to set on that column. - -#### "Common" Types: - -* `string` -* `text` -* `timestamp` -* `integer` -* `boolean` - -Any other type passed it will be be passed straight through to the underlying database. For example for PostgreSQL you could pass `jsonb`and it will be supported, however, SQLite will yell very loudly at you if you do the same thing! - -#### Supported Options: - -* `size` - The size of the column. For example if you wanted a `varchar(50)` in Postgres you would do: `t.Column("column_name", "string", {"size": 50})` -* `null` - By default columns are not allowed to be `null`. -* `default` - The default value you want for this column. By default this is `null`. - -## Drop a Table - -``` javascript -drop_table("table_name") -``` - -## Rename a Table - -``` javascript -rename_table("old_table_name", "new_table_name") -``` - -## Add a Column - -``` javascript -add_column("table_name", "column_name", "string", {}) -``` - -See [above](#column-info) for more details on column types and options. - -## Rename a Column - -``` javascript -rename_column("table_name", "old_column_name", "new_column_name") -``` - -## Drop a Column - -``` javascript -drop_column("table_name", "column_name") -``` - -## Add an Index - -#### Supported Options: - -* `name` - This defaults to `table_name_column_name_idx` -* `unique` - -### Simple Index: - -``` javascript -add_index("table_name", "column_name", {}) -``` - -### Multi-Column Index: - -``` javascript -add_index("table_name", ["column_1", "column_2"], {}) -``` - -### Unique Index: - -``` javascript -add_index("table_name", "column_name", {"unique": true}) -``` - -### Index Names: - -``` javascript -add_index("table_name", "column_name", {}) # name => table_name_column_name_idx -add_index("table_name", "column_name", {"name": "custom_index_name"}) -``` - -## Rename an Index - -``` javascript -rename_index("table_name", "old_index_name", "new_index_name") -``` - -## Drop an Index - -``` javascript -drop_index("table_name", "index_name") -``` - -## Raw SQL - -``` javascript -raw("select * from users;") -``` - -*All calls to `raw` must end with a `;`!* diff --git a/vendor/github.com/markbates/pop/fizz/bubbler.go b/vendor/github.com/markbates/pop/fizz/bubbler.go deleted file mode 100644 index 6af9ca45..00000000 --- a/vendor/github.com/markbates/pop/fizz/bubbler.go +++ /dev/null @@ -1,54 +0,0 @@ -package fizz - -import ( - "strings" - - "github.com/mattn/anko/vm" - "github.com/pkg/errors" - - core "github.com/mattn/anko/builtins" -) - -type BubbleType int - -type Bubbler struct { - Translator - data []string -} - -func NewBubbler(t Translator) *Bubbler { - return &Bubbler{ - Translator: t, - data: []string{}, - } -} - -func (b *Bubbler) String() string { - return strings.Join(b.data, "\n") -} - -func (b *Bubbler) Bubble(s string) (string, error) { - env := core.Import(vm.NewEnv()) - - f := fizzer{b} - - // columns: - env.Define("add_column", f.AddColumn()) - env.Define("drop_column", f.DropColumn()) - env.Define("rename_column", f.RenameColumn()) - - env.Define("raw", f.RawSql()) - - // indexes: - env.Define("add_index", f.AddIndex()) - env.Define("drop_index", f.DropIndex()) - env.Define("rename_index", f.RenameIndex()) - - // tables: - env.Define("create_table", f.CreateTable()) - env.Define("drop_table", f.DropTable()) - env.Define("rename_table", f.RenameTable()) - - _, err := env.Execute(s) - return b.String(), errors.Wrap(err, "parse error") -} diff --git a/vendor/github.com/markbates/pop/fizz/bubbler_test.go b/vendor/github.com/markbates/pop/fizz/bubbler_test.go deleted file mode 100644 index 6877ba9a..00000000 --- a/vendor/github.com/markbates/pop/fizz/bubbler_test.go +++ /dev/null @@ -1 +0,0 @@ -package fizz_test diff --git a/vendor/github.com/markbates/pop/fizz/columns.go b/vendor/github.com/markbates/pop/fizz/columns.go deleted file mode 100644 index dc161356..00000000 --- a/vendor/github.com/markbates/pop/fizz/columns.go +++ /dev/null @@ -1,62 +0,0 @@ -package fizz - -var INT_ID_COL = Column{ - Name: "id", - Primary: true, - ColType: "integer", - Options: Options{}, -} - -var UUID_ID_COL = Column{ - Name: "id", - Primary: true, - ColType: "uuid", - Options: Options{}, -} - -var CREATED_COL = Column{Name: "created_at", ColType: "timestamp", Options: Options{}} -var UPDATED_COL = Column{Name: "updated_at", ColType: "timestamp", Options: Options{}} - -type Column struct { - Name string - ColType string - Primary bool - Options map[string]interface{} -} - -func (f fizzer) AddColumn() interface{} { - return func(table, name, ctype string, options Options) { - t := Table{ - Name: table, - Columns: []Column{ - {Name: name, ColType: ctype, Options: options}, - }, - } - f.add(f.Bubbler.AddColumn(t)) - } -} - -func (f fizzer) DropColumn() interface{} { - return func(table, name string) { - t := Table{ - Name: table, - Columns: []Column{ - {Name: name}, - }, - } - f.add(f.Bubbler.DropColumn(t)) - } -} - -func (f fizzer) RenameColumn() interface{} { - return func(table, old, new string) error { - t := Table{ - Name: table, - Columns: []Column{ - {Name: old}, - {Name: new}, - }, - } - return f.add(f.Bubbler.RenameColumn(t)) - } -} diff --git a/vendor/github.com/markbates/pop/fizz/fizz.go b/vendor/github.com/markbates/pop/fizz/fizz.go deleted file mode 100644 index 35c5018d..00000000 --- a/vendor/github.com/markbates/pop/fizz/fizz.go +++ /dev/null @@ -1,34 +0,0 @@ -package fizz - -import ( - "io/ioutil" - "log" - "os" -) - -type Options map[string]interface{} - -type fizzer struct { - Bubbler *Bubbler -} - -func (f fizzer) add(s string, err error) error { - if err != nil { - panic(err.Error()) - } - f.Bubbler.data = append(f.Bubbler.data, s) - return nil -} - -func AFile(f *os.File, t Translator) (string, error) { - b, err := ioutil.ReadAll(f) - if err != nil { - log.Fatal(err) - } - return AString(string(b), t) -} - -func AString(s string, t Translator) (string, error) { - b := NewBubbler(t) - return b.Bubble(s) -} diff --git a/vendor/github.com/markbates/pop/fizz/index.go b/vendor/github.com/markbates/pop/fizz/index.go deleted file mode 100644 index 45980494..00000000 --- a/vendor/github.com/markbates/pop/fizz/index.go +++ /dev/null @@ -1,65 +0,0 @@ -package fizz - -import ( - "fmt" - "strings" -) - -type Index struct { - Name string - Columns []string - Unique bool - Options Options -} - -func (f fizzer) AddIndex() interface{} { - return func(table string, columns interface{}, options Options) { - i := Index{} - switch t := columns.(type) { - default: - fmt.Printf("unexpected type %T\n", t) // %T prints whatever type t has - case string: - i.Columns = []string{t} - case []interface{}: - cl := make([]string, len(t)) - for i, c := range t { - cl[i] = c.(string) - } - i.Columns = cl - } - - if options["name"] != nil { - i.Name = options["name"].(string) - } else { - i.Name = fmt.Sprintf("%s_%s_idx", table, strings.Join(i.Columns, "_")) - } - i.Unique = options["unique"] != nil - f.add(f.Bubbler.AddIndex(Table{ - Name: table, - Indexes: []Index{i}, - })) - } -} - -func (f fizzer) DropIndex() interface{} { - return func(table, name string) { - f.add(f.Bubbler.DropIndex(Table{ - Name: table, - Indexes: []Index{ - {Name: name}, - }, - })) - } -} - -func (f fizzer) RenameIndex() interface{} { - return func(table, old, new string) { - f.add(f.Bubbler.RenameIndex(Table{ - Name: table, - Indexes: []Index{ - {Name: old}, - {Name: new}, - }, - })) - } -} diff --git a/vendor/github.com/markbates/pop/fizz/raw_sql.go b/vendor/github.com/markbates/pop/fizz/raw_sql.go deleted file mode 100644 index f1684d0f..00000000 --- a/vendor/github.com/markbates/pop/fizz/raw_sql.go +++ /dev/null @@ -1,7 +0,0 @@ -package fizz - -func (f fizzer) RawSql() interface{} { - return func(sql string) { - f.add(sql, nil) - } -} diff --git a/vendor/github.com/markbates/pop/fizz/tables.go b/vendor/github.com/markbates/pop/fizz/tables.go deleted file mode 100644 index ebf7377e..00000000 --- a/vendor/github.com/markbates/pop/fizz/tables.go +++ /dev/null @@ -1,78 +0,0 @@ -package fizz - -type Table struct { - Name string `db:"name"` - Columns []Column - Indexes []Index -} - -func (t *Table) Column(name string, colType string, options map[string]interface{}) { - var primary bool - if _, ok := options["primary"]; ok { - primary = true - } - c := Column{ - Name: name, - ColType: colType, - Options: options, - Primary: primary, - } - t.Columns = append(t.Columns, c) -} - -func (t *Table) ColumnNames() []string { - cols := make([]string, len(t.Columns)) - for i, c := range t.Columns { - cols[i] = c.Name - } - return cols -} - -func (t *Table) HasColumns(args ...string) bool { - keys := map[string]struct{}{} - for _, k := range t.ColumnNames() { - keys[k] = struct{}{} - } - for _, a := range args { - if _, ok := keys[a]; !ok { - return false - } - } - return true -} - -func (f fizzer) CreateTable() interface{} { - return func(name string, fn func(t *Table)) { - t := Table{ - Name: name, - Columns: []Column{CREATED_COL, UPDATED_COL}, - } - fn(&t) - var foundPrimary bool - for _, c := range t.Columns { - if c.Primary { - foundPrimary = true - break - } - } - if !foundPrimary { - t.Columns = append(t.Columns, INT_ID_COL) - } - f.add(f.Bubbler.CreateTable(t)) - } -} - -func (f fizzer) DropTable() interface{} { - return func(name string) { - f.add(f.Bubbler.DropTable(Table{Name: name})) - } -} - -func (f fizzer) RenameTable() interface{} { - return func(old, new string) { - f.add(f.Bubbler.RenameTable([]Table{ - {Name: old}, - {Name: new}, - })) - } -} diff --git a/vendor/github.com/markbates/pop/fizz/translator.go b/vendor/github.com/markbates/pop/fizz/translator.go deleted file mode 100644 index f2bf5eec..00000000 --- a/vendor/github.com/markbates/pop/fizz/translator.go +++ /dev/null @@ -1,13 +0,0 @@ -package fizz - -type Translator interface { - CreateTable(Table) (string, error) - DropTable(Table) (string, error) - RenameTable([]Table) (string, error) - AddColumn(Table) (string, error) - DropColumn(Table) (string, error) - RenameColumn(Table) (string, error) - AddIndex(Table) (string, error) - DropIndex(Table) (string, error) - RenameIndex(Table) (string, error) -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/mysql.go b/vendor/github.com/markbates/pop/fizz/translators/mysql.go deleted file mode 100644 index 3dbfa877..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/mysql.go +++ /dev/null @@ -1,168 +0,0 @@ -package translators - -import ( - "fmt" - "regexp" - "strings" - - "github.com/pkg/errors" - - "github.com/markbates/pop/fizz" -) - -type MySQL struct { - Schema Schema -} - -func NewMySQL(url, name string) *MySQL { - return &MySQL{ - Schema: &mysqlSchema{URL: url, Name: name, schema: map[string]*fizz.Table{}}, - } -} - -func (p *MySQL) CreateTable(t fizz.Table) (string, error) { - sql := []string{} - cols := []string{} - for _, c := range t.Columns { - cols = append(cols, p.buildColumn(c)) - if c.Primary { - cols = append(cols, fmt.Sprintf("PRIMARY KEY(%s)", c.Name)) - } - } - s := fmt.Sprintf("CREATE TABLE %s (\n%s\n) ENGINE=InnoDB;", t.Name, strings.Join(cols, ",\n")) - - sql = append(sql, s) - - for _, i := range t.Indexes { - s, err := p.AddIndex(fizz.Table{ - Name: t.Name, - Indexes: []fizz.Index{i}, - }) - if err != nil { - return "", err - } - sql = append(sql, s) - } - - return strings.Join(sql, "\n"), nil -} - -func (p *MySQL) DropTable(t fizz.Table) (string, error) { - return fmt.Sprintf("DROP TABLE %s;", t.Name), nil -} - -func (p *MySQL) RenameTable(t []fizz.Table) (string, error) { - if len(t) < 2 { - return "", errors.New("Not enough table names supplied!") - } - return fmt.Sprintf("ALTER TABLE %s RENAME TO %s;", t[0].Name, t[1].Name), nil -} - -func (p *MySQL) AddColumn(t fizz.Table) (string, error) { - if len(t.Columns) == 0 { - return "", errors.New("Not enough columns supplied!") - } - c := t.Columns[0] - s := fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s;", t.Name, p.buildColumn(c)) - return s, nil -} - -func (p *MySQL) DropColumn(t fizz.Table) (string, error) { - if len(t.Columns) == 0 { - return "", errors.New("Not enough columns supplied!") - } - c := t.Columns[0] - return fmt.Sprintf("ALTER TABLE %s DROP COLUMN %s;", t.Name, c.Name), nil -} - -func (p *MySQL) RenameColumn(t fizz.Table) (string, error) { - if len(t.Columns) < 2 { - return "", errors.New("Not enough columns supplied!") - } - oc := t.Columns[0] - nc := t.Columns[1] - - ti, err := p.Schema.TableInfo(t.Name) - if err != nil { - return "", err - } - var c fizz.Column - for _, c = range ti.Columns { - if c.Name == oc.Name { - break - } - } - col := p.buildColumn(c) - col = strings.Replace(col, oc.Name, fmt.Sprintf("%s %s", oc.Name, nc.Name), -1) - s := fmt.Sprintf("ALTER TABLE %s CHANGE %s;", t.Name, col) - return s, nil -} - -func (p *MySQL) AddIndex(t fizz.Table) (string, error) { - if len(t.Indexes) == 0 { - return "", errors.New("Not enough indexes supplied!") - } - i := t.Indexes[0] - s := fmt.Sprintf("CREATE INDEX %s ON %s (%s);", i.Name, t.Name, strings.Join(i.Columns, ", ")) - if i.Unique { - s = strings.Replace(s, "CREATE", "CREATE UNIQUE", 1) - } - return s, nil -} - -func (p *MySQL) DropIndex(t fizz.Table) (string, error) { - if len(t.Indexes) == 0 { - return "", errors.New("Not enough indexes supplied!") - } - i := t.Indexes[0] - return fmt.Sprintf("DROP INDEX %s ON %s;", i.Name, t.Name), nil -} - -func (p *MySQL) RenameIndex(t fizz.Table) (string, error) { - ix := t.Indexes - if len(ix) < 2 { - return "", errors.New("Not enough indexes supplied!") - } - oi := ix[0] - ni := ix[1] - return fmt.Sprintf("ALTER TABLE %s RENAME INDEX %s TO %s;", t.Name, oi.Name, ni.Name), nil -} - -func (p *MySQL) buildColumn(c fizz.Column) string { - s := fmt.Sprintf("%s %s", c.Name, p.colType(c)) - if c.Options["null"] == nil || c.Primary { - s = fmt.Sprintf("%s NOT NULL", s) - } - if c.Options["default"] != nil { - d := fmt.Sprintf("%#v", c.Options["default"]) - re := regexp.MustCompile("^(\")(.+)(\")$") - d = re.ReplaceAllString(d, "'$2'") - s = fmt.Sprintf("%s DEFAULT %s", s, d) - } - if c.Options["default_raw"] != nil { - d := fmt.Sprintf("%s", c.Options["default_raw"]) - s = fmt.Sprintf("%s DEFAULT %s", s, d) - } - - if c.Primary && c.ColType == "integer" { - s = fmt.Sprintf("%s AUTO_INCREMENT", s) - } - return s -} - -func (p *MySQL) colType(c fizz.Column) string { - switch c.ColType { - case "string": - s := "255" - if c.Options["size"] != nil { - s = fmt.Sprintf("%d", c.Options["size"]) - } - return fmt.Sprintf("VARCHAR (%s)", s) - case "uuid": - return "char(36)" - case "timestamp": - return "DATETIME" - default: - return c.ColType - } -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/mysql_meta.go b/vendor/github.com/markbates/pop/fizz/translators/mysql_meta.go deleted file mode 100644 index 8e508352..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/mysql_meta.go +++ /dev/null @@ -1,111 +0,0 @@ -package translators - -import ( - "fmt" - "strings" - - "github.com/jmoiron/sqlx" - "github.com/markbates/pop/fizz" -) - -type mysqlTableInfo struct { - Field string `db:"Field"` - Type string `db:"Type"` - Null string `db:"Null"` - Key string `db:"Key"` - Default interface{} `db:"Default"` - Extra string `db:"Extra"` -} - -func (ti mysqlTableInfo) ToColumn() fizz.Column { - c := fizz.Column{ - Name: ti.Field, - ColType: ti.Type, - Primary: ti.Key == "PRI", - Options: map[string]interface{}{}, - } - if strings.ToLower(ti.Null) == "yes" { - c.Options["null"] = true - } - if ti.Default != nil { - d := fmt.Sprintf("%s", ti.Default) - c.Options["default"] = d - } - return c -} - -type mysqlSchema struct { - URL string - Name string - db *sqlx.DB - schema map[string]*fizz.Table -} - -func (p *mysqlSchema) Delete(table string) { - delete(p.schema, table) -} - -func (p *mysqlSchema) TableInfo(table string) (*fizz.Table, error) { - if ti, ok := p.schema[table]; ok { - return ti, nil - } - err := p.buildSchema() - if err != nil { - return nil, err - } - if ti, ok := p.schema[table]; ok { - return ti, nil - } - return nil, fmt.Errorf("Could not find table data for %s!", table) -} - -func (p *mysqlSchema) buildSchema() error { - var err error - p.db, err = sqlx.Open("mysql", p.URL) - if err != nil { - return err - } - defer p.db.Close() - - res, err := p.db.Queryx(fmt.Sprintf("select TABLE_NAME as name from information_schema.TABLES where TABLE_SCHEMA = '%s'", p.Name)) - if err != nil { - return err - } - for res.Next() { - table := &fizz.Table{ - Columns: []fizz.Column{}, - Indexes: []fizz.Index{}, - } - err = res.StructScan(table) - if err != nil { - return err - } - err = p.buildTableData(table) - if err != nil { - return err - } - - } - return nil -} - -func (p *mysqlSchema) buildTableData(table *fizz.Table) error { - prag := fmt.Sprintf("describe %s", table.Name) - - res, err := p.db.Queryx(prag) - if err != nil { - return nil - } - - for res.Next() { - ti := mysqlTableInfo{} - err = res.StructScan(&ti) - if err != nil { - return err - } - table.Columns = append(table.Columns, ti.ToColumn()) - } - - p.schema[table.Name] = table - return nil -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/mysql_test.go b/vendor/github.com/markbates/pop/fizz/translators/mysql_test.go deleted file mode 100644 index 381fc417..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/mysql_test.go +++ /dev/null @@ -1,194 +0,0 @@ -package translators_test - -import ( - "github.com/markbates/pop" - "github.com/markbates/pop/fizz" - "github.com/markbates/pop/fizz/translators" -) - -var _ fizz.Translator = (*translators.MySQL)(nil) -var myt = translators.NewMySQL("", "") - -func init() { - myconn, err := pop.Connect("mysql") - if err != nil { - panic(err.Error()) - } - deets := myconn.Dialect.Details() - myt = translators.NewMySQL(myconn.URL(), deets.Database) -} - -func (p *MySQLSuite) Test_MySQL_SchemaMigration() { - r := p.Require() - ddl := `CREATE TABLE schema_migrations ( -version VARCHAR (255) NOT NULL -) ENGINE=InnoDB; -CREATE UNIQUE INDEX version_idx ON schema_migrations (version);` - - res, err := myt.CreateTable(fizz.Table{ - Name: "schema_migrations", - Columns: []fizz.Column{ - {Name: "version", ColType: "string"}, - }, - Indexes: []fizz.Index{ - {Name: "version_idx", Columns: []string{"version"}, Unique: true}, - }, - }) - r.NoError(err) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_CreateTable() { - r := p.Require() - ddl := `CREATE TABLE users ( -created_at DATETIME NOT NULL, -updated_at DATETIME NOT NULL, -first_name VARCHAR (255) NOT NULL, -last_name VARCHAR (255) NOT NULL, -email VARCHAR (20) NOT NULL, -permissions text, -age integer DEFAULT 40, -id integer NOT NULL AUTO_INCREMENT, -PRIMARY KEY(id) -) ENGINE=InnoDB;` - - res, _ := fizz.AString(` - create_table("users", func(t) { - t.Column("first_name", "string", {}) - t.Column("last_name", "string", {}) - t.Column("email", "string", {"size":20}) - t.Column("permissions", "text", {"null": true}) - t.Column("age", "integer", {"null": true, "default": 40}) - }) - `, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_CreateTable_UUID() { - r := p.Require() - ddl := `CREATE TABLE users ( -created_at DATETIME NOT NULL, -updated_at DATETIME NOT NULL, -first_name VARCHAR (255) NOT NULL, -last_name VARCHAR (255) NOT NULL, -email VARCHAR (20) NOT NULL, -permissions text, -age integer DEFAULT 40, -company_id char(36) NOT NULL DEFAULT 'test', -uuid char(36) NOT NULL, -PRIMARY KEY(uuid) -) ENGINE=InnoDB;` - - res, _ := fizz.AString(` - create_table("users", func(t) { - t.Column("first_name", "string", {}) - t.Column("last_name", "string", {}) - t.Column("email", "string", {"size":20}) - t.Column("permissions", "text", {"null": true}) - t.Column("age", "integer", {"null": true, "default": 40}) - t.Column("company_id", "uuid", {"default_raw": "'test'"}) - t.Column("uuid", "uuid", {"primary": true}) - }) - `, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_DropTable() { - r := p.Require() - - ddl := `DROP TABLE users;` - - res, _ := fizz.AString(`drop_table("users")`, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_RenameTable() { - r := p.Require() - - ddl := `ALTER TABLE users RENAME TO people;` - - res, _ := fizz.AString(`rename_table("users", "people")`, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_RenameTable_NotEnoughValues() { - r := p.Require() - - _, err := myt.RenameTable([]fizz.Table{}) - r.Error(err) -} - -func (p *MySQLSuite) Test_MySQL_AddColumn() { - r := p.Require() - ddl := `ALTER TABLE users ADD COLUMN mycolumn VARCHAR (50) NOT NULL DEFAULT 'foo';` - - res, _ := fizz.AString(`add_column("users", "mycolumn", "string", {"default": "foo", "size": 50})`, myt) - - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_DropColumn() { - r := p.Require() - ddl := `ALTER TABLE users DROP COLUMN mycolumn;` - - res, _ := fizz.AString(`drop_column("users", "mycolumn")`, myt) - - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_RenameColumn() { - r := p.Require() - ddl := `ALTER TABLE users CHANGE email email_address varchar(50) NOT NULL DEFAULT 'foo@example.com';` - - res, _ := fizz.AString(`rename_column("users", "email", "email_address")`, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_AddIndex() { - r := p.Require() - ddl := `CREATE INDEX users_email_idx ON users (email);` - - res, _ := fizz.AString(`add_index("users", "email", {})`, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_AddIndex_Unique() { - r := p.Require() - ddl := `CREATE UNIQUE INDEX users_email_idx ON users (email);` - - res, _ := fizz.AString(`add_index("users", "email", {"unique": true})`, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_AddIndex_MultiColumn() { - r := p.Require() - ddl := `CREATE INDEX users_id_email_idx ON users (id, email);` - - res, _ := fizz.AString(`add_index("users", ["id", "email"], {})`, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_AddIndex_CustomName() { - r := p.Require() - ddl := `CREATE INDEX email_index ON users (email);` - - res, _ := fizz.AString(`add_index("users", "email", {"name": "email_index"})`, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_DropIndex() { - r := p.Require() - ddl := `DROP INDEX email_idx ON users;` - - res, _ := fizz.AString(`drop_index("users", "email_idx")`, myt) - r.Equal(ddl, res) -} - -func (p *MySQLSuite) Test_MySQL_RenameIndex() { - r := p.Require() - - ddl := `ALTER TABLE users RENAME INDEX email_idx TO email_address_ix;` - - res, _ := fizz.AString(`rename_index("users", "email_idx", "email_address_ix")`, myt) - r.Equal(ddl, res) -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/postgres.go b/vendor/github.com/markbates/pop/fizz/translators/postgres.go deleted file mode 100644 index 6c73af88..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/postgres.go +++ /dev/null @@ -1,150 +0,0 @@ -package translators - -import ( - "fmt" - "strings" - - "github.com/pkg/errors" - - "github.com/markbates/pop/fizz" -) - -type Postgres struct { -} - -func NewPostgres() *Postgres { - return &Postgres{} -} - -func (p *Postgres) CreateTable(t fizz.Table) (string, error) { - sql := []string{} - cols := []string{} - var s string - for _, c := range t.Columns { - if c.Primary { - switch c.ColType { - case "string", "uuid": - s = fmt.Sprintf("\"%s\" %s PRIMARY KEY", c.Name, p.colType(c)) - case "integer": - s = fmt.Sprintf("\"%s\" SERIAL PRIMARY KEY", c.Name) - default: - return "", errors.Errorf("can not use %s as a primary key", c.ColType) - } - } else { - s = p.buildColumn(c) - } - cols = append(cols, s) - } - s = fmt.Sprintf("CREATE TABLE \"%s\" (\n%s\n);", t.Name, strings.Join(cols, ",\n")) - sql = append(sql, s) - - for _, i := range t.Indexes { - s, err := p.AddIndex(fizz.Table{ - Name: t.Name, - Indexes: []fizz.Index{i}, - }) - if err != nil { - return "", err - } - sql = append(sql, s) - } - - return strings.Join(sql, "\n"), nil -} - -func (p *Postgres) DropTable(t fizz.Table) (string, error) { - return fmt.Sprintf("DROP TABLE \"%s\";", t.Name), nil -} - -func (p *Postgres) RenameTable(t []fizz.Table) (string, error) { - if len(t) < 2 { - return "", errors.New("Not enough table names supplied!") - } - return fmt.Sprintf("ALTER TABLE \"%s\" RENAME TO \"%s\";", t[0].Name, t[1].Name), nil -} - -func (p *Postgres) AddColumn(t fizz.Table) (string, error) { - if len(t.Columns) == 0 { - return "", errors.New("Not enough columns supplied!") - } - c := t.Columns[0] - s := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN %s;", t.Name, p.buildColumn(c)) - return s, nil -} - -func (p *Postgres) DropColumn(t fizz.Table) (string, error) { - if len(t.Columns) == 0 { - return "", errors.New("Not enough columns supplied!") - } - c := t.Columns[0] - return fmt.Sprintf("ALTER TABLE \"%s\" DROP COLUMN \"%s\";", t.Name, c.Name), nil -} - -func (p *Postgres) RenameColumn(t fizz.Table) (string, error) { - if len(t.Columns) < 2 { - return "", errors.New("Not enough columns supplied!") - } - oc := t.Columns[0] - nc := t.Columns[1] - s := fmt.Sprintf("ALTER TABLE \"%s\" RENAME COLUMN \"%s\" TO \"%s\";", t.Name, oc.Name, nc.Name) - return s, nil -} - -func (p *Postgres) AddIndex(t fizz.Table) (string, error) { - if len(t.Indexes) == 0 { - return "", errors.New("Not enough indexes supplied!") - } - i := t.Indexes[0] - s := fmt.Sprintf("CREATE INDEX \"%s\" ON \"%s\" (%s);", i.Name, t.Name, strings.Join(i.Columns, ", ")) - if i.Unique { - s = strings.Replace(s, "CREATE", "CREATE UNIQUE", 1) - } - return s, nil -} - -func (p *Postgres) DropIndex(t fizz.Table) (string, error) { - if len(t.Indexes) == 0 { - return "", errors.New("Not enough indexes supplied!") - } - i := t.Indexes[0] - return fmt.Sprintf("DROP INDEX \"%s\";", i.Name), nil -} - -func (p *Postgres) RenameIndex(t fizz.Table) (string, error) { - ix := t.Indexes - if len(ix) < 2 { - return "", errors.New("Not enough indexes supplied!") - } - oi := ix[0] - ni := ix[1] - return fmt.Sprintf("ALTER INDEX \"%s\" RENAME TO \"%s\";", oi.Name, ni.Name), nil -} - -func (p *Postgres) buildColumn(c fizz.Column) string { - s := fmt.Sprintf("\"%s\" %s", c.Name, p.colType(c)) - if c.Options["null"] == nil { - s = fmt.Sprintf("%s NOT NULL", s) - } - if c.Options["default"] != nil { - s = fmt.Sprintf("%s DEFAULT '%v'", s, c.Options["default"]) - } - if c.Options["default_raw"] != nil { - s = fmt.Sprintf("%s DEFAULT %s", s, c.Options["default_raw"]) - } - return s -} - -func (p *Postgres) colType(c fizz.Column) string { - switch c.ColType { - case "string": - s := "255" - if c.Options["size"] != nil { - s = fmt.Sprintf("%d", c.Options["size"]) - } - return fmt.Sprintf("VARCHAR (%s)", s) - case "uuid": - return "UUID" - default: - return c.ColType - } -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/postgres_test.go b/vendor/github.com/markbates/pop/fizz/translators/postgres_test.go deleted file mode 100644 index f795ab60..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/postgres_test.go +++ /dev/null @@ -1,162 +0,0 @@ -package translators_test - -import ( - "github.com/markbates/pop/fizz" - "github.com/markbates/pop/fizz/translators" -) - -var _ fizz.Translator = (*translators.Postgres)(nil) -var pgt = translators.NewPostgres() - -func (p *PostgreSQLSuite) Test_Postgres_CreateTable() { - r := p.Require() - ddl := `CREATE TABLE "users" ( -"created_at" timestamp NOT NULL, -"updated_at" timestamp NOT NULL, -"first_name" VARCHAR (255) NOT NULL, -"last_name" VARCHAR (255) NOT NULL, -"email" VARCHAR (20) NOT NULL, -"permissions" jsonb, -"age" integer DEFAULT '40', -"company_id" UUID NOT NULL DEFAULT uuid_generate_v1(), -"id" SERIAL PRIMARY KEY -);` - - res, _ := fizz.AString(` - create_table("users", func(t) { - t.Column("first_name", "string", {}) - t.Column("last_name", "string", {}) - t.Column("email", "string", {"size":20}) - t.Column("permissions", "jsonb", {"null": true}) - t.Column("age", "integer", {"null": true, "default": 40}) - t.Column("company_id", "uuid", {"default_raw": "uuid_generate_v1()"}) - }) - `, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_CreateTable_UUID() { - r := p.Require() - ddl := `CREATE TABLE "users" ( -"created_at" timestamp NOT NULL, -"updated_at" timestamp NOT NULL, -"first_name" VARCHAR (255) NOT NULL, -"last_name" VARCHAR (255) NOT NULL, -"email" VARCHAR (20) NOT NULL, -"permissions" jsonb, -"age" integer DEFAULT '40', -"uuid" UUID PRIMARY KEY -);` - - res, _ := fizz.AString(` - create_table("users", func(t) { - t.Column("first_name", "string", {}) - t.Column("last_name", "string", {}) - t.Column("email", "string", {"size":20}) - t.Column("permissions", "jsonb", {"null": true}) - t.Column("age", "integer", {"null": true, "default": 40}) - t.Column("uuid", "uuid", {"primary": true}) - }) - `, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_DropTable() { - r := p.Require() - - ddl := `DROP TABLE "users";` - - res, _ := fizz.AString(`drop_table("users")`, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_RenameTable() { - r := p.Require() - - ddl := `ALTER TABLE "users" RENAME TO "people";` - - res, _ := fizz.AString(`rename_table("users", "people")`, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_RenameTable_NotEnoughValues() { - r := p.Require() - - _, err := pgt.RenameTable([]fizz.Table{}) - r.Error(err) -} - -func (p *PostgreSQLSuite) Test_Postgres_AddColumn() { - r := p.Require() - ddl := `ALTER TABLE "mytable" ADD COLUMN "mycolumn" VARCHAR (50) NOT NULL DEFAULT 'foo';` - - res, _ := fizz.AString(`add_column("mytable", "mycolumn", "string", {"default": "foo", "size": 50})`, pgt) - - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_DropColumn() { - r := p.Require() - ddl := `ALTER TABLE "table_name" DROP COLUMN "column_name";` - - res, _ := fizz.AString(`drop_column("table_name", "column_name")`, pgt) - - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_RenameColumn() { - r := p.Require() - ddl := `ALTER TABLE "table_name" RENAME COLUMN "old_column" TO "new_column";` - - res, _ := fizz.AString(`rename_column("table_name", "old_column", "new_column")`, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_AddIndex() { - r := p.Require() - ddl := `CREATE INDEX "table_name_column_name_idx" ON "table_name" (column_name);` - - res, _ := fizz.AString(`add_index("table_name", "column_name", {})`, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_AddIndex_Unique() { - r := p.Require() - ddl := `CREATE UNIQUE INDEX "table_name_column_name_idx" ON "table_name" (column_name);` - - res, _ := fizz.AString(`add_index("table_name", "column_name", {"unique": true})`, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_AddIndex_MultiColumn() { - r := p.Require() - ddl := `CREATE INDEX "table_name_col1_col2_col3_idx" ON "table_name" (col1, col2, col3);` - - res, _ := fizz.AString(`add_index("table_name", ["col1", "col2", "col3"], {})`, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_AddIndex_CustomName() { - r := p.Require() - ddl := `CREATE INDEX "custom_name" ON "table_name" (column_name);` - - res, _ := fizz.AString(`add_index("table_name", "column_name", {"name": "custom_name"})`, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_DropIndex() { - r := p.Require() - ddl := `DROP INDEX "my_idx";` - - res, _ := fizz.AString(`drop_index("users", "my_idx")`, pgt) - r.Equal(ddl, res) -} - -func (p *PostgreSQLSuite) Test_Postgres_RenameIndex() { - r := p.Require() - - ddl := `ALTER INDEX "old_ix" RENAME TO "new_ix";` - - res, _ := fizz.AString(`rename_index("table", "old_ix", "new_ix")`, pgt) - r.Equal(ddl, res) -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/schema.go b/vendor/github.com/markbates/pop/fizz/translators/schema.go deleted file mode 100644 index 9a9d430d..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/schema.go +++ /dev/null @@ -1,8 +0,0 @@ -package translators - -import "github.com/markbates/pop/fizz" - -type Schema interface { - TableInfo(string) (*fizz.Table, error) - Delete(string) -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/sqlite.go b/vendor/github.com/markbates/pop/fizz/translators/sqlite.go deleted file mode 100644 index 1eede7a4..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/sqlite.go +++ /dev/null @@ -1,319 +0,0 @@ -package translators - -import ( - "fmt" - "strings" - - "github.com/pkg/errors" - - "github.com/markbates/pop/fizz" -) - -type SQLite struct { - Schema Schema -} - -func NewSQLite(url string) *SQLite { - return &SQLite{ - Schema: &sqliteSchema{ - URL: url, - schema: map[string]*fizz.Table{}, - }, - } -} - -func (p *SQLite) CreateTable(t fizz.Table) (string, error) { - sql := []string{} - cols := []string{} - var s string - for _, c := range t.Columns { - if c.Primary { - switch c.ColType { - case "integer": - s = fmt.Sprintf("\"%s\" INTEGER PRIMARY KEY AUTOINCREMENT", c.Name) - case "uuid", "string": - s = fmt.Sprintf("\"%s\" TEXT PRIMARY KEY", c.Name) - } - } else { - s = p.buildColumn(c) - } - cols = append(cols, s) - } - s = fmt.Sprintf("CREATE TABLE \"%s\" (\n%s\n);", t.Name, strings.Join(cols, ",\n")) - sql = append(sql, s) - - for _, i := range t.Indexes { - s, err := p.AddIndex(fizz.Table{ - Name: t.Name, - Indexes: []fizz.Index{i}, - }) - if err != nil { - return "", err - } - sql = append(sql, s) - } - - return strings.Join(sql, "\n"), nil -} - -func (p *SQLite) DropTable(t fizz.Table) (string, error) { - p.Schema.Delete(t.Name) - s := fmt.Sprintf("DROP TABLE \"%s\";", t.Name) - return s, nil -} - -func (p *SQLite) RenameTable(t []fizz.Table) (string, error) { - if len(t) < 2 { - return "", errors.New("Not enough table names supplied!") - } - oldName := t[0].Name - newName := t[1].Name - tableInfo, err := p.Schema.TableInfo(oldName) - if err != nil { - return "", err - } - tableInfo.Name = newName - s := fmt.Sprintf("ALTER TABLE \"%s\" RENAME TO \"%s\";", oldName, newName) - return s, nil -} - -func (p *SQLite) AddColumn(t fizz.Table) (string, error) { - if len(t.Columns) == 0 { - return "", errors.New("Not enough columns supplied!") - } - c := t.Columns[0] - - tableInfo, err := p.Schema.TableInfo(t.Name) - if err != nil { - return "", err - } - - tableInfo.Columns = append(tableInfo.Columns, c) - - s := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN %s;", t.Name, p.buildColumn(c)) - return s, nil -} - -func (p *SQLite) DropColumn(t fizz.Table) (string, error) { - if len(t.Columns) < 1 { - return "", errors.New("Not enough columns supplied!") - } - - tableInfo, err := p.Schema.TableInfo(t.Name) - if err != nil { - return "", err - } - - sql := []string{} - droppedColumn := t.Columns[0] - - newColumns := []fizz.Column{} - for _, c := range tableInfo.Columns { - if c.Name != droppedColumn.Name { - newColumns = append(newColumns, c) - } - } - tableInfo.Columns = newColumns - - newIndexes := []fizz.Index{} - for _, i := range tableInfo.Indexes { - s, err := p.DropIndex(fizz.Table{ - Name: tableInfo.Name, - Indexes: []fizz.Index{i}, - }) - if err != nil { - return "", err - } - sql = append(sql, s) - if tableInfo.HasColumns(i.Columns...) { - newIndexes = append(newIndexes, i) - } - } - tableInfo.Indexes = newIndexes - - s, err := p.withTempTable(t.Name, func(tempTable fizz.Table) (string, error) { - createTableSQL, err := p.CreateTable(*tableInfo) - if err != nil { - return "", err - } - - s := fmt.Sprintf("INSERT INTO \"%s\" (%s) SELECT %s FROM \"%s\";", tableInfo.Name, strings.Join(tableInfo.ColumnNames(), ", "), strings.Join(tableInfo.ColumnNames(), ", "), tempTable.Name) - - return strings.Join([]string{createTableSQL, s}, "\n"), nil - }) - - if err != nil { - return "", err - } - sql = append(sql, s) - - return strings.Join(sql, "\n"), nil -} - -func (p *SQLite) RenameColumn(t fizz.Table) (string, error) { - if len(t.Columns) < 2 { - return "", errors.New("Not enough columns supplied!") - } - - tableInfo, err := p.Schema.TableInfo(t.Name) - if err != nil { - return "", err - } - - oldColumn := t.Columns[0] - newColumn := t.Columns[1] - - sql := []string{} - - oldColumns := tableInfo.ColumnNames() - for ic, c := range tableInfo.Columns { - if c.Name == oldColumn.Name { - tableInfo.Columns[ic].Name = newColumn.Name - } - } - - for _, i := range tableInfo.Indexes { - s, err := p.DropIndex(fizz.Table{ - Name: tableInfo.Name, - Indexes: []fizz.Index{i}, - }) - if err != nil { - return "", err - } - sql = append(sql, s) - for ic, c := range i.Columns { - if c == oldColumn.Name { - i.Columns[ic] = newColumn.Name - } - } - } - - s, err := p.withTempTable(t.Name, func(tempTable fizz.Table) (string, error) { - createTableSQL, err := p.CreateTable(*tableInfo) - if err != nil { - return "", err - } - - ins := fmt.Sprintf("INSERT INTO \"%s\" (%s) SELECT %s FROM \"%s\";", t.Name, strings.Join(tableInfo.ColumnNames(), ", "), strings.Join(oldColumns, ", "), tempTable.Name) - return strings.Join([]string{createTableSQL, ins}, "\n"), nil - }) - - if err != nil { - return "", err - } - - sql = append(sql, s) - - return strings.Join(sql, "\n"), nil -} - -func (p *SQLite) AddIndex(t fizz.Table) (string, error) { - if len(t.Indexes) == 0 { - return "", errors.New("Not enough indexes supplied!") - } - i := t.Indexes[0] - s := fmt.Sprintf("CREATE INDEX \"%s\" ON \"%s\" (%s);", i.Name, t.Name, strings.Join(i.Columns, ", ")) - if i.Unique { - s = strings.Replace(s, "CREATE", "CREATE UNIQUE", 1) - } - return s, nil -} - -func (p *SQLite) DropIndex(t fizz.Table) (string, error) { - if len(t.Indexes) == 0 { - return "", errors.New("Not enough indexes supplied!") - } - i := t.Indexes[0] - s := fmt.Sprintf("DROP INDEX IF EXISTS \"%s\";", i.Name) - return s, nil -} - -func (p *SQLite) RenameIndex(t fizz.Table) (string, error) { - if len(t.Indexes) < 2 { - return "", errors.New("Not enough indexes supplied!") - } - - tableInfo, err := p.Schema.TableInfo(t.Name) - if err != nil { - return "", err - } - - sql := []string{} - - oldIndex := t.Indexes[0] - newIndex := t.Indexes[1] - - for _, ti := range tableInfo.Indexes { - if ti.Name == oldIndex.Name { - ti.Name = newIndex.Name - newIndex = ti - break - } - } - - s, err := p.DropIndex(fizz.Table{ - Name: tableInfo.Name, - Indexes: []fizz.Index{oldIndex}, - }) - - if err != nil { - return "", err - } - - sql = append(sql, s) - - s, err = p.AddIndex(fizz.Table{ - Name: t.Name, - Indexes: []fizz.Index{newIndex}, - }) - - if err != nil { - return "", err - } - - sql = append(sql, s) - - return strings.Join(sql, "\n"), nil -} - -func (p *SQLite) withTempTable(table string, fn func(fizz.Table) (string, error)) (string, error) { - tempTable := fizz.Table{Name: fmt.Sprintf("_%s_tmp", table)} - - sql := []string{fmt.Sprintf("ALTER TABLE \"%s\" RENAME TO \"%s\";", table, tempTable.Name)} - s, err := fn(tempTable) - if err != nil { - return "", err - } - sql = append(sql, s, fmt.Sprintf("DROP TABLE \"%s\";", tempTable.Name)) - - return strings.Join(sql, "\n"), nil -} - -func (p *SQLite) buildColumn(c fizz.Column) string { - s := fmt.Sprintf("\"%s\" %s", c.Name, p.colType(c)) - if c.Options["null"] == nil { - s = fmt.Sprintf("%s NOT NULL", s) - } - if c.Options["default"] != nil { - s = fmt.Sprintf("%s DEFAULT '%v'", s, c.Options["default"]) - } - if c.Options["default_raw"] != nil { - s = fmt.Sprintf("%s DEFAULT %s", s, c.Options["default_raw"]) - } - return s -} - -func (p *SQLite) colType(c fizz.Column) string { - switch c.ColType { - case "uuid": - return "char(36)" - case "timestamp": - return "DATETIME" - case "boolean", "DATE": - return "NUMERIC" - case "string": - return "TEXT" - default: - return c.ColType - } -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/sqlite_meta.go b/vendor/github.com/markbates/pop/fizz/translators/sqlite_meta.go deleted file mode 100644 index 15678b8e..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/sqlite_meta.go +++ /dev/null @@ -1,169 +0,0 @@ -package translators - -import ( - "fmt" - "strings" - - "github.com/jmoiron/sqlx" - "github.com/markbates/pop/fizz" -) - -type sqliteIndexListInfo struct { - Seq int `db:"seq"` - Name string `db:"name"` - Unique bool `db:"unique"` - Origin string `db:"origin"` - Partial string `db:"partial"` -} - -type sqliteIndexInfo struct { - Seq int `db:"seqno"` - CID int `db:"cid"` - Name string `db:"name"` -} - -type sqliteTableInfo struct { - CID int `db:"cid"` - Name string `db:"name"` - Type string `db:"type"` - NotNull bool `db:"notnull"` - Default interface{} `db:"dflt_value"` - PK bool `db:"pk"` -} - -func (t sqliteTableInfo) ToColumn() fizz.Column { - c := fizz.Column{ - Name: t.Name, - ColType: t.Type, - Primary: t.PK, - Options: fizz.Options{}, - } - if !t.NotNull { - c.Options["null"] = true - } - if t.Default != nil { - c.Options["default"] = strings.TrimSuffix(strings.TrimPrefix(fmt.Sprintf("%s", t.Default), "'"), "'") - } - return c -} - -type sqliteSchema struct { - URL string - db *sqlx.DB - schema map[string]*fizz.Table -} - -func (p *sqliteSchema) Delete(table string) { - delete(p.schema, table) -} - -func (p *sqliteSchema) TableInfo(table string) (*fizz.Table, error) { - if ti, ok := p.schema[table]; ok { - return ti, nil - } - err := p.buildSchema() - if err != nil { - return nil, err - } - if ti, ok := p.schema[table]; ok { - return ti, nil - } - return nil, fmt.Errorf("Could not find table data for %s!", table) -} - -func (p *sqliteSchema) buildSchema() error { - var err error - p.db, err = sqlx.Open("sqlite3", p.URL) - if err != nil { - return err - } - defer p.db.Close() - - res, err := p.db.Queryx("SELECT name FROM sqlite_master WHERE type='table';") - if err != nil { - return err - } - for res.Next() { - table := &fizz.Table{ - Columns: []fizz.Column{}, - Indexes: []fizz.Index{}, - } - err = res.StructScan(table) - if err != nil { - return err - } - if table.Name != "sqlite_sequence" { - err = p.buildTableData(table) - if err != nil { - return err - } - } - - } - return nil -} - -func (p *sqliteSchema) buildTableData(table *fizz.Table) error { - prag := fmt.Sprintf("PRAGMA table_info(%s)", table.Name) - - res, err := p.db.Queryx(prag) - if err != nil { - return nil - } - - for res.Next() { - ti := sqliteTableInfo{} - err = res.StructScan(&ti) - if err != nil { - return err - } - table.Columns = append(table.Columns, ti.ToColumn()) - } - err = p.buildTableIndexes(table) - if err != nil { - return err - } - p.schema[table.Name] = table - return nil -} - -func (p *sqliteSchema) buildTableIndexes(t *fizz.Table) error { - prag := fmt.Sprintf("PRAGMA index_list(%s)", t.Name) - res, err := p.db.Queryx(prag) - if err != nil { - return err - } - - for res.Next() { - li := sqliteIndexListInfo{} - err = res.StructScan(&li) - if err != nil { - return err - } - - i := fizz.Index{ - Name: li.Name, - Unique: li.Unique, - Columns: []string{}, - } - - prag = fmt.Sprintf("PRAGMA index_info(%s)", i.Name) - iires, err := p.db.Queryx(prag) - if err != nil { - return err - } - - for iires.Next() { - ii := sqliteIndexInfo{} - err = iires.StructScan(&ii) - if err != nil { - return err - } - i.Columns = append(i.Columns, ii.Name) - } - - t.Indexes = append(t.Indexes, i) - - } - return nil -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/sqlite_test.go b/vendor/github.com/markbates/pop/fizz/translators/sqlite_test.go deleted file mode 100644 index 3c0b3ba2..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/sqlite_test.go +++ /dev/null @@ -1,230 +0,0 @@ -package translators_test - -import ( - "fmt" - - "github.com/markbates/pop/fizz" - "github.com/markbates/pop/fizz/translators" -) - -var _ fizz.Translator = (*translators.SQLite)(nil) -var schema = &fauxSchema{schema: map[string]*fizz.Table{}} -var sqt = &translators.SQLite{Schema: schema} - -type fauxSchema struct { - schema map[string]*fizz.Table -} - -func (p *fauxSchema) Delete(table string) { - delete(p.schema, table) -} - -func (p *fauxSchema) TableInfo(table string) (*fizz.Table, error) { - if ti, ok := p.schema[table]; ok { - return ti, nil - } - return nil, fmt.Errorf("Could not find table data for %s!", table) -} - -func (p *SQLiteSuite) Test_SQLite_CreateTable() { - r := p.Require() - ddl := `CREATE TABLE "users" ( -"created_at" DATETIME NOT NULL, -"updated_at" DATETIME NOT NULL, -"first_name" TEXT NOT NULL, -"last_name" TEXT NOT NULL, -"email" TEXT NOT NULL, -"permissions" text, -"age" integer DEFAULT '40', -"id" INTEGER PRIMARY KEY AUTOINCREMENT -);` - - res, _ := fizz.AString(` - create_table("users", func(t) { - t.Column("first_name", "string", {}) - t.Column("last_name", "string", {}) - t.Column("email", "string", {"size":20}) - t.Column("permissions", "text", {"null": true}) - t.Column("age", "integer", {"null": true, "default": 40}) - }) - `, sqt) - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_CreateTable_UUID() { - r := p.Require() - ddl := `CREATE TABLE "users" ( -"created_at" DATETIME NOT NULL, -"updated_at" DATETIME NOT NULL, -"first_name" TEXT NOT NULL, -"last_name" TEXT NOT NULL, -"email" TEXT NOT NULL, -"permissions" text, -"age" integer DEFAULT '40', -"company_id" char(36) NOT NULL DEFAULT lower(hex(randomblob(16))), -"uuid" TEXT PRIMARY KEY -);` - - res, _ := fizz.AString(` - create_table("users", func(t) { - t.Column("first_name", "string", {}) - t.Column("last_name", "string", {}) - t.Column("email", "string", {"size":20}) - t.Column("permissions", "text", {"null": true}) - t.Column("age", "integer", {"null": true, "default": 40}) - t.Column("company_id", "uuid", {"default_raw": "lower(hex(randomblob(16)))"}) - t.Column("uuid", "uuid", {"primary": true}) - }) - `, sqt) - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_DropTable() { - r := p.Require() - - ddl := `DROP TABLE "users";` - - res, _ := fizz.AString(`drop_table("users")`, sqt) - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_RenameTable() { - r := p.Require() - - ddl := `ALTER TABLE "users" RENAME TO "people";` - schema.schema["users"] = &fizz.Table{} - - res, _ := fizz.AString(`rename_table("users", "people")`, sqt) - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_RenameTable_NotEnoughValues() { - r := p.Require() - - _, err := sqt.RenameTable([]fizz.Table{}) - r.Error(err) -} - -func (p *SQLiteSuite) Test_SQLite_AddColumn() { - r := p.Require() - - ddl := `ALTER TABLE "users" ADD COLUMN "mycolumn" TEXT NOT NULL DEFAULT 'foo';` - schema.schema["users"] = &fizz.Table{} - - res, _ := fizz.AString(`add_column("users", "mycolumn", "string", {"default": "foo", "size": 50})`, sqt) - - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_DropColumn() { - r := p.Require() - ddl := `ALTER TABLE "users" RENAME TO "_users_tmp"; -CREATE TABLE "users" ( -"id" INTEGER PRIMARY KEY AUTOINCREMENT, -"updated_at" DATETIME NOT NULL -); -INSERT INTO "users" (id, updated_at) SELECT id, updated_at FROM "_users_tmp"; -DROP TABLE "_users_tmp";` - - schema.schema["users"] = &fizz.Table{ - Name: "users", - Columns: []fizz.Column{ - fizz.INT_ID_COL, - fizz.CREATED_COL, - fizz.UPDATED_COL, - }, - } - res, _ := fizz.AString(`drop_column("users", "created_at")`, sqt) - - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_RenameColumn() { - r := p.Require() - ddl := `ALTER TABLE "users" RENAME TO "_users_tmp"; -CREATE TABLE "users" ( -"id" INTEGER PRIMARY KEY AUTOINCREMENT, -"created_when" DATETIME NOT NULL, -"updated_at" DATETIME NOT NULL -); -INSERT INTO "users" (id, created_when, updated_at) SELECT id, created_at, updated_at FROM "_users_tmp"; -DROP TABLE "_users_tmp";` - - schema.schema["users"] = &fizz.Table{ - Name: "users", - Columns: []fizz.Column{ - fizz.INT_ID_COL, - fizz.CREATED_COL, - fizz.UPDATED_COL, - }, - } - res, _ := fizz.AString(`rename_column("users", "created_at", "created_when")`, sqt) - - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_AddIndex() { - r := p.Require() - ddl := `CREATE INDEX "table_name_column_name_idx" ON "table_name" (column_name);` - - res, _ := fizz.AString(`add_index("table_name", "column_name", {})`, sqt) - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_AddIndex_Unique() { - r := p.Require() - ddl := `CREATE UNIQUE INDEX "table_name_column_name_idx" ON "table_name" (column_name);` - - res, _ := fizz.AString(`add_index("table_name", "column_name", {"unique": true})`, sqt) - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_AddIndex_MultiColumn() { - r := p.Require() - ddl := `CREATE INDEX "table_name_col1_col2_col3_idx" ON "table_name" (col1, col2, col3);` - - res, _ := fizz.AString(`add_index("table_name", ["col1", "col2", "col3"], {})`, sqt) - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_AddIndex_CustomName() { - r := p.Require() - ddl := `CREATE INDEX "custom_name" ON "table_name" (column_name);` - - res, _ := fizz.AString(`add_index("table_name", "column_name", {"name": "custom_name"})`, sqt) - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_DropIndex() { - r := p.Require() - ddl := `DROP INDEX IF EXISTS "my_idx";` - - res, _ := fizz.AString(`drop_index("my_table", "my_idx")`, sqt) - r.Equal(ddl, res) -} - -func (p *SQLiteSuite) Test_SQLite_RenameIndex() { - r := p.Require() - - ddl := `DROP INDEX IF EXISTS "old_ix"; -CREATE UNIQUE INDEX "new_ix" ON "users" (id, created_at);` - - schema.schema["users"] = &fizz.Table{ - Name: "users", - Columns: []fizz.Column{ - fizz.INT_ID_COL, - fizz.CREATED_COL, - fizz.UPDATED_COL, - }, - Indexes: []fizz.Index{ - { - Name: "old_ix", - Columns: []string{"id", "created_at"}, - Unique: true, - }, - }, - } - - res, _ := fizz.AString(`rename_index("users", "old_ix", "new_ix")`, sqt) - r.Equal(ddl, res) -} diff --git a/vendor/github.com/markbates/pop/fizz/translators/translators_test.go b/vendor/github.com/markbates/pop/fizz/translators/translators_test.go deleted file mode 100644 index a3b12568..00000000 --- a/vendor/github.com/markbates/pop/fizz/translators/translators_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package translators_test - -import ( - "os" - "testing" - - "github.com/stretchr/testify/suite" -) - -type PostgreSQLSuite struct { - suite.Suite -} - -type MySQLSuite struct { - suite.Suite -} - -type SQLiteSuite struct { - suite.Suite -} - -func TestSpecificSuites(t *testing.T) { - switch os.Getenv("SODA_DIALECT") { - case "postgres": - suite.Run(t, &PostgreSQLSuite{}) - case "mysql": - suite.Run(t, &MySQLSuite{}) - case "sqlite": - suite.Run(t, &SQLiteSuite{}) - } -} diff --git a/vendor/github.com/markbates/pop/grifts/release.go b/vendor/github.com/markbates/pop/grifts/release.go deleted file mode 100644 index a6c1e605..00000000 --- a/vendor/github.com/markbates/pop/grifts/release.go +++ /dev/null @@ -1,139 +0,0 @@ -package grifts - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "net/http" - "os" - "os/exec" - "path/filepath" - "regexp" - - . "github.com/markbates/grift/grift" -) - -var _ = Desc("release", "Generates a CHANGELOG and creates a new GitHub release based on what is in the version.go file.") -var _ = Add("release", func(c *Context) error { - Run("shoulders", c) - v, err := findVersion() - if err != nil { - return err - } - - err = installBin() - if err != nil { - return err - } - - err = localTest() - if err != nil { - return err - } - - err = tagRelease(v) - if err != nil { - return err - } - - err = runChangelogGenerator(v) - if err != nil { - return err - } - - return commitAndPush(v) -}) - -func installBin() error { - cmd := exec.Command("go", "install", "-v", "./soda") - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - return cmd.Run() -} - -func localTest() error { - cmd := exec.Command("./test.sh") - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - return cmd.Run() -} - -func tagRelease(v string) error { - token := os.Getenv("GITHUB_TOKEN") - if token == "" { - return errors.New("GITHUB_TOKEN is not set!!") - } - - body := map[string]interface{}{ - "tag_name": fmt.Sprintf("v%s", v), - "prerelease": false, - } - - b, err := json.Marshal(&body) - if err != nil { - return err - } - - res, err := http.Post(fmt.Sprintf("https://api.github.com/repos/markbates/pop/releases?access_token=%s", token), "application/json", bytes.NewReader(b)) - if err != nil { - return err - } - - code := res.StatusCode - if code < 200 || code >= 300 { - io.Copy(os.Stderr, res.Body) - return fmt.Errorf("got a not successful status code from github! %d", code) - } - - return nil -} - -func runChangelogGenerator(v string) error { - cmd := exec.Command("github_changelog_generator") - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - return cmd.Run() -} - -func commitAndPush(v string) error { - cmd := exec.Command("git", "commit", "CHANGELOG.md", "-m", fmt.Sprintf("Updated changelog for release v%s", v)) - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - err := cmd.Run() - if err != nil { - return err - } - - cmd = exec.Command("git", "push", "origin", "master") - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - return cmd.Run() -} - -func findVersion() (string, error) { - pwd, err := os.Getwd() - if err != nil { - return "", err - } - vfile, err := ioutil.ReadFile(filepath.Join(pwd, "soda/cmd/version.go")) - if err != nil { - return "", err - } - - //var Version = "0.4.0" - re := regexp.MustCompile(`const Version = "(.+)"`) - matches := re.FindStringSubmatch(string(vfile)) - if len(matches) < 2 { - return "", errors.New("failed to find the version!") - } - v := matches[1] - return v, nil -} diff --git a/vendor/github.com/markbates/pop/migration.go b/vendor/github.com/markbates/pop/migration.go deleted file mode 100644 index cdc5ce3c..00000000 --- a/vendor/github.com/markbates/pop/migration.go +++ /dev/null @@ -1,201 +0,0 @@ -package pop - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "regexp" - "sort" - "time" - - "github.com/markbates/pop/fizz" - _ "github.com/mattn/go-sqlite3" - "github.com/pkg/errors" -) - -var mrx = regexp.MustCompile("(\\d+)_(.+)\\.(up|down)\\.(sql|fizz)") - -func init() { - MapTableName("schema_migrations", "schema_migration") - MapTableName("schema_migration", "schema_migration") -} - -var schemaMigrations = fizz.Table{ - Name: "schema_migration", - Columns: []fizz.Column{ - {Name: "version", ColType: "string"}, - }, - Indexes: []fizz.Index{ - {Name: "version_idx", Columns: []string{"version"}, Unique: true}, - }, -} - -func MigrationCreate(path, name, ext string, up, down []byte) error { - n := time.Now().UTC() - s := n.Format("20060102150405") - - err := os.MkdirAll(path, 0766) - if err != nil { - return errors.Wrapf(err, "couldn't create migrations path %s", path) - } - - upf := filepath.Join(path, (fmt.Sprintf("%s_%s.up.%s", s, name, ext))) - err = ioutil.WriteFile(upf, up, 0666) - if err != nil { - return errors.Wrapf(err, "couldn't write up migration %s", upf) - } - fmt.Printf("> %s\n", upf) - - downf := filepath.Join(path, (fmt.Sprintf("%s_%s.down.%s", s, name, ext))) - err = ioutil.WriteFile(downf, down, 0666) - if err != nil { - return errors.Wrapf(err, "couldn't write up migration %s", downf) - } - - fmt.Printf("> %s\n", downf) - return nil -} - -func (c *Connection) MigrateUp(path string) error { - now := time.Now() - defer printTimer(now) - - err := c.createSchemaMigrations() - if err != nil { - return errors.Wrap(err, "migration up: problem creating schema migrations") - } - return findMigrations(path, "up", 0, func(m migrationFile) error { - exists, err := c.Where("version = ?", m.Version).Exists("schema_migration") - if err != nil || exists { - return errors.Wrapf(err, "problem checking for migration version %s", m.Version) - } - err = c.Transaction(func(tx *Connection) error { - err := m.Execute(tx) - if err != nil { - return err - } - _, err = tx.Store.Exec(fmt.Sprintf("insert into schema_migration (version) values ('%s')", m.Version)) - return errors.Wrapf(err, "problem inserting migration version %s", m.Version) - }) - if err == nil { - fmt.Printf("> %s\n", m.FileName) - } - return err - }, -1) -} - -func (c *Connection) MigrateDown(path string, step int) error { - now := time.Now() - defer printTimer(now) - - err := c.createSchemaMigrations() - if err != nil { - return errors.Wrap(err, "migration down: problem creating schema migrations") - } - - //increase skip by - count, err := c.Count("schema_migration") - if err != nil { - return errors.Wrap(err, "migration down: unable count existing migration") - } - - return findMigrations(path, "down", count, func(m migrationFile) error { - exists, err := c.Where("version = ?", m.Version).Exists("schema_migration") - if err != nil || !exists { - fmt.Errorf("migration missing: %s", m.Version) - return errors.Wrapf(err, "problem checking for migration version %s", m.Version) - } - err = c.Transaction(func(tx *Connection) error { - err := m.Execute(tx) - if err != nil { - return err - } - err = tx.RawQuery("delete from schema_migration where version = ?", m.Version).Exec() - return errors.Wrapf(err, "problem deleting migration version %s", m.Version) - }) - if err == nil { - fmt.Printf("< %s\n", m.FileName) - } - return err - }, step) -} - -func (c *Connection) MigrateReset(path string) error { - err := c.MigrateDown(path, -1) - if err != nil { - return err - } - return c.MigrateUp(path) -} - -func (c *Connection) createSchemaMigrations() error { - err := c.Open() - if err != nil { - return errors.Wrap(err, "could not open connection") - } - _, err = c.Store.Exec("select * from schema_migration") - if err == nil { - return nil - } - - return c.Transaction(func(tx *Connection) error { - smSQL, err := c.Dialect.FizzTranslator().CreateTable(schemaMigrations) - if err != nil { - return errors.Wrap(err, "could not build SQL for schema migration table") - } - return errors.Wrap(tx.RawQuery(smSQL).Exec(), "could not create schema migration table") - }) -} - -func findMigrations(dir string, direction string, runned int, fn func(migrationFile) error, step int) error { - mfs := migrationFiles{} - filepath.Walk(dir, func(p string, info os.FileInfo, err error) error { - if !info.IsDir() { - matches := mrx.FindAllStringSubmatch(info.Name(), -1) - if matches == nil || len(matches) == 0 { - return nil - } - m := matches[0] - mf := migrationFile{ - Path: p, - FileName: m[0], - Version: m[1], - Name: m[2], - Direction: m[3], - FileType: m[4], - } - if mf.Direction == direction { - mfs = append(mfs, mf) - } - } - return nil - }) - if direction == "down" { - sort.Sort(sort.Reverse(mfs)) - // skip all runned migration - mfs = mfs[len(mfs)-runned:] - // run only required steps - if step > 0 && len(mfs) >= step { - mfs = mfs[:step] - } - } else { - sort.Sort(mfs) - } - for _, mf := range mfs { - err := fn(mf) - if err != nil { - return errors.Wrap(err, "error from called function") - } - } - return nil -} - -func printTimer(timerStart time.Time) { - diff := time.Now().Sub(timerStart).Seconds() - if diff > 60 { - fmt.Printf("\n%.4f minutes\n", diff/60) - } else { - fmt.Printf("\n%.4f seconds\n", diff) - } -} diff --git a/vendor/github.com/markbates/pop/migration_file.go b/vendor/github.com/markbates/pop/migration_file.go deleted file mode 100644 index 6500a710..00000000 --- a/vendor/github.com/markbates/pop/migration_file.go +++ /dev/null @@ -1,76 +0,0 @@ -package pop - -import ( - "bytes" - "html/template" - "io/ioutil" - "path" - - "github.com/markbates/pop/fizz" - "github.com/pkg/errors" -) - -type migrationFile struct { - Path string - FileName string - Version string - Name string - Direction string - FileType string -} - -type migrationFiles []migrationFile - -func (mfs migrationFiles) Len() int { - return len(mfs) -} - -func (mfs migrationFiles) Less(i, j int) bool { - return mfs[i].Version < mfs[j].Version -} - -func (mfs migrationFiles) Swap(i, j int) { - mfs[i], mfs[j] = mfs[j], mfs[i] -} - -func (m migrationFile) Content(c *Connection) (string, error) { - b, err := ioutil.ReadFile(m.Path) - if err != nil { - return "", nil - } - content := string(b) - ext := path.Ext(m.FileName) - - t := template.Must(template.New("sql").Parse(content)) - var bb bytes.Buffer - err = t.Execute(&bb, c.Dialect.Details()) - if err != nil { - return "", errors.Wrapf(err, "could not execute migration template %s", m.Path) - } - content = bb.String() - - if ext == ".fizz" { - content, err = fizz.AString(content, c.Dialect.FizzTranslator()) - if err != nil { - return "", errors.Wrapf(err, "could not fizz the migration %s", m.Path) - } - } - return content, nil -} - -func (m migrationFile) Execute(c *Connection) error { - content, err := m.Content(c) - if err != nil { - return errors.Wrapf(err, "error processing %s", m.FileName) - } - - if content == "" { - return nil - } - - err = c.RawQuery(content).Exec() - if err != nil { - return errors.Wrapf(err, "error executing %s, sql: %s", m.FileName, content) - } - return nil -} diff --git a/vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests.down.fizz b/vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests.down.fizz deleted file mode 100644 index 8d01f68b..00000000 --- a/vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests.down.fizz +++ /dev/null @@ -1,4 +0,0 @@ -drop_table("users") -drop_table("good_friends") -drop_table("validatable_cars") -drop_table("not_validatable_cars") diff --git a/vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests.up.fizz b/vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests.up.fizz deleted file mode 100644 index 9ff5ad71..00000000 --- a/vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests.up.fizz +++ /dev/null @@ -1,21 +0,0 @@ -create_table("users", func(t) { - t.Column("name", "string", {}) - t.Column("alive", "boolean", {"null": true}) - t.Column("birth_date", "timestamp", {"null": true}) - t.Column("bio", "text", {"null": true}) - t.Column("price", "numeric", {"null": true, "default": "1.00"}) - t.Column("email", "string", {"default": "foo@example.com", "size": 50}) -}) - -create_table("good_friends", func(t) { - t.Column("first_name", "string", {}) - t.Column("last_name", "string", {}) -}) - -create_table("validatable_cars", func(t) { - t.Column("name", "string", {}) -}) - -create_table("not_validatable_cars", func(t) { - t.Column("name", "string", {}) -}) diff --git a/vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests2.down.fizz b/vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests2.down.fizz deleted file mode 100644 index 490dfe92..00000000 --- a/vendor/github.com/markbates/pop/migrations/20160808213308_setup_tests2.down.fizz +++ /dev/null @@ -1,4 +0,0 @@ -drop_table("songs") -{{ if eq .Dialect "postgres" }} -drop_table("cakes") -{{ end }} diff --git a/vendor/github.com/markbates/pop/migrations/20160808213310_setup_tests2.up.fizz b/vendor/github.com/markbates/pop/migrations/20160808213310_setup_tests2.up.fizz deleted file mode 100644 index b60b5691..00000000 --- a/vendor/github.com/markbates/pop/migrations/20160808213310_setup_tests2.up.fizz +++ /dev/null @@ -1,12 +0,0 @@ -create_table("songs", func(t) { - t.Column("id", "uuid", {"primary":true}) - t.Column("title", "string", {}) -}) - -{{ if eq .Dialect "postgres" }} -create_table("cakes", func(t) { - t.Column("int_slice", "int[]", {"null": true}) - t.Column("float_slice", "numeric[]", {"null": true}) - t.Column("string_slice", "varchar[]", {"null": true}) -}) -{{ end }} diff --git a/vendor/github.com/markbates/pop/model.go b/vendor/github.com/markbates/pop/model.go deleted file mode 100644 index 3b47bceb..00000000 --- a/vendor/github.com/markbates/pop/model.go +++ /dev/null @@ -1,186 +0,0 @@ -package pop - -import ( - "fmt" - "reflect" - "sync" - "time" - - "github.com/markbates/inflect" - "github.com/markbates/validate" - "github.com/pkg/errors" - "github.com/satori/go.uuid" -) - -var tableMap = map[string]string{} -var tableMapMu = sync.RWMutex{} - -// MapTableName allows for the customize table mapping -// between a name and the database. For example the value -// `User{}` will automatically map to "users". -// MapTableName would allow this to change. -// -// m := &pop.Model{Value: User{}} -// m.TableName() // "users" -// -// pop.MapTableName("user", "people") -// m = &pop.Model{Value: User{}} -// m.TableName() // "people" -func MapTableName(name string, tableName string) { - defer tableMapMu.Unlock() - tableMapMu.Lock() - tableMap[name] = tableName -} - -type Value interface{} - -// Model is used throughout Pop to wrap the end user interface -// that is passed in to many functions. -type Model struct { - Value - tableName string -} - -func (m *Model) runValidations(c *Connection, names ...string) (*validate.Errors, error) { - for _, n := range names { - rv := reflect.ValueOf(m.Value) - mv := rv.MethodByName(n) - if mv.IsValid() { - if mv.Type().NumOut() < 2 { - return nil, errors.Errorf("%s does not have the correct method signature!", n) - } - out := mv.Call([]reflect.Value{reflect.ValueOf(c)}) - verrs := validate.NewErrors() - var err error - if !out[0].IsNil() { - verrs = out[0].Interface().(*validate.Errors) - } - if !out[1].IsNil() { - err = out[1].Interface().(error) - } - if verrs.HasAny() || err != nil { - return verrs, err - } - } - } - return validate.NewErrors(), nil -} - -func (m *Model) validate(c *Connection) (*validate.Errors, error) { - return m.runValidations(c, "Validate") -} - -func (m *Model) validateCreate(c *Connection) (*validate.Errors, error) { - return m.runValidations(c, "Validate", "ValidateCreate") -} - -func (m *Model) validateSave(c *Connection) (*validate.Errors, error) { - return m.runValidations(c, "Validate", "ValidateSave") -} - -func (m *Model) validateUpdate(c *Connection) (*validate.Errors, error) { - return m.runValidations(c, "Validate", "ValidateUpdate") -} - -// ID returns the ID of the Model. All models must have an `ID` field this is -// of type `int` or of type `uuid.UUID`. -func (m *Model) ID() interface{} { - fbn, err := m.fieldByName("ID") - if err != nil { - return 0 - } - if m.PrimaryKeyType() == "UUID" { - return fbn.Interface().(uuid.UUID).String() - } - return fbn.Interface() -} - -func (m *Model) PrimaryKeyType() string { - fbn, err := m.fieldByName("ID") - if err != nil { - return "int" - } - return fbn.Type().Name() -} - -// TableName returns the corresponding name of the underlying database table -// for a given `Model`. See also `MapTableName` to change the default name of -// the table. -func (m *Model) TableName() string { - if m.tableName != "" { - return m.tableName - } - - t := reflect.TypeOf(m.Value) - name := m.typeName(t) - - defer tableMapMu.Unlock() - tableMapMu.Lock() - - if tableMap[name] == "" { - m.tableName = inflect.Tableize(name) - tableMap[name] = m.tableName - } - return tableMap[name] -} - -func (m *Model) typeName(t reflect.Type) string { - kind := t.Kind().String() - switch kind { - case "ptr": - st := reflect.ValueOf(m.Value).Elem() - return m.typeName(st.Type()) - case "string": - return m.Value.(string) - case "slice": - if t.Elem().Kind().String() == "ptr" { - return m.typeName(t.Elem().Elem()) - } - return t.Elem().Name() - default: - return t.Name() - } -} - -func (m *Model) fieldByName(s string) (reflect.Value, error) { - el := reflect.ValueOf(m.Value).Elem() - fbn := el.FieldByName(s) - if !fbn.IsValid() { - return fbn, errors.Errorf("Model does not have a field named %s", s) - } - return fbn, nil -} - -func (m *Model) associationName() string { - tn := inflect.Singularize(m.TableName()) - return fmt.Sprintf("%s_id", tn) -} - -func (m *Model) setID(i interface{}) { - fbn, err := m.fieldByName("ID") - if err == nil { - fbn.Set(reflect.ValueOf(i)) - } -} - -func (m *Model) touchCreatedAt() { - fbn, err := m.fieldByName("CreatedAt") - if err == nil { - fbn.Set(reflect.ValueOf(time.Now())) - } -} - -func (m *Model) touchUpdatedAt() { - fbn, err := m.fieldByName("UpdatedAt") - if err == nil { - fbn.Set(reflect.ValueOf(time.Now())) - } -} - -func (m *Model) whereID() string { - id := m.ID() - if _, ok := id.(int); ok { - return fmt.Sprintf("%s.id = %d", m.TableName(), id) - } - return fmt.Sprintf("%s.id ='%s'", m.TableName(), id) -} diff --git a/vendor/github.com/markbates/pop/model_test.go b/vendor/github.com/markbates/pop/model_test.go deleted file mode 100644 index c9932b19..00000000 --- a/vendor/github.com/markbates/pop/model_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package pop_test - -import ( - "testing" - - "github.com/markbates/pop" - "github.com/stretchr/testify/require" -) - -func Test_Model_TableName(t *testing.T) { - r := require.New(t) - - m := pop.Model{Value: User{}} - r.Equal(m.TableName(), "users") - - m = pop.Model{Value: &User{}} - r.Equal(m.TableName(), "users") - - m = pop.Model{Value: &Users{}} - r.Equal(m.TableName(), "users") - - m = pop.Model{Value: []User{}} - r.Equal(m.TableName(), "users") - - m = pop.Model{Value: &[]User{}} - r.Equal(m.TableName(), "users") - - m = pop.Model{Value: []*User{}} - r.Equal(m.TableName(), "users") - -} - -func Test_MapTableName(t *testing.T) { - r := require.New(t) - - pop.MapTableName("Friend", "good_friends") - - m := pop.Model{Value: Friend{}} - r.Equal(m.TableName(), "good_friends") - - m = pop.Model{Value: &Friend{}} - r.Equal(m.TableName(), "good_friends") - - m = pop.Model{Value: &Friends{}} - r.Equal(m.TableName(), "good_friends") - - m = pop.Model{Value: []Friend{}} - r.Equal(m.TableName(), "good_friends") - - m = pop.Model{Value: &[]Friend{}} - r.Equal(m.TableName(), "good_friends") -} diff --git a/vendor/github.com/markbates/pop/mysql.go b/vendor/github.com/markbates/pop/mysql.go deleted file mode 100644 index 047d8f0e..00000000 --- a/vendor/github.com/markbates/pop/mysql.go +++ /dev/null @@ -1,169 +0,0 @@ -package pop - -import ( - "fmt" - "io" - "os" - "os/exec" - "strings" - - _ "github.com/go-sql-driver/mysql" - . "github.com/markbates/pop/columns" - "github.com/markbates/pop/fizz" - "github.com/markbates/pop/fizz/translators" - "github.com/pkg/errors" -) - -var _ dialect = &mysql{} - -type mysql struct { - ConnectionDetails *ConnectionDetails -} - -func (m *mysql) Details() *ConnectionDetails { - return m.ConnectionDetails -} - -func (m *mysql) URL() string { - c := m.ConnectionDetails - if c.URL != "" { - return c.URL - } - - s := "%s:%s@(%s:%s)/%s?parseTime=true&multiStatements=true&readTimeout=1s" - return fmt.Sprintf(s, c.User, c.Password, c.Host, c.Port, c.Database) -} - -func (m *mysql) MigrationURL() string { - return m.URL() -} - -func (m *mysql) Create(s store, model *Model, cols Columns) error { - return errors.Wrap(genericCreate(s, model, cols), "mysql create") -} - -func (m *mysql) Update(s store, model *Model, cols Columns) error { - return errors.Wrap(genericUpdate(s, model, cols), "mysql update") -} - -func (m *mysql) Destroy(s store, model *Model) error { - return errors.Wrap(genericDestroy(s, model), "mysql destroy") -} - -func (m *mysql) SelectOne(s store, model *Model, query Query) error { - return errors.Wrap(genericSelectOne(s, model, query), "mysql select one") -} - -func (m *mysql) SelectMany(s store, models *Model, query Query) error { - return errors.Wrap(genericSelectMany(s, models, query), "mysql select many") -} - -func (m *mysql) CreateDB() error { - c := m.ConnectionDetails - cmd := exec.Command("mysql", "-u", c.User, "-p"+c.Password, "-h", c.Host, "-P", c.Port, "-e", fmt.Sprintf("create database %s", c.Database)) - Log(strings.Join(cmd.Args, " ")) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stderr - cmd.Stdout = os.Stdout - err := cmd.Run() - if err != nil { - return errors.Wrapf(err, "error creating MySQL database %s", c.Database) - } - fmt.Printf("created database %s\n", c.Database) - return nil -} - -func (m *mysql) DropDB() error { - c := m.ConnectionDetails - cmd := exec.Command("mysql", "-u", c.User, "-p"+c.Password, "-h", c.Host, "-P", c.Port, "-e", fmt.Sprintf("drop database %s", c.Database)) - Log(strings.Join(cmd.Args, " ")) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stderr - cmd.Stdout = os.Stdout - err := cmd.Run() - if err != nil { - return errors.Wrapf(err, "error dropping MySQL database %s", c.Database) - } - fmt.Printf("dropped database %s\n", c.Database) - return nil -} - -func (m *mysql) TranslateSQL(sql string) string { - return sql -} - -func (m *mysql) FizzTranslator() fizz.Translator { - t := translators.NewMySQL(m.URL(), m.Details().Database) - return t -} - -func (m *mysql) Lock(fn func() error) error { - return fn() -} - -func (m *mysql) DumpSchema(w io.Writer) error { - deets := m.Details() - cmd := exec.Command("mysqldump", "-d", "-h", deets.Host, "-P", deets.Port, "-u", deets.User, fmt.Sprintf("--password=%s", deets.Password), deets.Database) - Log(strings.Join(cmd.Args, " ")) - cmd.Stdout = w - cmd.Stderr = os.Stderr - - err := cmd.Run() - if err != nil { - return err - } - - fmt.Printf("dumped schema for %s\n", m.Details().Database) - return nil -} - -func (m *mysql) LoadSchema(r io.Reader) error { - deets := m.Details() - cmd := exec.Command("mysql", "-u", deets.User, fmt.Sprintf("--password=%s", deets.Password), "-h", deets.Host, "-P", deets.Port, "-D", deets.Database) - in, err := cmd.StdinPipe() - if err != nil { - return err - } - go func() { - defer in.Close() - io.Copy(in, r) - }() - Log(strings.Join(cmd.Args, " ")) - err = cmd.Start() - if err != nil { - return err - } - - err = cmd.Wait() - if err != nil { - return err - } - - fmt.Printf("loaded schema for %s\n", m.Details().Database) - return nil -} - -func (m *mysql) TruncateAll(tx *Connection) error { - stmts := []struct { - Stmt string `db:"stmt"` - }{} - err := tx.RawQuery(mysqlTruncate, m.Details().Database).All(&stmts) - if err != nil { - return err - } - qs := []string{} - for _, x := range stmts { - qs = append(qs, x.Stmt) - } - return tx.RawQuery(strings.Join(qs, " ")).Exec() -} - -func newMySQL(deets *ConnectionDetails) dialect { - cd := &mysql{ - ConnectionDetails: deets, - } - - return cd -} - -const mysqlTruncate = "SELECT concat('TRUNCATE TABLE `', TABLE_NAME, '`;') as stmt FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = ?" diff --git a/vendor/github.com/markbates/pop/nulls/README.md b/vendor/github.com/markbates/pop/nulls/README.md deleted file mode 100644 index d7ad3397..00000000 --- a/vendor/github.com/markbates/pop/nulls/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# github.com/markbates/pop/nulls - -This package should be used in place of the built-in null types in the `sql` package. - -The real benefit of this packages comes in its implementation of `MarshalJSON` and `UnmarshalJSON` to properly encode/decode `null` values. - -## Installation - -``` bash -$ go get github.com/markbates/pop/nulls -``` - -## Supported Datatypes - -* `string` (`nulls.String`) - Replaces `sql.NullString` -* `int64` (`nulls.Int64`) - Replaces `sql.NullInt64` -* `float64` (`nulls.Float64`) - Replaces `sql.NullFloat64` -* `bool` (`nulls.Bool`) - Replaces `sql.NullBool` -* `[]byte` (`nulls.ByteSlice`) -* `float32` (`nulls.Float32`) -* `int` (`nulls.Int`) -* `int32` (`nulls.Int32`) -* `uint32` (`nulls.UInt32`) -* `time.Time` (`nulls.Time`) diff --git a/vendor/github.com/markbates/pop/nulls/bool.go b/vendor/github.com/markbates/pop/nulls/bool.go deleted file mode 100644 index d3892005..00000000 --- a/vendor/github.com/markbates/pop/nulls/bool.go +++ /dev/null @@ -1,78 +0,0 @@ -package nulls - -import ( - "database/sql" - "database/sql/driver" - "encoding/json" -) - -// Bool replaces sql.NullBool with an implementation -// that supports proper JSON encoding/decoding. -type Bool struct { - Bool bool - Valid bool -} - -func (ns Bool) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.Bool -} - -// NewBool returns a new, properly instantiated -// Boll object. -func NewBool(b bool) Bool { - return Bool{Bool: b, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *Bool) Scan(value interface{}) error { - n := sql.NullBool{Bool: ns.Bool} - err := n.Scan(value) - ns.Bool, ns.Valid = n.Bool, n.Valid - return err -} - -// Value implements the driver Valuer interface. -func (ns Bool) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return ns.Bool, nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns Bool) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.Bool) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the proper representation of that value. The strings -// "true" and "t" will be considered "true", "false" and "f" will -// be treated as "false". All other values will -//be set to null by Valid = false -func (ns *Bool) UnmarshalJSON(text []byte) error { - t := string(text) - if t == "true" || t == "t" { - ns.Valid = true - ns.Bool = true - return nil - } - if t == "false" || t == "f" { - ns.Valid = true - ns.Bool = false - return nil - } - ns.Bool = false - ns.Valid = false - return nil -} - -func (ns *Bool) UnmarshalText(text []byte) error { - return ns.UnmarshalJSON(text) -} diff --git a/vendor/github.com/markbates/pop/nulls/byte_slice.go b/vendor/github.com/markbates/pop/nulls/byte_slice.go deleted file mode 100644 index 06930344..00000000 --- a/vendor/github.com/markbates/pop/nulls/byte_slice.go +++ /dev/null @@ -1,72 +0,0 @@ -package nulls - -import ( - "database/sql" - "database/sql/driver" - "encoding/base64" - "encoding/json" -) - -// ByteSlice adds an implementation for []byte -// that supports proper JSON encoding/decoding. -type ByteSlice struct { - ByteSlice []byte - Valid bool // Valid is true if ByteSlice is not NULL -} - -func (ns ByteSlice) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.ByteSlice -} - -// NewByteSlice returns a new, properly instantiated -// ByteSlice object. -func NewByteSlice(b []byte) ByteSlice { - return ByteSlice{ByteSlice: b, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *ByteSlice) Scan(value interface{}) error { - n := sql.NullString{String: base64.StdEncoding.EncodeToString(ns.ByteSlice)} - err := n.Scan(value) - //ns.Float32, ns.Valid = float32(n.Float64), n.Valid - ns.ByteSlice, err = base64.StdEncoding.DecodeString(n.String) - ns.Valid = n.Valid - return err -} - -// Value implements the driver Valuer interface. -func (ns ByteSlice) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return base64.StdEncoding.EncodeToString(ns.ByteSlice), nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns ByteSlice) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.ByteSlice) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the propert representation of that value. -func (ns *ByteSlice) UnmarshalJSON(text []byte) error { - ns.Valid = false - if string(text) == "null" { - return nil - } - - ns.ByteSlice = text - ns.Valid = true - return nil -} - -func (ns *ByteSlice) UnmarshalText(text []byte) error { - return ns.UnmarshalJSON(text) -} diff --git a/vendor/github.com/markbates/pop/nulls/float32.go b/vendor/github.com/markbates/pop/nulls/float32.go deleted file mode 100644 index c64478f9..00000000 --- a/vendor/github.com/markbates/pop/nulls/float32.go +++ /dev/null @@ -1,76 +0,0 @@ -package nulls - -import ( - "database/sql" - "database/sql/driver" - "encoding/json" - "strconv" -) - -// Float32 adds an implementation for float32 -// that supports proper JSON encoding/decoding. -type Float32 struct { - Float32 float32 - Valid bool // Valid is true if Float32 is not NULL -} - -func (ns Float32) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.Float32 -} - -// NewFloat32 returns a new, properly instantiated -// Float32 object. -func NewFloat32(i float32) Float32 { - return Float32{Float32: i, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *Float32) Scan(value interface{}) error { - n := sql.NullFloat64{Float64: float64(ns.Float32)} - err := n.Scan(value) - ns.Float32, ns.Valid = float32(n.Float64), n.Valid - return err -} - -// Value implements the driver Valuer interface. -func (ns Float32) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return float64(ns.Float32), nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns Float32) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.Float32) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the propert representation of that value. -func (ns *Float32) UnmarshalJSON(text []byte) error { - txt := string(text) - ns.Valid = true - if txt == "null" { - ns.Valid = false - return nil - } - i, err := strconv.ParseFloat(txt, 32) - if err != nil { - ns.Valid = false - return err - } - j := float32(i) - ns.Float32 = j - return nil -} - -func (ns *Float32) UnmarshalText(text []byte) error { - return ns.UnmarshalJSON(text) -} diff --git a/vendor/github.com/markbates/pop/nulls/float64.go b/vendor/github.com/markbates/pop/nulls/float64.go deleted file mode 100644 index 54a9f15e..00000000 --- a/vendor/github.com/markbates/pop/nulls/float64.go +++ /dev/null @@ -1,72 +0,0 @@ -package nulls - -import ( - "database/sql" - "database/sql/driver" - "encoding/json" - "strconv" -) - -// Float64 replaces sql.NullFloat64 with an implementation -// that supports proper JSON encoding/decoding. -type Float64 sql.NullFloat64 - -func (ns Float64) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.Float64 -} - -// NewFloat64 returns a new, properly instantiated -// Float64 object. -func NewFloat64(i float64) Float64 { - return Float64{Float64: i, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *Float64) Scan(value interface{}) error { - n := sql.NullFloat64{Float64: ns.Float64} - err := n.Scan(value) - ns.Float64, ns.Valid = n.Float64, n.Valid - return err -} - -// Value implements the driver Valuer interface. -func (ns Float64) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return ns.Float64, nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns Float64) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.Float64) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the propert representation of that value. -func (ns *Float64) UnmarshalJSON(text []byte) error { - t := string(text) - ns.Valid = true - if t == "null" { - ns.Valid = false - return nil - } - i, err := strconv.ParseFloat(t, 64) - if err != nil { - ns.Valid = false - return err - } - ns.Float64 = i - return nil -} - -func (ns *Float64) UnmarshalText(text []byte) error { - return ns.UnmarshalJSON(text) -} diff --git a/vendor/github.com/markbates/pop/nulls/int.go b/vendor/github.com/markbates/pop/nulls/int.go deleted file mode 100644 index 148da03d..00000000 --- a/vendor/github.com/markbates/pop/nulls/int.go +++ /dev/null @@ -1,76 +0,0 @@ -package nulls - -import ( - "database/sql" - "database/sql/driver" - "encoding/json" - "strconv" -) - -// Int adds an implementation for int -// that supports proper JSON encoding/decoding. -type Int struct { - Int int - Valid bool // Valid is true if Int is not NULL -} - -func (ns Int) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.Int -} - -// NewInt returns a new, properly instantiated -// Int object. -func NewInt(i int) Int { - return Int{Int: i, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *Int) Scan(value interface{}) error { - n := sql.NullInt64{Int64: int64(ns.Int)} - err := n.Scan(value) - ns.Int, ns.Valid = int(n.Int64), n.Valid - return err -} - -// Value implements the driver Valuer interface. -func (ns Int) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return int64(ns.Int), nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns Int) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.Int) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the propert representation of that value. -func (ns *Int) UnmarshalJSON(text []byte) error { - txt := string(text) - ns.Valid = true - if txt == "null" { - ns.Valid = false - return nil - } - i, err := strconv.ParseInt(txt, 10, strconv.IntSize) - if err != nil { - ns.Valid = false - return err - } - j := int(i) - ns.Int = j - return nil -} - -func (ns *Int) UnmarshalText(text []byte) error { - return ns.UnmarshalJSON(text) -} diff --git a/vendor/github.com/markbates/pop/nulls/int32.go b/vendor/github.com/markbates/pop/nulls/int32.go deleted file mode 100644 index 68f34dfb..00000000 --- a/vendor/github.com/markbates/pop/nulls/int32.go +++ /dev/null @@ -1,76 +0,0 @@ -package nulls - -import ( - "database/sql" - "database/sql/driver" - "encoding/json" - "strconv" -) - -// Int32 adds an implementation for int32 -// that supports proper JSON encoding/decoding. -type Int32 struct { - Int32 int32 - Valid bool // Valid is true if Int32 is not NULL -} - -func (ns Int32) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.Int32 -} - -// NewInt32 returns a new, properly instantiated -// Int object. -func NewInt32(i int32) Int32 { - return Int32{Int32: i, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *Int32) Scan(value interface{}) error { - n := sql.NullInt64{Int64: int64(ns.Int32)} - err := n.Scan(value) - ns.Int32, ns.Valid = int32(n.Int64), n.Valid - return err -} - -// Value implements the driver Valuer interface. -func (ns Int32) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return int64(ns.Int32), nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns Int32) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.Int32) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the propert representation of that value. -func (ns *Int32) UnmarshalJSON(text []byte) error { - txt := string(text) - ns.Valid = true - if txt == "null" { - ns.Valid = false - return nil - } - i, err := strconv.ParseInt(txt, 10, 32) - if err != nil { - ns.Valid = false - return err - } - j := int32(i) - ns.Int32 = j - return nil -} - -func (ns *Int32) UnmarshalText(text []byte) error { - return ns.UnmarshalJSON(text) -} diff --git a/vendor/github.com/markbates/pop/nulls/int64.go b/vendor/github.com/markbates/pop/nulls/int64.go deleted file mode 100644 index b4d91d49..00000000 --- a/vendor/github.com/markbates/pop/nulls/int64.go +++ /dev/null @@ -1,72 +0,0 @@ -package nulls - -import ( - "database/sql" - "database/sql/driver" - "encoding/json" - "strconv" -) - -// Int64 replaces sql.Int64 with an implementation -// that supports proper JSON encoding/decoding. -type Int64 sql.NullInt64 - -func (ns Int64) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.Int64 -} - -// NewInt64 returns a new, properly instantiated -// Int64 object. -func NewInt64(i int64) Int64 { - return Int64{Int64: i, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *Int64) Scan(value interface{}) error { - n := sql.NullInt64{Int64: ns.Int64} - err := n.Scan(value) - ns.Int64, ns.Valid = n.Int64, n.Valid - return err -} - -// Value implements the driver Valuer interface. -func (ns Int64) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return ns.Int64, nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns Int64) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.Int64) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the propert representation of that value. -func (ns *Int64) UnmarshalJSON(text []byte) error { - t := string(text) - ns.Valid = true - if t == "null" { - ns.Valid = false - return nil - } - i, err := strconv.ParseInt(t, 10, 64) - if err != nil { - ns.Valid = false - return err - } - ns.Int64 = i - return nil -} - -func (ns *Int64) UnmarshalText(text []byte) error { - return ns.UnmarshalJSON(text) -} diff --git a/vendor/github.com/markbates/pop/nulls/schema.go b/vendor/github.com/markbates/pop/nulls/schema.go deleted file mode 100644 index 0e1f7cb9..00000000 --- a/vendor/github.com/markbates/pop/nulls/schema.go +++ /dev/null @@ -1,59 +0,0 @@ -package nulls - -import "reflect" - -type register func(interface{}, func(string) reflect.Value) - -// RegisterWithSchema allows for the nulls package to be used with http://www.gorillatoolkit.org/pkg/schema#Converter -func RegisterWithSchema(reg register) { - reg(String{}, func(s string) reflect.Value { - ns := String{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) - reg(Bool{}, func(s string) reflect.Value { - ns := Bool{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) - reg(ByteSlice{}, func(s string) reflect.Value { - ns := ByteSlice{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) - reg(Float32{}, func(s string) reflect.Value { - ns := Float32{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) - reg(Float64{}, func(s string) reflect.Value { - ns := Float64{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) - reg(Int{}, func(s string) reflect.Value { - ns := Int{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) - reg(Int32{}, func(s string) reflect.Value { - ns := Int32{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) - reg(Int64{}, func(s string) reflect.Value { - ns := Int64{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) - reg(Time{}, func(s string) reflect.Value { - ns := Time{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) - reg(UInt32{}, func(s string) reflect.Value { - ns := UInt32{} - ns.Scan(s) - return reflect.ValueOf(ns) - }) -} diff --git a/vendor/github.com/markbates/pop/nulls/string.go b/vendor/github.com/markbates/pop/nulls/string.go deleted file mode 100644 index 1eaea896..00000000 --- a/vendor/github.com/markbates/pop/nulls/string.go +++ /dev/null @@ -1,76 +0,0 @@ -package nulls - -import ( - "database/sql" - "database/sql/driver" - "encoding/json" -) - -// String replaces sql.NullString with an implementation -// that supports proper JSON encoding/decoding. -type String sql.NullString - -func (ns String) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.String -} - -// NewString returns a new, properly instantiated -// String object. -func NewString(s string) String { - return String{String: s, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *String) Scan(value interface{}) error { - n := sql.NullString{String: ns.String} - err := n.Scan(value) - ns.String, ns.Valid = n.String, n.Valid - return err -} - -// Value implements the driver Valuer interface. -func (ns String) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return ns.String, nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns String) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.String) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the propert representation of that value. -func (ns *String) UnmarshalJSON(text []byte) error { - ns.Valid = false - if string(text) == "null" { - return nil - } - s := "" - err := json.Unmarshal(text, &s) - if err == nil { - ns.String = s - ns.Valid = true - } - return err -} - -func (ns *String) UnmarshalText(text []byte) error { - ns.Valid = false - t := string(text) - if t == "null" { - return nil - } - ns.String = t - ns.Valid = true - return nil -} diff --git a/vendor/github.com/markbates/pop/nulls/time.go b/vendor/github.com/markbates/pop/nulls/time.go deleted file mode 100644 index 1be34788..00000000 --- a/vendor/github.com/markbates/pop/nulls/time.go +++ /dev/null @@ -1,73 +0,0 @@ -package nulls - -import ( - "database/sql/driver" - "encoding/json" - "time" -) - -// Time replaces sql.NullTime with an implementation -// that supports proper JSON encoding/decoding. -type Time struct { - Time time.Time - Valid bool // Valid is true if Time is not NULL -} - -func (ns Time) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.Time -} - -// NewTime returns a new, properly instantiated -// Time object. -func NewTime(t time.Time) Time { - return Time{Time: t, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *Time) Scan(value interface{}) error { - ns.Time, ns.Valid = value.(time.Time) - return nil -} - -// Value implements the driver Valuer interface. -func (ns Time) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return ns.Time, nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns Time) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.Time) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the propert representation of that value. -func (ns *Time) UnmarshalJSON(text []byte) error { - ns.Valid = false - txt := string(text) - if txt == "null" || txt == "" { - return nil - } - - t := time.Time{} - err := t.UnmarshalJSON(text) - if err == nil { - ns.Time = t - ns.Valid = true - } - - return err -} - -func (ns *Time) UnmarshalText(text []byte) error { - return ns.UnmarshalJSON(text) -} diff --git a/vendor/github.com/markbates/pop/nulls/types_test.go b/vendor/github.com/markbates/pop/nulls/types_test.go deleted file mode 100644 index aae03385..00000000 --- a/vendor/github.com/markbates/pop/nulls/types_test.go +++ /dev/null @@ -1,190 +0,0 @@ -package nulls_test - -import ( - "encoding/json" - "fmt" - "os" - "strings" - "testing" - "time" - - "github.com/jmoiron/sqlx" - . "github.com/markbates/pop/nulls" - _ "github.com/mattn/go-sqlite3" - "github.com/stretchr/testify/require" -) - -type Foo struct { - ID Int64 `json:"id" db:"id"` - Name String `json:"name" db:"name"` - Alive Bool `json:"alive" db:"alive"` - Price Float64 `json:"price" db:"price"` - Birth Time `json:"birth" db:"birth"` - Price32 Float32 `json:"price32" db:"price32"` - Bytes ByteSlice `json:"bytes" db:"bytes"` - IntType Int `json:"intType" db:"int_type"` - Int32Type Int32 `json:"int32Type" db:"int32_type"` - UInt32Type UInt32 `json:"uint32Type" db:"uint32_type"` -} - -const schema = `CREATE TABLE "main"."foos" ( - "id" integer, - "name" text, - "alive" integer, - "price" float, - "birth" timestamp, - "price32" float, - "bytes" blob, - "int_type" integer, - "int32_type" integer, - "uint32_type" integer -);` - -var now = time.Now() - -func newValidFoo() Foo { - return Foo{ - ID: NewInt64(1), - Name: NewString("Mark"), - Alive: NewBool(true), - Price: NewFloat64(9.99), - Birth: NewTime(now), - Price32: NewFloat32(3.33), - Bytes: NewByteSlice([]byte("Byte Slice")), - IntType: NewInt(2), - Int32Type: NewInt32(3), - UInt32Type: NewUInt32(5), - } -} - -func Test_TypesMarshalProperly(t *testing.T) { - t.Parallel() - - a := require.New(t) - f := newValidFoo() - - ti, _ := json.Marshal(now) - ba, _ := json.Marshal(f.Bytes) - jsonString := fmt.Sprintf(`{"id":1,"name":"Mark","alive":true,"price":9.99,"birth":%s,"price32":3.33,"bytes":%s,"intType":2,"int32Type":3,"uint32Type":5}`, ti, ba) - - // check marshalling to json works: - data, _ := json.Marshal(f) - a.Equal(string(data), jsonString) - - // check unmarshalling from json works: - f = Foo{} - json.NewDecoder(strings.NewReader(jsonString)).Decode(&f) - a.Equal(f.ID.Int64, int64(1)) - a.Equal(f.Name.String, "Mark") - a.Equal(f.Alive.Bool, true) - a.Equal(f.Price.Float64, 9.99) - a.Equal(f.Birth.Time.Nanosecond(), now.Nanosecond()) - a.Equal(f.Price32.Float32, float32(3.33)) - a.Equal(f.Bytes.ByteSlice, ba) - a.Equal(f.IntType.Int, 2) - a.Equal(f.Int32Type.Int32, int32(3)) - a.Equal(f.UInt32Type.UInt32, uint32(5)) - - // check marshalling nulls works: - f = Foo{} - jsonString = `{"id":null,"name":null,"alive":null,"price":null,"birth":null,"price32":null,"bytes":null,"intType":null,"int32Type":null,"uint32Type":null}` - data, _ = json.Marshal(f) - a.Equal(string(data), jsonString) - - f = Foo{} - json.NewDecoder(strings.NewReader(jsonString)).Decode(&f) - a.Equal(f.ID.Int64, int64(0)) - a.False(f.ID.Valid) - a.Equal(f.Name.String, "") - a.False(f.Name.Valid) - a.Equal(f.Alive.Bool, false) - a.False(f.Alive.Valid) - a.Equal(f.Price.Float64, float64(0)) - a.False(f.Price.Valid) - a.Equal(f.Birth.Time, time.Time{}) - a.False(f.Birth.Valid) - a.Equal(f.Price32.Float32, float32(0)) - a.False(f.Price32.Valid) - a.Equal(f.Bytes.ByteSlice, []byte(nil)) - a.False(f.Bytes.Valid) - a.Equal(f.IntType.Int, 0) - a.False(f.IntType.Valid) - a.Equal(f.Int32Type.Int32, int32(0)) - a.False(f.Int32Type.Valid) - a.Equal(f.UInt32Type.UInt32, uint32(0)) - a.False(f.UInt32Type.Valid) -} - -func Test_TypeSaveAndRetrieveProperly(t *testing.T) { - t.Parallel() - - a := require.New(t) - - initDB(func(db *sqlx.DB) { - tx, err := db.Beginx() - a.NoError(err) - tx.Exec("insert into foos") - - f := Foo{} - tx.Get(&f, "select * from foos") - a.False(f.Alive.Valid) - a.False(f.Birth.Valid) - a.False(f.ID.Valid) - a.False(f.Name.Valid) - a.False(f.Price.Valid) - a.False(f.Alive.Bool) - a.False(f.Price32.Valid) - a.False(f.Bytes.Valid) - a.False(f.IntType.Valid) - a.False(f.Int32Type.Valid) - a.False(f.UInt32Type.Valid) - a.Equal(f.Birth.Time.UnixNano(), time.Time{}.UnixNano()) - a.Equal(f.ID.Int64, int64(0)) - a.Equal(f.Name.String, "") - a.Equal(f.Price.Float64, float64(0)) - a.Equal(f.Price32.Float32, float32(0)) - a.Equal(f.Bytes.ByteSlice, []byte(nil)) - a.Equal(f.IntType.Int, 0) - a.Equal(f.Int32Type.Int32, int32(0)) - a.Equal(f.UInt32Type.UInt32, uint32(0)) - tx.Rollback() - - tx, err = db.Beginx() - a.NoError(err) - - f = newValidFoo() - tx.NamedExec("INSERT INTO foos (id, name, alive, price, birth, price32, bytes, int_type, int32_type, uint32_type) VALUES (:id, :name, :alive, :price, :birth, :price32, :bytes, :int_type, :int32_type, :uint32_type)", &f) - f = Foo{} - tx.Get(&f, "select * from foos") - a.True(f.Alive.Valid) - a.True(f.Birth.Valid) - a.True(f.ID.Valid) - a.True(f.Name.Valid) - a.True(f.Price.Valid) - a.True(f.Alive.Bool) - a.True(f.Price32.Valid) - a.True(f.Bytes.Valid) - a.True(f.IntType.Valid) - a.True(f.Int32Type.Valid) - a.True(f.UInt32Type.Valid) - a.Equal(f.Birth.Time.UnixNano(), now.UnixNano()) - a.Equal(f.ID.Int64, int64(1)) - a.Equal(f.Name.String, "Mark") - a.Equal(f.Price.Float64, 9.99) - a.Equal(f.Price32.Float32, float32(3.33)) - a.Equal(f.Bytes.ByteSlice, []byte("Byte Slice")) - a.Equal(f.IntType.Int, 2) - a.Equal(f.Int32Type.Int32, int32(3)) - a.Equal(f.UInt32Type.UInt32, uint32(5)) - - tx.Rollback() - }) -} - -func initDB(f func(db *sqlx.DB)) { - os.Remove("./foo.db") - db, _ := sqlx.Open("sqlite3", "./foo.db") - db.MustExec(schema) - f(db) - os.Remove("./foo.db") -} diff --git a/vendor/github.com/markbates/pop/nulls/uint32.go b/vendor/github.com/markbates/pop/nulls/uint32.go deleted file mode 100644 index ee824603..00000000 --- a/vendor/github.com/markbates/pop/nulls/uint32.go +++ /dev/null @@ -1,76 +0,0 @@ -package nulls - -import ( - "database/sql" - "database/sql/driver" - "encoding/json" - "strconv" -) - -// UInt32 adds an implementation for int -// that supports proper JSON encoding/decoding. -type UInt32 struct { - UInt32 uint32 - Valid bool // Valid is true if Int is not NULL -} - -func (ns UInt32) Interface() interface{} { - if !ns.Valid { - return nil - } - return ns.UInt32 -} - -// NewUInt32 returns a new, properly instantiated -// Int object. -func NewUInt32(i uint32) UInt32 { - return UInt32{UInt32: i, Valid: true} -} - -// Scan implements the Scanner interface. -func (ns *UInt32) Scan(value interface{}) error { - n := sql.NullInt64{Int64: int64(ns.UInt32)} - err := n.Scan(value) - ns.UInt32, ns.Valid = uint32(n.Int64), n.Valid - return err -} - -// Value implements the driver Valuer interface. -func (ns UInt32) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return int64(ns.UInt32), nil -} - -// MarshalJSON marshals the underlying value to a -// proper JSON representation. -func (ns UInt32) MarshalJSON() ([]byte, error) { - if ns.Valid { - return json.Marshal(ns.UInt32) - } - return json.Marshal(nil) -} - -// UnmarshalJSON will unmarshal a JSON value into -// the propert representation of that value. -func (ns *UInt32) UnmarshalJSON(text []byte) error { - txt := string(text) - ns.Valid = true - if txt == "null" { - ns.Valid = false - return nil - } - i, err := strconv.ParseInt(txt, 10, 32) - if err != nil { - ns.Valid = false - return err - } - j := uint32(i) - ns.UInt32 = j - return nil -} - -func (ns *UInt32) UnmarshalText(text []byte) error { - return ns.UnmarshalJSON(text) -} diff --git a/vendor/github.com/markbates/pop/pagination_test.go b/vendor/github.com/markbates/pop/pagination_test.go deleted file mode 100644 index 4c6d4fc4..00000000 --- a/vendor/github.com/markbates/pop/pagination_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package pop_test - -import ( - "net/url" - "reflect" - "testing" - - "github.com/markbates/pop" - "github.com/markbates/pop/nulls" - "github.com/stretchr/testify/require" -) - -func Test_NewPaginator(t *testing.T) { - a := require.New(t) - - p := pop.NewPaginator(1, 10) - a.Equal(p.Offset, 0) - - p = pop.NewPaginator(2, 10) - a.Equal(p.Offset, 10) - - p = pop.NewPaginator(2, 30) - a.Equal(p.Offset, 30) -} - -func Test_NewPaginatorFromParams(t *testing.T) { - a := require.New(t) - - params := url.Values{} - - p := pop.NewPaginatorFromParams(params) - a.Equal(p.Page, 1) - a.Equal(p.PerPage, 20) - - params.Set("page", "2") - p = pop.NewPaginatorFromParams(params) - a.Equal(p.Page, 2) - a.Equal(p.PerPage, 20) - - params.Set("per_page", "30") - p = pop.NewPaginatorFromParams(params) - a.Equal(p.Page, 2) - a.Equal(p.PerPage, 30) -} - -func Test_Pagination(t *testing.T) { - transaction(func(tx *pop.Connection) { - a := require.New(t) - - for _, name := range []string{"Mark", "Joe", "Jane"} { - user := User{Name: nulls.NewString(name)} - err := tx.Create(&user) - a.NoError(err) - } - - u := Users{} - q := tx.Paginate(1, 2) - err := q.All(&u) - a.NoError(err) - a.Equal(len(u), 2) - - p := q.Paginator - a.Equal(p.CurrentEntriesSize, 2) - a.Equal(p.TotalEntriesSize, 3) - a.Equal(p.TotalPages, 2) - - u = Users{} - err = tx.Where("name = 'Mark'").All(&u) - a.NoError(err) - a.Equal(reflect.ValueOf(&u).Elem().Len(), 1) - }) -} diff --git a/vendor/github.com/markbates/pop/paginator.go b/vendor/github.com/markbates/pop/paginator.go deleted file mode 100644 index cff0c177..00000000 --- a/vendor/github.com/markbates/pop/paginator.go +++ /dev/null @@ -1,106 +0,0 @@ -package pop - -import ( - "encoding/json" - "strconv" - - "github.com/markbates/going/defaults" -) - -var PaginatorPerPageDefault = 20 -var PaginatorPageKey = "page" -var PaginatorPerPageKey = "per_page" - -// Paginator is a type used to represent the pagination of records -// from the database. -type Paginator struct { - // Current page you're on - Page int `json:"page"` - // Number of results you want per page - PerPage int `json:"per_page"` - // Page * PerPage (ex: 2 * 20, Offset == 40) - Offset int `json:"offset"` - // Total potential records matching the query - TotalEntriesSize int `json:"total_entries_size"` - // Total records returns, will be <= PerPage - CurrentEntriesSize int `json:"current_entries_size"` - // Total pages - TotalPages int `json:"total_pages"` -} - -func (p Paginator) String() string { - b, _ := json.Marshal(p) - return string(b) -} - -// NewPaginator returns a new `Paginator` value with the appropriate -// defaults set. -func NewPaginator(page int, per_page int) *Paginator { - p := &Paginator{Page: page, PerPage: per_page} - p.Offset = (p.Page - 1) * p.PerPage - return p -} - -type PaginationParams interface { - Get(key string) string -} - -// NewPaginatorFromParams takes an interface of type `PaginationParams`, -// the `url.Values` type works great with this interface, and returns -// a new `Paginator` based on the params or `PaginatorPageKey` and -// `PaginatorPerPageKey`. Defaults are `1` for the page and -// PaginatorPerPageDefault for the per page value. -func NewPaginatorFromParams(params PaginationParams) *Paginator { - page := defaults.String(params.Get("page"), "1") - - per_page := defaults.String(params.Get("per_page"), strconv.Itoa(PaginatorPerPageDefault)) - - p, err := strconv.Atoi(page) - if err != nil { - p = 1 - } - - pp, err := strconv.Atoi(per_page) - if err != nil { - pp = PaginatorPerPageDefault - } - return NewPaginator(p, pp) -} - -// Paginate records returned from the database. -// -// q := c.Paginate(2, 15) -// q.All(&[]User{}) -// q.Paginator -func (c *Connection) Paginate(page int, per_page int) *Query { - return Q(c).Paginate(page, per_page) -} - -// Paginate records returned from the database. -// -// q = q.Paginate(2, 15) -// q.All(&[]User{}) -// q.Paginator -func (q *Query) Paginate(page int, per_page int) *Query { - q.Paginator = NewPaginator(page, per_page) - return q -} - -// Paginate records returned from the database. -// -// q := c.PaginateFromParams(req.URL.Query()) -// q.All(&[]User{}) -// q.Paginator -func (c *Connection) PaginateFromParams(params PaginationParams) *Query { - return Q(c).PaginateFromParams(params) -} - -// Paginate records returned from the database. -// -// q = q.PaginateFromParams(req.URL.Query()) -// q.All(&[]User{}) -// q.Paginator -func (q *Query) PaginateFromParams(params PaginationParams) *Query { - q.Paginator = NewPaginatorFromParams(params) - return q -} diff --git a/vendor/github.com/markbates/pop/pop.go b/vendor/github.com/markbates/pop/pop.go deleted file mode 100644 index 7c397eff..00000000 --- a/vendor/github.com/markbates/pop/pop.go +++ /dev/null @@ -1,34 +0,0 @@ -package pop - -import ( - "fmt" - "log" - "os" - - "github.com/fatih/color" -) - -var Debug = false -var Color = true -var logger = log.New(os.Stdout, "[POP] ", log.LstdFlags) - -var Log = func(s string, args ...interface{}) { - if Debug { - if len(args) > 0 { - xargs := make([]string, len(args)) - for i, a := range args { - switch a.(type) { - case string: - xargs[i] = fmt.Sprintf("%q", a) - default: - xargs[i] = fmt.Sprintf("%v", a) - } - } - s = fmt.Sprintf("%s | %s", s, xargs) - } - if Color { - s = color.YellowString(s) - } - logger.Println(s) - } -} diff --git a/vendor/github.com/markbates/pop/pop_test.go b/vendor/github.com/markbates/pop/pop_test.go deleted file mode 100644 index c05e91cf..00000000 --- a/vendor/github.com/markbates/pop/pop_test.go +++ /dev/null @@ -1,145 +0,0 @@ -package pop_test - -import ( - "log" - "os" - "testing" - "time" - - _ "github.com/go-sql-driver/mysql" - _ "github.com/lib/pq" - "github.com/markbates/pop" - "github.com/markbates/pop/nulls" - "github.com/markbates/validate" - "github.com/markbates/validate/validators" - _ "github.com/mattn/go-sqlite3" - "github.com/satori/go.uuid" - "github.com/stretchr/testify/suite" -) - -var PDB *pop.Connection - -type PostgreSQLSuite struct { - suite.Suite -} - -type MySQLSuite struct { - suite.Suite -} - -type SQLiteSuite struct { - suite.Suite -} - -func TestSpecificSuites(t *testing.T) { - switch os.Getenv("SODA_DIALECT") { - case "postgres": - suite.Run(t, &PostgreSQLSuite{}) - case "mysql": - suite.Run(t, &MySQLSuite{}) - case "sqlite": - suite.Run(t, &SQLiteSuite{}) - } -} - -func init() { - pop.Debug = false - pop.AddLookupPaths("./") - - dialect := os.Getenv("SODA_DIALECT") - - var err error - PDB, err = pop.Connect(dialect) - if err != nil { - log.Panic(err) - } - - pop.MapTableName("Friend", "good_friends") - pop.MapTableName("Friends", "good_friends") -} - -func transaction(fn func(tx *pop.Connection)) { - err := PDB.Rollback(func(tx *pop.Connection) { - fn(tx) - }) - if err != nil { - log.Fatal(err) - } -} - -func ts(s string) string { - return PDB.Dialect.TranslateSQL(s) -} - -type User struct { - ID int `db:"id"` - Email string `db:"email"` - Name nulls.String `db:"name"` - Alive nulls.Bool `db:"alive"` - CreatedAt time.Time `db:"created_at"` - UpdatedAt time.Time `db:"updated_at"` - BirthDate nulls.Time `db:"birth_date"` - Bio nulls.String `db:"bio"` - Price nulls.Float64 `db:"price"` - FullName nulls.String `db:"full_name" select:"name as full_name"` -} - -type Users []User - -type Friend struct { - ID int `db:"id"` - FirstName string `db:"first_name"` - LastName string `db:"last_name"` - CreatedAt time.Time `db:"created_at"` - UpdatedAt time.Time `db:"updated_at"` -} - -type Friends []Friend - -type Enemy struct { - A string -} - -type Song struct { - ID uuid.UUID `db:"id"` - Title string `db:"title"` - CreatedAt time.Time `json:"created_at" db:"created_at"` - UpdatedAt time.Time `json:"updated_at" db:"updated_at"` -} - -type ValidatableCar struct { - ID int `db:"id"` - Name string `db:"name"` - CreatedAt time.Time `json:"created_at" db:"created_at"` - UpdatedAt time.Time `json:"updated_at" db:"updated_at"` -} - -var validationLogs = []string{} - -func (v *ValidatableCar) Validate(tx *pop.Connection) (*validate.Errors, error) { - validationLogs = append(validationLogs, "Validate") - verrs := validate.Validate(&validators.StringIsPresent{Field: v.Name, Name: "Name"}) - return verrs, nil -} - -func (v *ValidatableCar) ValidateSave(tx *pop.Connection) (*validate.Errors, error) { - validationLogs = append(validationLogs, "ValidateSave") - return nil, nil -} - -func (v *ValidatableCar) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) { - validationLogs = append(validationLogs, "ValidateUpdate") - return nil, nil -} - -func (v *ValidatableCar) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) { - validationLogs = append(validationLogs, "ValidateCreate") - return nil, nil -} - -type NotValidatableCar struct { - ID int `db:"id"` - Name string `db:"name"` - CreatedAt time.Time `json:"created_at" db:"created_at"` - UpdatedAt time.Time `json:"updated_at" db:"updated_at"` -} diff --git a/vendor/github.com/markbates/pop/postgresql.go b/vendor/github.com/markbates/pop/postgresql.go deleted file mode 100644 index ab34e90b..00000000 --- a/vendor/github.com/markbates/pop/postgresql.go +++ /dev/null @@ -1,216 +0,0 @@ -package pop - -import ( - "fmt" - "io" - "os" - "os/exec" - "strconv" - "strings" - "sync" - - _ "github.com/lib/pq" - . "github.com/markbates/pop/columns" - "github.com/markbates/pop/fizz" - "github.com/markbates/pop/fizz/translators" - "github.com/pkg/errors" -) - -var _ dialect = &postgresql{} - -type postgresql struct { - translateCache map[string]string - mu sync.Mutex - ConnectionDetails *ConnectionDetails -} - -func (p *postgresql) Details() *ConnectionDetails { - return p.ConnectionDetails -} - -func (p *postgresql) Create(s store, model *Model, cols Columns) error { - keyType := model.PrimaryKeyType() - switch keyType { - case "int": - cols.Remove("id") - id := struct { - ID int `db:"id"` - }{} - w := cols.Writeable() - query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s) returning id", model.TableName(), w.String(), w.SymbolizedString()) - Log(query) - stmt, err := s.PrepareNamed(query) - if err != nil { - return errors.Wrapf(err, "postgres error preparing insert statement %s", query) - } - err = stmt.Get(&id, model.Value) - if err != nil { - return errors.Wrap(err, "postgres error inserting record") - } - model.setID(id.ID) - return nil - case "UUID": - return genericCreate(s, model, cols) - } - return errors.Errorf("can not use %s as a primary key type!", keyType) -} - -func (p *postgresql) Update(s store, model *Model, cols Columns) error { - return errors.Wrap(genericUpdate(s, model, cols), "postgres update") -} - -func (p *postgresql) Destroy(s store, model *Model) error { - return errors.Wrap(genericDestroy(s, model), "postgres destroy") -} - -func (p *postgresql) SelectOne(s store, model *Model, query Query) error { - return errors.Wrap(genericSelectOne(s, model, query), "postgres select one") -} - -func (p *postgresql) SelectMany(s store, models *Model, query Query) error { - return errors.Wrap(genericSelectMany(s, models, query), "postgres select many") -} - -func (p *postgresql) CreateDB() error { - // createdb -h db -p 5432 -U postgres enterprise_development - deets := p.ConnectionDetails - cmd := exec.Command("createdb", "-e", "-h", deets.Host, "-p", deets.Port, "-U", deets.User, deets.Database) - Log(strings.Join(cmd.Args, " ")) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stderr - cmd.Stdout = os.Stdout - err := cmd.Run() - if err != nil { - return errors.Wrapf(err, "error creating PostgreSQL database %s", deets.Database) - } - - fmt.Printf("created database %s\n", deets.Database) - return nil -} - -func (p *postgresql) DropDB() error { - deets := p.ConnectionDetails - cmd := exec.Command("dropdb", "-e", "-h", deets.Host, "-p", deets.Port, "-U", deets.User, deets.Database) - Log(strings.Join(cmd.Args, " ")) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stderr - cmd.Stdout = os.Stdout - err := cmd.Run() - if err != nil { - return errors.Wrapf(err, "error dropping PostgreSQL database %s", deets.Database) - } - fmt.Printf("dropped database %s\n", deets.Database) - return nil -} - -func (m *postgresql) URL() string { - c := m.ConnectionDetails - if c.URL != "" { - return c.URL - } - - s := "postgres://%s:%s@%s:%s/%s?sslmode=disable" - return fmt.Sprintf(s, c.User, c.Password, c.Host, c.Port, c.Database) -} - -func (m *postgresql) MigrationURL() string { - return m.URL() -} - -func (p *postgresql) TranslateSQL(sql string) string { - defer p.mu.Unlock() - p.mu.Lock() - - if csql, ok := p.translateCache[sql]; ok { - return csql - } - curr := 1 - out := make([]byte, 0, len(sql)) - for i := 0; i < len(sql); i++ { - if sql[i] == '?' { - str := "$" + strconv.Itoa(curr) - for _, char := range str { - out = append(out, byte(char)) - } - curr += 1 - } else { - out = append(out, sql[i]) - } - } - csql := string(out) - p.translateCache[sql] = csql - return csql -} - -func (p *postgresql) FizzTranslator() fizz.Translator { - return translators.NewPostgres() -} - -func (p *postgresql) Lock(fn func() error) error { - return fn() -} - -func (p *postgresql) DumpSchema(w io.Writer) error { - cmd := exec.Command("pg_dump", "-s", fmt.Sprintf("--dbname=%s", p.URL())) - Log(strings.Join(cmd.Args, " ")) - cmd.Stdout = w - cmd.Stderr = os.Stderr - - err := cmd.Run() - if err != nil { - return err - } - - fmt.Printf("dumped schema for %s\n", p.Details().Database) - return nil -} - -func (p *postgresql) LoadSchema(r io.Reader) error { - cmd := exec.Command("psql", p.URL()) - in, err := cmd.StdinPipe() - if err != nil { - return err - } - go func() { - defer in.Close() - io.Copy(in, r) - }() - Log(strings.Join(cmd.Args, " ")) - err = cmd.Start() - if err != nil { - return err - } - err = cmd.Wait() - if err != nil { - return err - } - - fmt.Printf("loaded schema for %s\n", p.Details().Database) - return nil -} - -func (p *postgresql) TruncateAll(tx *Connection) error { - return tx.RawQuery(pgTruncate).Exec() -} - -func newPostgreSQL(deets *ConnectionDetails) dialect { - cd := &postgresql{ - ConnectionDetails: deets, - translateCache: map[string]string{}, - mu: sync.Mutex{}, - } - return cd -} - -const pgTruncate = `DO -$func$ -BEGIN - EXECUTE - (SELECT 'TRUNCATE TABLE ' - || string_agg(quote_ident(schemaname) || '.' || quote_ident(tablename), ', ') - || ' CASCADE' - FROM pg_tables - WHERE schemaname = 'public' - ); -END -$func$;` diff --git a/vendor/github.com/markbates/pop/query.go b/vendor/github.com/markbates/pop/query.go deleted file mode 100644 index 3987ef6a..00000000 --- a/vendor/github.com/markbates/pop/query.go +++ /dev/null @@ -1,97 +0,0 @@ -package pop - -// Query is the main value that is used to build up a query -// to be executed against the `Connection`. -type Query struct { - RawSQL *clause - limitResults int - whereClauses clauses - orderClauses clauses - fromClauses fromClauses - belongsToThroughClauses belongsToThroughClauses - Paginator *Paginator - Connection *Connection -} - -// RawQuery will override the query building feature of Pop and will use -// whatever query you want to execute against the `Connection`. You can continue -// to use the `?` argument syntax. -// -// c.RawQuery("select * from foo where id = ?", 1) -func (c *Connection) RawQuery(stmt string, args ...interface{}) *Query { - return Q(c).RawQuery(stmt, args...) -} - -// RawQuery will override the query building feature of Pop and will use -// whatever query you want to execute against the `Connection`. You can continue -// to use the `?` argument syntax. -// -// q.RawQuery("select * from foo where id = ?", 1) -func (q *Query) RawQuery(stmt string, args ...interface{}) *Query { - q.RawSQL = &clause{stmt, args} - return q -} - -// Where will append a where clause to the query. You may use `?` in place of -// arguments. -// -// c.Where("id = ?", 1) -func (c *Connection) Where(stmt string, args ...interface{}) *Query { - return Q(c).Where(stmt, args...) -} - -// Where will append a where clause to the query. You may use `?` in place of -// arguments. -// -// q.Where("id = ?", 1) -func (q *Query) Where(stmt string, args ...interface{}) *Query { - q.whereClauses = append(q.whereClauses, clause{stmt, args}) - return q -} - -// Order will append an order clause to the query. -// -// c.Order("name desc") -func (c *Connection) Order(stmt string) *Query { - return Q(c).Order(stmt) -} - -// Order will append an order clause to the query. -// -// q.Order("name desc") -func (q *Query) Order(stmt string) *Query { - q.orderClauses = append(q.orderClauses, clause{stmt, []interface{}{}}) - return q -} - -// Limit will add a limit clause to the query. -func (c *Connection) Limit(limit int) *Query { - return Q(c).Limit(limit) -} - -// Limit will add a limit clause to the query. -func (q *Query) Limit(limit int) *Query { - q.limitResults = limit - return q -} - -// Q will create a new "empty" query from the current connection. -func Q(c *Connection) *Query { - return &Query{ - RawSQL: &clause{}, - Connection: c, - } -} - -// ToSQL will generate SQL and the appropriate arguments for that SQL -// from the `Model` passed in. -func (q Query) ToSQL(model *Model, addColumns ...string) (string, []interface{}) { - sb := q.toSQLBuilder(model, addColumns...) - return sb.String(), sb.Args() -} - -// ToSQLBuilder returns a new `SQLBuilder` that can be used to generate SQL, -// get arguments, and more. -func (q Query) toSQLBuilder(model *Model, addColumns ...string) *sqlBuilder { - return newSQLBuilder(q, model, addColumns...) -} diff --git a/vendor/github.com/markbates/pop/query_test.go b/vendor/github.com/markbates/pop/query_test.go deleted file mode 100644 index 62886358..00000000 --- a/vendor/github.com/markbates/pop/query_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package pop_test - -import ( - "fmt" - "testing" - - "github.com/markbates/pop" - "github.com/stretchr/testify/require" -) - -func Test_Where(t *testing.T) { - a := require.New(t) - m := &pop.Model{Value: &Enemy{}} - - q := PDB.Where("id = ?", 1) - sql, _ := q.ToSQL(m) - a.Equal(ts("SELECT enemies.A FROM enemies AS enemies WHERE id = ?"), sql) - - q.Where("first_name = ? and last_name = ?", "Mark", "Bates") - sql, _ = q.ToSQL(m) - a.Equal(ts("SELECT enemies.A FROM enemies AS enemies WHERE id = ? AND first_name = ? and last_name = ?"), sql) - - q = PDB.Where("name = ?", "Mark 'Awesome' Bates") - sql, _ = q.ToSQL(m) - a.Equal(ts("SELECT enemies.A FROM enemies AS enemies WHERE name = ?"), sql) - - q = PDB.Where("name = ?", "'; truncate users; --") - sql, _ = q.ToSQL(m) - a.Equal(ts("SELECT enemies.A FROM enemies AS enemies WHERE name = ?"), sql) -} - -func Test_Order(t *testing.T) { - a := require.New(t) - - m := &pop.Model{Value: &Enemy{}} - q := PDB.Order("id desc") - sql, _ := q.ToSQL(m) - a.Equal(ts("SELECT enemies.A FROM enemies AS enemies ORDER BY id desc"), sql) - - q.Order("name desc") - sql, _ = q.ToSQL(m) - a.Equal(ts("SELECT enemies.A FROM enemies AS enemies ORDER BY id desc, name desc"), sql) -} - -func Test_ToSQL(t *testing.T) { - a := require.New(t) - transaction(func(tx *pop.Connection) { - user := &pop.Model{Value: &User{}} - - s := "SELECT name as full_name, users.alive, users.bio, users.birth_date, users.created_at, users.email, users.id, users.name, users.price, users.updated_at FROM users AS users" - - query := pop.Q(tx) - q, _ := query.ToSQL(user) - a.Equal(s, q) - - query.Order("id desc") - q, _ = query.ToSQL(user) - a.Equal(fmt.Sprintf("%s ORDER BY id desc", s), q) - - query = tx.Where("id = 1") - q, _ = query.ToSQL(user) - a.Equal(fmt.Sprintf("%s WHERE id = 1", s), q) - - query = tx.Where("id = 1").Where("name = 'Mark'") - q, _ = query.ToSQL(user) - a.Equal(fmt.Sprintf("%s WHERE id = 1 AND name = 'Mark'", s), q) - - query.Order("id desc") - q, _ = query.ToSQL(user) - a.Equal(fmt.Sprintf("%s WHERE id = 1 AND name = 'Mark' ORDER BY id desc", s), q) - - query.Order("name asc") - q, _ = query.ToSQL(user) - a.Equal(fmt.Sprintf("%s WHERE id = 1 AND name = 'Mark' ORDER BY id desc, name asc", s), q) - - query = tx.Limit(10) - q, _ = query.ToSQL(user) - a.Equal(fmt.Sprintf("%s LIMIT 10", s), q) - - query = tx.Paginate(3, 10) - q, _ = query.ToSQL(user) - a.Equal(fmt.Sprintf("%s LIMIT 10 OFFSET 20", s), q) - }) -} - -func Test_ToSQLInjection(t *testing.T) { - a := require.New(t) - transaction(func(tx *pop.Connection) { - user := &pop.Model{Value: &User{}} - query := tx.Where("name = '?'", "\\\u0027 or 1=1 limit 1;\n-- ") - q, _ := query.ToSQL(user) - a.NotEqual("SELECT * FROM users AS users WHERE name = '\\'' or 1=1 limit 1;\n-- '", q) - }) -} - -func Test_ToSQL_RawQuery(t *testing.T) { - a := require.New(t) - transaction(func(tx *pop.Connection) { - query := tx.RawQuery("this is some ? raw ?", "random", "query") - q, args := query.ToSQL(nil) - a.Equal(q, tx.Dialect.TranslateSQL("this is some ? raw ?")) - a.Equal(args, []interface{}{"random", "query"}) - }) -} diff --git a/vendor/github.com/markbates/pop/scopes.go b/vendor/github.com/markbates/pop/scopes.go deleted file mode 100644 index dceb996d..00000000 --- a/vendor/github.com/markbates/pop/scopes.go +++ /dev/null @@ -1,29 +0,0 @@ -package pop - -type ScopeFunc func(q *Query) *Query - -// Scope the query by using a `ScopeFunc` -// -// func ByName(name string) ScopeFunc { -// return func(q *Query) *Query { -// return q.Where("name = ?", name) -// } -// } -// -// q.Scope(ByName("mark").Where("id = ?", 1).First(&User{}) -func (q *Query) Scope(sf ScopeFunc) *Query { - return sf(q) -} - -// Scope the query by using a `ScopeFunc` -// -// func ByName(name string) ScopeFunc { -// return func(q *Query) *Query { -// return q.Where("name = ?", name) -// } -// } -// -// c.Scope(ByName("mark")).First(&User{}) -func (c *Connection) Scope(sf ScopeFunc) *Query { - return Q(c).Scope(sf) -} diff --git a/vendor/github.com/markbates/pop/scopes_test.go b/vendor/github.com/markbates/pop/scopes_test.go deleted file mode 100644 index 9b57e9b9..00000000 --- a/vendor/github.com/markbates/pop/scopes_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package pop_test - -import ( - "testing" - - "github.com/markbates/pop" - "github.com/stretchr/testify/require" -) - -func Test_Scopes(t *testing.T) { - r := require.New(t) - oql := "SELECT enemies.A FROM enemies AS enemies" - - m := &pop.Model{Value: &Enemy{}} - - q := PDB.Q() - s, _ := q.ToSQL(m) - r.Equal(oql, s) - - q.Scope(func(qy *pop.Query) *pop.Query { - return qy.Where("id = ?", 1) - }) - - s, _ = q.ToSQL(m) - r.Equal(ts(oql+" WHERE id = ?"), s) -} diff --git a/vendor/github.com/markbates/pop/slices/float.go b/vendor/github.com/markbates/pop/slices/float.go deleted file mode 100644 index 094d324a..00000000 --- a/vendor/github.com/markbates/pop/slices/float.go +++ /dev/null @@ -1,53 +0,0 @@ -package slices - -import ( - "database/sql/driver" - "fmt" - "strconv" - "strings" - - "github.com/pkg/errors" -) - -type Float []float64 - -func (s *Float) Scan(src interface{}) error { - b, ok := src.([]byte) - if !ok { - return errors.New("Scan source was not []byte") - } - str := string(b) - (*s) = strToFloat(str, *s) - return nil -} - -func (s Float) Value() (driver.Value, error) { - sa := make([]string, len(s)) - for x, i := range s { - sa[x] = strconv.FormatFloat(i, 'f', -1, 64) - } - return fmt.Sprintf("{%s}", strings.Join(sa, ",")), nil -} - -func (s *Float) UnmarshalText(text []byte) error { - ss := []float64{} - for _, x := range strings.Split(string(text), ",") { - f, err := strconv.ParseFloat(x, 64) - if err != nil { - return errors.WithStack(err) - } - ss = append(ss, f) - } - (*s) = ss - return nil -} - -func strToFloat(s string, a []float64) []float64 { - r := strings.Trim(s, "{}") - a = make([]float64, 0, 10) - for _, t := range strings.Split(r, ",") { - i, _ := strconv.ParseFloat(t, 64) - a = append(a, i) - } - return a -} diff --git a/vendor/github.com/markbates/pop/slices/int.go b/vendor/github.com/markbates/pop/slices/int.go deleted file mode 100644 index df5a2a2f..00000000 --- a/vendor/github.com/markbates/pop/slices/int.go +++ /dev/null @@ -1,53 +0,0 @@ -package slices - -import ( - "database/sql/driver" - "fmt" - "strconv" - "strings" - - "github.com/pkg/errors" -) - -type Int []int - -func (s *Int) Scan(src interface{}) error { - b, ok := src.([]byte) - if !ok { - return errors.New("Scan source was not []byte") - } - str := string(b) - (*s) = strToInt(str) - return nil -} - -func (s Int) Value() (driver.Value, error) { - sa := make([]string, len(s)) - for x, i := range s { - sa[x] = strconv.Itoa(i) - } - return fmt.Sprintf("{%s}", strings.Join(sa, ",")), nil -} - -func (s *Int) UnmarshalText(text []byte) error { - ss := []int{} - for _, x := range strings.Split(string(text), ",") { - f, err := strconv.Atoi(x) - if err != nil { - return errors.WithStack(err) - } - ss = append(ss, f) - } - (*s) = ss - return nil -} - -func strToInt(s string) []int { - r := strings.Trim(s, "{}") - a := make([]int, 0, 10) - for _, t := range strings.Split(r, ",") { - i, _ := strconv.Atoi(t) - a = append(a, i) - } - return a -} diff --git a/vendor/github.com/markbates/pop/slices/map.go b/vendor/github.com/markbates/pop/slices/map.go deleted file mode 100644 index 98687afb..00000000 --- a/vendor/github.com/markbates/pop/slices/map.go +++ /dev/null @@ -1,30 +0,0 @@ -package slices - -import ( - "database/sql/driver" - "encoding/json" - - "github.com/pkg/errors" -) - -type Map map[string]interface{} - -func (s *Map) Scan(src interface{}) error { - b, ok := src.([]byte) - if !ok { - return errors.New("Scan source was not []byte") - } - err := json.Unmarshal(b, s) - if err != nil { - return errors.WithStack(err) - } - return nil -} - -func (s Map) Value() (driver.Value, error) { - b, err := json.Marshal(s) - if err != nil { - return nil, errors.WithStack(err) - } - return string(b), nil -} diff --git a/vendor/github.com/markbates/pop/slices/string.go b/vendor/github.com/markbates/pop/slices/string.go deleted file mode 100644 index da54e6f2..00000000 --- a/vendor/github.com/markbates/pop/slices/string.go +++ /dev/null @@ -1,40 +0,0 @@ -package slices - -import ( - "database/sql/driver" - "fmt" - "strings" - - "github.com/pkg/errors" -) - -// For reading in arrays from postgres - -type String []string - -func (s *String) Scan(src interface{}) error { - b, ok := src.([]byte) - if !ok { - return errors.New("Scan source was not []byte") - } - (*s) = strToString(string(b)) - return nil -} - -func (s String) Value() (driver.Value, error) { - return fmt.Sprintf("{%s}", strings.Join(s, ",")), nil -} - -func (s *String) UnmarshalText(text []byte) error { - ss := []string{} - for _, x := range strings.Split(string(text), ",") { - ss = append(ss, strings.TrimSpace(x)) - } - (*s) = ss - return nil -} - -func strToString(s string) []string { - r := strings.Trim(s, "{}") - return strings.Split(r, ",") -} diff --git a/vendor/github.com/markbates/pop/slices_test.go b/vendor/github.com/markbates/pop/slices_test.go deleted file mode 100644 index 3477be3d..00000000 --- a/vendor/github.com/markbates/pop/slices_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package pop_test - -import ( - "time" - - "github.com/markbates/pop" - "github.com/markbates/pop/slices" -) - -type Cake struct { - ID int `db:"id"` - Int slices.Int `db:"int_slice"` - Float slices.Float `db:"float_slice"` - String slices.String `db:"string_slice"` - CreatedAt time.Time `json:"created_at" db:"created_at"` - UpdatedAt time.Time `json:"updated_at" db:"updated_at"` -} - -func (p *PostgreSQLSuite) Test_String() { - transaction(func(tx *pop.Connection) { - r := p.Require() - - c := &Cake{ - String: slices.String{"a", "b", "c"}, - } - err := tx.Create(c) - r.NoError(err) - - err = tx.Reload(c) - r.Equal(slices.String{"a", "b", "c"}, c.String) - }) -} - -func (p *PostgreSQLSuite) Test_Int() { - transaction(func(tx *pop.Connection) { - r := p.Require() - - c := &Cake{ - Int: slices.Int{1, 2, 3}, - } - err := tx.Create(c) - r.NoError(err) - - err = tx.Reload(c) - r.Equal(slices.Int{1, 2, 3}, c.Int) - }) -} - -func (p *PostgreSQLSuite) Test_Float() { - transaction(func(tx *pop.Connection) { - r := p.Require() - - c := &Cake{ - Float: slices.Float{1.0, 2.1, 3.2}, - } - err := tx.Create(c) - r.NoError(err) - - err = tx.Reload(c) - r.NoError(err) - r.Equal(slices.Float{1.0, 2.1, 3.2}, c.Float) - }) -} diff --git a/vendor/github.com/markbates/pop/soda/.gitignore b/vendor/github.com/markbates/pop/soda/.gitignore deleted file mode 100644 index 03a3eb95..00000000 --- a/vendor/github.com/markbates/pop/soda/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -config/ -models/ -migrations/ -*.sqlite diff --git a/vendor/github.com/markbates/pop/soda/cmd/create.go b/vendor/github.com/markbates/pop/soda/cmd/create.go deleted file mode 100644 index 9b07b4c5..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/create.go +++ /dev/null @@ -1,30 +0,0 @@ -package cmd - -import ( - "github.com/markbates/pop" - "github.com/spf13/cobra" -) - -var createCmd = &cobra.Command{ - Use: "create", - Short: "Creates databases for you", - RunE: func(cmd *cobra.Command, args []string) error { - var err error - if all { - for _, conn := range pop.Connections { - err = pop.CreateDB(conn) - if err != nil { - return err - } - } - } else { - err = pop.CreateDB(getConn()) - } - return err - }, -} - -func init() { - createCmd.Flags().BoolVarP(&all, "all", "a", false, "Creates all of the databases in the database.yml") - RootCmd.AddCommand(createCmd) -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/drop.go b/vendor/github.com/markbates/pop/soda/cmd/drop.go deleted file mode 100644 index d1e7bf4a..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/drop.go +++ /dev/null @@ -1,27 +0,0 @@ -package cmd - -import ( - "github.com/markbates/pop" - "github.com/spf13/cobra" -) - -var all bool - -var dropCmd = &cobra.Command{ - Use: "drop", - Short: "Drops databases for you", - Run: func(cmd *cobra.Command, args []string) { - if all { - for _, conn := range pop.Connections { - pop.DropDB(conn) - } - } else { - pop.DropDB(getConn()) - } - }, -} - -func init() { - dropCmd.Flags().BoolVarP(&all, "all", "a", false, "Drops all of the databases in the database.yml") - RootCmd.AddCommand(dropCmd) -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/generate.go b/vendor/github.com/markbates/pop/soda/cmd/generate.go deleted file mode 100644 index 05e96ad0..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/generate.go +++ /dev/null @@ -1,19 +0,0 @@ -package cmd - -import ( - "github.com/markbates/pop/soda/cmd/generate" - "github.com/spf13/cobra" -) - -var generateCmd = &cobra.Command{ - Use: "generate", - Aliases: []string{"g"}, -} - -func init() { - generateCmd.AddCommand(generate.ConfigCmd) - generateCmd.AddCommand(generate.FizzCmd) - generateCmd.AddCommand(generate.SQLCmd) - generateCmd.AddCommand(generate.ModelCmd) - RootCmd.AddCommand(generateCmd) -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/generate/config.go b/vendor/github.com/markbates/pop/soda/cmd/generate/config.go deleted file mode 100644 index 36c87092..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/generate/config.go +++ /dev/null @@ -1,57 +0,0 @@ -package generate - -import ( - "os" - "path" - "strings" - - "github.com/gobuffalo/envy" - "github.com/gobuffalo/makr" - "github.com/markbates/going/defaults" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -func init() { - ConfigCmd.Flags().StringVarP(&dialect, "type", "t", "postgres", "What type of database do you want to use? (postgres, mysql, sqlite3)") -} - -var dialect string - -var ConfigCmd = &cobra.Command{ - Use: "config", - Short: "Generates a database.yml file for your project.", - RunE: func(cmd *cobra.Command, args []string) error { - cflag := cmd.Flag("config") - cfgFile := defaults.String(cflag.Value.String(), "database.yml") - dir, err := os.Getwd() - if err != nil { - return errors.Wrap(err, "couldn't get the current directory") - } - data := map[string]interface{}{ - "dialect": dialect, - "name": path.Base(dir), - "packagePath": pkgPath(), - } - return GenerateConfig(cfgFile, data) - }, -} - -func pkgPath() string { - pwd, _ := os.Getwd() - - for _, p := range envy.GoPaths() { - pwd = strings.TrimPrefix(pwd, p) - } - return pwd -} - -func GenerateConfig(cfgFile string, data map[string]interface{}) error { - dialect = strings.ToLower(data["dialect"].(string)) - if t, ok := configTemplates[dialect]; ok { - g := makr.New() - g.Add(makr.NewFile(cfgFile, t)) - return g.Run(".", data) - } - return errors.Errorf("Could not initialize %s!", dialect) -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/generate/config_templates.go b/vendor/github.com/markbates/pop/soda/cmd/generate/config_templates.go deleted file mode 100644 index b8d01645..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/generate/config_templates.go +++ /dev/null @@ -1,50 +0,0 @@ -package generate - -var pgConfig = `development: - dialect: postgres - database: {{.name}}_development - user: postgres - password: postgres - host: 127.0.0.1 - pool: 5 - -test: - url: {{"{{"}}envOr "TEST_DATABASE_URL" "postgres://postgres:postgres@127.0.0.1:5432/{{.name}}_test?sslmode=disable"}} - -production: - url: {{"{{"}}envOr "DATABASE_URL" "postgres://postgres:postgres@127.0.0.1:5432/{{.name}}_production?sslmode=disable"}}` - -var mysqlConfig = `development: - dialect: "mysql" - database: "{{.name}}_development" - host: "localhost" - port: "3306" - user: "root" - password: "root" - -test: - url: {{"{{"}}envOr "TEST_DATABASE_URL" "mysql://root:root@localhost:3306/{{.name}}_test"}} - -production: - url: {{"{{"}}envOr "DATABASE_URL" "mysql://root:root@localhost:3306/{{.name}}_production"}}` - -var sqliteConfig = `development: - dialect: "sqlite3" - database: {{"{{"}}env "GOPATH" {{"}}"}}/{{.packagePath}}/{{.name}}_development.sqlite - -test: - dialect: "sqlite3" - database: {{"{{"}}env "GOPATH" {{"}}"}}/{{.packagePath}}/{{.name}}_test.sqlite - -production: - dialect: "sqlite3" - database: {{"{{"}}env "GOPATH" {{"}}"}}/{{.packagePath}}/{{.name}}_production.sqlite` - -var configTemplates = map[string]string{ - "postgres": pgConfig, - "postgresql": pgConfig, - "pg": pgConfig, - "mysql": mysqlConfig, - "sqlite3": sqliteConfig, - "sqlite": sqliteConfig, -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/generate/fizz_migration.go b/vendor/github.com/markbates/pop/soda/cmd/generate/fizz_migration.go deleted file mode 100644 index 95b31584..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/generate/fizz_migration.go +++ /dev/null @@ -1,23 +0,0 @@ -package generate - -import ( - "github.com/pkg/errors" - - "github.com/markbates/going/defaults" - "github.com/markbates/pop" - "github.com/spf13/cobra" -) - -var FizzCmd = &cobra.Command{ - Use: "fizz [name]", - Aliases: []string{"migration"}, - Short: "Generates Up/Down migrations for your database using fizz.", - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return errors.New("You must supply a name for your migration!") - } - cflag := cmd.Flag("path") - migrationPath := defaults.String(cflag.Value.String(), "./migrations") - return pop.MigrationCreate(migrationPath, args[0], "fizz", nil, nil) - }, -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/generate/model.go b/vendor/github.com/markbates/pop/soda/cmd/generate/model.go deleted file mode 100644 index 7516a264..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/generate/model.go +++ /dev/null @@ -1,212 +0,0 @@ -package generate - -import ( - "fmt" - "os" - "path/filepath" - "regexp" - "strings" - - "github.com/gobuffalo/makr" - "github.com/pkg/errors" - - "github.com/markbates/going/defaults" - "github.com/markbates/inflect" - "github.com/markbates/pop" - "github.com/spf13/cobra" -) - -var skipMigration bool - -func init() { - ModelCmd.Flags().BoolVarP(&skipMigration, "skip-migration", "s", false, "Skip creating a new fizz migration for this model.") -} - -var nrx = regexp.MustCompile(`^nulls\.(.+)`) - -type names struct { - Original string - Table string - Proper string - File string - Plural string - Char string -} - -func newName(name string) names { - return names{ - Original: name, - File: inflect.Underscore(inflect.Singularize(name)), - Table: inflect.Tableize(inflect.Pluralize(name)), - Proper: inflect.ForeignKeyToAttribute(name), - Plural: inflect.Pluralize(inflect.Camelize(name)), - Char: strings.ToLower(string([]byte(name)[0])), - } -} - -type attribute struct { - Names names - OriginalType string - GoType string - Nullable bool -} - -func (a attribute) String() string { - return fmt.Sprintf("\t%s %s `json:\"%s\" db:\"%s\"`", a.Names.Proper, a.GoType, a.Names.Original, a.Names.Original) -} - -type model struct { - Package string - Imports []string - Names names - Attributes []attribute - ValidatableAttributes []attribute -} - -func (m model) Generate() error { - g := makr.New() - ctx := makr.Data{} - ctx["model"] = m - ctx["plural_model_name"] = m.Names.Plural - ctx["model_name"] = m.Names.Proper - ctx["package_name"] = m.Package - ctx["char"] = m.Names.Char - - fname := filepath.Join(m.Package, m.Names.File+".go") - g.Add(makr.NewFile(fname, modelTemplate)) - tfname := filepath.Join(m.Package, m.Names.File+"_test.go") - g.Add(makr.NewFile(tfname, modelTestTemplate)) - g.Add(makr.NewCommand(makr.GoFmt())) - return g.Run(".", ctx) -} - -func (m model) Fizz() string { - s := []string{fmt.Sprintf("create_table(\"%s\", func(t) {", m.Names.Table)} - for _, a := range m.Attributes { - switch a.Names.Original { - case "created_at", "updated_at": - case "id": - s = append(s, fmt.Sprintf("\tt.Column(\"id\", \"%s\", {\"primary\": true})", fizzColType(a.OriginalType))) - default: - x := fmt.Sprintf("\tt.Column(\"%s\", \"%s\", {})", a.Names.Original, fizzColType(a.OriginalType)) - if a.Nullable { - x = strings.Replace(x, "{}", `{"null": true}`, -1) - } - s = append(s, x) - } - } - s = append(s, "})") - return strings.Join(s, "\n") -} - -func newModel(name string) model { - id := newName("id") - id.Proper = "ID" - m := model{ - Package: "models", - Imports: []string{"time", "encoding/json", "github.com/markbates/pop", "github.com/markbates/validate", "github.com/satori/go.uuid"}, - Names: newName(name), - Attributes: []attribute{ - {Names: id, OriginalType: "uuid.UUID", GoType: "uuid.UUID"}, - {Names: newName("created_at"), OriginalType: "time.Time", GoType: "time.Time"}, - {Names: newName("updated_at"), OriginalType: "time.Time", GoType: "time.Time"}, - }, - ValidatableAttributes: []attribute{}, - } - m.Names.Proper = inflect.Singularize(m.Names.Proper) - return m -} - -var ModelCmd = &cobra.Command{ - Use: "model [name]", - Aliases: []string{"m"}, - Short: "Generates a model for your database", - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return errors.New("You must supply a name for your model!") - } - - model := newModel(args[0]) - - hasNulls := false - for _, def := range args[1:] { - col := strings.Split(def, ":") - if len(col) == 1 { - col = append(col, "string") - } - nullable := nrx.MatchString(col[1]) - if !hasNulls && nullable { - hasNulls = true - model.Imports = append(model.Imports, "github.com/markbates/pop/nulls") - } - - a := attribute{ - Names: newName(col[0]), - OriginalType: col[1], - GoType: colType(col[1]), - Nullable: nullable, - } - model.Attributes = append(model.Attributes, a) - if !a.Nullable { - if a.GoType == "string" || a.GoType == "time.Time" || a.GoType == "int" { - if a.GoType == "time.Time" { - a.GoType = "Time" - } - model.ValidatableAttributes = append(model.ValidatableAttributes, a) - } - } - } - - err := os.MkdirAll(model.Package, 0766) - if err != nil { - return errors.Wrapf(err, "couldn't create folder %s", model.Package) - } - - err = model.Generate() - if err != nil { - return err - } - - if !skipMigration { - cflag := cmd.Flag("path") - migrationPath := defaults.String(cflag.Value.String(), "./migrations") - err = pop.MigrationCreate(migrationPath, fmt.Sprintf("create_%s", model.Names.Table), "fizz", []byte(model.Fizz()), []byte(fmt.Sprintf("drop_table(\"%s\")", model.Names.Table))) - if err != nil { - return err - } - } - - return nil - }, -} - -func colType(s string) string { - switch s { - case "text": - return "string" - case "time", "timestamp": - return "time.Time" - case "nulls.Text": - return "nulls.String" - case "uuid": - return "uuid.UUID" - default: - return s - } -} - -func fizzColType(s string) string { - if nrx.MatchString(s) { - return fizzColType(strings.Replace(s, "nulls.", "", -1)) - } - switch strings.ToLower(s) { - case "int": - return "integer" - case "time": - return "timestamp" - case "uuid.uuid", "uuid": - return "uuid" - default: - return strings.ToLower(s) - } -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/generate/model_templates.go b/vendor/github.com/markbates/pop/soda/cmd/generate/model_templates.go deleted file mode 100644 index ce27a949..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/generate/model_templates.go +++ /dev/null @@ -1,69 +0,0 @@ -package generate - -const modelTemplate = `package {{.package_name}} - -import ( - {{ range $i := .model.Imports -}} - "{{$i}}" - {{ end -}} - {{ if .model.ValidatableAttributes -}} - "github.com/markbates/validate/validators" - {{ end -}} -) - -type {{.model_name}} struct { - {{range $a := .model.Attributes -}} - {{$a}} - {{end -}} -} - -// String is not required by pop and may be deleted -func ({{.char}} {{.model_name}}) String() string { - j{{.char}}, _ := json.Marshal({{.char}}) - return string(j{{.char}}) -} - -// {{.plural_model_name}} is not required by pop and may be deleted -type {{.plural_model_name}} []{{.model_name}} - -// String is not required by pop and may be deleted -func ({{.char}} {{.plural_model_name}}) String() string { - j{{.char}}, _ := json.Marshal({{.char}}) - return string(j{{.char}}) -} - -// Validate gets run everytime you call a "pop.Validate" method. -// This method is not required and may be deleted. -func ({{.char}} *{{.model_name}}) Validate(tx *pop.Connection) (*validate.Errors, error) { - {{ if .model.ValidatableAttributes -}} - return validate.Validate( - {{ range $a := .model.ValidatableAttributes -}} - &validators.{{capitalize $a.GoType}}IsPresent{Field: {{$.char}}.{{$a.Names.Proper}}, Name: "{{$a.Names.Proper}}"}, - {{end -}} - ), nil - {{ else -}} - return validate.NewErrors(), nil - {{ end -}} -} - -// ValidateSave gets run everytime you call "pop.ValidateSave" method. -// This method is not required and may be deleted. -func ({{.char}} *{{.model_name}}) ValidateSave(tx *pop.Connection) (*validate.Errors, error) { - return validate.NewErrors(), nil -} - -// ValidateUpdate gets run everytime you call "pop.ValidateUpdate" method. -// This method is not required and may be deleted. -func ({{.char}} *{{.model_name}}) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) { - return validate.NewErrors(), nil -} -` - -const modelTestTemplate = `package {{.package_name}}_test - -import "testing" - -func Test_{{.model_name}}(t *testing.T) { - t.Fatal("This test needs to be implemented!") -} -` diff --git a/vendor/github.com/markbates/pop/soda/cmd/generate/model_test.go b/vendor/github.com/markbates/pop/soda/cmd/generate/model_test.go deleted file mode 100644 index 90744189..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/generate/model_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package generate - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func Test_newName(t *testing.T) { - r := require.New(t) - n := newName("carrot") - r.Equal(n.File, "carrot") - r.Equal(n.Proper, "Carrot") - r.Equal(n.Table, "carrots") - r.Equal(n.Plural, "Carrots") - r.Equal(n.Char, "c") -} - -func Test_newName_Plural(t *testing.T) { - r := require.New(t) - n := newName("carrots") - r.Equal(n.File, "carrot") - r.Equal("Carrots", n.Proper) - r.Equal(n.Table, "carrots") - r.Equal(n.Plural, "Carrots") - r.Equal(n.Char, "c") -} - -func Test_newName_multipleCamelCase(t *testing.T) { - r := require.New(t) - n := newName("carrotCake") - r.Equal(n.File, "carrot_cake") - r.Equal(n.Proper, "CarrotCake") - r.Equal(n.Table, "carrot_cakes") - r.Equal(n.Plural, "CarrotCakes") - r.Equal(n.Char, "c") -} - -func Test_newName_multipleCamelCase_Plural(t *testing.T) { - r := require.New(t) - n := newName("carrotCakes") - r.Equal(n.File, "carrot_cake") - r.Equal(n.Proper, "CarrotCakes") - r.Equal(n.Table, "carrot_cakes") - r.Equal(n.Plural, "CarrotCakes") - r.Equal(n.Char, "c") -} - -func Test_newName_multipleSnake(t *testing.T) { - r := require.New(t) - n := newName("carrot_cake") - r.Equal(n.File, "carrot_cake") - r.Equal(n.Proper, "CarrotCake") - r.Equal(n.Table, "carrot_cakes") - r.Equal(n.Plural, "CarrotCakes") - r.Equal(n.Char, "c") -} - -func Test_newName_multipleSnake_Plural(t *testing.T) { - r := require.New(t) - n := newName("carrot_cakes") - r.Equal(n.File, "carrot_cake") - r.Equal(n.Proper, "CarrotCakes") - r.Equal(n.Table, "carrot_cakes") - r.Equal(n.Plural, "CarrotCakes") - r.Equal(n.Char, "c") -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/generate/sql_migration.go b/vendor/github.com/markbates/pop/soda/cmd/generate/sql_migration.go deleted file mode 100644 index e6c90daa..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/generate/sql_migration.go +++ /dev/null @@ -1,22 +0,0 @@ -package generate - -import ( - "github.com/pkg/errors" - - "github.com/markbates/going/defaults" - "github.com/markbates/pop" - "github.com/spf13/cobra" -) - -var SQLCmd = &cobra.Command{ - Use: "sql [name]", - Short: "Generates Up/Down migrations for your database using SQL.", - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return errors.New("You must supply a name for your migration!") - } - cflag := cmd.Flag("path") - migrationPath := defaults.String(cflag.Value.String(), "./migrates") - return pop.MigrationCreate(migrationPath, args[0], "sql", nil, nil) - }, -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/migrate.go b/vendor/github.com/markbates/pop/soda/cmd/migrate.go deleted file mode 100644 index 717fc53c..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/migrate.go +++ /dev/null @@ -1,28 +0,0 @@ -package cmd - -import ( - "os" - - "github.com/spf13/cobra" -) - -var migrationPath string - -var migrateCmd = &cobra.Command{ - Use: "migrate", - Aliases: []string{"m"}, - Short: "Runs migrations against your database.", - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - RootCmd.PersistentPreRun(cmd, args) - return os.MkdirAll(migrationPath, 0766) - }, - RunE: func(cmd *cobra.Command, args []string) error { - c := getConn() - return c.MigrateUp(migrationPath) - }, -} - -func init() { - RootCmd.AddCommand(migrateCmd) - RootCmd.PersistentFlags().StringVarP(&migrationPath, "path", "p", "./migrations", "Path to the migrations folder") -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/migrate_create.go b/vendor/github.com/markbates/pop/soda/cmd/migrate_create.go deleted file mode 100644 index ce4d6470..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/migrate_create.go +++ /dev/null @@ -1,32 +0,0 @@ -package cmd - -import ( - "fmt" - - "github.com/pkg/errors" - - "github.com/markbates/pop" - "github.com/spf13/cobra" -) - -var migrationType string - -var depWarning = "[DEPRACTION WARNING] This command is deprecated. Please use `soda generate fizz` or `soda generate sql` instead." - -var migrateCreateCmd = &cobra.Command{ - Use: "create [name]", - Short: depWarning, - RunE: func(cmd *cobra.Command, args []string) error { - fmt.Println(depWarning) - if len(args) == 0 { - return errors.New("You must supply a name for your migration!") - } - - return pop.MigrationCreate(migrationPath, args[0], migrationType, nil, nil) - }, -} - -func init() { - migrateCmd.AddCommand(migrateCreateCmd) - migrateCreateCmd.Flags().StringVarP(&migrationType, "type", "t", "fizz", "Which type of migration file do you want? fizz or sql?") -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/migrate_down.go b/vendor/github.com/markbates/pop/soda/cmd/migrate_down.go deleted file mode 100644 index faa18589..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/migrate_down.go +++ /dev/null @@ -1,19 +0,0 @@ -package cmd - -import "github.com/spf13/cobra" - -var migrationStep int - -var migrateDownCmd = &cobra.Command{ - Use: "down", - Short: "Apply one or more of the 'down' migrations.", - RunE: func(cmd *cobra.Command, args []string) error { - c := getConn() - return c.MigrateDown(migrationPath, migrationStep) - }, -} - -func init() { - migrateCmd.AddCommand(migrateDownCmd) - migrateDownCmd.Flags().IntVarP(&migrationStep, "step", "s", 1, "Number of migration to down") -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/migrate_reset.go b/vendor/github.com/markbates/pop/soda/cmd/migrate_reset.go deleted file mode 100644 index 3ab1b745..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/migrate_reset.go +++ /dev/null @@ -1,16 +0,0 @@ -package cmd - -import "github.com/spf13/cobra" - -var migrateResetCmd = &cobra.Command{ - Use: "reset", - Short: "The equivalent of running `migrate down` and then `migrate up`", - RunE: func(cmd *cobra.Command, args []string) error { - c := getConn() - return c.MigrateReset(migrationPath) - }, -} - -func init() { - migrateCmd.AddCommand(migrateResetCmd) -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/migrate_up.go b/vendor/github.com/markbates/pop/soda/cmd/migrate_up.go deleted file mode 100644 index bee1a5f3..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/migrate_up.go +++ /dev/null @@ -1,16 +0,0 @@ -package cmd - -import "github.com/spf13/cobra" - -var migrateUpCmd = &cobra.Command{ - Use: "up", - Short: "Apply all of the 'up' migrations.", - RunE: func(cmd *cobra.Command, args []string) error { - c := getConn() - return c.MigrateUp(migrationPath) - }, -} - -func init() { - migrateCmd.AddCommand(migrateUpCmd) -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/root.go b/vendor/github.com/markbates/pop/soda/cmd/root.go deleted file mode 100644 index d56f96a1..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/root.go +++ /dev/null @@ -1,67 +0,0 @@ -package cmd - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/markbates/going/defaults" - "github.com/markbates/pop" - "github.com/spf13/cobra" -) - -var cfgFile string -var env string -var version bool - -var RootCmd = &cobra.Command{ - Use: "soda", - Aliases: []string{"db"}, - Short: "A tasty treat for all your database needs", - PersistentPreRun: func(c *cobra.Command, args []string) { - fmt.Printf("v%s\n\n", Version) - env = defaults.String(os.Getenv("GO_ENV"), env) - setConfigLocation() - }, - Run: func(cmd *cobra.Command, args []string) { - if !version { - cmd.Help() - } - }, -} - -func Execute() { - if err := RootCmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(-1) - } -} - -func init() { - RootCmd.Flags().BoolVarP(&version, "version", "v", false, "Show version information") - RootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "The configuration file you would like to use.") - RootCmd.PersistentFlags().StringVarP(&env, "env", "e", "development", "The environment you want to run migrations against. Will use $GO_ENV if set.") - RootCmd.PersistentFlags().BoolVarP(&pop.Debug, "debug", "d", false, "Use debug/verbose mode") -} - -func setConfigLocation() { - if cfgFile != "" { - abs, err := filepath.Abs(cfgFile) - if err != nil { - return - } - dir, file := filepath.Split(abs) - pop.AddLookupPaths(dir) - pop.ConfigName = file - } - pop.LoadConfig() -} - -func getConn() *pop.Connection { - conn := pop.Connections[env] - if conn == nil { - fmt.Printf("There is no connection named %s defined!\n", env) - os.Exit(1) - } - return conn -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/schema.go b/vendor/github.com/markbates/pop/soda/cmd/schema.go deleted file mode 100644 index fc7243ab..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/schema.go +++ /dev/null @@ -1,18 +0,0 @@ -package cmd - -import ( - "github.com/markbates/pop/soda/cmd/schema" - "github.com/spf13/cobra" -) - -// schemaCmd represents the schema command -var schemaCmd = &cobra.Command{ - Use: "schema", - Short: "Tools for working with your database schema", -} - -func init() { - schemaCmd.AddCommand(schema.LoadCmd) - schemaCmd.AddCommand(schema.DumpCmd) - RootCmd.AddCommand(schemaCmd) -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/schema/dump.go b/vendor/github.com/markbates/pop/soda/cmd/schema/dump.go deleted file mode 100644 index d1b48fa0..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/schema/dump.go +++ /dev/null @@ -1,49 +0,0 @@ -package schema - -import ( - "io" - "os" - "path/filepath" - - "github.com/markbates/pop" - "github.com/spf13/cobra" -) - -var dumpOptions = struct { - env string - output string -}{} - -var DumpCmd = &cobra.Command{ - Use: "dump", - Short: "Dumps out the schema of the selected database", - RunE: func(cmd *cobra.Command, args []string) error { - c, err := pop.Connect(dumpOptions.env) - if err != nil { - return err - } - var out io.Writer - if dumpOptions.output == "-" { - out = os.Stdout - } else { - err = os.MkdirAll(filepath.Dir(dumpOptions.output), 0755) - if err != nil { - return err - } - out, err = os.Create(dumpOptions.output) - if err != nil { - return err - } - } - err = c.Dialect.DumpSchema(out) - if err != nil { - return err - } - return nil - }, -} - -func init() { - DumpCmd.Flags().StringVarP(&dumpOptions.env, "env", "e", "development", "The environment you want to run schema against. Will use $GO_ENV if set.") - DumpCmd.Flags().StringVarP(&dumpOptions.output, "output", "o", "schema.sql", "The path to dump the schema to.") -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/schema/load.go b/vendor/github.com/markbates/pop/soda/cmd/schema/load.go deleted file mode 100644 index 3e843a90..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/schema/load.go +++ /dev/null @@ -1,40 +0,0 @@ -package schema - -import ( - "os" - - "github.com/markbates/pop" - "github.com/spf13/cobra" -) - -var loadOptions = struct { - env string - input string -}{} - -var LoadCmd = &cobra.Command{ - Use: "load", - Short: "Load a schema.sql file into a database", - RunE: func(cmd *cobra.Command, args []string) error { - f, err := os.Open(loadOptions.input) - if err != nil { - return err - } - - c, err := pop.Connect(loadOptions.env) - if err != nil { - return err - } - - err = c.Dialect.LoadSchema(f) - if err != nil { - return err - } - return nil - }, -} - -func init() { - LoadCmd.Flags().StringVarP(&loadOptions.env, "env", "e", "development", "The environment you want to run schema against. Will use $GO_ENV if set.") - LoadCmd.Flags().StringVarP(&loadOptions.input, "input", "i", "schema.sql", "The path to the schema file you want to load") -} diff --git a/vendor/github.com/markbates/pop/soda/cmd/version.go b/vendor/github.com/markbates/pop/soda/cmd/version.go deleted file mode 100644 index 186632d8..00000000 --- a/vendor/github.com/markbates/pop/soda/cmd/version.go +++ /dev/null @@ -1,3 +0,0 @@ -package cmd - -const Version = "3.18.0" diff --git a/vendor/github.com/markbates/pop/soda/main.go b/vendor/github.com/markbates/pop/soda/main.go deleted file mode 100644 index 816c56db..00000000 --- a/vendor/github.com/markbates/pop/soda/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/markbates/pop/soda/cmd" - -func main() { - cmd.Execute() -} diff --git a/vendor/github.com/markbates/pop/sql_builder.go b/vendor/github.com/markbates/pop/sql_builder.go deleted file mode 100644 index 5fe6b419..00000000 --- a/vendor/github.com/markbates/pop/sql_builder.go +++ /dev/null @@ -1,156 +0,0 @@ -package pop - -import ( - "fmt" - "regexp" - "strings" - - "github.com/jmoiron/sqlx" - . "github.com/markbates/pop/columns" -) - -type sqlBuilder struct { - Query Query - Model *Model - AddColumns []string - sql string - args []interface{} -} - -func newSQLBuilder(q Query, m *Model, addColumns ...string) *sqlBuilder { - return &sqlBuilder{ - Query: q, - Model: m, - AddColumns: addColumns, - args: []interface{}{}, - } -} - -func (sq *sqlBuilder) String() string { - if sq.sql == "" { - sq.compile() - } - return sq.sql -} - -func (sq *sqlBuilder) Args() []interface{} { - if len(sq.args) == 0 { - if len(sq.Query.RawSQL.Arguments) > 0 { - sq.args = sq.Query.RawSQL.Arguments - } else { - sq.compile() - } - } - return sq.args -} - -func (sq *sqlBuilder) compile() { - if sq.sql == "" { - if sq.Query.RawSQL.Fragment != "" { - sq.sql = sq.Query.RawSQL.Fragment - } else { - sq.sql = sq.buildSelectSQL() - } - re := regexp.MustCompile(`(?i)in\s*\(\s*\?\s*\)`) - if re.MatchString(sq.sql) { - s, _, err := sqlx.In(sq.sql, sq.Args()) - if err == nil { - sq.sql = s - } - } - sq.sql = sq.Query.Connection.Dialect.TranslateSQL(sq.sql) - } -} - -func (sq *sqlBuilder) buildSelectSQL() string { - cols := sq.buildColumns() - - fc := sq.buildfromClauses() - - sql := fmt.Sprintf("SELECT %s FROM %s", cols.Readable().SelectString(), fc) - - sql = sq.buildWhereClauses(sql) - sql = sq.buildOrderClauses(sql) - sql = sq.buildPaginationClauses(sql) - - return sql -} - -func (sq *sqlBuilder) buildfromClauses() fromClauses { - models := []*Model{ - sq.Model, - } - for _, mc := range sq.Query.belongsToThroughClauses { - models = append(models, mc.Through) - } - - fc := sq.Query.fromClauses - for _, m := range models { - tableName := m.TableName() - fc = append(fc, fromClause{ - From: tableName, - As: strings.Replace(tableName, ".", "_", -1), - }) - } - - return fc -} - -func (sq *sqlBuilder) buildWhereClauses(sql string) string { - mcs := sq.Query.belongsToThroughClauses - for _, mc := range mcs { - sq.Query.Where(fmt.Sprintf("%s.%s = ?", mc.Through.TableName(), mc.BelongsTo.associationName()), mc.BelongsTo.ID()) - sq.Query.Where(fmt.Sprintf("%s.id = %s.%s", sq.Model.TableName(), mc.Through.TableName(), sq.Model.associationName())) - } - - wc := sq.Query.whereClauses - if len(wc) > 0 { - sql = fmt.Sprintf("%s WHERE %s", sql, wc.Join(" AND ")) - for _, arg := range wc.Args() { - sq.args = append(sq.args, arg) - } - } - return sql -} - -func (sq *sqlBuilder) buildOrderClauses(sql string) string { - oc := sq.Query.orderClauses - if len(oc) > 0 { - sql = fmt.Sprintf("%s ORDER BY %s", sql, oc.Join(", ")) - for _, arg := range oc.Args() { - sq.args = append(sq.args, arg) - } - } - return sql -} - -func (sq *sqlBuilder) buildPaginationClauses(sql string) string { - if sq.Query.limitResults > 0 && sq.Query.Paginator == nil { - sql = fmt.Sprintf("%s LIMIT %d", sql, sq.Query.limitResults) - } - if sq.Query.Paginator != nil { - sql = fmt.Sprintf("%s LIMIT %d", sql, sq.Query.Paginator.PerPage) - sql = fmt.Sprintf("%s OFFSET %d", sql, sq.Query.Paginator.Offset) - } - return sql -} - -var columnCache = map[string]Columns{} - -func (sq *sqlBuilder) buildColumns() Columns { - tableName := sq.Model.TableName() - acl := len(sq.AddColumns) - if acl <= 0 { - cols, ok := columnCache[tableName] - if ok { - return cols - } - cols = ColumnsForStruct(sq.Model.Value, tableName) - columnCache[tableName] = cols - return cols - } else { - cols := NewColumns("") - cols.Add(sq.AddColumns...) - return cols - } -} diff --git a/vendor/github.com/markbates/pop/sqlite.go b/vendor/github.com/markbates/pop/sqlite.go deleted file mode 100644 index 6ed26b33..00000000 --- a/vendor/github.com/markbates/pop/sqlite.go +++ /dev/null @@ -1,185 +0,0 @@ -package pop - -import ( - "fmt" - "io" - "os" - "os/exec" - "path/filepath" - "strings" - "sync" - "time" - - "github.com/markbates/going/defaults" - . "github.com/markbates/pop/columns" - "github.com/markbates/pop/fizz" - "github.com/markbates/pop/fizz/translators" - "github.com/pkg/errors" -) - -var _ dialect = &sqlite{} - -type sqlite struct { - gil *sync.Mutex - smGil *sync.Mutex - ConnectionDetails *ConnectionDetails -} - -func (m *sqlite) Details() *ConnectionDetails { - return m.ConnectionDetails -} - -func (m *sqlite) URL() string { - return m.ConnectionDetails.Database + "?_busy_timeout=5000" -} - -func (m *sqlite) MigrationURL() string { - return m.ConnectionDetails.URL -} - -func (m *sqlite) Create(s store, model *Model, cols Columns) error { - return m.locker(m.smGil, func() error { - return errors.Wrap(genericCreate(s, model, cols), "sqlite create") - }) -} - -func (m *sqlite) Update(s store, model *Model, cols Columns) error { - return m.locker(m.smGil, func() error { - return errors.Wrap(genericUpdate(s, model, cols), "sqlite update") - }) -} - -func (m *sqlite) Destroy(s store, model *Model) error { - return m.locker(m.smGil, func() error { - return errors.Wrap(genericDestroy(s, model), "sqlite destroy") - }) -} - -func (m *sqlite) SelectOne(s store, model *Model, query Query) error { - return m.locker(m.smGil, func() error { - return errors.Wrap(genericSelectOne(s, model, query), "sqlite select one") - }) -} - -func (m *sqlite) SelectMany(s store, models *Model, query Query) error { - return m.locker(m.smGil, func() error { - return errors.Wrap(genericSelectMany(s, models, query), "sqlite select many") - }) -} - -func (m *sqlite) Lock(fn func() error) error { - return m.locker(m.gil, fn) -} - -func (m *sqlite) locker(l *sync.Mutex, fn func() error) error { - if defaults.String(m.Details().Options["lock"], "true") == "true" { - defer l.Unlock() - l.Lock() - } - err := fn() - attempts := 0 - for err != nil && err.Error() == "database is locked" && attempts <= m.Details().RetryLimit() { - time.Sleep(m.Details().RetrySleep()) - err = fn() - attempts++ - } - return err -} - -func (m *sqlite) CreateDB() error { - d := filepath.Dir(m.ConnectionDetails.Database) - err := os.MkdirAll(d, 0766) - if err != nil { - return errors.Wrapf(err, "could not create SQLite database %s", m.ConnectionDetails.Database) - } - fmt.Printf("created database %s\n", m.ConnectionDetails.Database) - return nil -} - -func (m *sqlite) DropDB() error { - err := os.Remove(m.ConnectionDetails.Database) - if err != nil { - return errors.Wrapf(err, "could not drop SQLite database %s", m.ConnectionDetails.Database) - } - fmt.Printf("dropped database %s\n", m.ConnectionDetails.Database) - return nil -} - -func (m *sqlite) TranslateSQL(sql string) string { - return sql -} - -func (m *sqlite) FizzTranslator() fizz.Translator { - return translators.NewSQLite(m.Details().Database) -} - -func (m *sqlite) DumpSchema(w io.Writer) error { - cmd := exec.Command("sqlite3", m.Details().Database, ".schema") - Log(strings.Join(cmd.Args, " ")) - cmd.Stdout = w - cmd.Stderr = os.Stderr - - err := cmd.Run() - if err != nil { - return err - } - - fmt.Printf("dumped schema for %s\n", m.Details().Database) - return nil -} - -func (m *sqlite) LoadSchema(r io.Reader) error { - cmd := exec.Command("sqlite3", m.ConnectionDetails.Database) - in, err := cmd.StdinPipe() - if err != nil { - return err - } - go func() { - defer in.Close() - io.Copy(in, r) - }() - Log(strings.Join(cmd.Args, " ")) - err = cmd.Start() - if err != nil { - return err - } - - err = cmd.Wait() - if err != nil { - return err - } - - fmt.Printf("loaded schema for %s\n", m.Details().Database) - return nil -} - -func (m *sqlite) TruncateAll(tx *Connection) error { - const tableNames = `SELECT name FROM sqlite_master WHERE type = "table"` - names := []struct { - Name string `db:"name"` - }{} - - err := tx.RawQuery(tableNames).All(&names) - if err != nil { - return err - } - stmts := []string{} - for _, n := range names { - stmts = append(stmts, fmt.Sprintf("DELETE FROM %s", n.Name)) - } - if len(stmts) == 0 { - return nil - } - return tx.RawQuery(strings.Join(stmts, "; ")).Exec() -} - -func newSQLite(deets *ConnectionDetails) dialect { - deets.URL = fmt.Sprintf("sqlite3://%s", deets.Database) - cd := &sqlite{ - gil: &sync.Mutex{}, - smGil: &sync.Mutex{}, - ConnectionDetails: deets, - } - - return cd -} diff --git a/vendor/github.com/markbates/pop/store.go b/vendor/github.com/markbates/pop/store.go deleted file mode 100644 index 9101f77c..00000000 --- a/vendor/github.com/markbates/pop/store.go +++ /dev/null @@ -1,21 +0,0 @@ -package pop - -import ( - "database/sql" - - "github.com/jmoiron/sqlx" -) - -// Store is an interface that must be implemented in order for Pop -// to be able to use the value as a way of talking to a datastore. -type store interface { - Select(interface{}, string, ...interface{}) error - Get(interface{}, string, ...interface{}) error - NamedExec(string, interface{}) (sql.Result, error) - Exec(string, ...interface{}) (sql.Result, error) - PrepareNamed(string) (*sqlx.NamedStmt, error) - Transaction() (*tX, error) - Rollback() error - Commit() error - Close() error -} diff --git a/vendor/github.com/markbates/pop/test.sh b/vendor/github.com/markbates/pop/test.sh deleted file mode 100755 index 32cf884f..00000000 --- a/vendor/github.com/markbates/pop/test.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -set -e -clear - -verbose="" - -echo $@ - -if [[ "$@" == "-v" ]] -then - verbose="-v" -fi - - -go build -o tsoda ./soda - -function test { - echo "Testing $1" - export SODA_DIALECT=$1 - echo ./tsoda -v - ! ./tsoda drop -e $SODA_DIALECT -c ./database.yml - ! ./tsoda create -d -e $SODA_DIALECT -c ./database.yml - ./tsoda migrate -d -e $SODA_DIALECT -c ./database.yml -d - ./tsoda migrate down -d -e $SODA_DIALECT -c ./database.yml -d - ./tsoda migrate down -d -e $SODA_DIALECT -c ./database.yml -d - ./tsoda migrate -d -e $SODA_DIALECT -c ./database.yml -d - go test ./... $verbose -} - -test "sqlite" -test "postgres" -test "mysql" - -rm tsoda diff --git a/vendor/github.com/markbates/pop/tx.go b/vendor/github.com/markbates/pop/tx.go deleted file mode 100644 index 814c912e..00000000 --- a/vendor/github.com/markbates/pop/tx.go +++ /dev/null @@ -1,37 +0,0 @@ -package pop - -import ( - "math/rand" - "time" - - "github.com/jmoiron/sqlx" - "github.com/pkg/errors" -) - -func init() { - rand.Seed(time.Now().UnixNano()) -} - -type tX struct { - ID int - *sqlx.Tx -} - -func newTX(db *dB) (*tX, error) { - t := &tX{ - ID: rand.Int(), - } - tx, err := db.Beginx() - t.Tx = tx - return t, errors.Wrap(err, "could not create new transaction") -} - -// Transaction simply returns the current transaction, -// this is defined so it implements the `Store` interface. -func (tx *tX) Transaction() (*tX, error) { - return tx, nil -} - -func (tx *tX) Close() error { - return nil -}