Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle https://xorm.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

220 lines
9.3 KiB

  1. IMPORT := xorm.io/xorm
  2. export GO111MODULE=on
  3. GO ?= go
  4. GOFMT ?= gofmt -s
  5. TAGS ?=
  6. SED_INPLACE := sed -i
  7. GOFILES := $(shell find . -name "*.go" -type f)
  8. INTEGRATION_PACKAGES := xorm.io/xorm/integrations
  9. PACKAGES ?= $(filter-out $(INTEGRATION_PACKAGES),$(shell $(GO) list ./...))
  10. TEST_COCKROACH_HOST ?= cockroach:26257
  11. TEST_COCKROACH_SCHEMA ?=
  12. TEST_COCKROACH_DBNAME ?= xorm_test
  13. TEST_COCKROACH_USERNAME ?= postgres
  14. TEST_COCKROACH_PASSWORD ?=
  15. TEST_MSSQL_HOST ?= mssql:1433
  16. TEST_MSSQL_DBNAME ?= gitea
  17. TEST_MSSQL_USERNAME ?= sa
  18. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  19. TEST_MYSQL_HOST ?= mysql:3306
  20. TEST_MYSQL_CHARSET ?= utf8
  21. TEST_MYSQL_DBNAME ?= xorm_test
  22. TEST_MYSQL_USERNAME ?= root
  23. TEST_MYSQL_PASSWORD ?=
  24. TEST_PGSQL_HOST ?= pgsql:5432
  25. TEST_PGSQL_SCHEMA ?=
  26. TEST_PGSQL_DBNAME ?= xorm_test
  27. TEST_PGSQL_USERNAME ?= postgres
  28. TEST_PGSQL_PASSWORD ?= mysecretpassword
  29. TEST_TIDB_HOST ?= tidb:4000
  30. TEST_TIDB_DBNAME ?= xorm_test
  31. TEST_TIDB_USERNAME ?= root
  32. TEST_TIDB_PASSWORD ?=
  33. TEST_CACHE_ENABLE ?= false
  34. TEST_QUOTE_POLICY ?= always
  35. .PHONY: all
  36. all: build
  37. .PHONY: build
  38. build: go-check $(GO_SOURCES)
  39. $(GO) build $(PACKAGES)
  40. .PHONY: clean
  41. clean:
  42. $(GO) clean -i ./...
  43. rm -rf *.sql *.log test.db *coverage.out coverage.all integrations/*.sql
  44. .PHONY: coverage
  45. coverage:
  46. @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  47. $(GO) get -u github.com/wadey/gocovmerge; \
  48. fi
  49. gocovmerge $(shell find . -type f -name "coverage.out") > coverage.all;\
  50. .PHONY: fmt
  51. fmt:
  52. $(GOFMT) -w $(GOFILES)
  53. .PHONY: fmt-check
  54. fmt-check:
  55. # get all go files and run go fmt on them
  56. @diff=$$($(GOFMT) -d $(GOFILES)); \
  57. if [ -n "$$diff" ]; then \
  58. echo "Please run 'make fmt' and commit the result:"; \
  59. echo "$${diff}"; \
  60. exit 1; \
  61. fi;
  62. .PHONY: go-check
  63. go-check:
  64. $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?\s' | tr '.' ' ');))
  65. @if [ "$(GO_VERSION)" -lt "001011000" ]; then \
  66. echo "Gitea requires Go 1.11.0 or greater to build. You can get it at https://golang.org/dl/"; \
  67. exit 1; \
  68. fi
  69. .PHONY: help
  70. help:
  71. @echo "Make Routines:"
  72. @echo " - equivalent to \"build\""
  73. @echo " - build creates the entire project"
  74. @echo " - clean delete integration files and build files but not css and js files"
  75. @echo " - fmt format the code"
  76. @echo " - lint run code linter revive"
  77. @echo " - misspell check if a word is written wrong"
  78. @echo " - test run default unit test"
  79. @echo " - test-cockroach run integration tests for cockroach"
  80. @echo " - test-mysql run integration tests for mysql"
  81. @echo " - test-mssql run integration tests for mssql"
  82. @echo " - test-postgres run integration tests for postgres"
  83. @echo " - test-sqlite run integration tests for sqlite"
  84. @echo " - test-tidb run integration tests for tidb"
  85. @echo " - vet examines Go source code and reports suspicious constructs"
  86. .PHONY: lint
  87. lint: revive
  88. .PHONY: revive
  89. revive:
  90. @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  91. $(GO) get -u github.com/mgechev/revive; \
  92. fi
  93. revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
  94. .PHONY: misspell
  95. misspell:
  96. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  97. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  98. fi
  99. misspell -w -i unknwon $(GOFILES)
  100. .PHONY: misspell-check
  101. misspell-check:
  102. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  103. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  104. fi
  105. misspell -error -i unknwon,destory $(GOFILES)
  106. .PHONY: test
  107. test: go-check
  108. $(GO) test $(PACKAGES)
  109. .PNONY: test-cockroach
  110. test-cockroach: go-check
  111. $(GO) test $(INTEGRATION_PACKAGES) -v -race -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
  112. -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \
  113. -ignore_update_limit=true -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  114. .PHONY: test-cockroach\#%
  115. test-cockroach\#%: go-check
  116. $(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
  117. -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \
  118. -ignore_update_limit=true -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  119. .PNONY: test-mssql
  120. test-mssql: go-check
  121. $(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
  122. -conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \
  123. -coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  124. .PNONY: test-mssql\#%
  125. test-mssql\#%: go-check
  126. $(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
  127. -conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \
  128. -coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  129. .PNONY: test-mymysql
  130. test-mymysql: go-check
  131. $(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
  132. -conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \
  133. -coverprofile=mymysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  134. .PNONY: test-mymysql\#%
  135. test-mymysql\#%: go-check
  136. $(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
  137. -conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \
  138. -coverprofile=mymysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  139. .PNONY: test-mysql
  140. test-mysql: go-check
  141. $(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
  142. -conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \
  143. -coverprofile=mysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  144. .PHONY: test-mysql\#%
  145. test-mysql\#%: go-check
  146. $(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
  147. -conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \
  148. -coverprofile=mysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  149. .PNONY: test-postgres
  150. test-postgres: go-check
  151. $(GO) test $(INTEGRATION_PACKAGES) -v -race -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
  152. -conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \
  153. -quote=$(TEST_QUOTE_POLICY) -coverprofile=postgres.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  154. .PHONY: test-postgres\#%
  155. test-postgres\#%: go-check
  156. $(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
  157. -conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \
  158. -quote=$(TEST_QUOTE_POLICY) -coverprofile=postgres.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  159. .PHONY: test-sqlite
  160. test-sqlite: go-check
  161. $(GO) test $(INTEGRATION_PACKAGES) -v -race -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
  162. -quote=$(TEST_QUOTE_POLICY) -coverprofile=sqlite.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  163. .PHONY: test-sqlite-schema
  164. test-sqlite-schema: go-check
  165. $(GO) test $(INTEGRATION_PACKAGES) -v -race -schema=xorm -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
  166. -quote=$(TEST_QUOTE_POLICY) -coverprofile=sqlite.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  167. .PHONY: test-sqlite\#%
  168. test-sqlite\#%: go-check
  169. $(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
  170. -quote=$(TEST_QUOTE_POLICY) -coverprofile=sqlite.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  171. .PNONY: test-tidb
  172. test-tidb: go-check
  173. $(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
  174. -conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \
  175. -quote=$(TEST_QUOTE_POLICY) -coverprofile=tidb.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  176. .PHONY: test-tidb\#%
  177. test-tidb\#%: go-check
  178. $(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
  179. -conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \
  180. -quote=$(TEST_QUOTE_POLICY) -coverprofile=tidb.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
  181. .PHONY: vet
  182. vet:
  183. $(GO) vet $(shell $(GO) list ./...)