Merge branch 'master' into master
This commit is contained in:
commit
0523107992
437
.drone.yml
437
.drone.yml
|
@ -1,437 +0,0 @@
|
|||
---
|
||||
kind: pipeline
|
||||
name: test-mysql
|
||||
environment:
|
||||
GO111MODULE: "on"
|
||||
GOPROXY: "https://goproxy.io"
|
||||
CGO_ENABLED: 1
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-vet
|
||||
image: golang:1.15
|
||||
pull: always
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
commands:
|
||||
- make vet
|
||||
- name: test-sqlite3
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
depends_on:
|
||||
- test-vet
|
||||
commands:
|
||||
- make fmt-check
|
||||
- make test
|
||||
- make test-sqlite3
|
||||
- TEST_CACHE_ENABLE=true make test-sqlite3
|
||||
- name: test-sqlite
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
depends_on:
|
||||
- test-vet
|
||||
commands:
|
||||
- make test-sqlite
|
||||
- TEST_QUOTE_POLICY=reserved make test-sqlite
|
||||
- name: test-mysql
|
||||
image: golang:1.15
|
||||
pull: never
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
depends_on:
|
||||
- test-vet
|
||||
environment:
|
||||
TEST_MYSQL_HOST: mysql
|
||||
TEST_MYSQL_CHARSET: utf8
|
||||
TEST_MYSQL_DBNAME: xorm_test
|
||||
TEST_MYSQL_USERNAME: root
|
||||
TEST_MYSQL_PASSWORD:
|
||||
commands:
|
||||
- TEST_CACHE_ENABLE=true make test-mysql
|
||||
|
||||
- name: test-mysql-utf8mb4
|
||||
image: golang:1.15
|
||||
pull: never
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
depends_on:
|
||||
- test-mysql
|
||||
environment:
|
||||
TEST_MYSQL_HOST: mysql
|
||||
TEST_MYSQL_CHARSET: utf8mb4
|
||||
TEST_MYSQL_DBNAME: xorm_test
|
||||
TEST_MYSQL_USERNAME: root
|
||||
TEST_MYSQL_PASSWORD:
|
||||
commands:
|
||||
- make test-mysql
|
||||
- TEST_QUOTE_POLICY=reserved make test-mysql-tls
|
||||
|
||||
volumes:
|
||||
- name: cache
|
||||
host:
|
||||
path: /tmp/cache
|
||||
|
||||
services:
|
||||
- name: mysql
|
||||
image: mysql:5.7
|
||||
environment:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
MYSQL_DATABASE: xorm_test
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: test-mysql8
|
||||
depends_on:
|
||||
- test-mysql
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-mysql8
|
||||
image: golang:1.15
|
||||
pull: never
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
environment:
|
||||
TEST_MYSQL_HOST: mysql8
|
||||
TEST_MYSQL_CHARSET: utf8mb4
|
||||
TEST_MYSQL_DBNAME: xorm_test
|
||||
TEST_MYSQL_USERNAME: root
|
||||
TEST_MYSQL_PASSWORD:
|
||||
commands:
|
||||
- make test-mysql
|
||||
- TEST_CACHE_ENABLE=true make test-mysql
|
||||
|
||||
volumes:
|
||||
- name: cache
|
||||
host:
|
||||
path: /tmp/cache
|
||||
|
||||
services:
|
||||
- name: mysql8
|
||||
image: mysql:8.0
|
||||
environment:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
MYSQL_DATABASE: xorm_test
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: test-mariadb
|
||||
depends_on:
|
||||
- test-mysql8
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-mariadb
|
||||
image: golang:1.15
|
||||
pull: never
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
environment:
|
||||
TEST_MYSQL_HOST: mariadb
|
||||
TEST_MYSQL_CHARSET: utf8mb4
|
||||
TEST_MYSQL_DBNAME: xorm_test
|
||||
TEST_MYSQL_USERNAME: root
|
||||
TEST_MYSQL_PASSWORD:
|
||||
commands:
|
||||
- make test-mysql
|
||||
- TEST_QUOTE_POLICY=reserved make test-mysql
|
||||
|
||||
volumes:
|
||||
- name: cache
|
||||
host:
|
||||
path: /tmp/cache
|
||||
|
||||
services:
|
||||
- name: mariadb
|
||||
image: mariadb:10.4
|
||||
environment:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
MYSQL_DATABASE: xorm_test
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: test-postgres
|
||||
depends_on:
|
||||
- test-mariadb
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-postgres
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
environment:
|
||||
TEST_PGSQL_HOST: pgsql
|
||||
TEST_PGSQL_DBNAME: xorm_test
|
||||
TEST_PGSQL_USERNAME: postgres
|
||||
TEST_PGSQL_PASSWORD: postgres
|
||||
commands:
|
||||
- make test-postgres
|
||||
- TEST_CACHE_ENABLE=true make test-postgres
|
||||
|
||||
- name: test-postgres-schema
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
depends_on:
|
||||
- test-postgres
|
||||
environment:
|
||||
TEST_PGSQL_HOST: pgsql
|
||||
TEST_PGSQL_SCHEMA: xorm
|
||||
TEST_PGSQL_DBNAME: xorm_test
|
||||
TEST_PGSQL_USERNAME: postgres
|
||||
TEST_PGSQL_PASSWORD: postgres
|
||||
commands:
|
||||
- TEST_QUOTE_POLICY=reserved make test-postgres
|
||||
|
||||
- name: test-pgx
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
depends_on:
|
||||
- test-postgres-schema
|
||||
environment:
|
||||
TEST_PGSQL_HOST: pgsql
|
||||
TEST_PGSQL_DBNAME: xorm_test
|
||||
TEST_PGSQL_USERNAME: postgres
|
||||
TEST_PGSQL_PASSWORD: postgres
|
||||
commands:
|
||||
- make test-pgx
|
||||
- TEST_CACHE_ENABLE=true make test-pgx
|
||||
- TEST_QUOTE_POLICY=reserved make test-pgx
|
||||
|
||||
- name: test-pgx-schema
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
depends_on:
|
||||
- test-pgx
|
||||
environment:
|
||||
TEST_PGSQL_HOST: pgsql
|
||||
TEST_PGSQL_SCHEMA: xorm
|
||||
TEST_PGSQL_DBNAME: xorm_test
|
||||
TEST_PGSQL_USERNAME: postgres
|
||||
TEST_PGSQL_PASSWORD: postgres
|
||||
commands:
|
||||
- make test-pgx
|
||||
- TEST_CACHE_ENABLE=true make test-pgx
|
||||
- TEST_QUOTE_POLICY=reserved make test-pgx
|
||||
|
||||
volumes:
|
||||
- name: cache
|
||||
host:
|
||||
path: /tmp/cache
|
||||
|
||||
services:
|
||||
- name: pgsql
|
||||
image: postgres:9.5
|
||||
environment:
|
||||
POSTGRES_DB: xorm_test
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: test-mssql
|
||||
depends_on:
|
||||
- test-postgres
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-mssql
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
environment:
|
||||
TEST_MSSQL_HOST: mssql
|
||||
TEST_MSSQL_DBNAME: xorm_test
|
||||
TEST_MSSQL_USERNAME: sa
|
||||
TEST_MSSQL_PASSWORD: "yourStrong(!)Password"
|
||||
commands:
|
||||
- make test-mssql
|
||||
- TEST_MSSQL_DEFAULT_VARCHAR=NVARCHAR TEST_MSSQL_DEFAULT_CHAR=NCHAR make test-mssql
|
||||
|
||||
volumes:
|
||||
- name: cache
|
||||
host:
|
||||
path: /tmp/cache
|
||||
|
||||
services:
|
||||
- name: mssql
|
||||
pull: always
|
||||
image: mcr.microsoft.com/mssql/server:latest
|
||||
environment:
|
||||
ACCEPT_EULA: Y
|
||||
SA_PASSWORD: yourStrong(!)Password
|
||||
MSSQL_PID: Standard
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: test-tidb
|
||||
depends_on:
|
||||
- test-mssql
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-tidb
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
environment:
|
||||
TEST_TIDB_HOST: "tidb:4000"
|
||||
TEST_TIDB_DBNAME: xorm_test
|
||||
TEST_TIDB_USERNAME: root
|
||||
TEST_TIDB_PASSWORD:
|
||||
commands:
|
||||
- make test-tidb
|
||||
|
||||
volumes:
|
||||
- name: cache
|
||||
host:
|
||||
path: /tmp/cache
|
||||
|
||||
services:
|
||||
- name: tidb
|
||||
image: pingcap/tidb:v3.0.3
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: test-cockroach
|
||||
depends_on:
|
||||
- test-tidb
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-cockroach
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
environment:
|
||||
TEST_COCKROACH_HOST: "cockroach:26257"
|
||||
TEST_COCKROACH_DBNAME: xorm_test
|
||||
TEST_COCKROACH_USERNAME: root
|
||||
TEST_COCKROACH_PASSWORD:
|
||||
commands:
|
||||
- sleep 10
|
||||
- make test-cockroach
|
||||
|
||||
volumes:
|
||||
- name: cache
|
||||
host:
|
||||
path: /tmp/cache
|
||||
|
||||
services:
|
||||
- name: cockroach
|
||||
image: cockroachdb/cockroach:v19.2.4
|
||||
commands:
|
||||
- /cockroach/cockroach start --insecure
|
||||
|
||||
# ---
|
||||
# kind: pipeline
|
||||
# name: test-dameng
|
||||
# depends_on:
|
||||
# - test-cockroach
|
||||
# trigger:
|
||||
# ref:
|
||||
# - refs/heads/master
|
||||
# - refs/pull/*/head
|
||||
# steps:
|
||||
# - name: test-dameng
|
||||
# pull: never
|
||||
# image: golang:1.15
|
||||
# volumes:
|
||||
# - name: cache
|
||||
# path: /go/pkg/mod
|
||||
# environment:
|
||||
# TEST_DAMENG_HOST: "dameng:5236"
|
||||
# TEST_DAMENG_USERNAME: SYSDBA
|
||||
# TEST_DAMENG_PASSWORD: SYSDBA
|
||||
# commands:
|
||||
# - sleep 30
|
||||
# - make test-dameng
|
||||
|
||||
# volumes:
|
||||
# - name: cache
|
||||
# host:
|
||||
# path: /tmp/cache
|
||||
|
||||
# services:
|
||||
# - name: dameng
|
||||
# image: lunny/dm:v1.0
|
||||
# commands:
|
||||
# - /bin/bash /startDm.sh
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: merge_coverage
|
||||
depends_on:
|
||||
- test-mysql
|
||||
- test-mysql8
|
||||
- test-mariadb
|
||||
- test-postgres
|
||||
- test-mssql
|
||||
- test-tidb
|
||||
- test-cockroach
|
||||
#- test-dameng
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: merge_coverage
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- make coverage
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: release-tag
|
||||
trigger:
|
||||
event:
|
||||
- tag
|
||||
steps:
|
||||
- name: release-tag-gitea
|
||||
pull: always
|
||||
image: plugins/gitea-release:latest
|
||||
settings:
|
||||
base_url: https://gitea.com
|
||||
title: '${DRONE_TAG} is released'
|
||||
api_key:
|
||||
from_secret: gitea_token
|
|
@ -0,0 +1,23 @@
|
|||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: setup go
|
||||
uses: https://github.com/actions/setup-go@v4
|
||||
with:
|
||||
go-version: '>=1.20.1'
|
||||
- name: Use Go Action
|
||||
id: use-go-action
|
||||
uses: actions/release-action@main
|
||||
with:
|
||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
|
@ -0,0 +1,55 @@
|
|||
name: test cockroach
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
GOPATH: /go_path
|
||||
GOCACHE: /go_cache
|
||||
|
||||
jobs:
|
||||
test-cockroach:
|
||||
name: test cockroach
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# - name: cache go path
|
||||
# id: cache-go-path
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_path
|
||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_path-${{ github.repository }}-
|
||||
# go_path-
|
||||
# - name: cache go cache
|
||||
# id: cache-go-cache
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_cache
|
||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_cache-${{ github.repository }}-
|
||||
# go_cache-
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.20
|
||||
- uses: https://github.com/actions/checkout@v3
|
||||
- name: test cockroach
|
||||
env:
|
||||
TEST_COCKROACH_HOST: "cockroach:26257"
|
||||
TEST_COCKROACH_DBNAME: xorm_test
|
||||
TEST_COCKROACH_USERNAME: root
|
||||
TEST_COCKROACH_PASSWORD:
|
||||
run: sleep 20 && make test-cockroach
|
||||
|
||||
services:
|
||||
cockroach:
|
||||
image: cockroachdb/cockroach:v19.2.4
|
||||
ports:
|
||||
- 26257:26257
|
||||
cmd:
|
||||
- 'start'
|
||||
- '--insecure'
|
|
@ -0,0 +1,56 @@
|
|||
name: test mariadb
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
GOPATH: /go_path
|
||||
GOCACHE: /go_cache
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: test mariadb
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# - name: cache go path
|
||||
# id: cache-go-path
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_path
|
||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_path-${{ github.repository }}-
|
||||
# go_path-
|
||||
# - name: cache go cache
|
||||
# id: cache-go-cache
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_cache
|
||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_cache-${{ github.repository }}-
|
||||
# go_cache-
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.20
|
||||
- uses: https://github.com/actions/checkout@v3
|
||||
- name: test mariadb
|
||||
env:
|
||||
TEST_MYSQL_HOST: mariadb
|
||||
TEST_MYSQL_CHARSET: utf8mb4
|
||||
TEST_MYSQL_DBNAME: xorm_test
|
||||
TEST_MYSQL_USERNAME: root
|
||||
TEST_MYSQL_PASSWORD:
|
||||
run: TEST_QUOTE_POLICY=reserved make test-mysql
|
||||
|
||||
services:
|
||||
mariadb:
|
||||
image: mariadb:10.4
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
MYSQL_DATABASE: xorm_test
|
||||
ports:
|
||||
- 3306:3306
|
|
@ -0,0 +1,56 @@
|
|||
name: test mssql
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
GOPATH: /go_path
|
||||
GOCACHE: /go_cache
|
||||
|
||||
jobs:
|
||||
test-mssql:
|
||||
name: test mssql
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# - name: cache go path
|
||||
# id: cache-go-path
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_path
|
||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_path-${{ github.repository }}-
|
||||
# go_path-
|
||||
# - name: cache go cache
|
||||
# id: cache-go-cache
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_cache
|
||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_cache-${{ github.repository }}-
|
||||
# go_cache-
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.20
|
||||
- uses: https://github.com/actions/checkout@v3
|
||||
- name: test mssql
|
||||
env:
|
||||
TEST_MSSQL_HOST: mssql
|
||||
TEST_MSSQL_DBNAME: xorm_test
|
||||
TEST_MSSQL_USERNAME: sa
|
||||
TEST_MSSQL_PASSWORD: "yourStrong(!)Password"
|
||||
run: TEST_MSSQL_DEFAULT_VARCHAR=NVARCHAR TEST_MSSQL_DEFAULT_CHAR=NCHAR make test-mssql
|
||||
|
||||
services:
|
||||
mssql:
|
||||
image: mcr.microsoft.com/mssql/server:latest
|
||||
env:
|
||||
ACCEPT_EULA: Y
|
||||
SA_PASSWORD: yourStrong(!)Password
|
||||
MSSQL_PID: Standard
|
||||
ports:
|
||||
- 1433:1433
|
|
@ -0,0 +1,56 @@
|
|||
name: test mysql
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
GOPATH: /go_path
|
||||
GOCACHE: /go_cache
|
||||
|
||||
jobs:
|
||||
test-mysql:
|
||||
name: test mysql
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# - name: cache go path
|
||||
# id: cache-go-path
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_path
|
||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_path-${{ github.repository }}-
|
||||
# go_path-
|
||||
# - name: cache go cache
|
||||
# id: cache-go-cache
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_cache
|
||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_cache-${{ github.repository }}-
|
||||
# go_cache-
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.20
|
||||
- uses: https://github.com/actions/checkout@v3
|
||||
- name: test mysql utf8mb4
|
||||
env:
|
||||
TEST_MYSQL_HOST: mysql
|
||||
TEST_MYSQL_CHARSET: utf8mb4
|
||||
TEST_MYSQL_DBNAME: xorm_test
|
||||
TEST_MYSQL_USERNAME: root
|
||||
TEST_MYSQL_PASSWORD:
|
||||
run: TEST_QUOTE_POLICY=reserved make test-mysql-tls
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
MYSQL_DATABASE: xorm_test
|
||||
ports:
|
||||
- 3306:3306
|
|
@ -0,0 +1,56 @@
|
|||
name: test mysql8
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
GOPATH: /go_path
|
||||
GOCACHE: /go_cache
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: test mysql8
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# - name: cache go path
|
||||
# id: cache-go-path
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_path
|
||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_path-${{ github.repository }}-
|
||||
# go_path-
|
||||
# - name: cache go cache
|
||||
# id: cache-go-cache
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_cache
|
||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_cache-${{ github.repository }}-
|
||||
# go_cache-
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.20
|
||||
- uses: https://github.com/actions/checkout@v3
|
||||
- name: test mysql8
|
||||
env:
|
||||
TEST_MYSQL_HOST: mysql8
|
||||
TEST_MYSQL_CHARSET: utf8mb4
|
||||
TEST_MYSQL_DBNAME: xorm_test
|
||||
TEST_MYSQL_USERNAME: root
|
||||
TEST_MYSQL_PASSWORD:
|
||||
run: TEST_CACHE_ENABLE=true make test-mysql
|
||||
|
||||
services:
|
||||
mysql8:
|
||||
image: mysql:8.0
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
MYSQL_DATABASE: xorm_test
|
||||
ports:
|
||||
- 3306:3306
|
|
@ -0,0 +1,79 @@
|
|||
name: test postgres
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
GOPATH: /go_path
|
||||
GOCACHE: /go_cache
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: test postgres
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# - name: cache go path
|
||||
# id: cache-go-path
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_path
|
||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_path-${{ github.repository }}-
|
||||
# go_path-
|
||||
# - name: cache go cache
|
||||
# id: cache-go-cache
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_cache
|
||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_cache-${{ github.repository }}-
|
||||
# go_cache-
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.20
|
||||
- uses: https://github.com/actions/checkout@v3
|
||||
- name: test postgres
|
||||
env:
|
||||
TEST_PGSQL_HOST: pgsql
|
||||
TEST_PGSQL_DBNAME: xorm_test
|
||||
TEST_PGSQL_USERNAME: postgres
|
||||
TEST_PGSQL_PASSWORD: postgres
|
||||
run: TEST_CACHE_ENABLE=true make test-postgres
|
||||
- name: test postgres with schema
|
||||
env:
|
||||
TEST_PGSQL_HOST: pgsql
|
||||
TEST_PGSQL_SCHEMA: xorm
|
||||
TEST_PGSQL_DBNAME: xorm_test
|
||||
TEST_PGSQL_USERNAME: postgres
|
||||
TEST_PGSQL_PASSWORD: postgres
|
||||
run: TEST_QUOTE_POLICY=reserved make test-postgres
|
||||
- name: test pgx
|
||||
env:
|
||||
TEST_PGSQL_HOST: pgsql
|
||||
TEST_PGSQL_DBNAME: xorm_test
|
||||
TEST_PGSQL_USERNAME: postgres
|
||||
TEST_PGSQL_PASSWORD: postgres
|
||||
run: TEST_CACHE_ENABLE=true make test-pgx
|
||||
- name: test pgx with schema
|
||||
env:
|
||||
TEST_PGSQL_HOST: pgsql
|
||||
TEST_PGSQL_SCHEMA: xorm
|
||||
TEST_PGSQL_DBNAME: xorm_test
|
||||
TEST_PGSQL_USERNAME: postgres
|
||||
TEST_PGSQL_PASSWORD: postgres
|
||||
run: TEST_QUOTE_POLICY=reserved make test-pgx
|
||||
|
||||
services:
|
||||
pgsql:
|
||||
image: postgres:9.5
|
||||
env:
|
||||
POSTGRES_DB: xorm_test
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
ports:
|
||||
- 5432:5432
|
|
@ -0,0 +1,49 @@
|
|||
name: test sqlite
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
GOPATH: /go_path
|
||||
GOCACHE: /go_cache
|
||||
|
||||
jobs:
|
||||
test-sqlite:
|
||||
name: unit test & test sqlite
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# - name: cache go path
|
||||
# id: cache-go-path
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_path
|
||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_path-${{ github.repository }}-
|
||||
# go_path-
|
||||
# - name: cache go cache
|
||||
# id: cache-go-cache
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_cache
|
||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_cache-${{ github.repository }}-
|
||||
# go_cache-
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.20
|
||||
- uses: https://github.com/actions/checkout@v3
|
||||
- name: vet
|
||||
run: make vet
|
||||
- name: format check
|
||||
run: make fmt-check
|
||||
- name: unit test
|
||||
run: make test
|
||||
- name: test sqlite3
|
||||
run: make test-sqlite3
|
||||
- name: test sqlite3 with cache
|
||||
run: TEST_CACHE_ENABLE=true make test-sqlite3
|
|
@ -0,0 +1,52 @@
|
|||
name: test tidb
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
GOPATH: /go_path
|
||||
GOCACHE: /go_cache
|
||||
|
||||
jobs:
|
||||
test-tidb:
|
||||
name: test tidb
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# - name: cache go path
|
||||
# id: cache-go-path
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_path
|
||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_path-${{ github.repository }}-
|
||||
# go_path-
|
||||
# - name: cache go cache
|
||||
# id: cache-go-cache
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: /go_cache
|
||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||
# restore-keys: |
|
||||
# go_cache-${{ github.repository }}-
|
||||
# go_cache-
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.20
|
||||
- uses: https://github.com/actions/checkout@v3
|
||||
- name: test tidb
|
||||
env:
|
||||
TEST_TIDB_HOST: "tidb:4000"
|
||||
TEST_TIDB_DBNAME: xorm_test
|
||||
TEST_TIDB_USERNAME: root
|
||||
TEST_TIDB_PASSWORD:
|
||||
run: make test-tidb
|
||||
|
||||
services:
|
||||
tidb:
|
||||
image: pingcap/tidb:v3.0.3
|
||||
ports:
|
||||
- 4000:4000
|
|
@ -37,4 +37,5 @@ test.db.sql
|
|||
test.db
|
||||
integrations/*.sql
|
||||
integrations/test_sqlite*
|
||||
cover.out
|
||||
cover.out
|
||||
cover.html
|
||||
|
|
49
CHANGELOG.md
49
CHANGELOG.md
|
@ -3,6 +3,55 @@
|
|||
This changelog goes through all the changes that have been made in each release
|
||||
without substantial changes to our git log.
|
||||
|
||||
## [1.3.2](https://gitea.com/xorm/xorm/releases/tag/1.3.2) - 2022-09-03
|
||||
|
||||
* BUGFIXES
|
||||
* Change schemas.Column to use int64 (#2160)
|
||||
* MISC
|
||||
* Prevent Sync failure with non-regular indexes on Postgres (#2174)
|
||||
|
||||
## [1.3.1](https://gitea.com/xorm/xorm/releases/tag/1.3.1) - 2022-06-03
|
||||
|
||||
* BREAKING
|
||||
* Refactor orderby and support arguments (#2150)
|
||||
* return a clear error for set TEXT type as compare condition (#2062)
|
||||
* BUGFIXES
|
||||
* Fix oid index for postgres (#2154)
|
||||
* Add ORDER BY SEQ_IN_INDEX to MySQL GetIndexes to Fix IndexTests (#2152)
|
||||
* some improvement (#2136)
|
||||
* ENHANCEMENTS
|
||||
* Add interface to allow structs to provide specific index information (#2137)
|
||||
* MySQL/MariaDB: return max length for text columns (#2133)
|
||||
* PostgreSQL: enable comment on column (#2131)
|
||||
* TESTING
|
||||
* Add test for find date (#2121)
|
||||
|
||||
## [1.3.0](https://gitea.com/xorm/xorm/releases/tag/1.3.0) - 2022-04-14
|
||||
|
||||
* BREAKING
|
||||
* New Prepare useage (#2061)
|
||||
* Make Get and Rows.Scan accept multiple parameters (#2029)
|
||||
* Drop sync function and rename sync2 to sync (#2018)
|
||||
* FEATURES
|
||||
* Add dameng support (#2007)
|
||||
* BUGFIXES
|
||||
* bugfix :Oid It's a special index. You can't put it in (#2105)
|
||||
* Fix new-lined query execution in master DB node. (#2066)
|
||||
* Fix bug of Rows (#2048)
|
||||
* Fix bug (#2046)
|
||||
* fix panic when `Iterate()` fails (#2040)
|
||||
* fix panic when convert sql and args with nil time.Time pointer (#2038)
|
||||
* ENHANCEMENTS
|
||||
* Fix to add session.statement.IsForUpdate check in Session.queryRows() (#2064)
|
||||
* Expose ScanString / ScanInterface and etc (#2039)
|
||||
* TESTING
|
||||
* Add test for mysql tls (#2049)
|
||||
* BUILD
|
||||
* Upgrade dependencies modules (#2078)
|
||||
* MISC
|
||||
* Fix oracle keyword AS (#2109)
|
||||
* Some performance optimization for get (#2043)
|
||||
|
||||
## [1.2.2](https://gitea.com/xorm/xorm/releases/tag/1.2.2) - 2021-08-11
|
||||
|
||||
* MISC
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
## Contributing to xorm
|
||||
|
||||
`xorm` has a backlog of [pull requests](https://help.github.com/articles/using-pull-requests), but contributions are still very
|
||||
much welcome. You can help with patch review, submitting bug reports,
|
||||
`xorm` has a backlog of [pull requests](https://gitea.com/xorm/xorm/pulls), but contributions are still very
|
||||
much welcome. You can help with patch review, submitting [bug reports](https://gitea.com/xorm/xorm/issues),
|
||||
or adding new functionality. There is no formal style guide, but
|
||||
please conform to the style of existing code and general Go formatting
|
||||
conventions when submitting patches.
|
||||
|
||||
* [fork a repo](https://help.github.com/articles/fork-a-repo)
|
||||
* [creating a pull request ](https://help.github.com/articles/creating-a-pull-request)
|
||||
* [fork the repo](https://gitea.com/repo/fork/2038)
|
||||
* [creating a pull request ](https://docs.gitea.io/en-us/pull-request/)
|
||||
|
||||
### Language
|
||||
|
||||
|
@ -15,7 +15,7 @@ Since `xorm` is a world-wide open source project, please describe your issues or
|
|||
|
||||
### Sign your codes with comments
|
||||
```
|
||||
// !<you github id>! your comments
|
||||
// !<your gitea.com id>! your comments
|
||||
|
||||
e.g.,
|
||||
|
||||
|
@ -65,7 +65,7 @@ And if your branch is related with cache, you could also enable it via `TEST_CAC
|
|||
|
||||
### Patch review
|
||||
|
||||
Help review existing open [pull requests](https://help.github.com/articles/using-pull-requests) by commenting on the code or
|
||||
Help review existing open [pull requests](https://gitea.com/xorm/xorm/pulls) by commenting on the code or
|
||||
proposed functionality.
|
||||
|
||||
### Bug reports
|
||||
|
|
5
Makefile
5
Makefile
|
@ -60,7 +60,7 @@ build: go-check $(GO_SOURCES)
|
|||
.PHONY: clean
|
||||
clean:
|
||||
$(GO) clean -i ./...
|
||||
rm -rf *.sql *.log test.db *coverage.out coverage.all integrations/*.sql
|
||||
rm -rf *.sql *.log test.db cover.out cover.html *coverage.out coverage.all integrations/*.sql
|
||||
|
||||
.PHONY: coverage
|
||||
coverage:
|
||||
|
@ -132,7 +132,8 @@ golangci-lint-check:
|
|||
|
||||
.PHONY: test
|
||||
test: go-check
|
||||
$(GO) test $(PACKAGES)
|
||||
$(GO) test -cover -coverprofile=cover.out $(PACKAGES)
|
||||
$(GO) tool cover -html=cover.out -o cover.html
|
||||
|
||||
.PNONY: test-cockroach
|
||||
test-cockroach: go-check
|
||||
|
|
|
@ -45,7 +45,7 @@ Drivers for Go's sql package which currently support database/sql includes:
|
|||
|
||||
* [SQLite](https://sqlite.org)
|
||||
- [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)
|
||||
- [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) (windows unsupported)
|
||||
- [modernc.org/sqlite](https://gitlab.com/cznic/sqlite)
|
||||
|
||||
* MsSql
|
||||
- [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb)
|
||||
|
@ -53,6 +53,7 @@ Drivers for Go's sql package which currently support database/sql includes:
|
|||
* Oracle
|
||||
- [github.com/godror/godror](https://github.com/godror/godror) (experiment)
|
||||
- [github.com/mattn/go-oci8](https://github.com/mattn/go-oci8) (experiment)
|
||||
- [github.com/sijms/go-ora](https://github.com/sijms/go-ora) (experiment)
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ v1.0.0 相对于 v0.8.2 有以下不兼容的变更:
|
|||
|
||||
* [SQLite](https://sqlite.org)
|
||||
- [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)
|
||||
- [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) (Windows试验性支持)
|
||||
- [modernc.org/sqlite](https://gitlab.com/cznic/sqlite)
|
||||
|
||||
* MsSql
|
||||
- [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb)
|
||||
|
@ -52,6 +52,7 @@ v1.0.0 相对于 v0.8.2 有以下不兼容的变更:
|
|||
* Oracle
|
||||
- [github.com/godror/godror](https://github.com/godror/godror) (试验性支持)
|
||||
- [github.com/mattn/go-oci8](https://github.com/mattn/go-oci8) (试验性支持)
|
||||
- [github.com/sijms/go-ora](https://github.com/sijms/go-ora) (试验性支持)
|
||||
|
||||
## 安装
|
||||
|
||||
|
|
|
@ -24,7 +24,10 @@ func Interface2Interface(userLocation *time.Location, v interface{}) (interface{
|
|||
return vv.String, nil
|
||||
case *sql.RawBytes:
|
||||
if len([]byte(*vv)) > 0 {
|
||||
return []byte(*vv), nil
|
||||
src := []byte(*vv)
|
||||
dest := make([]byte, len(src))
|
||||
copy(dest, src)
|
||||
return dest, nil
|
||||
}
|
||||
return nil, nil
|
||||
case *sql.NullInt32:
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
)
|
||||
|
||||
// String2Time converts a string to time with original location
|
||||
// be aware for time strings (HH:mm:ss) returns zero year (LMT) for converted location
|
||||
func String2Time(s string, originalLocation *time.Location, convertedLocation *time.Location) (*time.Time, error) {
|
||||
if len(s) == 19 {
|
||||
if s == utils.ZeroTime0 || s == utils.ZeroTime1 {
|
||||
|
@ -32,6 +33,7 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
|||
return nil, err
|
||||
}
|
||||
dt = dt.In(convertedLocation)
|
||||
dt.IsZero()
|
||||
return &dt, nil
|
||||
} else if len(s) == 25 && s[10] == 'T' && s[19] == '+' && s[22] == ':' {
|
||||
dt, err := time.Parse(time.RFC3339, s)
|
||||
|
@ -40,8 +42,15 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
|||
}
|
||||
dt = dt.In(convertedLocation)
|
||||
return &dt, nil
|
||||
} else if len(s) >= 21 && s[10] == 'T' && s[19] == '.' {
|
||||
dt, err := time.Parse(time.RFC3339Nano, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dt = dt.In(convertedLocation)
|
||||
return &dt, nil
|
||||
} else if len(s) >= 21 && s[19] == '.' {
|
||||
var layout = "2006-01-02 15:04:05." + strings.Repeat("0", len(s)-20)
|
||||
layout := "2006-01-02 15:04:05." + strings.Repeat("0", len(s)-20)
|
||||
dt, err := time.ParseInLocation(layout, s, originalLocation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -58,6 +67,18 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
|||
}
|
||||
dt = dt.In(convertedLocation)
|
||||
return &dt, nil
|
||||
} else if len(s) == 8 && s[2] == ':' && s[5] == ':' {
|
||||
currentDate := time.Now()
|
||||
dt, err := time.ParseInLocation("15:04:05", s, originalLocation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// add current date for correct time locations
|
||||
dt = dt.AddDate(currentDate.Year(), int(currentDate.Month()), currentDate.Day())
|
||||
dt = dt.In(convertedLocation)
|
||||
// back to zero year
|
||||
dt = dt.AddDate(-currentDate.Year(), int(-currentDate.Month()), -currentDate.Day())
|
||||
return &dt, nil
|
||||
} else {
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
if err == nil {
|
||||
|
|
|
@ -15,13 +15,23 @@ func TestString2Time(t *testing.T) {
|
|||
expectedLoc, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
|
||||
var kases = map[string]time.Time{
|
||||
"2021-08-10": time.Date(2021, 8, 10, 8, 0, 0, 0, expectedLoc),
|
||||
"2021-06-06T22:58:20+08:00": time.Date(2021, 6, 6, 22, 58, 20, 0, expectedLoc),
|
||||
"2021-07-11 10:44:00": time.Date(2021, 7, 11, 18, 44, 0, 0, expectedLoc),
|
||||
"2021-08-10T10:33:04Z": time.Date(2021, 8, 10, 18, 33, 04, 0, expectedLoc),
|
||||
cases := map[string]time.Time{
|
||||
"2021-08-10": time.Date(2021, 8, 10, 8, 0, 0, 0, expectedLoc),
|
||||
"2021-07-11 10:44:00": time.Date(2021, 7, 11, 18, 44, 0, 0, expectedLoc),
|
||||
"2021-07-11 10:44:00.999": time.Date(2021, 7, 11, 18, 44, 0, 999000000, expectedLoc),
|
||||
"2021-07-11 10:44:00.999999": time.Date(2021, 7, 11, 18, 44, 0, 999999000, expectedLoc),
|
||||
"2021-07-11 10:44:00.999999999": time.Date(2021, 7, 11, 18, 44, 0, 999999999, expectedLoc),
|
||||
"2021-06-06T22:58:20+08:00": time.Date(2021, 6, 6, 22, 58, 20, 0, expectedLoc),
|
||||
"2021-06-06T22:58:20.999+08:00": time.Date(2021, 6, 6, 22, 58, 20, 999000000, expectedLoc),
|
||||
"2021-06-06T22:58:20.999999+08:00": time.Date(2021, 6, 6, 22, 58, 20, 999999000, expectedLoc),
|
||||
"2021-06-06T22:58:20.999999999+08:00": time.Date(2021, 6, 6, 22, 58, 20, 999999999, expectedLoc),
|
||||
"2021-08-10T10:33:04Z": time.Date(2021, 8, 10, 18, 33, 0o4, 0, expectedLoc),
|
||||
"2021-08-10T10:33:04.999Z": time.Date(2021, 8, 10, 18, 33, 0o4, 999000000, expectedLoc),
|
||||
"2021-08-10T10:33:04.999999Z": time.Date(2021, 8, 10, 18, 33, 0o4, 999999000, expectedLoc),
|
||||
"2021-08-10T10:33:04.999999999Z": time.Date(2021, 8, 10, 18, 33, 0o4, 999999999, expectedLoc),
|
||||
"10:22:33": time.Date(0, 1, 1, 18, 22, 33, 0, expectedLoc),
|
||||
}
|
||||
for layout, tm := range kases {
|
||||
for layout, tm := range cases {
|
||||
t.Run(layout, func(t *testing.T) {
|
||||
target, err := String2Time(layout, time.UTC, expectedLoc)
|
||||
assert.NoError(t, err)
|
||||
|
|
|
@ -622,9 +622,9 @@ func (db *dameng) SQLType(c *schemas.Column) string {
|
|||
hasLen2 := (c.Length2 > 0)
|
||||
|
||||
if hasLen2 {
|
||||
res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
||||
} else if hasLen1 {
|
||||
res += "(" + strconv.Itoa(c.Length) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + ")"
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@ -659,7 +659,7 @@ func (db *dameng) DropTableSQL(tableName string) (string, bool) {
|
|||
|
||||
// ModifyColumnSQL returns a SQL to modify SQL
|
||||
func (db *dameng) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||
s, _ := ColumnString(db.dialect, col, false)
|
||||
s, _ := ColumnString(db.dialect, col, false, false)
|
||||
return fmt.Sprintf("ALTER TABLE %s MODIFY %s", db.quoter.Quote(tableName), s)
|
||||
}
|
||||
|
||||
|
@ -692,7 +692,7 @@ func (db *dameng) CreateTableSQL(ctx context.Context, queryer core.Queryer, tabl
|
|||
}
|
||||
}
|
||||
|
||||
s, _ := ColumnString(db, col, false)
|
||||
s, _ := ColumnString(db, col, false, false)
|
||||
if _, err := b.WriteString(s); err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
|
@ -709,7 +709,13 @@ func (db *dameng) CreateTableSQL(ctx context.Context, queryer core.Queryer, tabl
|
|||
return "", false, err
|
||||
}
|
||||
}
|
||||
if _, err := b.WriteString(fmt.Sprintf("CONSTRAINT PK_%s PRIMARY KEY (", tableName)); err != nil {
|
||||
if _, err := b.WriteString("CONSTRAINT PK_"); err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
if _, err := b.WriteString(tableName); err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
if _, err := b.WriteString(" PRIMARY KEY ("); err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
if err := quoter.JoinWrite(&b, pkList, ","); err != nil {
|
||||
|
@ -729,11 +735,11 @@ func (db *dameng) CreateTableSQL(ctx context.Context, queryer core.Queryer, tabl
|
|||
func (db *dameng) SetQuotePolicy(quotePolicy QuotePolicy) {
|
||||
switch quotePolicy {
|
||||
case QuotePolicyNone:
|
||||
var q = damengQuoter
|
||||
q := damengQuoter
|
||||
q.IsReserved = schemas.AlwaysNoReserve
|
||||
db.quoter = q
|
||||
case QuotePolicyReserved:
|
||||
var q = damengQuoter
|
||||
q := damengQuoter
|
||||
q.IsReserved = db.IsReserved
|
||||
db.quoter = q
|
||||
case QuotePolicyAlways:
|
||||
|
@ -792,7 +798,7 @@ type dmClobObject interface {
|
|||
ReadString(int, int) (string, error)
|
||||
}
|
||||
|
||||
//var _ dmClobObject = &dm.DmClob{}
|
||||
// var _ dmClobObject = &dm.DmClob{}
|
||||
|
||||
func (d *dmClobScanner) Scan(data interface{}) error {
|
||||
if data == nil {
|
||||
|
@ -837,7 +843,11 @@ func addSingleQuote(name string) string {
|
|||
if name[0] == '\'' && name[len(name)-1] == '\'' {
|
||||
return name
|
||||
}
|
||||
return fmt.Sprintf("'%s'", name)
|
||||
var b strings.Builder
|
||||
b.WriteRune('\'')
|
||||
b.WriteString(name)
|
||||
b.WriteRune('\'')
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (db *dameng) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
|
@ -927,7 +937,7 @@ func (db *dameng) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
var (
|
||||
ignore bool
|
||||
dt string
|
||||
len1, len2 int
|
||||
len1, len2 int64
|
||||
)
|
||||
|
||||
dts := strings.Split(dataType.String, "(")
|
||||
|
@ -935,10 +945,10 @@ func (db *dameng) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
if len(dts) > 1 {
|
||||
lens := strings.Split(dts[1][:len(dts[1])-1], ",")
|
||||
if len(lens) > 1 {
|
||||
len1, _ = strconv.Atoi(lens[0])
|
||||
len2, _ = strconv.Atoi(lens[1])
|
||||
len1, _ = strconv.ParseInt(lens[0], 10, 64)
|
||||
len2, _ = strconv.ParseInt(lens[1], 10, 64)
|
||||
} else {
|
||||
len1, _ = strconv.Atoi(lens[0])
|
||||
len1, _ = strconv.ParseInt(lens[0], 10, 64)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -972,9 +982,9 @@ func (db *dameng) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
}
|
||||
|
||||
if col.SQLType.Name == "TIMESTAMP" {
|
||||
col.Length = int(dataScale.Int64)
|
||||
col.Length = dataScale.Int64
|
||||
} else {
|
||||
col.Length = int(dataLen.Int64)
|
||||
col.Length = dataLen.Int64
|
||||
}
|
||||
|
||||
if col.SQLType.IsTime() {
|
||||
|
@ -1140,8 +1150,8 @@ func (d *damengDriver) GenScanResult(colType string) (interface{}, error) {
|
|||
}
|
||||
|
||||
func (d *damengDriver) Scan(ctx *ScanContext, rows *core.Rows, types []*sql.ColumnType, vv ...interface{}) error {
|
||||
var scanResults = make([]interface{}, 0, len(types))
|
||||
var replaces = make([]bool, 0, len(types))
|
||||
scanResults := make([]interface{}, 0, len(types))
|
||||
replaces := make([]bool, 0, len(types))
|
||||
var err error
|
||||
for i, v := range vv {
|
||||
var replaced bool
|
||||
|
|
|
@ -85,8 +85,6 @@ type Dialect interface {
|
|||
AddColumnSQL(tableName string, col *schemas.Column) string
|
||||
ModifyColumnSQL(tableName string, col *schemas.Column) string
|
||||
|
||||
ForUpdateSQL(query string) string
|
||||
|
||||
Filters() []Filter
|
||||
SetParams(params map[string]string)
|
||||
}
|
||||
|
@ -135,7 +133,7 @@ func (db *Base) CreateTableSQL(ctx context.Context, queryer core.Queryer, table
|
|||
|
||||
for i, colName := range table.ColumnsSeq() {
|
||||
col := table.GetColumn(colName)
|
||||
s, _ := ColumnString(db.dialect, col, col.IsPrimaryKey && len(table.PrimaryKeys) == 1)
|
||||
s, _ := ColumnString(db.dialect, col, col.IsPrimaryKey && len(table.PrimaryKeys) == 1, false)
|
||||
b.WriteString(s)
|
||||
|
||||
if i != len(table.ColumnsSeq())-1 {
|
||||
|
@ -209,7 +207,7 @@ func (db *Base) IsColumnExist(queryer core.Queryer, ctx context.Context, tableNa
|
|||
|
||||
// AddColumnSQL returns a SQL to add a column
|
||||
func (db *Base) AddColumnSQL(tableName string, col *schemas.Column) string {
|
||||
s, _ := ColumnString(db.dialect, col, true)
|
||||
s, _ := ColumnString(db.dialect, col, true, false)
|
||||
return fmt.Sprintf("ALTER TABLE %s ADD %s", db.dialect.Quoter().Quote(tableName), s)
|
||||
}
|
||||
|
||||
|
@ -241,22 +239,15 @@ func (db *Base) DropIndexSQL(tableName string, index *schemas.Index) string {
|
|||
|
||||
// ModifyColumnSQL returns a SQL to modify SQL
|
||||
func (db *Base) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||
s, _ := ColumnString(db.dialect, col, false)
|
||||
s, _ := ColumnString(db.dialect, col, false, false)
|
||||
return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", db.quoter.Quote(tableName), s)
|
||||
}
|
||||
|
||||
// ForUpdateSQL returns for updateSQL
|
||||
func (db *Base) ForUpdateSQL(query string) string {
|
||||
return query + " FOR UPDATE"
|
||||
}
|
||||
|
||||
// SetParams set params
|
||||
func (db *Base) SetParams(params map[string]string) {
|
||||
}
|
||||
|
||||
var (
|
||||
dialects = map[string]func() Dialect{}
|
||||
)
|
||||
var dialects = map[string]func() Dialect{}
|
||||
|
||||
// RegisterDialect register database dialect
|
||||
func RegisterDialect(dbName schemas.DBType, dialectFunc func() Dialect) {
|
||||
|
@ -290,6 +281,7 @@ func regDrvsNDialects() bool {
|
|||
"sqlite": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
|
||||
"oci8": {"oracle", func() Driver { return &oci8Driver{} }, func() Dialect { return &oracle{} }},
|
||||
"godror": {"oracle", func() Driver { return &godrorDriver{} }, func() Dialect { return &oracle{} }},
|
||||
"oracle": {"oracle", func() Driver { return &oracleDriver{} }, func() Dialect { return &oracle{} }},
|
||||
}
|
||||
|
||||
for driverName, v := range providedDrvsNDialects {
|
||||
|
@ -306,7 +298,7 @@ func init() {
|
|||
}
|
||||
|
||||
// ColumnString generate column description string according dialect
|
||||
func ColumnString(dialect Dialect, col *schemas.Column, includePrimaryKey bool) (string, error) {
|
||||
func ColumnString(dialect Dialect, col *schemas.Column, includePrimaryKey, supportCollation bool) (string, error) {
|
||||
bd := strings.Builder{}
|
||||
|
||||
if err := dialect.Quoter().QuoteTo(&bd, col.Name); err != nil {
|
||||
|
@ -321,6 +313,15 @@ func ColumnString(dialect Dialect, col *schemas.Column, includePrimaryKey bool)
|
|||
return "", err
|
||||
}
|
||||
|
||||
if supportCollation && col.Collation != "" {
|
||||
if _, err := bd.WriteString(" COLLATE "); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err := bd.WriteString(col.Collation); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
if includePrimaryKey && col.IsPrimaryKey {
|
||||
if _, err := bd.WriteString(" PRIMARY KEY"); err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -5,22 +5,24 @@
|
|||
package dialects
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Filter is an interface to filter SQL
|
||||
type Filter interface {
|
||||
Do(sql string) string
|
||||
Do(ctx context.Context, sql string) string
|
||||
}
|
||||
|
||||
// SeqFilter filter SQL replace ?, ? ... to $1, $2 ...
|
||||
type SeqFilter struct {
|
||||
// postgresSeqFilter filter SQL replace ?, ? ... to $1, $2 ...
|
||||
type postgresSeqFilter struct {
|
||||
Prefix string
|
||||
Start int
|
||||
}
|
||||
|
||||
func convertQuestionMark(sql, prefix string, start int) string {
|
||||
func postgresSeqFilterConvertQuestionMark(sql, prefix string, start int) string {
|
||||
var buf strings.Builder
|
||||
var beginSingleQuote bool
|
||||
var isLineComment bool
|
||||
|
@ -28,10 +30,77 @@ func convertQuestionMark(sql, prefix string, start int) string {
|
|||
var isMaybeLineComment bool
|
||||
var isMaybeComment bool
|
||||
var isMaybeCommentEnd bool
|
||||
var index = start
|
||||
var isMaybeJsonbQuestion bool
|
||||
index := start
|
||||
for i, c := range sql {
|
||||
if !beginSingleQuote && !isLineComment && !isComment && !isMaybeJsonbQuestion && c == '?' {
|
||||
buf.WriteString(fmt.Sprintf("%s%v", prefix, index))
|
||||
index++
|
||||
} else {
|
||||
if isMaybeJsonbQuestion && c == '?' {
|
||||
isMaybeJsonbQuestion = false
|
||||
} else if isMaybeLineComment {
|
||||
if c == '-' {
|
||||
isLineComment = true
|
||||
}
|
||||
isMaybeLineComment = false
|
||||
} else if isMaybeComment {
|
||||
if c == '*' {
|
||||
isComment = true
|
||||
}
|
||||
isMaybeComment = false
|
||||
} else if isMaybeCommentEnd {
|
||||
if c == '/' {
|
||||
isComment = false
|
||||
}
|
||||
isMaybeCommentEnd = false
|
||||
} else if isLineComment {
|
||||
if c == '\n' {
|
||||
isLineComment = false
|
||||
}
|
||||
} else if isComment {
|
||||
if c == '*' {
|
||||
isMaybeCommentEnd = true
|
||||
}
|
||||
} else if !beginSingleQuote && c == '-' {
|
||||
isMaybeLineComment = true
|
||||
} else if !beginSingleQuote && c == '/' {
|
||||
isMaybeComment = true
|
||||
} else if !beginSingleQuote && c == ' ' && i >= 7 && strings.TrimSpace(sql[i-7:i]) == "::jsonb" {
|
||||
isMaybeJsonbQuestion = true
|
||||
} else if c == '\'' {
|
||||
beginSingleQuote = !beginSingleQuote
|
||||
}
|
||||
buf.WriteRune(c)
|
||||
}
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// Do implements Filter
|
||||
func (s *postgresSeqFilter) Do(ctx context.Context, sql string) string {
|
||||
return postgresSeqFilterConvertQuestionMark(sql, s.Prefix, s.Start)
|
||||
}
|
||||
|
||||
// oracleSeqFilter filter SQL replace ?, ? ... to :1, :2 ...
|
||||
type oracleSeqFilter struct {
|
||||
Prefix string
|
||||
Start int
|
||||
}
|
||||
|
||||
func oracleSeqFilterConvertQuestionMark(sql, prefix string, start int) string {
|
||||
var buf strings.Builder
|
||||
var beginSingleQuote bool
|
||||
var isLineComment bool
|
||||
var isComment bool
|
||||
var isMaybeLineComment bool
|
||||
var isMaybeComment bool
|
||||
var isMaybeCommentEnd bool
|
||||
index := start
|
||||
for _, c := range sql {
|
||||
if !beginSingleQuote && !isLineComment && !isComment && c == '?' {
|
||||
buf.WriteString(fmt.Sprintf("%s%v", prefix, index))
|
||||
buf.WriteString(prefix)
|
||||
buf.WriteString(strconv.Itoa(index))
|
||||
index++
|
||||
} else {
|
||||
if isMaybeLineComment {
|
||||
|
@ -71,6 +140,6 @@ func convertQuestionMark(sql, prefix string, start int) string {
|
|||
}
|
||||
|
||||
// Do implements Filter
|
||||
func (s *SeqFilter) Do(sql string) string {
|
||||
return convertQuestionMark(sql, s.Prefix, s.Start)
|
||||
func (s *oracleSeqFilter) Do(ctx context.Context, sql string) string {
|
||||
return oracleSeqFilterConvertQuestionMark(sql, s.Prefix, s.Start)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func TestSeqFilter(t *testing.T) {
|
||||
var kases = map[string]string{
|
||||
kases := map[string]string{
|
||||
"SELECT * FROM TABLE1 WHERE a=? AND b=?": "SELECT * FROM TABLE1 WHERE a=$1 AND b=$2",
|
||||
"SELECT 1, '???', '2006-01-02 15:04:05' FROM TABLE1 WHERE a=? AND b=?": "SELECT 1, '???', '2006-01-02 15:04:05' FROM TABLE1 WHERE a=$1 AND b=$2",
|
||||
"select '1''?' from issue": "select '1''?' from issue",
|
||||
|
@ -16,12 +16,12 @@ func TestSeqFilter(t *testing.T) {
|
|||
"select '1\\''?',? from issue": "select '1\\''?',$1 from issue",
|
||||
}
|
||||
for sql, result := range kases {
|
||||
assert.EqualValues(t, result, convertQuestionMark(sql, "$", 1))
|
||||
assert.EqualValues(t, result, postgresSeqFilterConvertQuestionMark(sql, "$", 1))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeqFilterLineComment(t *testing.T) {
|
||||
var kases = map[string]string{
|
||||
kases := map[string]string{
|
||||
`SELECT *
|
||||
FROM TABLE1
|
||||
WHERE foo='bar'
|
||||
|
@ -49,12 +49,12 @@ func TestSeqFilterLineComment(t *testing.T) {
|
|||
AND b=$2`,
|
||||
}
|
||||
for sql, result := range kases {
|
||||
assert.EqualValues(t, result, convertQuestionMark(sql, "$", 1))
|
||||
assert.EqualValues(t, result, postgresSeqFilterConvertQuestionMark(sql, "$", 1))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeqFilterComment(t *testing.T) {
|
||||
var kases = map[string]string{
|
||||
kases := map[string]string{
|
||||
`SELECT *
|
||||
FROM TABLE1
|
||||
WHERE a=? /* it's a comment */
|
||||
|
@ -73,6 +73,17 @@ func TestSeqFilterComment(t *testing.T) {
|
|||
AND b=$2`,
|
||||
}
|
||||
for sql, result := range kases {
|
||||
assert.EqualValues(t, result, convertQuestionMark(sql, "$", 1))
|
||||
assert.EqualValues(t, result, postgresSeqFilterConvertQuestionMark(sql, "$", 1))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeqFilterPostgresQuestions(t *testing.T) {
|
||||
kases := map[string]string{
|
||||
`SELECT '{"a":1, "b":2}'::jsonb ? 'b'
|
||||
FROM table1 WHERE c = ?`: `SELECT '{"a":1, "b":2}'::jsonb ? 'b'
|
||||
FROM table1 WHERE c = $1`,
|
||||
}
|
||||
for sql, result := range kases {
|
||||
assert.EqualValues(t, result, postgresSeqFilterConvertQuestionMark(sql, "$", 1))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ func (db *mssql) Init(uri *URI) error {
|
|||
func (db *mssql) SetParams(params map[string]string) {
|
||||
defaultVarchar, ok := params["DEFAULT_VARCHAR"]
|
||||
if ok {
|
||||
var t = strings.ToUpper(defaultVarchar)
|
||||
t := strings.ToUpper(defaultVarchar)
|
||||
switch t {
|
||||
case "NVARCHAR", "VARCHAR":
|
||||
db.defaultVarchar = t
|
||||
|
@ -242,7 +242,7 @@ func (db *mssql) SetParams(params map[string]string) {
|
|||
|
||||
defaultChar, ok := params["DEFAULT_CHAR"]
|
||||
if ok {
|
||||
var t = strings.ToUpper(defaultChar)
|
||||
t := strings.ToUpper(defaultChar)
|
||||
switch t {
|
||||
case "NCHAR", "CHAR":
|
||||
db.defaultChar = t
|
||||
|
@ -375,9 +375,9 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
|||
hasLen2 := (c.Length2 > 0)
|
||||
|
||||
if hasLen2 {
|
||||
res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
||||
} else if hasLen1 {
|
||||
res += "(" + strconv.Itoa(c.Length) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + ")"
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@ -403,11 +403,11 @@ func (db *mssql) IsReserved(name string) bool {
|
|||
func (db *mssql) SetQuotePolicy(quotePolicy QuotePolicy) {
|
||||
switch quotePolicy {
|
||||
case QuotePolicyNone:
|
||||
var q = mssqlQuoter
|
||||
q := mssqlQuoter
|
||||
q.IsReserved = schemas.AlwaysNoReserve
|
||||
db.quoter = q
|
||||
case QuotePolicyReserved:
|
||||
var q = mssqlQuoter
|
||||
q := mssqlQuoter
|
||||
q.IsReserved = db.IsReserved
|
||||
db.quoter = q
|
||||
case QuotePolicyAlways:
|
||||
|
@ -428,7 +428,7 @@ func (db *mssql) DropTableSQL(tableName string) (string, bool) {
|
|||
}
|
||||
|
||||
func (db *mssql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||
s, _ := ColumnString(db.dialect, col, false)
|
||||
s, _ := ColumnString(db.dialect, col, false, true)
|
||||
return fmt.Sprintf("ALTER TABLE %s ALTER COLUMN %s", db.quoter.Quote(tableName), s)
|
||||
}
|
||||
|
||||
|
@ -454,7 +454,7 @@ func (db *mssql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable,
|
||||
"default_is_null" = (CASE WHEN c.text is null THEN 1 ELSE 0 END),
|
||||
replace(replace(isnull(c.text,''),'(',''),')','') as vdefault,
|
||||
ISNULL(p.is_primary_key, 0), a.is_identity as is_identity
|
||||
ISNULL(p.is_primary_key, 0), a.is_identity as is_identity, a.collation_name
|
||||
from sys.columns a
|
||||
left join sys.types b on a.user_type_id=b.user_type_id
|
||||
left join sys.syscomments c on a.default_object_id=c.id
|
||||
|
@ -475,9 +475,10 @@ func (db *mssql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
colSeq := make([]string, 0)
|
||||
for rows.Next() {
|
||||
var name, ctype, vdefault string
|
||||
var maxLen, precision, scale int
|
||||
var collation *string
|
||||
var maxLen, precision, scale int64
|
||||
var nullable, isPK, defaultIsNull, isIncrement bool
|
||||
err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale, &nullable, &defaultIsNull, &vdefault, &isPK, &isIncrement)
|
||||
err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale, &nullable, &defaultIsNull, &vdefault, &isPK, &isIncrement, &collation)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -499,6 +500,9 @@ func (db *mssql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
} else {
|
||||
col.Length = maxLen
|
||||
}
|
||||
if collation != nil {
|
||||
col.Collation = *collation
|
||||
}
|
||||
switch ct {
|
||||
case "DATETIMEOFFSET":
|
||||
col.SQLType = schemas.SQLType{Name: schemas.TimeStampz, DefaultLength: 0, DefaultLength2: 0}
|
||||
|
@ -646,7 +650,7 @@ func (db *mssql) CreateTableSQL(ctx context.Context, queryer core.Queryer, table
|
|||
|
||||
for i, colName := range table.ColumnsSeq() {
|
||||
col := table.GetColumn(colName)
|
||||
s, _ := ColumnString(db.dialect, col, col.IsPrimaryKey && len(table.PrimaryKeys) == 1)
|
||||
s, _ := ColumnString(db.dialect, col, col.IsPrimaryKey && len(table.PrimaryKeys) == 1, true)
|
||||
b.WriteString(s)
|
||||
|
||||
if i != len(table.ColumnsSeq())-1 {
|
||||
|
@ -665,10 +669,6 @@ func (db *mssql) CreateTableSQL(ctx context.Context, queryer core.Queryer, table
|
|||
return b.String(), true, nil
|
||||
}
|
||||
|
||||
func (db *mssql) ForUpdateSQL(query string) string {
|
||||
return query
|
||||
}
|
||||
|
||||
func (db *mssql) Filters() []Filter {
|
||||
return []Filter{}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ var (
|
|||
"CALL": true,
|
||||
"CASCADE": true,
|
||||
"CASE": true,
|
||||
"CHAIN": true,
|
||||
"CHANGE": true,
|
||||
"CHAR": true,
|
||||
"CHARACTER": true,
|
||||
|
@ -128,6 +129,7 @@ var (
|
|||
"OUT": true, "OUTER": true, "OUTFILE": true,
|
||||
"PRECISION": true, "PRIMARY": true, "PROCEDURE": true,
|
||||
"PURGE": true, "RAID0": true, "RANGE": true,
|
||||
"RANK": true,
|
||||
"READ": true, "READS": true, "REAL": true,
|
||||
"REFERENCES": true, "REGEXP": true, "RELEASE": true,
|
||||
"RENAME": true, "REPEAT": true, "REPLACE": true,
|
||||
|
@ -179,11 +181,9 @@ func (db *mysql) Init(uri *URI) error {
|
|||
return db.Base.Init(db, uri)
|
||||
}
|
||||
|
||||
var (
|
||||
mysqlColAliases = map[string]string{
|
||||
"numeric": "decimal",
|
||||
}
|
||||
)
|
||||
var mysqlColAliases = map[string]string{
|
||||
"numeric": "decimal",
|
||||
}
|
||||
|
||||
// Alias returns a alias of column
|
||||
func (db *mysql) Alias(col string) string {
|
||||
|
@ -243,7 +243,7 @@ func (db *mysql) Features() *DialectFeatures {
|
|||
func (db *mysql) SetParams(params map[string]string) {
|
||||
rowFormat, ok := params["rowFormat"]
|
||||
if ok {
|
||||
var t = strings.ToUpper(rowFormat)
|
||||
t := strings.ToUpper(rowFormat)
|
||||
switch t {
|
||||
case "COMPACT":
|
||||
fallthrough
|
||||
|
@ -333,9 +333,9 @@ func (db *mysql) SQLType(c *schemas.Column) string {
|
|||
}
|
||||
|
||||
if hasLen2 {
|
||||
res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
||||
} else if hasLen1 {
|
||||
res += "(" + strconv.Itoa(c.Length) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + ")"
|
||||
}
|
||||
|
||||
if isUnsigned {
|
||||
|
@ -383,12 +383,27 @@ func (db *mysql) IsTableExist(queryer core.Queryer, ctx context.Context, tableNa
|
|||
|
||||
func (db *mysql) AddColumnSQL(tableName string, col *schemas.Column) string {
|
||||
quoter := db.dialect.Quoter()
|
||||
s, _ := ColumnString(db, col, true)
|
||||
sql := fmt.Sprintf("ALTER TABLE %v ADD %v", quoter.Quote(tableName), s)
|
||||
s, _ := ColumnString(db, col, true, true)
|
||||
var b strings.Builder
|
||||
b.WriteString("ALTER TABLE ")
|
||||
quoter.QuoteTo(&b, tableName)
|
||||
b.WriteString(" ADD ")
|
||||
b.WriteString(s)
|
||||
if len(col.Comment) > 0 {
|
||||
sql += " COMMENT '" + col.Comment + "'"
|
||||
b.WriteString(" COMMENT '")
|
||||
b.WriteString(col.Comment)
|
||||
b.WriteString("'")
|
||||
}
|
||||
return sql
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// ModifyColumnSQL returns a SQL to modify SQL
|
||||
func (db *mysql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||
s, _ := ColumnString(db.dialect, col, false, true)
|
||||
if col.Comment != "" {
|
||||
s += fmt.Sprintf(" COMMENT '%s'", col.Comment)
|
||||
}
|
||||
return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", db.quoter.Quote(tableName), s)
|
||||
}
|
||||
|
||||
func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
|
@ -400,10 +415,10 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
"(SUBSTRING_INDEX(SUBSTRING(VERSION(), 4), '.', 1) = 2 && " +
|
||||
"SUBSTRING_INDEX(SUBSTRING(VERSION(), 6), '-', 1) >= 7)))))"
|
||||
s := "SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`," +
|
||||
" `COLUMN_KEY`, `EXTRA`, `COLUMN_COMMENT`, " +
|
||||
alreadyQuoted + " AS NEEDS_QUOTE " +
|
||||
" `COLUMN_KEY`, `EXTRA`, `COLUMN_COMMENT`, `CHARACTER_MAXIMUM_LENGTH`, " +
|
||||
alreadyQuoted + " AS NEEDS_QUOTE, `COLLATION_NAME` " +
|
||||
"FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?" +
|
||||
" ORDER BY `COLUMNS`.ORDINAL_POSITION"
|
||||
" ORDER BY `COLUMNS`.ORDINAL_POSITION ASC"
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
if err != nil {
|
||||
|
@ -419,8 +434,8 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
|
||||
var columnName, nullableStr, colType, colKey, extra, comment string
|
||||
var alreadyQuoted, isUnsigned bool
|
||||
var colDefault *string
|
||||
err = rows.Scan(&columnName, &nullableStr, &colDefault, &colType, &colKey, &extra, &comment, &alreadyQuoted)
|
||||
var colDefault, maxLength, collation *string
|
||||
err = rows.Scan(&columnName, &nullableStr, &colDefault, &colType, &colKey, &extra, &comment, &maxLength, &alreadyQuoted, &collation)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -436,6 +451,9 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
} else {
|
||||
col.DefaultIsEmpty = true
|
||||
}
|
||||
if collation != nil {
|
||||
col.Collation = *collation
|
||||
}
|
||||
|
||||
fields := strings.Fields(colType)
|
||||
if len(fields) == 2 && fields[1] == "unsigned" {
|
||||
|
@ -447,7 +465,7 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
// Remove the /* mariadb-5.3 */ suffix from coltypes
|
||||
colName = strings.TrimSuffix(colName, "/* mariadb-5.3 */")
|
||||
colType = strings.ToUpper(colName)
|
||||
var len1, len2 int
|
||||
var len1, len2 int64
|
||||
if len(cts) == 2 {
|
||||
idx := strings.Index(cts[1], ")")
|
||||
if colType == schemas.Enum && cts[1][0] == '\'' { // enum
|
||||
|
@ -468,17 +486,25 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
}
|
||||
} else {
|
||||
lens := strings.Split(cts[1][0:idx], ",")
|
||||
len1, err = strconv.Atoi(strings.TrimSpace(lens[0]))
|
||||
len1, err = strconv.ParseInt(strings.TrimSpace(lens[0]), 10, 64)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if len(lens) == 2 {
|
||||
len2, err = strconv.Atoi(lens[1])
|
||||
len2, err = strconv.ParseInt(lens[1], 10, 64)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch colType {
|
||||
case "MEDIUMTEXT", "LONGTEXT", "TEXT":
|
||||
len1, err = strconv.ParseInt(*maxLength, 10, 64)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if isUnsigned {
|
||||
colType = "UNSIGNED " + colType
|
||||
|
@ -520,7 +546,7 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
|
||||
func (db *mysql) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
|
||||
args := []interface{}{db.uri.DBName}
|
||||
s := "SELECT `TABLE_NAME`, `ENGINE`, `AUTO_INCREMENT`, `TABLE_COMMENT` from " +
|
||||
s := "SELECT `TABLE_NAME`, `ENGINE`, `AUTO_INCREMENT`, `TABLE_COMMENT`, `TABLE_COLLATION` from " +
|
||||
"`INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB' OR `ENGINE` = 'TokuDB')"
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
|
@ -532,9 +558,9 @@ func (db *mysql) GetTables(queryer core.Queryer, ctx context.Context) ([]*schema
|
|||
tables := make([]*schemas.Table, 0)
|
||||
for rows.Next() {
|
||||
table := schemas.NewEmptyTable()
|
||||
var name, engine string
|
||||
var name, engine, collation string
|
||||
var autoIncr, comment *string
|
||||
err = rows.Scan(&name, &engine, &autoIncr, &comment)
|
||||
err = rows.Scan(&name, &engine, &autoIncr, &comment, &collation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -544,6 +570,7 @@ func (db *mysql) GetTables(queryer core.Queryer, ctx context.Context) ([]*schema
|
|||
table.Comment = *comment
|
||||
}
|
||||
table.StoreEngine = engine
|
||||
table.Collation = collation
|
||||
tables = append(tables, table)
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
|
@ -555,11 +582,11 @@ func (db *mysql) GetTables(queryer core.Queryer, ctx context.Context) ([]*schema
|
|||
func (db *mysql) SetQuotePolicy(quotePolicy QuotePolicy) {
|
||||
switch quotePolicy {
|
||||
case QuotePolicyNone:
|
||||
var q = mysqlQuoter
|
||||
q := mysqlQuoter
|
||||
q.IsReserved = schemas.AlwaysNoReserve
|
||||
db.quoter = q
|
||||
case QuotePolicyReserved:
|
||||
var q = mysqlQuoter
|
||||
q := mysqlQuoter
|
||||
q.IsReserved = db.IsReserved
|
||||
db.quoter = q
|
||||
case QuotePolicyAlways:
|
||||
|
@ -571,7 +598,7 @@ func (db *mysql) SetQuotePolicy(quotePolicy QuotePolicy) {
|
|||
|
||||
func (db *mysql) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []interface{}{db.uri.DBName, tableName}
|
||||
s := "SELECT `INDEX_NAME`, `NON_UNIQUE`, `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?"
|
||||
s := "SELECT `INDEX_NAME`, `NON_UNIQUE`, `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? ORDER BY `SEQ_IN_INDEX`"
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
if err != nil {
|
||||
|
@ -635,7 +662,7 @@ func (db *mysql) CreateTableSQL(ctx context.Context, queryer core.Queryer, table
|
|||
|
||||
for i, colName := range table.ColumnsSeq() {
|
||||
col := table.GetColumn(colName)
|
||||
s, _ := ColumnString(db.dialect, col, col.IsPrimaryKey && len(table.PrimaryKeys) == 1)
|
||||
s, _ := ColumnString(db.dialect, col, col.IsPrimaryKey && len(table.PrimaryKeys) == 1, true)
|
||||
b.WriteString(s)
|
||||
|
||||
if len(col.Comment) > 0 {
|
||||
|
@ -662,7 +689,7 @@ func (db *mysql) CreateTableSQL(ctx context.Context, queryer core.Queryer, table
|
|||
b.WriteString(table.StoreEngine)
|
||||
}
|
||||
|
||||
var charset = table.Charset
|
||||
charset := table.Charset
|
||||
if len(charset) == 0 {
|
||||
charset = db.URI().Charset
|
||||
}
|
||||
|
@ -733,8 +760,9 @@ func (p *mysqlDriver) Parse(driverName, dataSourceName string) (*URI, error) {
|
|||
}
|
||||
|
||||
func (p *mysqlDriver) GenScanResult(colType string) (interface{}, error) {
|
||||
colType = strings.Replace(colType, "UNSIGNED ", "", -1)
|
||||
switch colType {
|
||||
case "CHAR", "VARCHAR", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "ENUM", "SET":
|
||||
case "CHAR", "VARCHAR", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "ENUM", "SET", "JSON":
|
||||
var s sql.NullString
|
||||
return &s, nil
|
||||
case "BIGINT":
|
||||
|
|
|
@ -548,7 +548,14 @@ func (db *oracle) Features() *DialectFeatures {
|
|||
func (db *oracle) SQLType(c *schemas.Column) string {
|
||||
var res string
|
||||
switch t := c.SQLType.Name; t {
|
||||
case schemas.Bit, schemas.TinyInt, schemas.SmallInt, schemas.MediumInt, schemas.Int, schemas.Integer, schemas.BigInt, schemas.Bool, schemas.Serial, schemas.BigSerial:
|
||||
case schemas.Bool:
|
||||
if c.Default == "true" {
|
||||
c.Default = "1"
|
||||
} else if c.Default == "false" {
|
||||
c.Default = "0"
|
||||
}
|
||||
res = "NUMBER(1,0)"
|
||||
case schemas.Bit, schemas.TinyInt, schemas.SmallInt, schemas.MediumInt, schemas.Int, schemas.Integer, schemas.BigInt, schemas.Serial, schemas.BigSerial:
|
||||
res = "NUMBER"
|
||||
case schemas.Binary, schemas.VarBinary, schemas.Blob, schemas.TinyBlob, schemas.MediumBlob, schemas.LongBlob, schemas.Bytea:
|
||||
return schemas.Blob
|
||||
|
@ -570,9 +577,9 @@ func (db *oracle) SQLType(c *schemas.Column) string {
|
|||
hasLen2 := (c.Length2 > 0)
|
||||
|
||||
if hasLen2 {
|
||||
res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
||||
} else if hasLen1 {
|
||||
res += "(" + strconv.Itoa(c.Length) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + ")"
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@ -602,11 +609,11 @@ func (db *oracle) IsReserved(name string) bool {
|
|||
}
|
||||
|
||||
func (db *oracle) DropTableSQL(tableName string) (string, bool) {
|
||||
return fmt.Sprintf("DROP TABLE `%s`", tableName), false
|
||||
return fmt.Sprintf("DROP TABLE \"%s\"", tableName), false
|
||||
}
|
||||
|
||||
func (db *oracle) CreateTableSQL(ctx context.Context, queryer core.Queryer, table *schemas.Table, tableName string) (string, bool, error) {
|
||||
var sql = "CREATE TABLE "
|
||||
sql := "CREATE TABLE "
|
||||
if tableName == "" {
|
||||
tableName = table.Name
|
||||
}
|
||||
|
@ -621,7 +628,7 @@ func (db *oracle) CreateTableSQL(ctx context.Context, queryer core.Queryer, tabl
|
|||
/*if col.IsPrimaryKey && len(pkList) == 1 {
|
||||
sql += col.String(b.dialect)
|
||||
} else {*/
|
||||
s, _ := ColumnString(db, col, false)
|
||||
s, _ := ColumnString(db, col, false, false)
|
||||
sql += s
|
||||
// }
|
||||
sql = strings.TrimSpace(sql)
|
||||
|
@ -638,14 +645,18 @@ func (db *oracle) CreateTableSQL(ctx context.Context, queryer core.Queryer, tabl
|
|||
return sql, false, nil
|
||||
}
|
||||
|
||||
func (db *oracle) IsSequenceExist(ctx context.Context, queryer core.Queryer, seqName string) (bool, error) {
|
||||
return db.HasRecords(queryer, ctx, `SELECT sequence_name FROM user_sequences WHERE sequence_name = :1`, seqName)
|
||||
}
|
||||
|
||||
func (db *oracle) SetQuotePolicy(quotePolicy QuotePolicy) {
|
||||
switch quotePolicy {
|
||||
case QuotePolicyNone:
|
||||
var q = oracleQuoter
|
||||
q := oracleQuoter
|
||||
q.IsReserved = schemas.AlwaysNoReserve
|
||||
db.quoter = q
|
||||
case QuotePolicyReserved:
|
||||
var q = oracleQuoter
|
||||
q := oracleQuoter
|
||||
q.IsReserved = db.IsReserved
|
||||
db.quoter = q
|
||||
case QuotePolicyAlways:
|
||||
|
@ -690,7 +701,7 @@ func (db *oracle) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
col.Indexes = make(map[string]int)
|
||||
|
||||
var colName, colDefault, nullable, dataType, dataPrecision, dataScale *string
|
||||
var dataLen int
|
||||
var dataLen int64
|
||||
|
||||
err = rows.Scan(&colName, &colDefault, &dataType, &dataLen, &dataPrecision,
|
||||
&dataScale, &nullable)
|
||||
|
@ -713,16 +724,16 @@ func (db *oracle) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
var ignore bool
|
||||
|
||||
var dt string
|
||||
var len1, len2 int
|
||||
var len1, len2 int64
|
||||
dts := strings.Split(*dataType, "(")
|
||||
dt = dts[0]
|
||||
if len(dts) > 1 {
|
||||
lens := strings.Split(dts[1][:len(dts[1])-1], ",")
|
||||
if len(lens) > 1 {
|
||||
len1, _ = strconv.Atoi(lens[0])
|
||||
len2, _ = strconv.Atoi(lens[1])
|
||||
len1, _ = strconv.ParseInt(lens[0], 10, 64)
|
||||
len2, _ = strconv.ParseInt(lens[1], 10, 64)
|
||||
} else {
|
||||
len1, _ = strconv.Atoi(lens[0])
|
||||
len1, _ = strconv.ParseInt(lens[0], 10, 64)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -852,7 +863,7 @@ func (db *oracle) GetIndexes(queryer core.Queryer, ctx context.Context, tableNam
|
|||
|
||||
func (db *oracle) Filters() []Filter {
|
||||
return []Filter{
|
||||
&SeqFilter{Prefix: ":", Start: 1},
|
||||
&oracleSeqFilter{Prefix: ":", Start: 1},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -932,3 +943,7 @@ func (o *oci8Driver) Parse(driverName, dataSourceName string) (*URI, error) {
|
|||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
type oracleDriver struct {
|
||||
godrorDriver
|
||||
}
|
||||
|
|
|
@ -862,11 +862,11 @@ func (db *postgres) needQuote(name string) bool {
|
|||
func (db *postgres) SetQuotePolicy(quotePolicy QuotePolicy) {
|
||||
switch quotePolicy {
|
||||
case QuotePolicyNone:
|
||||
var q = postgresQuoter
|
||||
q := postgresQuoter
|
||||
q.IsReserved = schemas.AlwaysNoReserve
|
||||
db.quoter = q
|
||||
case QuotePolicyReserved:
|
||||
var q = postgresQuoter
|
||||
q := postgresQuoter
|
||||
q.IsReserved = db.needQuote
|
||||
db.quoter = q
|
||||
case QuotePolicyAlways:
|
||||
|
@ -934,9 +934,9 @@ func (db *postgres) SQLType(c *schemas.Column) string {
|
|||
hasLen2 := (c.Length2 > 0)
|
||||
|
||||
if hasLen2 {
|
||||
res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
||||
} else if hasLen1 {
|
||||
res += "(" + strconv.Itoa(c.Length) + ")"
|
||||
res += "(" + strconv.FormatInt(c.Length, 10) + ")"
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@ -992,7 +992,7 @@ func (db *postgres) IsTableExist(queryer core.Queryer, ctx context.Context, tabl
|
|||
}
|
||||
|
||||
func (db *postgres) AddColumnSQL(tableName string, col *schemas.Column) string {
|
||||
s, _ := ColumnString(db.dialect, col, true)
|
||||
s, _ := ColumnString(db.dialect, col, true, false)
|
||||
|
||||
quoter := db.dialect.Quoter()
|
||||
addColumnSQL := ""
|
||||
|
@ -1030,11 +1030,10 @@ func (db *postgres) DropIndexSQL(tableName string, index *schemas.Index) string
|
|||
tableParts := strings.Split(strings.Replace(tableName, `"`, "", -1), ".")
|
||||
tableName = tableParts[len(tableParts)-1]
|
||||
|
||||
if !strings.HasPrefix(idxName, "UQE_") &&
|
||||
!strings.HasPrefix(idxName, "IDX_") {
|
||||
if index.Type == schemas.UniqueType {
|
||||
if index.IsRegular {
|
||||
if index.Type == schemas.UniqueType && !strings.HasPrefix(idxName, "UQE_") {
|
||||
idxName = fmt.Sprintf("UQE_%v_%v", tableName, index.Name)
|
||||
} else {
|
||||
} else if index.Type == schemas.IndexType && !strings.HasPrefix(idxName, "IDX_") {
|
||||
idxName = fmt.Sprintf("IDX_%v_%v", tableName, index.Name)
|
||||
}
|
||||
}
|
||||
|
@ -1079,7 +1078,7 @@ FROM pg_attribute f
|
|||
LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY (p.conkey)
|
||||
LEFT JOIN pg_class AS g ON p.confrelid = g.oid
|
||||
LEFT JOIN INFORMATION_SCHEMA.COLUMNS s ON s.column_name=f.attname AND c.relname=s.table_name
|
||||
WHERE n.nspname= s.table_schema AND c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.attnum;`
|
||||
WHERE n.nspname= s.table_schema AND c.relkind = 'r' AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.attnum;`
|
||||
|
||||
schema := db.getSchema()
|
||||
if schema != "" {
|
||||
|
@ -1110,9 +1109,9 @@ WHERE n.nspname= s.table_schema AND c.relkind = 'r'::char AND c.relname = $1%s A
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
var maxLen int
|
||||
var maxLen int64
|
||||
if maxLenStr != nil {
|
||||
maxLen, err = strconv.Atoi(*maxLenStr)
|
||||
maxLen, err = strconv.ParseInt(*maxLenStr, 10, 64)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -1125,7 +1124,7 @@ WHERE n.nspname= s.table_schema AND c.relkind = 'r'::char AND c.relname = $1%s A
|
|||
col.Name = strings.Trim(colName, `" `)
|
||||
|
||||
if colDefault != nil {
|
||||
var theDefault = *colDefault
|
||||
theDefault := *colDefault
|
||||
// cockroach has type with the default value with :::
|
||||
// and postgres with ::, we should remove them before store them
|
||||
idx := strings.Index(theDefault, ":::")
|
||||
|
@ -1186,7 +1185,7 @@ WHERE n.nspname= s.table_schema AND c.relkind = 'r'::char AND c.relname = $1%s A
|
|||
startIdx := strings.Index(strings.ToLower(dataType), "string(")
|
||||
if startIdx != -1 && strings.HasSuffix(dataType, ")") {
|
||||
length := dataType[startIdx+8 : len(dataType)-1]
|
||||
l, _ := strconv.Atoi(length)
|
||||
l, _ := strconv.ParseInt(length, 10, 64)
|
||||
col.SQLType = schemas.SQLType{Name: "STRING", DefaultLength: l, DefaultLength2: 0}
|
||||
} else {
|
||||
col.SQLType = schemas.SQLType{Name: strings.ToUpper(dataType), DefaultLength: 0, DefaultLength2: 0}
|
||||
|
@ -1301,15 +1300,8 @@ func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableN
|
|||
}
|
||||
colNames = getIndexColName(indexdef)
|
||||
|
||||
isSkip := false
|
||||
//Oid It's a special index. You can't put it in
|
||||
for _, element := range colNames {
|
||||
if "oid" == element {
|
||||
isSkip = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if isSkip {
|
||||
// Oid It's a special index. You can't put it in. TODO: This is not perfect.
|
||||
if indexName == tableName+"_oid_index" && len(colNames) == 1 && colNames[0] == "oid" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -1351,14 +1343,22 @@ func (db *postgres) CreateTableSQL(ctx context.Context, queryer core.Queryer, ta
|
|||
commentSQL := "; "
|
||||
if table.Comment != "" {
|
||||
// support schema.table -> "schema"."table"
|
||||
commentSQL += fmt.Sprintf("COMMENT ON TABLE %s IS '%s'", quoter.Quote(tableName), table.Comment)
|
||||
commentSQL += fmt.Sprintf("COMMENT ON TABLE %s IS '%s'; ", quoter.Quote(tableName), table.Comment)
|
||||
}
|
||||
|
||||
for _, colName := range table.ColumnsSeq() {
|
||||
col := table.GetColumn(colName)
|
||||
|
||||
if len(col.Comment) > 0 {
|
||||
commentSQL += fmt.Sprintf("COMMENT ON COLUMN %s.%s IS '%s'; ", quoter.Quote(tableName), quoter.Quote(col.Name), col.Comment)
|
||||
}
|
||||
}
|
||||
|
||||
return createTableSQL + commentSQL, true, nil
|
||||
}
|
||||
|
||||
func (db *postgres) Filters() []Filter {
|
||||
return []Filter{&SeqFilter{Prefix: "$", Start: 1}}
|
||||
return []Filter{&postgresSeqFilter{Prefix: "$", Start: 1}}
|
||||
}
|
||||
|
||||
type pqDriver struct {
|
||||
|
|
|
@ -193,11 +193,11 @@ func (db *sqlite3) Features() *DialectFeatures {
|
|||
func (db *sqlite3) SetQuotePolicy(quotePolicy QuotePolicy) {
|
||||
switch quotePolicy {
|
||||
case QuotePolicyNone:
|
||||
var q = sqlite3Quoter
|
||||
q := sqlite3Quoter
|
||||
q.IsReserved = schemas.AlwaysNoReserve
|
||||
db.quoter = q
|
||||
case QuotePolicyReserved:
|
||||
var q = sqlite3Quoter
|
||||
q := sqlite3Quoter
|
||||
q.IsReserved = db.IsReserved
|
||||
db.quoter = q
|
||||
case QuotePolicyAlways:
|
||||
|
@ -291,10 +291,6 @@ func (db *sqlite3) DropIndexSQL(tableName string, index *schemas.Index) string {
|
|||
return fmt.Sprintf("DROP INDEX %v", db.Quoter().Quote(idxName))
|
||||
}
|
||||
|
||||
func (db *sqlite3) ForUpdateSQL(query string) string {
|
||||
return query
|
||||
}
|
||||
|
||||
func (db *sqlite3) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
|
||||
query := "SELECT * FROM " + tableName + " LIMIT 0"
|
||||
rows, err := queryer.QueryContext(ctx, query)
|
||||
|
@ -320,7 +316,7 @@ func (db *sqlite3) IsColumnExist(queryer core.Queryer, ctx context.Context, tabl
|
|||
// splitColStr splits a sqlite col strings as fields
|
||||
func splitColStr(colStr string) []string {
|
||||
colStr = strings.TrimSpace(colStr)
|
||||
var results = make([]string, 0, 10)
|
||||
results := make([]string, 0, 10)
|
||||
var lastIdx int
|
||||
var hasC, hasQuote bool
|
||||
for i, c := range colStr {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/names"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
// TableNameWithSchema will add schema prefix on table name if possible
|
||||
|
@ -29,6 +30,9 @@ func TableNameNoSchema(dialect Dialect, mapper names.Mapper, tableName interface
|
|||
switch tt := tableName.(type) {
|
||||
case []string:
|
||||
if len(tt) > 1 {
|
||||
if dialect.URI().DBType == schemas.ORACLE {
|
||||
return fmt.Sprintf("%v %v", quote(tt[0]), quote(tt[1]))
|
||||
}
|
||||
return fmt.Sprintf("%v AS %v", quote(tt[0]), quote(tt[1]))
|
||||
} else if len(tt) == 1 {
|
||||
return quote(tt[0])
|
||||
|
@ -54,6 +58,9 @@ func TableNameNoSchema(dialect Dialect, mapper names.Mapper, tableName interface
|
|||
}
|
||||
}
|
||||
if l > 1 {
|
||||
if dialect.URI().DBType == schemas.ORACLE {
|
||||
return fmt.Sprintf("%v %v", quote(table), quote(fmt.Sprintf("%v", tt[1])))
|
||||
}
|
||||
return fmt.Sprintf("%v AS %v", quote(table), quote(fmt.Sprintf("%v", tt[1])))
|
||||
} else if l == 1 {
|
||||
return quote(table)
|
||||
|
|
|
@ -23,7 +23,7 @@ func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.C
|
|||
}
|
||||
}
|
||||
|
||||
var tmZone = dbLocation
|
||||
tmZone := dbLocation
|
||||
if col.TimeZone != nil {
|
||||
tmZone = col.TimeZone
|
||||
}
|
||||
|
@ -34,15 +34,17 @@ func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.C
|
|||
case schemas.Date:
|
||||
return t.Format("2006-01-02"), nil
|
||||
case schemas.Time:
|
||||
var layout = "15:04:05"
|
||||
layout := "15:04:05"
|
||||
if col.Length > 0 {
|
||||
layout += "." + strings.Repeat("0", col.Length)
|
||||
// we can use int(...) casting here as it's very unlikely to a huge sized field
|
||||
layout += "." + strings.Repeat("0", int(col.Length))
|
||||
}
|
||||
return t.Format(layout), nil
|
||||
case schemas.DateTime, schemas.TimeStamp:
|
||||
var layout = "2006-01-02 15:04:05"
|
||||
layout := "2006-01-02 15:04:05"
|
||||
if col.Length > 0 {
|
||||
layout += "." + strings.Repeat("0", col.Length)
|
||||
// we can use int(...) casting here as it's very unlikely to a huge sized field
|
||||
layout += "." + strings.Repeat("0", int(col.Length))
|
||||
}
|
||||
return t.Format(layout), nil
|
||||
case schemas.Varchar:
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
// Copyright 2019 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package dialects
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
type dialect struct {
|
||||
Dialect
|
||||
dbType schemas.DBType
|
||||
}
|
||||
|
||||
func (d dialect) URI() *URI {
|
||||
return &URI{
|
||||
DBType: d.dbType,
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatColumnTime(t *testing.T) {
|
||||
date := time.Date(2020, 10, 23, 10, 14, 15, 123456, time.Local)
|
||||
tests := []struct {
|
||||
name string
|
||||
dialect Dialect
|
||||
location *time.Location
|
||||
column *schemas.Column
|
||||
time time.Time
|
||||
wantRes interface{}
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
name: "nullable",
|
||||
dialect: nil,
|
||||
location: nil,
|
||||
column: &schemas.Column{Nullable: true},
|
||||
time: time.Time{},
|
||||
wantRes: nil,
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "invalid sqltype",
|
||||
dialect: nil,
|
||||
location: nil,
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.Bit}},
|
||||
time: time.Time{},
|
||||
wantRes: 0,
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "return default",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.Bit}},
|
||||
time: date,
|
||||
wantRes: date,
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "return default (set timezone)",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.Bit}, TimeZone: time.UTC},
|
||||
time: date,
|
||||
wantRes: date.In(time.UTC),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format date",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.Date}},
|
||||
time: date,
|
||||
wantRes: date.Format("2006-01-02"),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format time",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.Time}},
|
||||
time: date,
|
||||
wantRes: date.Format("15:04:05"),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format time (set length)",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.Time}, Length: 64},
|
||||
time: date,
|
||||
wantRes: date.Format("15:04:05.999999999"),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format datetime",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.DateTime}},
|
||||
time: date,
|
||||
wantRes: date.Format("2006-01-02 15:04:05"),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format datetime (set length)",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.DateTime}, Length: 64},
|
||||
time: date,
|
||||
wantRes: date.Format("2006-01-02 15:04:05.999999999"),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format timestamp",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.TimeStamp}},
|
||||
time: date,
|
||||
wantRes: date.Format("2006-01-02 15:04:05"),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format timestamp (set length)",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.TimeStamp}, Length: 64},
|
||||
time: date,
|
||||
wantRes: date.Format("2006-01-02 15:04:05.999999999"),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format varchar",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.Varchar}},
|
||||
time: date,
|
||||
wantRes: date.Format("2006-01-02 15:04:05"),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format timestampz",
|
||||
dialect: dialect{},
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.TimeStampz}},
|
||||
time: date,
|
||||
wantRes: date.Format(time.RFC3339Nano),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format timestampz (mssql)",
|
||||
dialect: dialect{dbType: schemas.MSSQL},
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.TimeStampz}},
|
||||
time: date,
|
||||
wantRes: date.Format("2006-01-02T15:04:05.9999999Z07:00"),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format int",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.Int}},
|
||||
time: date,
|
||||
wantRes: date.Unix(),
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "format bigint",
|
||||
dialect: nil,
|
||||
location: date.Location(),
|
||||
column: &schemas.Column{SQLType: schemas.SQLType{Name: schemas.BigInt}},
|
||||
time: date,
|
||||
wantRes: date.Unix(),
|
||||
wantErr: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := FormatColumnTime(tt.dialect, tt.location, tt.column, tt.time)
|
||||
assert.Equal(t, tt.wantErr, err)
|
||||
assert.Equal(t, tt.wantRes, got)
|
||||
})
|
||||
}
|
||||
}
|
251
doc.go
251
doc.go
|
@ -3,247 +3,246 @@
|
|||
// license that can be found in the LICENSE file.
|
||||
|
||||
/*
|
||||
|
||||
Package xorm is a simple and powerful ORM for Go.
|
||||
|
||||
Installation
|
||||
# Installation
|
||||
|
||||
Make sure you have installed Go 1.11+ and then:
|
||||
|
||||
go get xorm.io/xorm
|
||||
go get xorm.io/xorm
|
||||
|
||||
Create Engine
|
||||
# Create Engine
|
||||
|
||||
Firstly, we should create an engine for a database
|
||||
|
||||
engine, err := xorm.NewEngine(driverName, dataSourceName)
|
||||
engine, err := xorm.NewEngine(driverName, dataSourceName)
|
||||
|
||||
Method NewEngine's parameters are the same as sql.Open which depend drivers' implementation.
|
||||
Generally, one engine for an application is enough. You can define it as a package variable.
|
||||
|
||||
Raw Methods
|
||||
# Raw Methods
|
||||
|
||||
XORM supports raw SQL execution:
|
||||
|
||||
1. query with a SQL string, the returned results is []map[string][]byte
|
||||
|
||||
results, err := engine.Query("select * from user")
|
||||
results, err := engine.Query("select * from user")
|
||||
|
||||
2. query with a SQL string, the returned results is []map[string]string
|
||||
|
||||
results, err := engine.QueryString("select * from user")
|
||||
results, err := engine.QueryString("select * from user")
|
||||
|
||||
3. query with a SQL string, the returned results is []map[string]interface{}
|
||||
|
||||
results, err := engine.QueryInterface("select * from user")
|
||||
results, err := engine.QueryInterface("select * from user")
|
||||
|
||||
4. execute with a SQL string, the returned results
|
||||
|
||||
affected, err := engine.Exec("update user set .... where ...")
|
||||
affected, err := engine.Exec("update user set .... where ...")
|
||||
|
||||
ORM Methods
|
||||
# ORM Methods
|
||||
|
||||
There are 8 major ORM methods and many helpful methods to use to operate database.
|
||||
|
||||
1. Insert one or multiple records to database
|
||||
|
||||
affected, err := engine.Insert(&struct)
|
||||
// INSERT INTO struct () values ()
|
||||
affected, err := engine.Insert(&struct1, &struct2)
|
||||
// INSERT INTO struct1 () values ()
|
||||
// INSERT INTO struct2 () values ()
|
||||
affected, err := engine.Insert(&sliceOfStruct)
|
||||
// INSERT INTO struct () values (),(),()
|
||||
affected, err := engine.Insert(&struct1, &sliceOfStruct2)
|
||||
// INSERT INTO struct1 () values ()
|
||||
// INSERT INTO struct2 () values (),(),()
|
||||
affected, err := engine.Insert(&struct)
|
||||
// INSERT INTO struct () values ()
|
||||
affected, err := engine.Insert(&struct1, &struct2)
|
||||
// INSERT INTO struct1 () values ()
|
||||
// INSERT INTO struct2 () values ()
|
||||
affected, err := engine.Insert(&sliceOfStruct)
|
||||
// INSERT INTO struct () values (),(),()
|
||||
affected, err := engine.Insert(&struct1, &sliceOfStruct2)
|
||||
// INSERT INTO struct1 () values ()
|
||||
// INSERT INTO struct2 () values (),(),()
|
||||
|
||||
2. Query one record or one variable from database
|
||||
|
||||
has, err := engine.Get(&user)
|
||||
// SELECT * FROM user LIMIT 1
|
||||
has, err := engine.Get(&user)
|
||||
// SELECT * FROM user LIMIT 1
|
||||
|
||||
var id int64
|
||||
has, err := engine.Table("user").Where("name = ?", name).Get(&id)
|
||||
// SELECT id FROM user WHERE name = ? LIMIT 1
|
||||
var id int64
|
||||
has, err := engine.Table("user").Where("name = ?", name).Get(&id)
|
||||
// SELECT id FROM user WHERE name = ? LIMIT 1
|
||||
|
||||
var id int64
|
||||
var name string
|
||||
has, err := engine.Table(&user).Cols("id", "name").Get(&id, &name)
|
||||
// SELECT id, name FROM user LIMIT 1
|
||||
var id int64
|
||||
var name string
|
||||
has, err := engine.Table(&user).Cols("id", "name").Get(&id, &name)
|
||||
// SELECT id, name FROM user LIMIT 1
|
||||
|
||||
3. Query multiple records from database
|
||||
|
||||
var sliceOfStructs []Struct
|
||||
err := engine.Find(&sliceOfStructs)
|
||||
// SELECT * FROM user
|
||||
var sliceOfStructs []Struct
|
||||
err := engine.Find(&sliceOfStructs)
|
||||
// SELECT * FROM user
|
||||
|
||||
var mapOfStructs = make(map[int64]Struct)
|
||||
err := engine.Find(&mapOfStructs)
|
||||
// SELECT * FROM user
|
||||
var mapOfStructs = make(map[int64]Struct)
|
||||
err := engine.Find(&mapOfStructs)
|
||||
// SELECT * FROM user
|
||||
|
||||
var int64s []int64
|
||||
err := engine.Table("user").Cols("id").Find(&int64s)
|
||||
// SELECT id FROM user
|
||||
var int64s []int64
|
||||
err := engine.Table("user").Cols("id").Find(&int64s)
|
||||
// SELECT id FROM user
|
||||
|
||||
4. Query multiple records and record by record handle, there two methods, one is Iterate,
|
||||
another is Rows
|
||||
|
||||
err := engine.Iterate(new(User), func(i int, bean interface{}) error {
|
||||
// do something
|
||||
})
|
||||
// SELECT * FROM user
|
||||
err := engine.Iterate(new(User), func(i int, bean interface{}) error {
|
||||
// do something
|
||||
})
|
||||
// SELECT * FROM user
|
||||
|
||||
rows, err := engine.Rows(...)
|
||||
// SELECT * FROM user
|
||||
defer rows.Close()
|
||||
bean := new(Struct)
|
||||
for rows.Next() {
|
||||
err = rows.Scan(bean)
|
||||
}
|
||||
rows, err := engine.Rows(...)
|
||||
// SELECT * FROM user
|
||||
defer rows.Close()
|
||||
bean := new(Struct)
|
||||
for rows.Next() {
|
||||
err = rows.Scan(bean)
|
||||
}
|
||||
|
||||
or
|
||||
|
||||
rows, err := engine.Cols("name", "age").Rows(...)
|
||||
// SELECT * FROM user
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var name string
|
||||
var age int
|
||||
err = rows.Scan(&name, &age)
|
||||
}
|
||||
rows, err := engine.Cols("name", "age").Rows(...)
|
||||
// SELECT * FROM user
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var name string
|
||||
var age int
|
||||
err = rows.Scan(&name, &age)
|
||||
}
|
||||
|
||||
5. Update one or more records
|
||||
|
||||
affected, err := engine.ID(...).Update(&user)
|
||||
// UPDATE user SET ...
|
||||
affected, err := engine.ID(...).Update(&user)
|
||||
// UPDATE user SET ...
|
||||
|
||||
6. Delete one or more records, Delete MUST has condition
|
||||
|
||||
affected, err := engine.Where(...).Delete(&user)
|
||||
// DELETE FROM user Where ...
|
||||
affected, err := engine.Where(...).Delete(&user)
|
||||
// DELETE FROM user Where ...
|
||||
|
||||
7. Count records
|
||||
|
||||
counts, err := engine.Count(&user)
|
||||
// SELECT count(*) AS total FROM user
|
||||
counts, err := engine.Count(&user)
|
||||
// SELECT count(*) AS total FROM user
|
||||
|
||||
counts, err := engine.SQL("select count(*) FROM user").Count()
|
||||
// select count(*) FROM user
|
||||
counts, err := engine.SQL("select count(*) FROM user").Count()
|
||||
// select count(*) FROM user
|
||||
|
||||
8. Sum records
|
||||
|
||||
sumFloat64, err := engine.Sum(&user, "id")
|
||||
// SELECT sum(id) from user
|
||||
sumFloat64, err := engine.Sum(&user, "id")
|
||||
// SELECT sum(id) from user
|
||||
|
||||
sumFloat64s, err := engine.Sums(&user, "id1", "id2")
|
||||
// SELECT sum(id1), sum(id2) from user
|
||||
sumFloat64s, err := engine.Sums(&user, "id1", "id2")
|
||||
// SELECT sum(id1), sum(id2) from user
|
||||
|
||||
sumInt64s, err := engine.SumsInt(&user, "id1", "id2")
|
||||
// SELECT sum(id1), sum(id2) from user
|
||||
sumInt64s, err := engine.SumsInt(&user, "id1", "id2")
|
||||
// SELECT sum(id1), sum(id2) from user
|
||||
|
||||
Conditions
|
||||
# Conditions
|
||||
|
||||
The above 8 methods could use with condition methods chainable.
|
||||
Notice: the above 8 methods should be the last chainable method.
|
||||
|
||||
1. ID, In
|
||||
|
||||
engine.ID(1).Get(&user) // for single primary key
|
||||
// SELECT * FROM user WHERE id = 1
|
||||
engine.ID(schemas.PK{1, 2}).Get(&user) // for composite primary keys
|
||||
// SELECT * FROM user WHERE id1 = 1 AND id2 = 2
|
||||
engine.In("id", 1, 2, 3).Find(&users)
|
||||
// SELECT * FROM user WHERE id IN (1, 2, 3)
|
||||
engine.In("id", []int{1, 2, 3}).Find(&users)
|
||||
// SELECT * FROM user WHERE id IN (1, 2, 3)
|
||||
engine.ID(1).Get(&user) // for single primary key
|
||||
// SELECT * FROM user WHERE id = 1
|
||||
engine.ID(schemas.PK{1, 2}).Get(&user) // for composite primary keys
|
||||
// SELECT * FROM user WHERE id1 = 1 AND id2 = 2
|
||||
engine.In("id", 1, 2, 3).Find(&users)
|
||||
// SELECT * FROM user WHERE id IN (1, 2, 3)
|
||||
engine.In("id", []int{1, 2, 3}).Find(&users)
|
||||
// SELECT * FROM user WHERE id IN (1, 2, 3)
|
||||
|
||||
2. Where, And, Or
|
||||
|
||||
engine.Where().And().Or().Find()
|
||||
// SELECT * FROM user WHERE (.. AND ..) OR ...
|
||||
engine.Where().And().Or().Find()
|
||||
// SELECT * FROM user WHERE (.. AND ..) OR ...
|
||||
|
||||
3. OrderBy, Asc, Desc
|
||||
|
||||
engine.Asc().Desc().Find()
|
||||
// SELECT * FROM user ORDER BY .. ASC, .. DESC
|
||||
engine.OrderBy().Find()
|
||||
// SELECT * FROM user ORDER BY ..
|
||||
engine.Asc().Desc().Find()
|
||||
// SELECT * FROM user ORDER BY .. ASC, .. DESC
|
||||
engine.OrderBy().Find()
|
||||
// SELECT * FROM user ORDER BY ..
|
||||
|
||||
4. Limit, Top
|
||||
|
||||
engine.Limit().Find()
|
||||
// SELECT * FROM user LIMIT .. OFFSET ..
|
||||
engine.Top(5).Find()
|
||||
// SELECT TOP 5 * FROM user // for mssql
|
||||
// SELECT * FROM user LIMIT .. OFFSET 0 //for other databases
|
||||
engine.Limit().Find()
|
||||
// SELECT * FROM user LIMIT .. OFFSET ..
|
||||
engine.Top(5).Find()
|
||||
// SELECT TOP 5 * FROM user // for mssql
|
||||
// SELECT * FROM user LIMIT .. OFFSET 0 //for other databases
|
||||
|
||||
5. SQL, let you custom SQL
|
||||
|
||||
var users []User
|
||||
engine.SQL("select * from user").Find(&users)
|
||||
var users []User
|
||||
engine.SQL("select * from user").Find(&users)
|
||||
|
||||
6. Cols, Omit, Distinct
|
||||
|
||||
var users []*User
|
||||
engine.Cols("col1, col2").Find(&users)
|
||||
// SELECT col1, col2 FROM user
|
||||
engine.Cols("col1", "col2").Where().Update(user)
|
||||
// UPDATE user set col1 = ?, col2 = ? Where ...
|
||||
engine.Omit("col1").Find(&users)
|
||||
// SELECT col2, col3 FROM user
|
||||
engine.Omit("col1").Insert(&user)
|
||||
// INSERT INTO table (non-col1) VALUES ()
|
||||
engine.Distinct("col1").Find(&users)
|
||||
// SELECT DISTINCT col1 FROM user
|
||||
var users []*User
|
||||
engine.Cols("col1, col2").Find(&users)
|
||||
// SELECT col1, col2 FROM user
|
||||
engine.Cols("col1", "col2").Where().Update(user)
|
||||
// UPDATE user set col1 = ?, col2 = ? Where ...
|
||||
engine.Omit("col1").Find(&users)
|
||||
// SELECT col2, col3 FROM user
|
||||
engine.Omit("col1").Insert(&user)
|
||||
// INSERT INTO table (non-col1) VALUES ()
|
||||
engine.Distinct("col1").Find(&users)
|
||||
// SELECT DISTINCT col1 FROM user
|
||||
|
||||
7. Join, GroupBy, Having
|
||||
|
||||
engine.GroupBy("name").Having("name='xlw'").Find(&users)
|
||||
//SELECT * FROM user GROUP BY name HAVING name='xlw'
|
||||
engine.Join("LEFT", "userdetail", "user.id=userdetail.id").Find(&users)
|
||||
//SELECT * FROM user LEFT JOIN userdetail ON user.id=userdetail.id
|
||||
engine.GroupBy("name").Having("name='xlw'").Find(&users)
|
||||
//SELECT * FROM user GROUP BY name HAVING name='xlw'
|
||||
engine.Join("LEFT", "userdetail", "user.id=userdetail.id").Find(&users)
|
||||
//SELECT * FROM user LEFT JOIN userdetail ON user.id=userdetail.id
|
||||
|
||||
Builder
|
||||
# Builder
|
||||
|
||||
xorm could work with xorm.io/builder directly.
|
||||
|
||||
1. With Where
|
||||
|
||||
var cond = builder.Eq{"a":1, "b":2}
|
||||
engine.Where(cond).Find(&users)
|
||||
var cond = builder.Eq{"a":1, "b":2}
|
||||
engine.Where(cond).Find(&users)
|
||||
|
||||
2. With In
|
||||
|
||||
var subQuery = builder.Select("name").From("group")
|
||||
engine.In("group_name", subQuery).Find(&users)
|
||||
var subQuery = builder.Select("name").From("group")
|
||||
engine.In("group_name", subQuery).Find(&users)
|
||||
|
||||
3. With Join
|
||||
|
||||
var subQuery = builder.Select("name").From("group")
|
||||
engine.Join("INNER", subQuery, "group.id = user.group_id").Find(&users)
|
||||
var subQuery = builder.Select("name").From("group")
|
||||
engine.Join("INNER", subQuery, "group.id = user.group_id").Find(&users)
|
||||
|
||||
4. With SetExprs
|
||||
|
||||
var subQuery = builder.Select("name").From("group")
|
||||
engine.ID(1).SetExprs("name", subQuery).Update(new(User))
|
||||
var subQuery = builder.Select("name").From("group")
|
||||
engine.ID(1).SetExprs("name", subQuery).Update(new(User))
|
||||
|
||||
5. With SQL
|
||||
|
||||
var query = builder.Select("name").From("group")
|
||||
results, err := engine.SQL(query).Find(&groups)
|
||||
var query = builder.Select("name").From("group")
|
||||
results, err := engine.SQL(query).Find(&groups)
|
||||
|
||||
6. With Query
|
||||
|
||||
var query = builder.Select("name").From("group")
|
||||
results, err := engine.Query(query)
|
||||
results, err := engine.QueryString(query)
|
||||
results, err := engine.QueryInterface(query)
|
||||
var query = builder.Select("name").From("group")
|
||||
results, err := engine.Query(query)
|
||||
results, err := engine.QueryString(query)
|
||||
results, err := engine.QueryInterface(query)
|
||||
|
||||
7. With Exec
|
||||
|
||||
var query = builder.Insert("a, b").Into("table1").Select("b, c").From("table2")
|
||||
results, err := engine.Exec(query)
|
||||
var query = builder.Insert("a, b").Into("table1").Select("b, c").From("table2")
|
||||
results, err := engine.Exec(query)
|
||||
|
||||
More usage, please visit http://xorm.io/docs
|
||||
*/
|
||||
|
|
68
engine.go
68
engine.go
|
@ -254,6 +254,11 @@ func (engine *Engine) SetConnMaxLifetime(d time.Duration) {
|
|||
engine.DB().SetConnMaxLifetime(d)
|
||||
}
|
||||
|
||||
// SetConnMaxIdleTime sets the maximum amount of time a connection may be idle.
|
||||
func (engine *Engine) SetConnMaxIdleTime(d time.Duration) {
|
||||
engine.DB().SetConnMaxIdleTime(d)
|
||||
}
|
||||
|
||||
// SetMaxOpenConns is only available for go 1.2+
|
||||
func (engine *Engine) SetMaxOpenConns(conns int) {
|
||||
engine.DB().SetMaxOpenConns(conns)
|
||||
|
@ -330,7 +335,7 @@ func (engine *Engine) Ping() error {
|
|||
// SQL method let's you manually write raw SQL and operate
|
||||
// For example:
|
||||
//
|
||||
// engine.SQL("select * from user").Find(&users)
|
||||
// engine.SQL("select * from user").Find(&users)
|
||||
//
|
||||
// This code will execute "select * from user" and set the records to users
|
||||
func (engine *Engine) SQL(query interface{}, args ...interface{}) *Session {
|
||||
|
@ -355,15 +360,15 @@ func (engine *Engine) NoAutoCondition(no ...bool) *Session {
|
|||
return session.NoAutoCondition(no...)
|
||||
}
|
||||
|
||||
func (engine *Engine) loadTableInfo(table *schemas.Table) error {
|
||||
colSeq, cols, err := engine.dialect.GetColumns(engine.db, engine.defaultContext, table.Name)
|
||||
func (engine *Engine) loadTableInfo(ctx context.Context, table *schemas.Table) error {
|
||||
colSeq, cols, err := engine.dialect.GetColumns(engine.db, ctx, table.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, name := range colSeq {
|
||||
table.AddColumn(cols[name])
|
||||
}
|
||||
indexes, err := engine.dialect.GetIndexes(engine.db, engine.defaultContext, table.Name)
|
||||
indexes, err := engine.dialect.GetIndexes(engine.db, ctx, table.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -380,7 +385,7 @@ func (engine *Engine) loadTableInfo(table *schemas.Table) error {
|
|||
seq = 0
|
||||
}
|
||||
}
|
||||
var colName = strings.Trim(parts[0], `"`)
|
||||
colName := strings.Trim(parts[0], `"`)
|
||||
if col := table.GetColumn(colName); col != nil {
|
||||
col.Indexes[index.Name] = index.Type
|
||||
} else {
|
||||
|
@ -399,7 +404,7 @@ func (engine *Engine) DBMetas() ([]*schemas.Table, error) {
|
|||
}
|
||||
|
||||
for _, table := range tables {
|
||||
if err = engine.loadTableInfo(table); err != nil {
|
||||
if err = engine.loadTableInfo(engine.defaultContext, table); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -502,9 +507,9 @@ func (engine *Engine) dumpTables(ctx context.Context, tables []*schemas.Table, w
|
|||
}
|
||||
}
|
||||
|
||||
var dstTableName = dstTable.Name
|
||||
var quoter = dstDialect.Quoter().Quote
|
||||
var quotedDstTableName = quoter(dstTable.Name)
|
||||
dstTableName := dstTable.Name
|
||||
quoter := dstDialect.Quoter().Quote
|
||||
quotedDstTableName := quoter(dstTable.Name)
|
||||
if dstDialect.URI().Schema != "" {
|
||||
dstTableName = fmt.Sprintf("%s.%s", dstDialect.URI().Schema, dstTable.Name)
|
||||
quotedDstTableName = fmt.Sprintf("%s.%s", quoter(dstDialect.URI().Schema), quoter(dstTable.Name))
|
||||
|
@ -815,6 +820,9 @@ func (engine *Engine) dumpTables(ctx context.Context, tables []*schemas.Table, w
|
|||
return err
|
||||
}
|
||||
}
|
||||
// !datbeohbbh! if no error, manually close
|
||||
rows.Close()
|
||||
sess.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -996,9 +1004,8 @@ func (engine *Engine) Desc(colNames ...string) *Session {
|
|||
// Asc will generate "ORDER BY column1,column2 Asc"
|
||||
// This method can chainable use.
|
||||
//
|
||||
// engine.Desc("name").Asc("age").Find(&users)
|
||||
// // SELECT * FROM user ORDER BY name DESC, age ASC
|
||||
//
|
||||
// engine.Desc("name").Asc("age").Find(&users)
|
||||
// // SELECT * FROM user ORDER BY name DESC, age ASC
|
||||
func (engine *Engine) Asc(colNames ...string) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
|
@ -1006,10 +1013,10 @@ func (engine *Engine) Asc(colNames ...string) *Session {
|
|||
}
|
||||
|
||||
// OrderBy will generate "ORDER BY order"
|
||||
func (engine *Engine) OrderBy(order string) *Session {
|
||||
func (engine *Engine) OrderBy(order interface{}, args ...interface{}) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.OrderBy(order)
|
||||
return session.OrderBy(order, args...)
|
||||
}
|
||||
|
||||
// Prepare enables prepare statement
|
||||
|
@ -1020,7 +1027,7 @@ func (engine *Engine) Prepare() *Session {
|
|||
}
|
||||
|
||||
// Join the join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
|
||||
func (engine *Engine) Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session {
|
||||
func (engine *Engine) Join(joinOperator string, tablename interface{}, condition interface{}, args ...interface{}) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.Join(joinOperator, tablename, condition, args...)
|
||||
|
@ -1113,21 +1120,6 @@ func (engine *Engine) UnMapType(t reflect.Type) {
|
|||
engine.tagParser.ClearCacheTable(t)
|
||||
}
|
||||
|
||||
// Sync the new struct changes to database, this method will automatically add
|
||||
// table, column, index, unique. but will not delete or change anything.
|
||||
// If you change some field, you should change the database manually.
|
||||
func (engine *Engine) Sync(beans ...interface{}) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Sync(beans...)
|
||||
}
|
||||
|
||||
// Sync2 synchronize structs to database tables
|
||||
// Depricated
|
||||
func (engine *Engine) Sync2(beans ...interface{}) error {
|
||||
return engine.Sync(beans...)
|
||||
}
|
||||
|
||||
// CreateTables create tabls according bean
|
||||
func (engine *Engine) CreateTables(beans ...interface{}) error {
|
||||
session := engine.NewSession()
|
||||
|
@ -1220,9 +1212,10 @@ func (engine *Engine) InsertOne(bean interface{}) (int64, error) {
|
|||
// Update records, bean's non-empty fields are updated contents,
|
||||
// condiBean' non-empty filds are conditions
|
||||
// CAUTION:
|
||||
// 1.bool will defaultly be updated content nor conditions
|
||||
// You should call UseBool if you have bool to use.
|
||||
// 2.float32 & float64 may be not inexact as conditions
|
||||
//
|
||||
// 1.bool will defaultly be updated content nor conditions
|
||||
// You should call UseBool if you have bool to use.
|
||||
// 2.float32 & float64 may be not inexact as conditions
|
||||
func (engine *Engine) Update(bean interface{}, condiBeans ...interface{}) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
|
@ -1230,12 +1223,21 @@ func (engine *Engine) Update(bean interface{}, condiBeans ...interface{}) (int64
|
|||
}
|
||||
|
||||
// Delete records, bean's non-empty fields are conditions
|
||||
// At least one condition must be set.
|
||||
func (engine *Engine) Delete(beans ...interface{}) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Delete(beans...)
|
||||
}
|
||||
|
||||
// Truncate records, bean's non-empty fields are conditions
|
||||
// In contrast to Delete this method allows deletes without conditions.
|
||||
func (engine *Engine) Truncate(beans ...interface{}) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Truncate(beans...)
|
||||
}
|
||||
|
||||
// Get retrieve one record from table, bean's non-empty fields
|
||||
// are conditions
|
||||
func (engine *Engine) Get(beans ...interface{}) (bool, error) {
|
||||
|
|
20
go.mod
20
go.mod
|
@ -1,21 +1,21 @@
|
|||
module xorm.io/xorm
|
||||
|
||||
go 1.13
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
gitee.com/travelliu/dm v1.8.11192
|
||||
github.com/denisenkom/go-mssqldb v0.10.0
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/denisenkom/go-mssqldb v0.12.3
|
||||
github.com/go-sql-driver/mysql v1.7.0
|
||||
github.com/goccy/go-json v0.8.1
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/jackc/pgx/v4 v4.12.0
|
||||
github.com/jackc/pgx/v4 v4.18.0
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/lib/pq v1.10.2
|
||||
github.com/mattn/go-sqlite3 v1.14.9
|
||||
github.com/shopspring/decimal v1.2.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/lib/pq v1.10.7
|
||||
github.com/mattn/go-sqlite3 v1.14.16
|
||||
github.com/shopspring/decimal v1.3.1
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/syndtr/goleveldb v1.0.0
|
||||
github.com/ziutek/mymysql v1.5.4
|
||||
modernc.org/sqlite v1.14.2
|
||||
xorm.io/builder v0.3.9
|
||||
modernc.org/sqlite v1.20.4
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978
|
||||
)
|
||||
|
|
572
go.sum
572
go.sum
|
@ -1,151 +1,60 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
|
||||
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
|
||||
gitee.com/travelliu/dm v1.8.11192 h1:aqJT0xhodZjRutIfEXxKYv0CxqmHUHzsbz6SFaRL6OY=
|
||||
gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
|
||||
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
|
||||
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
|
||||
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
|
||||
github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic=
|
||||
github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
|
||||
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
|
||||
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
|
||||
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/denisenkom/go-mssqldb v0.10.0 h1:QykgLZBorFE95+gO3u9esLd0BmbvpWp0/waNNZfHBM8=
|
||||
github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/denisenkom/go-mssqldb v0.12.3 h1:pBSGx9Tq67pBOTLmxNuirNTeB8Vjmf886Kx+8Y+8shw=
|
||||
github.com/denisenkom/go-mssqldb v0.12.3/go.mod h1:k0mtMFOnU+AihqFxPMiF05rtiDrorD1Vrm1KEz5hxDo=
|
||||
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
|
||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
|
||||
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
|
||||
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
|
||||
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/goccy/go-json v0.8.1 h1:4/Wjm0JIJaTDm8K1KcGrLHJoa8EsJ13YWeX+6Kfq6uI=
|
||||
github.com/goccy/go-json v0.8.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
|
||||
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
|
||||
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.5.3 h1:x95R7cp+rSeeqAMI2knLtQ0DKlaBhv2NrtrOvafPHRo=
|
||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
|
||||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
||||
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
|
||||
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
|
||||
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
|
||||
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
|
||||
|
@ -154,18 +63,17 @@ github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgO
|
|||
github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA=
|
||||
github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE=
|
||||
github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s=
|
||||
github.com/jackc/pgconn v1.4.0/go.mod h1:Y2O3ZDF0q4mMacyWV3AstPJpeHXWGEetiFttmq5lahk=
|
||||
github.com/jackc/pgconn v1.5.0/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
|
||||
github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
|
||||
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
|
||||
github.com/jackc/pgconn v1.8.1/go.mod h1:JV6m6b6jhjdmzchES0drzCcYcAHS1OPD5xu3OZ/lE2g=
|
||||
github.com/jackc/pgconn v1.9.0 h1:gqibKSTJup/ahCsNKyMZAniPuZEfIqfXFc8FOWVYR+Q=
|
||||
github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY=
|
||||
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
|
||||
github.com/jackc/pgconn v1.14.0 h1:vrbA9Ud87g6JdFWkHTJXppVce58qPIdP7N8y0Ml/A7Q=
|
||||
github.com/jackc/pgconn v1.14.0/go.mod h1:9mBNlny0UvkgJdCDvdVHYSjI+8tD2rnKK69Wz8ti++E=
|
||||
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
|
||||
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
|
||||
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
|
||||
github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd h1:eDErF6V/JPJON/B7s68BxwHgfmyOntHJQ8IOaz0x4R8=
|
||||
github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c=
|
||||
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc=
|
||||
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
|
||||
|
@ -174,52 +82,36 @@ github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod
|
|||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
|
||||
github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
||||
github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
||||
github.com/jackc/pgproto3/v2 v2.0.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgproto3/v2 v2.1.1 h1:7PQ/4gLoqnl87ZxL7xjO0DR5gYuviDCZxQJsUlFW1eI=
|
||||
github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg=
|
||||
github.com/jackc/pgproto3/v2 v2.3.2 h1:7eY55bdBeCz1F2fTzSz69QC+pG46jYq9/jtSPiJ5nn0=
|
||||
github.com/jackc/pgproto3/v2 v2.3.2/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
|
||||
github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
|
||||
github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
|
||||
github.com/jackc/pgtype v1.2.0/go.mod h1:5m2OfMh1wTK7x+Fk952IDmI4nw3nPrvtQdM0ZT4WpC0=
|
||||
github.com/jackc/pgtype v1.3.1-0.20200510190516-8cd94a14c75a/go.mod h1:vaogEUkALtxZMCH411K+tKzNpwzCKU+AnPzBKZ+I+Po=
|
||||
github.com/jackc/pgtype v1.3.1-0.20200606141011-f6355165a91c/go.mod h1:cvk9Bgu/VzJ9/lxTO5R5sf80p0DiucVtN7ZxvaC4GmQ=
|
||||
github.com/jackc/pgtype v1.7.0/go.mod h1:ZnHF+rMePVqDKaOfJVI4Q8IVvAQMryDlDkZnKOI75BE=
|
||||
github.com/jackc/pgtype v1.8.0 h1:iFVCcVhYlw0PulYCVoguRGm0SE9guIcPcccnLzHj8bA=
|
||||
github.com/jackc/pgtype v1.8.0/go.mod h1:PqDKcEBtllAtk/2p6z6SHdXW5UB+MhE75tUol2OKexE=
|
||||
github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM=
|
||||
github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw=
|
||||
github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
|
||||
github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
|
||||
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
|
||||
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
|
||||
github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXgo+kA=
|
||||
github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o=
|
||||
github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg=
|
||||
github.com/jackc/pgx/v4 v4.11.0/go.mod h1:i62xJgdrtVDsnL3U8ekyrQXEwGNTRoG7/8r+CIdYfcc=
|
||||
github.com/jackc/pgx/v4 v4.12.0 h1:xiP3TdnkwyslWNp77yE5XAPfxAsU9RMFDe0c1SwN8h4=
|
||||
github.com/jackc/pgx/v4 v4.12.0/go.mod h1:fE547h6VulLPA3kySjfnSG/e2D861g/50JlVUa/ub60=
|
||||
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
|
||||
github.com/jackc/pgx/v4 v4.18.0 h1:Ltaa1ePvc7msFGALnCrqKJVEByu/qYh5jJBYcDtAno4=
|
||||
github.com/jackc/pgx/v4 v4.18.0/go.mod h1:FydWkUyadDmdNH/mHnGob881GawxeEm7TcMCzkb+qQE=
|
||||
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
|
@ -229,151 +121,68 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
|
||||
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
|
||||
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA=
|
||||
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
|
||||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
|
||||
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
|
||||
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
|
||||
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
|
||||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
||||
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
||||
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
|
||||
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
|
||||
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA=
|
||||
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
||||
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
||||
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
|
||||
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
||||
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
|
||||
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
|
||||
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
|
||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
|
||||
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
|
@ -385,279 +194,152 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E
|
|||
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw=
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78 h1:M8tBwCtWD/cZV9DZpFYRUgaymAYAr+aIUTWzDaM3uPs=
|
||||
golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
|
||||
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
|
||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
lukechampine.com/uint128 v1.1.1 h1:pnxCASz787iMf+02ssImqk6OLt+Z5QHMoZyUXR4z6JU=
|
||||
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
||||
modernc.org/cc/v3 v3.33.6/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.33.9/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.33.11/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.34.0/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.0/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.4/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.5/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.7/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.8/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.10/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.15/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.16/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.17/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.35.18 h1:rMZhRcWrba0y3nVmdiQ7kxAgOOSq2m2f2VzjHLgEs6U=
|
||||
modernc.org/cc/v3 v3.35.18/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/ccgo/v3 v3.9.5/go.mod h1:umuo2EP2oDSBnD3ckjaVUXMrmeAw8C8OSICVa0iFf60=
|
||||
modernc.org/ccgo/v3 v3.10.0/go.mod h1:c0yBmkRFi7uW4J7fwx/JiijwOjeAeR2NoSaRVFPmjMw=
|
||||
modernc.org/ccgo/v3 v3.11.0/go.mod h1:dGNposbDp9TOZ/1KBxghxtUp/bzErD0/0QW4hhSaBMI=
|
||||
modernc.org/ccgo/v3 v3.11.1/go.mod h1:lWHxfsn13L3f7hgGsGlU28D9eUOf6y3ZYHKoPaKU0ag=
|
||||
modernc.org/ccgo/v3 v3.11.3/go.mod h1:0oHunRBMBiXOKdaglfMlRPBALQqsfrCKXgw9okQ3GEw=
|
||||
modernc.org/ccgo/v3 v3.12.4/go.mod h1:Bk+m6m2tsooJchP/Yk5ji56cClmN6R1cqc9o/YtbgBQ=
|
||||
modernc.org/ccgo/v3 v3.12.6/go.mod h1:0Ji3ruvpFPpz+yu+1m0wk68pdr/LENABhTrDkMDWH6c=
|
||||
modernc.org/ccgo/v3 v3.12.8/go.mod h1:Hq9keM4ZfjCDuDXxaHptpv9N24JhgBZmUG5q60iLgUo=
|
||||
modernc.org/ccgo/v3 v3.12.11/go.mod h1:0jVcmyDwDKDGWbcrzQ+xwJjbhZruHtouiBEvDfoIsdg=
|
||||
modernc.org/ccgo/v3 v3.12.14/go.mod h1:GhTu1k0YCpJSuWwtRAEHAol5W7g1/RRfS4/9hc9vF5I=
|
||||
modernc.org/ccgo/v3 v3.12.18/go.mod h1:jvg/xVdWWmZACSgOiAhpWpwHWylbJaSzayCqNOJKIhs=
|
||||
modernc.org/ccgo/v3 v3.12.20/go.mod h1:aKEdssiu7gVgSy/jjMastnv/q6wWGRbszbheXgWRHc8=
|
||||
modernc.org/ccgo/v3 v3.12.21/go.mod h1:ydgg2tEprnyMn159ZO/N4pLBqpL7NOkJ88GT5zNU2dE=
|
||||
modernc.org/ccgo/v3 v3.12.22/go.mod h1:nyDVFMmMWhMsgQw+5JH6B6o4MnZ+UQNw1pp52XYFPRk=
|
||||
modernc.org/ccgo/v3 v3.12.25/go.mod h1:UaLyWI26TwyIT4+ZFNjkyTbsPsY3plAEB6E7L/vZV3w=
|
||||
modernc.org/ccgo/v3 v3.12.29/go.mod h1:FXVjG7YLf9FetsS2OOYcwNhcdOLGt8S9bQ48+OP75cE=
|
||||
modernc.org/ccgo/v3 v3.12.36/go.mod h1:uP3/Fiezp/Ga8onfvMLpREq+KUjUmYMxXPO8tETHtA8=
|
||||
modernc.org/ccgo/v3 v3.12.38/go.mod h1:93O0G7baRST1vNj4wnZ49b1kLxt0xCW5Hsa2qRaZPqc=
|
||||
modernc.org/ccgo/v3 v3.12.43/go.mod h1:k+DqGXd3o7W+inNujK15S5ZYuPoWYLpF5PYougCmthU=
|
||||
modernc.org/ccgo/v3 v3.12.46/go.mod h1:UZe6EvMSqOxaJ4sznY7b23/k13R8XNlyWsO5bAmSgOE=
|
||||
modernc.org/ccgo/v3 v3.12.47/go.mod h1:m8d6p0zNps187fhBwzY/ii6gxfjob1VxWb919Nk1HUk=
|
||||
modernc.org/ccgo/v3 v3.12.50/go.mod h1:bu9YIwtg+HXQxBhsRDE+cJjQRuINuT9PUK4orOco/JI=
|
||||
modernc.org/ccgo/v3 v3.12.51/go.mod h1:gaIIlx4YpmGO2bLye04/yeblmvWEmE4BBBls4aJXFiE=
|
||||
modernc.org/ccgo/v3 v3.12.53/go.mod h1:8xWGGTFkdFEWBEsUmi+DBjwu/WLy3SSOrqEmKUjMeEg=
|
||||
modernc.org/ccgo/v3 v3.12.54/go.mod h1:yANKFTm9llTFVX1FqNKHE0aMcQb1fuPJx6p8AcUx+74=
|
||||
modernc.org/ccgo/v3 v3.12.55/go.mod h1:rsXiIyJi9psOwiBkplOaHye5L4MOOaCjHg1Fxkj7IeU=
|
||||
modernc.org/ccgo/v3 v3.12.56/go.mod h1:ljeFks3faDseCkr60JMpeDb2GSO3TKAmrzm7q9YOcMU=
|
||||
modernc.org/ccgo/v3 v3.12.57/go.mod h1:hNSF4DNVgBl8wYHpMvPqQWDQx8luqxDnNGCMM4NFNMc=
|
||||
modernc.org/ccgo/v3 v3.12.60/go.mod h1:k/Nn0zdO1xHVWjPYVshDeWKqbRWIfif5dtsIOCUVMqM=
|
||||
modernc.org/ccgo/v3 v3.12.65/go.mod h1:D6hQtKxPNZiY6wDBtehSGKFKmyXn53F8nGTpH+POmS4=
|
||||
modernc.org/ccgo/v3 v3.12.66/go.mod h1:jUuxlCFZTUZLMV08s7B1ekHX5+LIAurKTTaugUr/EhQ=
|
||||
modernc.org/ccgo/v3 v3.12.67/go.mod h1:Bll3KwKvGROizP2Xj17GEGOTrlvB1XcVaBrC90ORO84=
|
||||
modernc.org/ccgo/v3 v3.12.73/go.mod h1:hngkB+nUUqzOf3iqsM48Gf1FZhY599qzVg1iX+BT3cQ=
|
||||
modernc.org/ccgo/v3 v3.12.81/go.mod h1:p2A1duHoBBg1mFtYvnhAnQyI6vL0uw5PGYLSIgF6rYY=
|
||||
modernc.org/ccgo/v3 v3.12.82 h1:wudcnJyjLj1aQQCXF3IM9Gz2X6UNjw+afIghzdtn0v8=
|
||||
modernc.org/ccgo/v3 v3.12.82/go.mod h1:ApbflUfa5BKadjHynCficldU1ghjen84tuM5jRynB7w=
|
||||
modernc.org/ccorpus v1.11.1 h1:K0qPfpVG1MJh5BYazccnmhywH4zHuOgJXgbjzyp6dWA=
|
||||
modernc.org/ccorpus v1.11.1/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ=
|
||||
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
|
||||
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
||||
modernc.org/cc/v3 v3.37.0/go.mod h1:vtL+3mdHx/wcj3iEGz84rQa8vEqR6XM84v5Lcvfph20=
|
||||
modernc.org/cc/v3 v3.38.1/go.mod h1:vtL+3mdHx/wcj3iEGz84rQa8vEqR6XM84v5Lcvfph20=
|
||||
modernc.org/cc/v3 v3.40.0 h1:P3g79IUS/93SYhtoeaHW+kRCIrYaxJ27MFPv+7kaTOw=
|
||||
modernc.org/cc/v3 v3.40.0/go.mod h1:/bTg4dnWkSXowUO6ssQKnOV0yMVxDYNIsIrzqTFDGH0=
|
||||
modernc.org/ccgo/v3 v3.0.0-20220904174949-82d86e1b6d56/go.mod h1:YSXjPL62P2AMSxBphRHPn7IkzhVHqkvOnRKAKh+W6ZI=
|
||||
modernc.org/ccgo/v3 v3.0.0-20220910160915-348f15de615a/go.mod h1:8p47QxPkdugex9J4n9P2tLZ9bK01yngIVp00g4nomW0=
|
||||
modernc.org/ccgo/v3 v3.16.13-0.20221017192402-261537637ce8/go.mod h1:fUB3Vn0nVPReA+7IG7yZDfjv1TMWjhQP8gCxrFAtL5g=
|
||||
modernc.org/ccgo/v3 v3.16.13 h1:Mkgdzl46i5F/CNR/Kj80Ri59hC8TKAhZrYSaqvkwzUw=
|
||||
modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY=
|
||||
modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
|
||||
modernc.org/ccorpus v1.11.6/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ=
|
||||
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
|
||||
modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM=
|
||||
modernc.org/libc v1.9.8/go.mod h1:U1eq8YWr/Kc1RWCMFUWEdkTg8OTcfLw2kY8EDwl039w=
|
||||
modernc.org/libc v1.9.11/go.mod h1:NyF3tsA5ArIjJ83XB0JlqhjTabTCHm9aX4XMPHyQn0Q=
|
||||
modernc.org/libc v1.11.0/go.mod h1:2lOfPmj7cz+g1MrPNmX65QCzVxgNq2C5o0jdLY2gAYg=
|
||||
modernc.org/libc v1.11.2/go.mod h1:ioIyrl3ETkugDO3SGZ+6EOKvlP3zSOycUETe4XM4n8M=
|
||||
modernc.org/libc v1.11.5/go.mod h1:k3HDCP95A6U111Q5TmG3nAyUcp3kR5YFZTeDS9v8vSU=
|
||||
modernc.org/libc v1.11.6/go.mod h1:ddqmzR6p5i4jIGK1d/EiSw97LBcE3dK24QEwCFvgNgE=
|
||||
modernc.org/libc v1.11.11/go.mod h1:lXEp9QOOk4qAYOtL3BmMve99S5Owz7Qyowzvg6LiZso=
|
||||
modernc.org/libc v1.11.13/go.mod h1:ZYawJWlXIzXy2Pzghaf7YfM8OKacP3eZQI81PDLFdY8=
|
||||
modernc.org/libc v1.11.16/go.mod h1:+DJquzYi+DMRUtWI1YNxrlQO6TcA5+dRRiq8HWBWRC8=
|
||||
modernc.org/libc v1.11.19/go.mod h1:e0dgEame6mkydy19KKaVPBeEnyJB4LGNb0bBH1EtQ3I=
|
||||
modernc.org/libc v1.11.24/go.mod h1:FOSzE0UwookyT1TtCJrRkvsOrX2k38HoInhw+cSCUGk=
|
||||
modernc.org/libc v1.11.26/go.mod h1:SFjnYi9OSd2W7f4ct622o/PAYqk7KHv6GS8NZULIjKY=
|
||||
modernc.org/libc v1.11.27/go.mod h1:zmWm6kcFXt/jpzeCgfvUNswM0qke8qVwxqZrnddlDiE=
|
||||
modernc.org/libc v1.11.28/go.mod h1:Ii4V0fTFcbq3qrv3CNn+OGHAvzqMBvC7dBNyC4vHZlg=
|
||||
modernc.org/libc v1.11.31/go.mod h1:FpBncUkEAtopRNJj8aRo29qUiyx5AvAlAxzlx9GNaVM=
|
||||
modernc.org/libc v1.11.34/go.mod h1:+Tzc4hnb1iaX/SKAutJmfzES6awxfU1BPvrrJO0pYLg=
|
||||
modernc.org/libc v1.11.37/go.mod h1:dCQebOwoO1046yTrfUE5nX1f3YpGZQKNcITUYWlrAWo=
|
||||
modernc.org/libc v1.11.39/go.mod h1:mV8lJMo2S5A31uD0k1cMu7vrJbSA3J3waQJxpV4iqx8=
|
||||
modernc.org/libc v1.11.42/go.mod h1:yzrLDU+sSjLE+D4bIhS7q1L5UwXDOw99PLSX0BlZvSQ=
|
||||
modernc.org/libc v1.11.44/go.mod h1:KFq33jsma7F5WXiYelU8quMJasCCTnHK0mkri4yPHgA=
|
||||
modernc.org/libc v1.11.45/go.mod h1:Y192orvfVQQYFzCNsn+Xt0Hxt4DiO4USpLNXBlXg/tM=
|
||||
modernc.org/libc v1.11.47/go.mod h1:tPkE4PzCTW27E6AIKIR5IwHAQKCAtudEIeAV1/SiyBg=
|
||||
modernc.org/libc v1.11.49/go.mod h1:9JrJuK5WTtoTWIFQ7QjX2Mb/bagYdZdscI3xrvHbXjE=
|
||||
modernc.org/libc v1.11.51/go.mod h1:R9I8u9TS+meaWLdbfQhq2kFknTW0O3aw3kEMqDDxMaM=
|
||||
modernc.org/libc v1.11.53/go.mod h1:5ip5vWYPAoMulkQ5XlSJTy12Sz5U6blOQiYasilVPsU=
|
||||
modernc.org/libc v1.11.54/go.mod h1:S/FVnskbzVUrjfBqlGFIPA5m7UwB3n9fojHhCNfSsnw=
|
||||
modernc.org/libc v1.11.55/go.mod h1:j2A5YBRm6HjNkoSs/fzZrSxCuwWqcMYTDPLNx0URn3M=
|
||||
modernc.org/libc v1.11.56/go.mod h1:pakHkg5JdMLt2OgRadpPOTnyRXm/uzu+Yyg/LSLdi18=
|
||||
modernc.org/libc v1.11.58/go.mod h1:ns94Rxv0OWyoQrDqMFfWwka2BcaF6/61CqJRK9LP7S8=
|
||||
modernc.org/libc v1.11.70/go.mod h1:DUOmMYe+IvKi9n6Mycyx3DbjfzSKrdr/0Vgt3j7P5gw=
|
||||
modernc.org/libc v1.11.71/go.mod h1:DUOmMYe+IvKi9n6Mycyx3DbjfzSKrdr/0Vgt3j7P5gw=
|
||||
modernc.org/libc v1.11.75/go.mod h1:dGRVugT6edz361wmD9gk6ax1AbDSe0x5vji0dGJiPT0=
|
||||
modernc.org/libc v1.11.82/go.mod h1:NF+Ek1BOl2jeC7lw3a7Jj5PWyHPwWD4aq3wVKxqV1fI=
|
||||
modernc.org/libc v1.11.86/go.mod h1:ePuYgoQLmvxdNT06RpGnaDKJmDNEkV7ZPKI2jnsvZoE=
|
||||
modernc.org/libc v1.11.87 h1:PzIzOqtlzMDDcCzJ5cUP6h/Ku6Fa9iyflP2ccTY64aE=
|
||||
modernc.org/libc v1.11.87/go.mod h1:Qvd5iXTeLhI5PS0XSyqMY99282y+3euapQFxM7jYnpY=
|
||||
modernc.org/mathutil v1.1.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||
modernc.org/mathutil v1.4.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||
modernc.org/mathutil v1.4.1 h1:ij3fYGe8zBF4Vu+g0oT7mB06r8sqGWKuJu1yXeR4by8=
|
||||
modernc.org/mathutil v1.4.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||
modernc.org/memory v1.0.4/go.mod h1:nV2OApxradM3/OVbs2/0OsP6nPfakXpi50C7dcoHXlc=
|
||||
modernc.org/memory v1.0.5 h1:XRch8trV7GgvTec2i7jc33YlUI0RKVDBvZ5eZ5m8y14=
|
||||
modernc.org/memory v1.0.5/go.mod h1:B7OYswTRnfGg+4tDH1t1OeUNnsy2viGTdME4tzd+IjM=
|
||||
modernc.org/opt v0.1.1 h1:/0RX92k9vwVeDXj+Xn23DKp2VJubL7k8qNffND6qn3A=
|
||||
modernc.org/libc v1.17.4/go.mod h1:WNg2ZH56rDEwdropAJeZPQkXmDwh+JCA1s/htl6r2fA=
|
||||
modernc.org/libc v1.18.0/go.mod h1:vj6zehR5bfc98ipowQOM2nIDUZnVew/wNC/2tOGS+q0=
|
||||
modernc.org/libc v1.19.0/go.mod h1:ZRfIaEkgrYgZDl6pa4W39HgN5G/yDW+NRmNKZBDFrk0=
|
||||
modernc.org/libc v1.20.3/go.mod h1:ZRfIaEkgrYgZDl6pa4W39HgN5G/yDW+NRmNKZBDFrk0=
|
||||
modernc.org/libc v1.21.4/go.mod h1:przBsL5RDOZajTVslkugzLBj1evTue36jEomFQOoYuI=
|
||||
modernc.org/libc v1.22.2 h1:4U7v51GyhlWqQmwCHj28Rdq2Yzwk55ovjFrdPjs8Hb0=
|
||||
modernc.org/libc v1.22.2/go.mod h1:uvQavJ1pZ0hIoC/jfqNoMLURIMhKzINIWypNM17puug=
|
||||
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
|
||||
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||
modernc.org/memory v1.3.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
|
||||
modernc.org/memory v1.4.0 h1:crykUfNSnMAXaOJnnxcSzbUGMqkLWjklJKkBK2nwZwk=
|
||||
modernc.org/memory v1.4.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
|
||||
modernc.org/opt v0.1.1/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sqlite v1.14.2 h1:ohsW2+e+Qe2To1W6GNezzKGwjXwSax6R+CrhRxVaFbE=
|
||||
modernc.org/sqlite v1.14.2/go.mod h1:yqfn85u8wVOE6ub5UT8VI9JjhrwBUUCNyTACN0h6Sx8=
|
||||
modernc.org/strutil v1.1.1 h1:xv+J1BXY3Opl2ALrBwyfEikFAj8pmqcpnfmuwUwcozs=
|
||||
modernc.org/strutil v1.1.1/go.mod h1:DE+MQQ/hjKBZS2zNInV5hhcipt5rLPWkmpbGeW5mmdw=
|
||||
modernc.org/tcl v1.8.13 h1:V0sTNBw0Re86PvXZxuCub3oO9WrSTqALgrwNZNvLFGw=
|
||||
modernc.org/tcl v1.8.13/go.mod h1:V+q/Ef0IJaNUSECieLU4o+8IScapxnMyFV6i/7uQlAY=
|
||||
modernc.org/token v1.0.0 h1:a0jaWiNMDhDUtqOj09wvjWWAqd3q7WpBulmL9H2egsk=
|
||||
modernc.org/token v1.0.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
modernc.org/z v1.2.19 h1:BGyRFWhDVn5LFS5OcX4Yd/MlpRTOc7hOPTdcIpCiUao=
|
||||
modernc.org/z v1.2.19/go.mod h1:+ZpP0pc4zz97eukOzW3xagV/lS82IpPN9NGG5pNF9vY=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
||||
xorm.io/builder v0.3.9 h1:Sd65/LdWyO7LR8+Cbd+e7mm3sK/7U9k0jS3999IDHMc=
|
||||
xorm.io/builder v0.3.9/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sqlite v1.20.4 h1:J8+m2trkN+KKoE7jglyHYYYiaq5xmz2HoHJIiBlRzbE=
|
||||
modernc.org/sqlite v1.20.4/go.mod h1:zKcGyrICaxNTMEHSr1HQ2GUraP0j+845GYw37+EyT6A=
|
||||
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
|
||||
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
|
||||
modernc.org/tcl v1.15.0 h1:oY+JeD11qVVSgVvodMJsu7Edf8tr5E/7tuhF5cNYz34=
|
||||
modernc.org/tcl v1.15.0/go.mod h1:xRoGotBZ6dU+Zo2tca+2EqVEeMmOUBzHnhIwq4YrVnE=
|
||||
modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg=
|
||||
modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
modernc.org/z v1.7.0 h1:xkDw/KepgEjeizO2sNco+hqYkU12taxQFqPEmgm1GWE=
|
||||
modernc.org/z v1.7.0/go.mod h1:hVdgNMh8ggTuRG1rGU8x+xGRFfiQUIAw0ZqlPy8+HyQ=
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 h1:bvLlAPW1ZMTWA32LuZMBEGHAUOcATZjzHcotf3SWweM=
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build dm
|
||||
// +build dm
|
||||
|
||||
package integrations
|
||||
|
|
|
@ -255,33 +255,31 @@ func TestDBVersion(t *testing.T) {
|
|||
fmt.Println(testEngine.Dialect().URI().DBType, "version is", version)
|
||||
}
|
||||
|
||||
func TestGetColumns(t *testing.T) {
|
||||
if testEngine.Dialect().URI().DBType != schemas.POSTGRES {
|
||||
func TestGetColumnsComment(t *testing.T) {
|
||||
switch testEngine.Dialect().URI().DBType {
|
||||
case schemas.POSTGRES, schemas.MYSQL:
|
||||
default:
|
||||
t.Skip()
|
||||
return
|
||||
}
|
||||
comment := "this is a comment"
|
||||
type TestCommentStruct struct {
|
||||
HasComment int
|
||||
HasComment int `xorm:"comment('this is a comment')"`
|
||||
NoComment int
|
||||
}
|
||||
|
||||
assertSync(t, new(TestCommentStruct))
|
||||
|
||||
comment := "this is a comment"
|
||||
sql := fmt.Sprintf("comment on column %s.%s is '%s'", testEngine.TableName(new(TestCommentStruct), true), "has_comment", comment)
|
||||
_, err := testEngine.Exec(sql)
|
||||
assert.NoError(t, err)
|
||||
|
||||
tables, err := testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
tableName := testEngine.GetColumnMapper().Obj2Table("TestCommentStruct")
|
||||
var hasComment, noComment string
|
||||
for _, table := range tables {
|
||||
if table.Name == tableName {
|
||||
col := table.GetColumn("has_comment")
|
||||
col := table.GetColumn(testEngine.GetColumnMapper().Obj2Table("HasComment"))
|
||||
assert.NotNil(t, col)
|
||||
hasComment = col.Comment
|
||||
col2 := table.GetColumn("no_comment")
|
||||
col2 := table.GetColumn(testEngine.GetColumnMapper().Obj2Table("NoComment"))
|
||||
assert.NotNil(t, col2)
|
||||
noComment = col2.Comment
|
||||
break
|
||||
|
@ -290,3 +288,76 @@ func TestGetColumns(t *testing.T) {
|
|||
assert.Equal(t, comment, hasComment)
|
||||
assert.Zero(t, noComment)
|
||||
}
|
||||
|
||||
type TestCommentUpdate struct {
|
||||
HasComment int `xorm:"bigint comment('this is a comment before update')"`
|
||||
}
|
||||
|
||||
func (m *TestCommentUpdate) TableName() string {
|
||||
return "test_comment_struct"
|
||||
}
|
||||
|
||||
type TestCommentUpdate2 struct {
|
||||
HasComment int `xorm:"bigint comment('this is a comment after update')"`
|
||||
}
|
||||
|
||||
func (m *TestCommentUpdate2) TableName() string {
|
||||
return "test_comment_struct"
|
||||
}
|
||||
|
||||
func TestColumnCommentUpdate(t *testing.T) {
|
||||
comment := "this is a comment after update"
|
||||
assertSync(t, new(TestCommentUpdate))
|
||||
assert.NoError(t, testEngine.Sync2(new(TestCommentUpdate2))) // modify table column comment
|
||||
|
||||
switch testEngine.Dialect().URI().DBType {
|
||||
case schemas.POSTGRES, schemas.MYSQL: // only postgres / mysql dialect implement the feature of modify comment in postgres.ModifyColumnSQL
|
||||
default:
|
||||
t.Skip()
|
||||
return
|
||||
}
|
||||
tables, err := testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
tableName := "test_comment_struct"
|
||||
var hasComment string
|
||||
for _, table := range tables {
|
||||
if table.Name == tableName {
|
||||
col := table.GetColumn(testEngine.GetColumnMapper().Obj2Table("HasComment"))
|
||||
assert.NotNil(t, col)
|
||||
hasComment = col.Comment
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.Equal(t, comment, hasComment)
|
||||
}
|
||||
|
||||
func TestGetColumnsLength(t *testing.T) {
|
||||
var max_length int64
|
||||
switch testEngine.Dialect().URI().DBType {
|
||||
case schemas.POSTGRES:
|
||||
max_length = 0
|
||||
case schemas.MYSQL:
|
||||
max_length = 65535
|
||||
default:
|
||||
t.Skip()
|
||||
return
|
||||
}
|
||||
|
||||
type TestLengthStringStruct struct {
|
||||
Content string `xorm:"TEXT NOT NULL"`
|
||||
}
|
||||
|
||||
assertSync(t, new(TestLengthStringStruct))
|
||||
|
||||
tables, err := testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
tableLengthStringName := testEngine.GetColumnMapper().Obj2Table("TestLengthStringStruct")
|
||||
for _, table := range tables {
|
||||
if table.Name == tableLengthStringName {
|
||||
col := table.GetColumn("content")
|
||||
assert.Equal(t, col.Length, max_length)
|
||||
assert.Zero(t, col.Length2)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ func TestRows(t *testing.T) {
|
|||
}
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var tbName = testEngine.Quote(testEngine.TableName(user, true))
|
||||
tbName := testEngine.Quote(testEngine.TableName(user, true))
|
||||
rows2, err := testEngine.SQL("SELECT * FROM " + tbName).Rows(new(UserRows))
|
||||
assert.NoError(t, err)
|
||||
defer rows2.Close()
|
||||
|
@ -92,7 +92,7 @@ func TestRowsMyTableName(t *testing.T) {
|
|||
IsMan bool
|
||||
}
|
||||
|
||||
var tableName = "user_rows_my_table_name"
|
||||
tableName := "user_rows_my_table_name"
|
||||
|
||||
assert.NoError(t, testEngine.Table(tableName).Sync(new(UserRowsMyTable)))
|
||||
|
||||
|
@ -206,3 +206,75 @@ func TestRowsScanVars(t *testing.T) {
|
|||
assert.NoError(t, rows.Err())
|
||||
assert.EqualValues(t, 2, cnt)
|
||||
}
|
||||
|
||||
func TestRowsScanBytes(t *testing.T) {
|
||||
type RowsScanBytes struct {
|
||||
Id int64
|
||||
Bytes1 []byte
|
||||
Bytes2 []byte
|
||||
}
|
||||
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assert.NoError(t, testEngine.Sync(new(RowsScanBytes)))
|
||||
|
||||
cnt, err := testEngine.Insert(&RowsScanBytes{
|
||||
Bytes1: []byte("bytes1"),
|
||||
Bytes2: []byte("bytes2"),
|
||||
}, &RowsScanBytes{
|
||||
Bytes1: []byte("bytes1-1"),
|
||||
Bytes2: []byte("bytes2-2"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, cnt)
|
||||
|
||||
{
|
||||
rows, err := testEngine.Cols("bytes1, bytes2").Rows(new(RowsScanBytes))
|
||||
assert.NoError(t, err)
|
||||
defer rows.Close()
|
||||
|
||||
cnt = 0
|
||||
var bytes1 []byte
|
||||
var bytes2 []byte
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&bytes1, &bytes2)
|
||||
assert.NoError(t, err)
|
||||
if cnt == 0 {
|
||||
assert.EqualValues(t, []byte("bytes1"), bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2"), bytes2)
|
||||
} else if cnt == 1 {
|
||||
// bytes1 now should be `bytes1` but will be override
|
||||
assert.EqualValues(t, []byte("bytes1-1"), bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2-2"), bytes2)
|
||||
}
|
||||
cnt++
|
||||
}
|
||||
assert.NoError(t, rows.Err())
|
||||
assert.EqualValues(t, 2, cnt)
|
||||
rows.Close()
|
||||
}
|
||||
|
||||
{
|
||||
rows, err := testEngine.Cols("bytes1, bytes2").Rows(new(RowsScanBytes))
|
||||
assert.NoError(t, err)
|
||||
defer rows.Close()
|
||||
|
||||
cnt = 0
|
||||
var rsb RowsScanBytes
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&rsb)
|
||||
assert.NoError(t, err)
|
||||
if cnt == 0 {
|
||||
assert.EqualValues(t, []byte("bytes1"), rsb.Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2"), rsb.Bytes2)
|
||||
} else if cnt == 1 {
|
||||
// bytes1 now should be `bytes1` but will be override
|
||||
assert.EqualValues(t, []byte("bytes1-1"), rsb.Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2-2"), rsb.Bytes2)
|
||||
}
|
||||
cnt++
|
||||
}
|
||||
assert.NoError(t, rows.Err())
|
||||
assert.EqualValues(t, 2, cnt)
|
||||
rows.Close()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
package integrations
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -248,7 +250,9 @@ func TestSyncTable3(t *testing.T) {
|
|||
tableInfo, err := testEngine.TableInfo(new(SyncTable5))
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, testEngine.Dialect().SQLType(tableInfo.GetColumn("name")), testEngine.Dialect().SQLType(tables[0].GetColumn("name")))
|
||||
assert.EqualValues(t, testEngine.Dialect().SQLType(tableInfo.GetColumn("text")), testEngine.Dialect().SQLType(tables[0].GetColumn("text")))
|
||||
/* Engine.DBMetas() returns the size of the column from the database but Engine.TableInfo() might not be able to guess the column size.
|
||||
For example using MySQL/MariaDB: when utf-8 charset is used, "`xorm:"TEXT(21846)`" creates a MEDIUMTEXT column not a TEXT column. */
|
||||
assert.True(t, testEngine.Dialect().SQLType(tables[0].GetColumn("text")) == testEngine.Dialect().SQLType(tableInfo.GetColumn("text")) || strings.HasPrefix(testEngine.Dialect().SQLType(tables[0].GetColumn("text")), testEngine.Dialect().SQLType(tableInfo.GetColumn("text"))+"("))
|
||||
assert.EqualValues(t, testEngine.Dialect().SQLType(tableInfo.GetColumn("char")), testEngine.Dialect().SQLType(tables[0].GetColumn("char")))
|
||||
assert.EqualValues(t, testEngine.Dialect().SQLType(tableInfo.GetColumn("ten_char")), testEngine.Dialect().SQLType(tables[0].GetColumn("ten_char")))
|
||||
assert.EqualValues(t, testEngine.Dialect().SQLType(tableInfo.GetColumn("ten_var_char")), testEngine.Dialect().SQLType(tables[0].GetColumn("ten_var_char")))
|
||||
|
@ -322,14 +326,14 @@ func TestIsTableEmpty(t *testing.T) {
|
|||
|
||||
type PictureEmpty struct {
|
||||
Id int64
|
||||
Url string `xorm:"unique"` //image's url
|
||||
Url string `xorm:"unique"` // image's url
|
||||
Title string
|
||||
Description string
|
||||
Created time.Time `xorm:"created"`
|
||||
ILike int
|
||||
PageView int
|
||||
From_url string // nolint
|
||||
Pre_url string `xorm:"unique"` //pre view image's url
|
||||
Pre_url string `xorm:"unique"` // pre view image's url
|
||||
Uid int64
|
||||
}
|
||||
|
||||
|
@ -455,7 +459,7 @@ func TestSync2_2(t *testing.T) {
|
|||
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
var tableNames = make(map[string]bool)
|
||||
tableNames := make(map[string]bool)
|
||||
for i := 0; i < 10; i++ {
|
||||
tableName := fmt.Sprintf("test_sync2_index_%d", i)
|
||||
tableNames[tableName] = true
|
||||
|
@ -533,3 +537,111 @@ func TestModifyColum(t *testing.T) {
|
|||
_, err := testEngine.Exec(alterSQL)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
type TestCollateColumn struct {
|
||||
Id int64
|
||||
UserId int64 `xorm:"unique(s)"`
|
||||
Name string `xorm:"varchar(20) unique(s)"`
|
||||
dbtype string `xorm:"-"`
|
||||
}
|
||||
|
||||
func (t TestCollateColumn) TableCollations() []*schemas.Collation {
|
||||
if t.dbtype == string(schemas.MYSQL) {
|
||||
return []*schemas.Collation{
|
||||
{
|
||||
Name: "utf8mb4_general_ci",
|
||||
Column: "name",
|
||||
},
|
||||
}
|
||||
} else if t.dbtype == string(schemas.MSSQL) {
|
||||
return []*schemas.Collation{
|
||||
{
|
||||
Name: "Latin1_General_CI_AS",
|
||||
Column: "name",
|
||||
},
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestCollate(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, &TestCollateColumn{
|
||||
dbtype: string(testEngine.Dialect().URI().DBType),
|
||||
})
|
||||
|
||||
_, err := testEngine.Insert(&TestCollateColumn{
|
||||
UserId: 1,
|
||||
Name: "test",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
_, err = testEngine.Insert(&TestCollateColumn{
|
||||
UserId: 1,
|
||||
Name: "Test",
|
||||
})
|
||||
if testEngine.Dialect().URI().DBType == schemas.MYSQL {
|
||||
ver, err1 := testEngine.DBVersion()
|
||||
assert.NoError(t, err1)
|
||||
|
||||
tables, err1 := testEngine.DBMetas()
|
||||
assert.NoError(t, err1)
|
||||
for _, table := range tables {
|
||||
if table.Name == "test_collate_column" {
|
||||
col := table.GetColumn("name")
|
||||
if col == nil {
|
||||
assert.Error(t, errors.New("not found column"))
|
||||
return
|
||||
}
|
||||
// tidb doesn't follow utf8mb4_general_ci
|
||||
if col.Collation == "utf8mb4_general_ci" && ver.Edition != "TiDB" {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if testEngine.Dialect().URI().DBType == schemas.MSSQL {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// Since SQLITE don't support modify column SQL, currrently just ignore
|
||||
if testEngine.Dialect().URI().DBType != schemas.MYSQL && testEngine.Dialect().URI().DBType != schemas.MSSQL {
|
||||
return
|
||||
}
|
||||
|
||||
var newCollation string
|
||||
if testEngine.Dialect().URI().DBType == schemas.MYSQL {
|
||||
newCollation = "utf8mb4_bin"
|
||||
} else if testEngine.Dialect().URI().DBType != schemas.MSSQL {
|
||||
newCollation = "Latin1_General_CS_AS"
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
alterSQL := testEngine.Dialect().ModifyColumnSQL("test_collate_column", &schemas.Column{
|
||||
Name: "name",
|
||||
SQLType: schemas.SQLType{
|
||||
Name: "VARCHAR",
|
||||
},
|
||||
Length: 20,
|
||||
Nullable: true,
|
||||
DefaultIsEmpty: true,
|
||||
Collation: newCollation,
|
||||
})
|
||||
_, err = testEngine.Exec(alterSQL)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = testEngine.Insert(&TestCollateColumn{
|
||||
UserId: 1,
|
||||
Name: "test1",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
_, err = testEngine.Insert(&TestCollateColumn{
|
||||
UserId: 1,
|
||||
Name: "Test1",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
}
|
|
@ -89,7 +89,7 @@ func TestCountWithOthers(t *testing.T) {
|
|||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
total, err := testEngine.OrderBy("`id` desc").Limit(1).Count(new(CountWithOthers))
|
||||
total, err := testEngine.OrderBy("count(`id`) desc").Limit(1).Count(new(CountWithOthers))
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, total)
|
||||
}
|
||||
|
@ -118,11 +118,16 @@ func TestWithTableName(t *testing.T) {
|
|||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
total, err := testEngine.OrderBy("`id` desc").Count(new(CountWithTableName))
|
||||
total, err := testEngine.OrderBy("count(`id`) desc").Count(new(CountWithTableName))
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, total)
|
||||
|
||||
total, err = testEngine.OrderBy("`id` desc").Count(CountWithTableName{})
|
||||
total, err = testEngine.OrderBy("count(`id`) desc").Count(CountWithTableName{})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, total)
|
||||
|
||||
// the orderby will be ignored by count because some databases will return errors if the orderby columns not in group by
|
||||
total, err = testEngine.OrderBy("`name`").Count(CountWithTableName{})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, total)
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ func TestUnscopeDelete(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var nowUnix = time.Now().Unix()
|
||||
nowUnix := time.Now().Unix()
|
||||
var s UnscopeDeleteStruct
|
||||
cnt, err = testEngine.ID(1).Delete(&s)
|
||||
assert.NoError(t, err)
|
||||
|
@ -266,3 +266,28 @@ func TestDelete2(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.False(t, has)
|
||||
}
|
||||
|
||||
func TestTruncate(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TruncateUser struct {
|
||||
Uid int64 `xorm:"id pk not null autoincr"`
|
||||
}
|
||||
|
||||
assert.NoError(t, testEngine.Sync(new(TruncateUser)))
|
||||
|
||||
cnt, err := testEngine.Insert(&TruncateUser{})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
_, err = testEngine.Delete(&TruncateUser{})
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = testEngine.Truncate(&TruncateUser{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
user2 := TruncateUser{}
|
||||
has, err := testEngine.ID(1).Get(&user2)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, has)
|
||||
}
|
||||
|
|
|
@ -8,9 +8,11 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/names"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -40,14 +42,14 @@ func TestJoinLimit(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var checklist = CheckList{
|
||||
checklist := CheckList{
|
||||
Eid: emp.Id,
|
||||
}
|
||||
cnt, err = testEngine.Insert(&checklist)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var salary = Salary{
|
||||
salary := Salary{
|
||||
Lid: checklist.Id,
|
||||
}
|
||||
cnt, err = testEngine.Insert(&salary)
|
||||
|
@ -89,7 +91,7 @@ func TestFind(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
users2 := make([]Userinfo, 0)
|
||||
var tbName = testEngine.Quote(testEngine.TableName(new(Userinfo), true))
|
||||
tbName := testEngine.Quote(testEngine.TableName(new(Userinfo), true))
|
||||
err = testEngine.SQL("select * from " + tbName).Find(&users2)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
@ -119,7 +121,7 @@ func (TeamUser) TableName() string {
|
|||
}
|
||||
|
||||
func TestFind3(t *testing.T) {
|
||||
var teamUser = new(TeamUser)
|
||||
teamUser := new(TeamUser)
|
||||
assert.NoError(t, PrepareEngine())
|
||||
err := testEngine.Sync(new(Team), teamUser)
|
||||
assert.NoError(t, err)
|
||||
|
@ -247,6 +249,10 @@ func TestOrder(t *testing.T) {
|
|||
users2 := make([]Userinfo, 0)
|
||||
err = testEngine.Asc("id", "username").Desc("height").Find(&users2)
|
||||
assert.NoError(t, err)
|
||||
|
||||
users = make([]Userinfo, 0)
|
||||
err = testEngine.OrderBy("CASE WHEN username LIKE ? THEN 0 ELSE 1 END DESC", "a").Find(&users)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestGroupBy(t *testing.T) {
|
||||
|
@ -426,7 +432,7 @@ func TestFindBool(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, cnt)
|
||||
|
||||
var results = make([]FindBoolStruct, 0, 2)
|
||||
results := make([]FindBoolStruct, 0, 2)
|
||||
err = testEngine.Find(&results)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, len(results))
|
||||
|
@ -457,7 +463,7 @@ func TestFindMark(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, cnt)
|
||||
|
||||
var results = make([]Mark, 0, 2)
|
||||
results := make([]Mark, 0, 2)
|
||||
err = testEngine.Find(&results)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, len(results))
|
||||
|
@ -486,7 +492,7 @@ func TestFindAndCountOneFunc(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, cnt)
|
||||
|
||||
var results = make([]FindAndCountStruct, 0, 2)
|
||||
results := make([]FindAndCountStruct, 0, 2)
|
||||
cnt, err = testEngine.Limit(1).FindAndCount(&results)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(results))
|
||||
|
@ -611,14 +617,14 @@ func TestFindAndCount2(t *testing.T) {
|
|||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestFindAndCountUser), new(TestFindAndCountHotel))
|
||||
|
||||
var u = TestFindAndCountUser{
|
||||
u := TestFindAndCountUser{
|
||||
Name: "myname",
|
||||
}
|
||||
cnt, err := testEngine.Insert(&u)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var hotel = TestFindAndCountHotel{
|
||||
hotel := TestFindAndCountHotel{
|
||||
Name: "myhotel",
|
||||
Code: "111",
|
||||
Region: "222",
|
||||
|
@ -961,6 +967,10 @@ func TestFindJoin(t *testing.T) {
|
|||
scenes = make([]SceneItem, 0)
|
||||
err = testEngine.Join("INNER", "order", "`scene_item`.`device_id`=`order`.`id`").Find(&scenes)
|
||||
assert.NoError(t, err)
|
||||
|
||||
scenes = make([]SceneItem, 0)
|
||||
err = testEngine.Join("INNER", "order", builder.Expr("`scene_item`.`device_id`=`order`.`id`")).Find(&scenes)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestJoinFindLimit(t *testing.T) {
|
||||
|
@ -1063,7 +1073,7 @@ func TestUpdateFind(t *testing.T) {
|
|||
session := testEngine.NewSession()
|
||||
defer session.Close()
|
||||
|
||||
var tuf = TestUpdateFind{
|
||||
tuf := TestUpdateFind{
|
||||
Name: "test",
|
||||
}
|
||||
_, err := session.Insert(&tuf)
|
||||
|
@ -1095,7 +1105,7 @@ func TestFindAnonymousStruct(t *testing.T) {
|
|||
assert.EqualValues(t, 1, cnt)
|
||||
assert.NoError(t, err)
|
||||
|
||||
var findRes = make([]struct {
|
||||
findRes := make([]struct {
|
||||
Id int64
|
||||
Name string
|
||||
}, 0)
|
||||
|
@ -1115,3 +1125,115 @@ func TestFindAnonymousStruct(t *testing.T) {
|
|||
assert.EqualValues(t, 1, findRes[0].Id)
|
||||
assert.EqualValues(t, "xlw", findRes[0].Name)
|
||||
}
|
||||
|
||||
func TestFindBytesVars(t *testing.T) {
|
||||
type FindBytesVars struct {
|
||||
Id int64
|
||||
Bytes1 []byte
|
||||
Bytes2 []byte
|
||||
}
|
||||
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(FindBytesVars))
|
||||
|
||||
_, err := testEngine.Insert([]FindBytesVars{
|
||||
{
|
||||
Bytes1: []byte("bytes1"),
|
||||
Bytes2: []byte("bytes2"),
|
||||
},
|
||||
{
|
||||
Bytes1: []byte("bytes1-1"),
|
||||
Bytes2: []byte("bytes2-2"),
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var gbv []FindBytesVars
|
||||
err = testEngine.Find(&gbv)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, len(gbv))
|
||||
assert.EqualValues(t, []byte("bytes1"), gbv[0].Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2"), gbv[0].Bytes2)
|
||||
assert.EqualValues(t, []byte("bytes1-1"), gbv[1].Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2-2"), gbv[1].Bytes2)
|
||||
|
||||
err = testEngine.Find(&gbv)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 4, len(gbv))
|
||||
assert.EqualValues(t, []byte("bytes1"), gbv[0].Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2"), gbv[0].Bytes2)
|
||||
assert.EqualValues(t, []byte("bytes1-1"), gbv[1].Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2-2"), gbv[1].Bytes2)
|
||||
assert.EqualValues(t, []byte("bytes1"), gbv[2].Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2"), gbv[2].Bytes2)
|
||||
assert.EqualValues(t, []byte("bytes1-1"), gbv[3].Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2-2"), gbv[3].Bytes2)
|
||||
}
|
||||
|
||||
func TestUpdateFindDate(t *testing.T) {
|
||||
type TestUpdateFindDate struct {
|
||||
Id int64
|
||||
Name string
|
||||
Tm time.Time `xorm:"DATE created"`
|
||||
}
|
||||
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestUpdateFindDate))
|
||||
|
||||
session := testEngine.NewSession()
|
||||
defer session.Close()
|
||||
|
||||
tuf := TestUpdateFindDate{
|
||||
Name: "test",
|
||||
}
|
||||
_, err := session.Insert(&tuf)
|
||||
assert.NoError(t, err)
|
||||
_, err = session.Where("`id` = ?", tuf.Id).Update(&TestUpdateFindDate{})
|
||||
assert.EqualError(t, xorm.ErrNoColumnsTobeUpdated, err.Error())
|
||||
|
||||
var tufs []TestUpdateFindDate
|
||||
err = session.Find(&tufs)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(tufs))
|
||||
assert.EqualValues(t, tuf.Tm.Format("2006-01-02"), tufs[0].Tm.Format("2006-01-02"))
|
||||
}
|
||||
|
||||
func TestBuilderDialect(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TestBuilderDialect struct {
|
||||
Id int64
|
||||
Name string `xorm:"index"`
|
||||
Age2 int
|
||||
}
|
||||
|
||||
type TestBuilderDialectFoo struct {
|
||||
Id int64
|
||||
DialectId int64 `xorm:"index"`
|
||||
Age int
|
||||
}
|
||||
|
||||
assertSync(t, new(TestBuilderDialect), new(TestBuilderDialectFoo))
|
||||
|
||||
session := testEngine.NewSession()
|
||||
defer session.Close()
|
||||
|
||||
var dialect string
|
||||
switch testEngine.Dialect().URI().DBType {
|
||||
case schemas.MYSQL:
|
||||
dialect = builder.MYSQL
|
||||
case schemas.MSSQL:
|
||||
dialect = builder.MSSQL
|
||||
case schemas.POSTGRES:
|
||||
dialect = builder.POSTGRES
|
||||
case schemas.SQLITE:
|
||||
dialect = builder.SQLITE
|
||||
}
|
||||
|
||||
tbName := testEngine.TableName(new(TestBuilderDialectFoo), dialect == builder.POSTGRES)
|
||||
|
||||
inner := builder.Dialect(dialect).Select("*").From(tbName).Where(builder.Eq{"age": 20})
|
||||
result := make([]*TestBuilderDialect, 0, 10)
|
||||
err := testEngine.Table("test_builder_dialect").Where(builder.Eq{"age2": 2}).Join("INNER", inner, "test_builder_dialect_foo.dialect_id = test_builder_dialect.id").Find(&result)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestGetVar(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(GetVar)))
|
||||
|
||||
var data = GetVar{
|
||||
data := GetVar{
|
||||
Msg: "hi",
|
||||
Age: 28,
|
||||
Money: 1.5,
|
||||
|
@ -175,7 +175,7 @@ func TestGetVar(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, false, has)
|
||||
|
||||
var valuesString = make(map[string]string)
|
||||
valuesString := make(map[string]string)
|
||||
has, err = testEngine.Table("get_var").Get(&valuesString)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, has)
|
||||
|
@ -187,7 +187,7 @@ func TestGetVar(t *testing.T) {
|
|||
|
||||
// for mymysql driver, interface{} will be []byte, so ignore it currently
|
||||
if testEngine.DriverName() != "mymysql" {
|
||||
var valuesInter = make(map[string]interface{})
|
||||
valuesInter := make(map[string]interface{})
|
||||
has, err = testEngine.Table("get_var").Where("`id` = ?", 1).Select("*").Get(&valuesInter)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, has)
|
||||
|
@ -198,7 +198,7 @@ func TestGetVar(t *testing.T) {
|
|||
assert.Equal(t, "1.5", fmt.Sprintf("%v", valuesInter["money"]))
|
||||
}
|
||||
|
||||
var valuesSliceString = make([]string, 5)
|
||||
valuesSliceString := make([]string, 5)
|
||||
has, err = testEngine.Table("get_var").Get(&valuesSliceString)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, has)
|
||||
|
@ -207,7 +207,7 @@ func TestGetVar(t *testing.T) {
|
|||
assert.Equal(t, "28", valuesSliceString[2])
|
||||
assert.Equal(t, "1.5", valuesSliceString[3])
|
||||
|
||||
var valuesSliceInter = make([]interface{}, 5)
|
||||
valuesSliceInter := make([]interface{}, 5)
|
||||
has, err = testEngine.Table("get_var").Get(&valuesSliceInter)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, has)
|
||||
|
@ -317,7 +317,7 @@ func TestGetMap(t *testing.T) {
|
|||
_, err := testEngine.Exec(fmt.Sprintf("INSERT INTO %s (`is_man`) VALUES (NULL)", tableName))
|
||||
assert.NoError(t, err)
|
||||
|
||||
var valuesString = make(map[string]string)
|
||||
valuesString := make(map[string]string)
|
||||
has, err := testEngine.Table("userinfo_map").Get(&valuesString)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, has)
|
||||
|
@ -336,7 +336,7 @@ func TestGetError(t *testing.T) {
|
|||
|
||||
assertSync(t, new(GetError))
|
||||
|
||||
var info = new(GetError)
|
||||
info := new(GetError)
|
||||
has, err := testEngine.Get(&info)
|
||||
assert.False(t, has)
|
||||
assert.Error(t, err)
|
||||
|
@ -456,7 +456,7 @@ func TestGetActionMapping(t *testing.T) {
|
|||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var valuesSlice = make([]string, 2)
|
||||
valuesSlice := make([]string, 2)
|
||||
has, err := testEngine.Table(new(ActionMapping)).
|
||||
Cols("script_id", "rollback_id").
|
||||
ID("1").Get(&valuesSlice)
|
||||
|
@ -483,7 +483,7 @@ func TestGetStructId(t *testing.T) {
|
|||
Id int64
|
||||
}
|
||||
|
||||
//var id int64
|
||||
// var id int64
|
||||
var maxid maxidst
|
||||
sql := "select max(`id`) as id from " + testEngine.Quote(testEngine.TableName(&TestGetStruct{}, true))
|
||||
has, err := testEngine.SQL(sql).Get(&maxid)
|
||||
|
@ -693,7 +693,7 @@ func TestCustomTypes(t *testing.T) {
|
|||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestCustomizeStruct))
|
||||
|
||||
var s = TestCustomizeStruct{
|
||||
s := TestCustomizeStruct{
|
||||
Name: "test",
|
||||
Age: 32,
|
||||
}
|
||||
|
@ -763,7 +763,7 @@ func TestGetBigFloat(t *testing.T) {
|
|||
assertSync(t, new(GetBigFloat))
|
||||
|
||||
{
|
||||
var gf = GetBigFloat{
|
||||
gf := GetBigFloat{
|
||||
Money: big.NewFloat(999999.99),
|
||||
}
|
||||
_, err := testEngine.Insert(&gf)
|
||||
|
@ -774,8 +774,8 @@ func TestGetBigFloat(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.True(t, m.String() == gf.Money.String(), "%v != %v", m.String(), gf.Money.String())
|
||||
//fmt.Println(m.Cmp(gf.Money))
|
||||
//assert.True(t, m.Cmp(gf.Money) == 0, "%v != %v", m.String(), gf.Money.String())
|
||||
// fmt.Println(m.Cmp(gf.Money))
|
||||
// assert.True(t, m.Cmp(gf.Money) == 0, "%v != %v", m.String(), gf.Money.String())
|
||||
}
|
||||
|
||||
type GetBigFloat2 struct {
|
||||
|
@ -788,7 +788,7 @@ func TestGetBigFloat(t *testing.T) {
|
|||
assertSync(t, new(GetBigFloat2))
|
||||
|
||||
{
|
||||
var gf2 = GetBigFloat2{
|
||||
gf2 := GetBigFloat2{
|
||||
Money: big.NewFloat(9999999.99),
|
||||
Money2: *big.NewFloat(99.99),
|
||||
}
|
||||
|
@ -800,8 +800,8 @@ func TestGetBigFloat(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.True(t, m2.String() == gf2.Money.String(), "%v != %v", m2.String(), gf2.Money.String())
|
||||
//fmt.Println(m.Cmp(gf.Money))
|
||||
//assert.True(t, m.Cmp(gf.Money) == 0, "%v != %v", m.String(), gf.Money.String())
|
||||
// fmt.Println(m.Cmp(gf.Money))
|
||||
// assert.True(t, m.Cmp(gf.Money) == 0, "%v != %v", m.String(), gf.Money.String())
|
||||
|
||||
var gf3 GetBigFloat2
|
||||
has, err = testEngine.ID(gf2.Id).Get(&gf3)
|
||||
|
@ -829,7 +829,7 @@ func TestGetDecimal(t *testing.T) {
|
|||
assertSync(t, new(GetDecimal))
|
||||
|
||||
{
|
||||
var gf = GetDecimal{
|
||||
gf := GetDecimal{
|
||||
Money: decimal.NewFromFloat(999999.99),
|
||||
}
|
||||
_, err := testEngine.Insert(&gf)
|
||||
|
@ -840,8 +840,8 @@ func TestGetDecimal(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.True(t, m.String() == gf.Money.String(), "%v != %v", m.String(), gf.Money.String())
|
||||
//fmt.Println(m.Cmp(gf.Money))
|
||||
//assert.True(t, m.Cmp(gf.Money) == 0, "%v != %v", m.String(), gf.Money.String())
|
||||
// fmt.Println(m.Cmp(gf.Money))
|
||||
// assert.True(t, m.Cmp(gf.Money) == 0, "%v != %v", m.String(), gf.Money.String())
|
||||
}
|
||||
|
||||
type GetDecimal2 struct {
|
||||
|
@ -854,7 +854,7 @@ func TestGetDecimal(t *testing.T) {
|
|||
|
||||
{
|
||||
v := decimal.NewFromFloat(999999.99)
|
||||
var gf = GetDecimal2{
|
||||
gf := GetDecimal2{
|
||||
Money: &v,
|
||||
}
|
||||
_, err := testEngine.Insert(&gf)
|
||||
|
@ -865,10 +865,11 @@ func TestGetDecimal(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.True(t, m.String() == gf.Money.String(), "%v != %v", m.String(), gf.Money.String())
|
||||
//fmt.Println(m.Cmp(gf.Money))
|
||||
//assert.True(t, m.Cmp(gf.Money) == 0, "%v != %v", m.String(), gf.Money.String())
|
||||
// fmt.Println(m.Cmp(gf.Money))
|
||||
// assert.True(t, m.Cmp(gf.Money) == 0, "%v != %v", m.String(), gf.Money.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTime(t *testing.T) {
|
||||
type GetTimeStruct struct {
|
||||
Id int64
|
||||
|
@ -878,7 +879,7 @@ func TestGetTime(t *testing.T) {
|
|||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(GetTimeStruct))
|
||||
|
||||
var gts = GetTimeStruct{
|
||||
gts := GetTimeStruct{
|
||||
CreateTime: time.Now().In(testEngine.GetTZLocation()),
|
||||
}
|
||||
_, err := testEngine.Insert(>s)
|
||||
|
@ -976,3 +977,39 @@ func TestGetWithPrepare(t *testing.T) {
|
|||
err = sess.Commit()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestGetBytesVars(t *testing.T) {
|
||||
type GetBytesVars struct {
|
||||
Id int64
|
||||
Bytes1 []byte
|
||||
Bytes2 []byte
|
||||
}
|
||||
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(GetBytesVars))
|
||||
|
||||
_, err := testEngine.Insert([]GetBytesVars{
|
||||
{
|
||||
Bytes1: []byte("bytes1"),
|
||||
Bytes2: []byte("bytes2"),
|
||||
},
|
||||
{
|
||||
Bytes1: []byte("bytes1-1"),
|
||||
Bytes2: []byte("bytes2-2"),
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var gbv GetBytesVars
|
||||
has, err := testEngine.Asc("id").Get(&gbv)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.EqualValues(t, []byte("bytes1"), gbv.Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2"), gbv.Bytes2)
|
||||
|
||||
has, err = testEngine.Desc("id").NoAutoCondition().Get(&gbv)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.EqualValues(t, []byte("bytes1-1"), gbv.Bytes1)
|
||||
assert.EqualValues(t, []byte("bytes2-2"), gbv.Bytes2)
|
||||
}
|
||||
|
|
|
@ -744,7 +744,8 @@ func TestInsertMap(t *testing.T) {
|
|||
assert.EqualValues(t, "lunny", ims[3].Name)
|
||||
}
|
||||
|
||||
/*INSERT INTO `issue` (`repo_id`, `poster_id`, ... ,`name`, `content`, ... ,`index`)
|
||||
/*
|
||||
INSERT INTO `issue` (`repo_id`, `poster_id`, ... ,`name`, `content`, ... ,`index`)
|
||||
SELECT $1, $2, ..., $14, $15, ..., MAX(`index`) + 1 FROM `issue` WHERE `repo_id` = $1;
|
||||
*/
|
||||
func TestInsertWhere(t *testing.T) {
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
package integrations
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"xorm.io/builder"
|
||||
|
||||
"xorm.io/xorm/schemas"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -28,7 +30,7 @@ func TestQueryString(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(GetVar2)))
|
||||
|
||||
var data = GetVar2{
|
||||
data := GetVar2{
|
||||
Msg: "hi",
|
||||
Age: 28,
|
||||
Money: 1.5,
|
||||
|
@ -56,7 +58,7 @@ func TestQueryString2(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(GetVar3)))
|
||||
|
||||
var data = GetVar3{
|
||||
data := GetVar3{
|
||||
Msg: false,
|
||||
}
|
||||
_, err := testEngine.Insert(data)
|
||||
|
@ -93,7 +95,7 @@ func TestQueryInterface(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(GetVarInterface)))
|
||||
|
||||
var data = GetVarInterface{
|
||||
data := GetVarInterface{
|
||||
Msg: "hi",
|
||||
Age: 28,
|
||||
Money: 1.5,
|
||||
|
@ -126,7 +128,7 @@ func TestQueryNoParams(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(QueryNoParams)))
|
||||
|
||||
var q = QueryNoParams{
|
||||
q := QueryNoParams{
|
||||
Msg: "message",
|
||||
Age: 20,
|
||||
Money: 3000,
|
||||
|
@ -170,7 +172,7 @@ func TestQueryStringNoParam(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(GetVar4)))
|
||||
|
||||
var data = GetVar4{
|
||||
data := GetVar4{
|
||||
Msg: false,
|
||||
}
|
||||
_, err := testEngine.Insert(data)
|
||||
|
@ -207,7 +209,7 @@ func TestQuerySliceStringNoParam(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(GetVar6)))
|
||||
|
||||
var data = GetVar6{
|
||||
data := GetVar6{
|
||||
Msg: false,
|
||||
}
|
||||
_, err := testEngine.Insert(data)
|
||||
|
@ -244,7 +246,7 @@ func TestQueryInterfaceNoParam(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(GetVar5)))
|
||||
|
||||
var data = GetVar5{
|
||||
data := GetVar5{
|
||||
Msg: false,
|
||||
}
|
||||
_, err := testEngine.Insert(data)
|
||||
|
@ -278,7 +280,7 @@ func TestQueryWithBuilder(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(QueryWithBuilder)))
|
||||
|
||||
var q = QueryWithBuilder{
|
||||
q := QueryWithBuilder{
|
||||
Msg: "message",
|
||||
Age: 20,
|
||||
Money: 3000,
|
||||
|
@ -327,14 +329,14 @@ func TestJoinWithSubQuery(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(JoinWithSubQuery1), new(JoinWithSubQueryDepart)))
|
||||
|
||||
var depart = JoinWithSubQueryDepart{
|
||||
depart := JoinWithSubQueryDepart{
|
||||
Name: "depart1",
|
||||
}
|
||||
cnt, err := testEngine.Insert(&depart)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var q = JoinWithSubQuery1{
|
||||
q := JoinWithSubQuery1{
|
||||
Msg: "message",
|
||||
DepartId: depart.Id,
|
||||
Money: 3000,
|
||||
|
@ -381,3 +383,119 @@ func TestQueryStringWithLimit(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 0, len(data))
|
||||
}
|
||||
|
||||
func TestQueryBLOBInMySQL(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
var err error
|
||||
type Avatar struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
Avatar []byte `xorm:"BLOB"`
|
||||
}
|
||||
|
||||
assert.NoError(t, testEngine.Sync(new(Avatar)))
|
||||
testEngine.Delete(Avatar{})
|
||||
|
||||
repeatBytes := func(n int, b byte) []byte {
|
||||
return bytes.Repeat([]byte{b}, n)
|
||||
}
|
||||
|
||||
const N = 10
|
||||
data := []Avatar{}
|
||||
for i := 0; i < N; i++ {
|
||||
// allocate a []byte that is as twice big as the last one
|
||||
// so that the underlying buffer will need to reallocate when querying
|
||||
bs := repeatBytes(1<<(i+2), 'A'+byte(i))
|
||||
data = append(data, Avatar{
|
||||
Avatar: bs,
|
||||
})
|
||||
}
|
||||
_, err = testEngine.Insert(data)
|
||||
assert.NoError(t, err)
|
||||
defer func() {
|
||||
testEngine.Delete(Avatar{})
|
||||
}()
|
||||
|
||||
{
|
||||
records, err := testEngine.QueryInterface("select avatar from " + testEngine.Quote(testEngine.TableName("avatar", true)))
|
||||
assert.NoError(t, err)
|
||||
for i, record := range records {
|
||||
bs := record["avatar"].([]byte)
|
||||
assert.EqualValues(t, repeatBytes(1<<(i+2), 'A'+byte(i))[:3], bs[:3])
|
||||
t.Logf("%d => %p => %02x %02x %02x", i, bs, bs[0], bs[1], bs[2])
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
arr := make([][]interface{}, 0)
|
||||
err = testEngine.Table(testEngine.Quote(testEngine.TableName("avatar", true))).Cols("avatar").Find(&arr)
|
||||
assert.NoError(t, err)
|
||||
for i, record := range arr {
|
||||
bs := record[0].([]byte)
|
||||
assert.EqualValues(t, repeatBytes(1<<(i+2), 'A'+byte(i))[:3], bs[:3])
|
||||
t.Logf("%d => %p => %02x %02x %02x", i, bs, bs[0], bs[1], bs[2])
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
arr := make([]map[string]interface{}, 0)
|
||||
err = testEngine.Table(testEngine.Quote(testEngine.TableName("avatar", true))).Cols("avatar").Find(&arr)
|
||||
assert.NoError(t, err)
|
||||
for i, record := range arr {
|
||||
bs := record["avatar"].([]byte)
|
||||
assert.EqualValues(t, repeatBytes(1<<(i+2), 'A'+byte(i))[:3], bs[:3])
|
||||
t.Logf("%d => %p => %02x %02x %02x", i, bs, bs[0], bs[1], bs[2])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRowsReset(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type RowsReset1 struct {
|
||||
Id int64
|
||||
Name string
|
||||
}
|
||||
|
||||
type RowsReset2 struct {
|
||||
Id int64
|
||||
Name string
|
||||
}
|
||||
|
||||
assert.NoError(t, testEngine.Sync(new(RowsReset1), new(RowsReset2)))
|
||||
|
||||
data := []RowsReset1{
|
||||
{0, "1"},
|
||||
{0, "2"},
|
||||
{0, "3"},
|
||||
}
|
||||
_, err := testEngine.Insert(data)
|
||||
assert.NoError(t, err)
|
||||
|
||||
data2 := []RowsReset2{
|
||||
{0, "4"},
|
||||
{0, "5"},
|
||||
{0, "6"},
|
||||
}
|
||||
_, err = testEngine.Insert(data2)
|
||||
assert.NoError(t, err)
|
||||
|
||||
sess := testEngine.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
rows, err := sess.Rows(new(RowsReset1))
|
||||
assert.NoError(t, err)
|
||||
for rows.Next() {
|
||||
var data1 RowsReset1
|
||||
assert.NoError(t, rows.Scan(&data1))
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
var rrs []RowsReset2
|
||||
assert.NoError(t, sess.Find(&rrs))
|
||||
|
||||
assert.Len(t, rrs, 3)
|
||||
assert.EqualValues(t, "4", rrs[0].Name)
|
||||
assert.EqualValues(t, "5", rrs[1].Name)
|
||||
assert.EqualValues(t, "6", rrs[2].Name)
|
||||
}
|
||||
|
|
|
@ -185,3 +185,36 @@ func TestMultipleTransaction(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 0, len(ms))
|
||||
}
|
||||
|
||||
func TestInsertMulti2InterfaceTransaction(t *testing.T) {
|
||||
|
||||
type Multi2InterfaceTransaction struct {
|
||||
ID uint64 `xorm:"id pk autoincr"`
|
||||
Name string
|
||||
Alias string
|
||||
CreateTime time.Time `xorm:"created"`
|
||||
UpdateTime time.Time `xorm:"updated"`
|
||||
}
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Multi2InterfaceTransaction))
|
||||
session := testEngine.NewSession()
|
||||
defer session.Close()
|
||||
err := session.Begin()
|
||||
assert.NoError(t, err)
|
||||
|
||||
users := []interface{}{
|
||||
&Multi2InterfaceTransaction{Name: "a", Alias: "A"},
|
||||
&Multi2InterfaceTransaction{Name: "b", Alias: "B"},
|
||||
&Multi2InterfaceTransaction{Name: "c", Alias: "C"},
|
||||
&Multi2InterfaceTransaction{Name: "d", Alias: "D"},
|
||||
}
|
||||
cnt, err := session.Insert(&users)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, len(users), cnt)
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
err = session.Commit()
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func TestUpdateMap(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.NoError(t, testEngine.Sync(new(UpdateTable)))
|
||||
var tb = UpdateTable{
|
||||
tb := UpdateTable{
|
||||
Name: "test",
|
||||
Age: 35,
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func TestUpdateLimit(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.NoError(t, testEngine.Sync(new(UpdateTable2)))
|
||||
var tb = UpdateTable2{
|
||||
tb := UpdateTable2{
|
||||
Name: "test1",
|
||||
Age: 35,
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ func TestUpdate1(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var s = "test"
|
||||
s := "test"
|
||||
|
||||
col1 := &UpdateAllCols{Ptr: &s}
|
||||
err = testEngine.Sync(col1)
|
||||
|
@ -864,7 +864,7 @@ func TestCreatedUpdated2(t *testing.T) {
|
|||
|
||||
assertSync(t, new(CreatedUpdatedStruct))
|
||||
|
||||
var s = CreatedUpdatedStruct{
|
||||
s := CreatedUpdatedStruct{
|
||||
Name: "test",
|
||||
}
|
||||
cnt, err := testEngine.Insert(&s)
|
||||
|
@ -874,7 +874,7 @@ func TestCreatedUpdated2(t *testing.T) {
|
|||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
var s1 = CreatedUpdatedStruct{
|
||||
s1 := CreatedUpdatedStruct{
|
||||
Name: "test1",
|
||||
CreateAt: s.CreateAt,
|
||||
UpdateAt: s.UpdateAt,
|
||||
|
@ -907,7 +907,7 @@ func TestDeletedUpdate(t *testing.T) {
|
|||
|
||||
assertSync(t, new(DeletedUpdatedStruct))
|
||||
|
||||
var s = DeletedUpdatedStruct{
|
||||
s := DeletedUpdatedStruct{
|
||||
Name: "test",
|
||||
}
|
||||
cnt, err := testEngine.Insert(&s)
|
||||
|
@ -956,7 +956,7 @@ func TestUpdateMapCondition(t *testing.T) {
|
|||
|
||||
assertSync(t, new(UpdateMapCondition))
|
||||
|
||||
var c = UpdateMapCondition{
|
||||
c := UpdateMapCondition{
|
||||
String: "string",
|
||||
}
|
||||
_, err := testEngine.Insert(&c)
|
||||
|
@ -990,7 +990,7 @@ func TestUpdateMapContent(t *testing.T) {
|
|||
|
||||
assertSync(t, new(UpdateMapContent))
|
||||
|
||||
var c = UpdateMapContent{
|
||||
c := UpdateMapContent{
|
||||
Name: "lunny",
|
||||
IsMan: true,
|
||||
Gender: 1,
|
||||
|
@ -1126,7 +1126,7 @@ func TestUpdateDeleted(t *testing.T) {
|
|||
|
||||
assertSync(t, new(UpdateDeletedStruct))
|
||||
|
||||
var s = UpdateDeletedStruct{
|
||||
s := UpdateDeletedStruct{
|
||||
Name: "test",
|
||||
}
|
||||
cnt, err := testEngine.Insert(&s)
|
||||
|
@ -1232,7 +1232,7 @@ func TestUpdateExprs2(t *testing.T) {
|
|||
|
||||
assertSync(t, new(UpdateExprsRelease))
|
||||
|
||||
var uer = UpdateExprsRelease{
|
||||
uer := UpdateExprsRelease{
|
||||
RepoId: 1,
|
||||
IsTag: false,
|
||||
IsDraft: false,
|
||||
|
@ -1407,7 +1407,7 @@ func TestNilFromDB(t *testing.T) {
|
|||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestTable1))
|
||||
|
||||
var tt0 = TestTable1{
|
||||
tt0 := TestTable1{
|
||||
Field1: &TestFieldType1{
|
||||
cb: []byte("string"),
|
||||
},
|
||||
|
@ -1437,7 +1437,7 @@ func TestNilFromDB(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var tt = TestTable1{
|
||||
tt := TestTable1{
|
||||
UpdateTime: time.Now(),
|
||||
Field1: &TestFieldType1{
|
||||
cb: nil,
|
||||
|
@ -1453,7 +1453,7 @@ func TestNilFromDB(t *testing.T) {
|
|||
assert.True(t, has)
|
||||
assert.Nil(t, tt2.Field1)
|
||||
|
||||
var tt3 = TestTable1{
|
||||
tt3 := TestTable1{
|
||||
UpdateTime: time.Now(),
|
||||
Field1: &TestFieldType1{
|
||||
cb: []byte{},
|
||||
|
@ -1470,3 +1470,34 @@ func TestNilFromDB(t *testing.T) {
|
|||
assert.NotNil(t, tt4.Field1)
|
||||
assert.NotNil(t, tt4.Field1.cb)
|
||||
}
|
||||
|
||||
/*
|
||||
func TestUpdateWithJoin(t *testing.T) {
|
||||
type TestUpdateWithJoin struct {
|
||||
Id int64
|
||||
ExtId int64
|
||||
Name string
|
||||
}
|
||||
|
||||
type TestUpdateWithJoin2 struct {
|
||||
Id int64
|
||||
Name string
|
||||
}
|
||||
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestUpdateWithJoin), new(TestUpdateWithJoin2))
|
||||
|
||||
b := TestUpdateWithJoin2{Name: "test"}
|
||||
_, err := testEngine.Insert(&b)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = testEngine.Insert(&TestUpdateWithJoin{ExtId: b.Id, Name: "test"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = testEngine.Table("test_update_with_join").
|
||||
Join("INNER", "test_update_with_join2", "test_update_with_join.ext_id = test_update_with_join2.id").
|
||||
Where("test_update_with_join2.name = ?", "test").
|
||||
Update(&TestUpdateWithJoin{Name: "test2"})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -165,7 +165,7 @@ func TestExtends(t *testing.T) {
|
|||
assert.True(t, info2.Userinfo.Uid > 0, "all of the id should has value")
|
||||
assert.True(t, info2.Userdetail.Id > 0, "all of the id should has value")
|
||||
|
||||
var infos2 = make([]UserAndDetail, 0)
|
||||
infos2 := make([]UserAndDetail, 0)
|
||||
err = testEngine.Table(&Userinfo{}).
|
||||
Join("LEFT", qt(ud), qt(ui)+"."+qt("detail_id")+" = "+qt(ud)+"."+qt(uiid)).
|
||||
NoCascade().
|
||||
|
@ -219,9 +219,9 @@ func TestExtends2(t *testing.T) {
|
|||
err = testEngine.CreateTables(&Message{}, &MessageUser{}, &MessageType{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var sender = MessageUser{Name: "sender"}
|
||||
var receiver = MessageUser{Name: "receiver"}
|
||||
var msgtype = MessageType{Name: "type"}
|
||||
sender := MessageUser{Name: "sender"}
|
||||
receiver := MessageUser{Name: "receiver"}
|
||||
msgtype := MessageType{Name: "type"}
|
||||
_, err = testEngine.Insert(&sender, &receiver, &msgtype)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
@ -254,8 +254,8 @@ func TestExtends2(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
var mapper = testEngine.GetTableMapper().Obj2Table
|
||||
var quote = testEngine.Quote
|
||||
mapper := testEngine.GetTableMapper().Obj2Table
|
||||
quote := testEngine.Quote
|
||||
userTableName := quote(testEngine.TableName(mapper("MessageUser"), true))
|
||||
typeTableName := quote(testEngine.TableName(mapper("MessageType"), true))
|
||||
msgTableName := quote(testEngine.TableName(mapper("Message"), true))
|
||||
|
@ -280,9 +280,9 @@ func TestExtends3(t *testing.T) {
|
|||
err = testEngine.CreateTables(&Message{}, &MessageUser{}, &MessageType{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var sender = MessageUser{Name: "sender"}
|
||||
var receiver = MessageUser{Name: "receiver"}
|
||||
var msgtype = MessageType{Name: "type"}
|
||||
sender := MessageUser{Name: "sender"}
|
||||
receiver := MessageUser{Name: "receiver"}
|
||||
msgtype := MessageType{Name: "type"}
|
||||
_, err = testEngine.Insert(&sender, &receiver, &msgtype)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
@ -314,8 +314,8 @@ func TestExtends3(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
var mapper = testEngine.GetTableMapper().Obj2Table
|
||||
var quote = testEngine.Quote
|
||||
mapper := testEngine.GetTableMapper().Obj2Table
|
||||
quote := testEngine.Quote
|
||||
userTableName := quote(testEngine.TableName(mapper("MessageUser"), true))
|
||||
typeTableName := quote(testEngine.TableName(mapper("MessageType"), true))
|
||||
msgTableName := quote(testEngine.TableName(mapper("Message"), true))
|
||||
|
@ -345,8 +345,8 @@ func TestExtends4(t *testing.T) {
|
|||
err = testEngine.CreateTables(&Message{}, &MessageUser{}, &MessageType{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var sender = MessageUser{Name: "sender"}
|
||||
var msgtype = MessageType{Name: "type"}
|
||||
sender := MessageUser{Name: "sender"}
|
||||
msgtype := MessageType{Name: "type"}
|
||||
_, err = testEngine.Insert(&sender, &msgtype)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
@ -377,8 +377,8 @@ func TestExtends4(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
var mapper = testEngine.GetTableMapper().Obj2Table
|
||||
var quote = testEngine.Quote
|
||||
mapper := testEngine.GetTableMapper().Obj2Table
|
||||
quote := testEngine.Quote
|
||||
userTableName := quote(testEngine.TableName(mapper("MessageUser"), true))
|
||||
typeTableName := quote(testEngine.TableName(mapper("MessageType"), true))
|
||||
msgTableName := quote(testEngine.TableName(mapper("Message"), true))
|
||||
|
@ -417,29 +417,29 @@ func TestExtends5(t *testing.T) {
|
|||
err = testEngine.CreateTables(&Size{}, &Book{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var sc = Size{Width: 0.2, Height: 0.4}
|
||||
var so = Size{Width: 0.2, Height: 0.8}
|
||||
var s = Size{Width: 0.15, Height: 1.5}
|
||||
var bk1 = Book{
|
||||
sc := Size{Width: 0.2, Height: 0.4}
|
||||
so := Size{Width: 0.2, Height: 0.8}
|
||||
s := Size{Width: 0.15, Height: 1.5}
|
||||
bk1 := Book{
|
||||
SizeOpen: &so,
|
||||
SizeClosed: &sc,
|
||||
Size: &s,
|
||||
}
|
||||
var bk2 = Book{
|
||||
bk2 := Book{
|
||||
SizeOpen: &so,
|
||||
}
|
||||
var bk3 = Book{
|
||||
bk3 := Book{
|
||||
SizeClosed: &sc,
|
||||
Size: &s,
|
||||
}
|
||||
var bk4 = Book{}
|
||||
var bk5 = Book{Size: &s}
|
||||
bk4 := Book{}
|
||||
bk5 := Book{Size: &s}
|
||||
_, err = testEngine.Insert(&sc, &so, &s, &bk1, &bk2, &bk3, &bk4, &bk5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var books = map[int64]Book{
|
||||
books := map[int64]Book{
|
||||
bk1.ID: bk1,
|
||||
bk2.ID: bk2,
|
||||
bk3.ID: bk3,
|
||||
|
@ -450,8 +450,8 @@ func TestExtends5(t *testing.T) {
|
|||
session := testEngine.NewSession()
|
||||
defer session.Close()
|
||||
|
||||
var mapper = testEngine.GetTableMapper().Obj2Table
|
||||
var quote = testEngine.Quote
|
||||
mapper := testEngine.GetTableMapper().Obj2Table
|
||||
quote := testEngine.Quote
|
||||
bookTableName := quote(testEngine.TableName(mapper("Book"), true))
|
||||
sizeTableName := quote(testEngine.TableName(mapper("Size"), true))
|
||||
|
||||
|
@ -1301,7 +1301,7 @@ func TestVersion2(t *testing.T) {
|
|||
err = testEngine.CreateTables(new(VersionS))
|
||||
assert.NoError(t, err)
|
||||
|
||||
var vers = []VersionS{
|
||||
vers := []VersionS{
|
||||
{Name: "sfsfdsfds"},
|
||||
{Name: "xxxxx"},
|
||||
}
|
||||
|
@ -1359,7 +1359,7 @@ func TestVersion4(t *testing.T) {
|
|||
err = testEngine.CreateTables(new(VersionUintS))
|
||||
assert.NoError(t, err)
|
||||
|
||||
var vers = []VersionUintS{
|
||||
vers := []VersionUintS{
|
||||
{Name: "sfsfdsfds"},
|
||||
{Name: "xxxxx"},
|
||||
}
|
||||
|
@ -1400,3 +1400,55 @@ func TestIndexes(t *testing.T) {
|
|||
assert.EqualValues(t, slice1, slice2)
|
||||
assert.EqualValues(t, 3, len(tables[0].Indexes))
|
||||
}
|
||||
|
||||
type TestTableIndicesStruct struct {
|
||||
Id int64
|
||||
Name string `xorm:"index index(f_one_f_two) unique(s)"` // we're going to override the index f_one_f_two in TableIndices and remove it from this column
|
||||
Email string `xorm:"index unique(s)"`
|
||||
FTwo string `xorm:"index(f_two_f_one) index(f_one_f_two) f_two"`
|
||||
FOne string `xorm:"index(f_two_f_one) f_one"`
|
||||
}
|
||||
|
||||
func (t *TestTableIndicesStruct) TableIndices() []*schemas.Index {
|
||||
newIndex := schemas.NewIndex("f_one_f_two", schemas.IndexType)
|
||||
newIndex.AddColumn("f_one", "f_two")
|
||||
|
||||
return []*schemas.Index{newIndex}
|
||||
}
|
||||
|
||||
func TestTableIndices(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assertSync(t, new(TestTableIndicesStruct))
|
||||
|
||||
tables, err := testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(tables))
|
||||
assert.EqualValues(t, 5, len(tables[0].Columns()))
|
||||
slice1 := []string{
|
||||
testEngine.GetColumnMapper().Obj2Table("Id"),
|
||||
testEngine.GetColumnMapper().Obj2Table("Name"),
|
||||
testEngine.GetColumnMapper().Obj2Table("Email"),
|
||||
testEngine.GetColumnMapper().Obj2Table("FTwo"),
|
||||
testEngine.GetColumnMapper().Obj2Table("FOne"),
|
||||
}
|
||||
slice2 := []string{
|
||||
tables[0].Columns()[0].Name,
|
||||
tables[0].Columns()[1].Name,
|
||||
tables[0].Columns()[2].Name,
|
||||
tables[0].Columns()[3].Name,
|
||||
tables[0].Columns()[4].Name,
|
||||
}
|
||||
sort.Strings(slice1)
|
||||
sort.Strings(slice2)
|
||||
assert.EqualValues(t, slice1, slice2)
|
||||
assert.EqualValues(t, 5, len(tables[0].Indexes))
|
||||
index, ok := tables[0].Indexes["f_one_f_two"]
|
||||
if assert.True(t, ok) {
|
||||
assert.EqualValues(t, []string{"f_one", "f_two"}, index.Cols)
|
||||
}
|
||||
index, ok = tables[0].Indexes["f_two_f_one"]
|
||||
if assert.True(t, ok) {
|
||||
assert.EqualValues(t, []string{"f_two", "f_one"}, index.Cols)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,11 @@ package integrations
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"xorm.io/xorm/convert"
|
||||
|
||||
"xorm.io/xorm/internal/utils"
|
||||
|
||||
|
@ -619,3 +621,59 @@ func TestTimestamp(t *testing.T) {
|
|||
assert.EqualValues(t, formatTime(d3.InsertTime, 6), formatTime(d4.InsertTime, 6))
|
||||
}*/
|
||||
}
|
||||
|
||||
func TestString2Time(t *testing.T) {
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
var timeTmp1 = time.Date(2023, 7, 14, 11, 30, 0, 0, loc)
|
||||
var timeTmp2 = time.Date(2023, 7, 14, 0, 0, 0, 0, loc)
|
||||
var time1StampStr = strconv.FormatInt(timeTmp1.Unix(), 10)
|
||||
var timeStr = "0000-00-00 00:00:00"
|
||||
dt, err := convert.String2Time(timeStr, time.Local, time.Local)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, dt.Nanosecond() == 0)
|
||||
|
||||
timeStr = "0001-01-01 00:00:00"
|
||||
dt, err = convert.String2Time(timeStr, time.Local, time.Local)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, dt.Nanosecond() == 0)
|
||||
|
||||
timeStr = "2023-07-14 11:30:00"
|
||||
dt, err = convert.String2Time(timeStr, loc, time.UTC)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, timeTmp1.In(time.UTC).Equal(*dt))
|
||||
|
||||
timeStr = "2023-07-14T11:30:00Z"
|
||||
dt, err = convert.String2Time(timeStr, loc, time.UTC)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, timeTmp1.In(time.UTC).Equal(*dt))
|
||||
|
||||
timeStr = "2023-07-14T11:30:00+08:00"
|
||||
dt, err = convert.String2Time(timeStr, loc, time.UTC)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, timeTmp1.In(time.UTC).Equal(*dt))
|
||||
|
||||
timeStr = "2023-07-14T11:30:00.00000000+08:00"
|
||||
dt, err = convert.String2Time(timeStr, loc, time.UTC)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, timeTmp1.In(time.UTC).Equal(*dt))
|
||||
|
||||
timeStr = "0000-00-00"
|
||||
dt, err = convert.String2Time(timeStr, loc, time.UTC)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, dt.Nanosecond() == 0)
|
||||
|
||||
timeStr = "0001-01-01"
|
||||
dt, err = convert.String2Time(timeStr, loc, time.UTC)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, dt.Nanosecond() == 0)
|
||||
|
||||
timeStr = "2023-07-14"
|
||||
dt, err = convert.String2Time(timeStr, loc, time.UTC)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, timeTmp2.In(time.UTC).Equal(*dt))
|
||||
|
||||
dt, err = convert.String2Time(time1StampStr, loc, time.UTC)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, timeTmp1.In(time.UTC).Equal(*dt))
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestArrayField(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(ArrayStruct)))
|
||||
|
||||
var as = ArrayStruct{
|
||||
as := ArrayStruct{
|
||||
Name: [20]byte{
|
||||
96, 96, 96, 96, 96,
|
||||
96, 96, 96, 96, 96,
|
||||
|
@ -54,7 +54,7 @@ func TestArrayField(t *testing.T) {
|
|||
assert.EqualValues(t, 1, len(arrs))
|
||||
assert.Equal(t, as.Name, arrs[0].Name)
|
||||
|
||||
var newName = [20]byte{
|
||||
newName := [20]byte{
|
||||
90, 96, 96, 96, 96,
|
||||
96, 96, 96, 96, 96,
|
||||
96, 96, 96, 96, 96,
|
||||
|
@ -252,9 +252,11 @@ func TestConversion(t *testing.T) {
|
|||
assert.Nil(t, c1.Nullable2)
|
||||
}
|
||||
|
||||
type MyInt int
|
||||
type MyUInt uint
|
||||
type MyFloat float64
|
||||
type (
|
||||
MyInt int
|
||||
MyUInt uint
|
||||
MyFloat float64
|
||||
)
|
||||
|
||||
type MyStruct struct {
|
||||
Type MyInt
|
||||
|
@ -273,7 +275,7 @@ type MyStruct struct {
|
|||
UIA32 []uint32
|
||||
UIA64 []uint64
|
||||
UI uint
|
||||
//C64 complex64
|
||||
// C64 complex64
|
||||
MSS map[string]string
|
||||
}
|
||||
|
||||
|
@ -304,6 +306,13 @@ func TestCustomType1(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
// since mssql don't support use text as index condition, we have to ignore below
|
||||
// get and find tests
|
||||
if testEngine.Dialect().URI().DBType == schemas.MSSQL {
|
||||
t.Skip()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(i)
|
||||
i.NameArray = []string{}
|
||||
i.MSS = map[string]string{}
|
||||
|
@ -598,7 +607,7 @@ func TestMyArray(t *testing.T) {
|
|||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(MyArrayStruct))
|
||||
|
||||
var v = [20]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
||||
v := [20]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
||||
_, err := testEngine.Insert(&MyArrayStruct{
|
||||
Content: v,
|
||||
})
|
||||
|
|
|
@ -31,6 +31,7 @@ type Interface interface {
|
|||
Decr(column string, arg ...interface{}) *Session
|
||||
Desc(...string) *Session
|
||||
Delete(...interface{}) (int64, error)
|
||||
Truncate(...interface{}) (int64, error)
|
||||
Distinct(columns ...string) *Session
|
||||
DropIndexes(bean interface{}) error
|
||||
Exec(sqlOrArgs ...interface{}) (sql.Result, error)
|
||||
|
@ -52,9 +53,9 @@ type Interface interface {
|
|||
NoAutoCondition(...bool) *Session
|
||||
NotIn(string, ...interface{}) *Session
|
||||
Nullable(...string) *Session
|
||||
Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session
|
||||
Join(joinOperator string, tablename interface{}, condition interface{}, args ...interface{}) *Session
|
||||
Omit(columns ...string) *Session
|
||||
OrderBy(order string) *Session
|
||||
OrderBy(order interface{}, args ...interface{}) *Session
|
||||
Ping() error
|
||||
Query(sqlOrArgs ...interface{}) (resultsSlice []map[string][]byte, err error)
|
||||
QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build gojson
|
||||
// +build gojson
|
||||
|
||||
package json
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build jsoniter
|
||||
// +build jsoniter
|
||||
|
||||
package json
|
||||
|
|
|
@ -6,6 +6,7 @@ package statements
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"xorm.io/xorm/internal/utils"
|
||||
|
@ -26,14 +27,19 @@ func (statement *Statement) ConvertIDSQL(sqlStr string) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
var top string
|
||||
var b strings.Builder
|
||||
b.WriteString("SELECT ")
|
||||
pLimitN := statement.LimitN
|
||||
if pLimitN != nil && statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
top = fmt.Sprintf("TOP %d ", *pLimitN)
|
||||
b.WriteString("TOP ")
|
||||
b.WriteString(strconv.Itoa(*pLimitN))
|
||||
b.WriteString(" ")
|
||||
}
|
||||
b.WriteString(colstrs)
|
||||
b.WriteString(" FROM ")
|
||||
b.WriteString(sqls[1])
|
||||
|
||||
newsql := fmt.Sprintf("SELECT %s%s FROM %v", top, colstrs, sqls[1])
|
||||
return newsql
|
||||
return b.String()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -54,7 +60,7 @@ func (statement *Statement) ConvertUpdateSQL(sqlStr string) (string, string) {
|
|||
return "", ""
|
||||
}
|
||||
|
||||
var whereStr = sqls[1]
|
||||
whereStr := sqls[1]
|
||||
|
||||
// TODO: for postgres only, if any other database?
|
||||
var paraStr string
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
// Copyright 2022 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package statements
|
||||
|
||||
import (
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
type QuoteReplacer struct {
|
||||
*builder.BytesWriter
|
||||
quoter schemas.Quoter
|
||||
}
|
||||
|
||||
func (q *QuoteReplacer) Write(p []byte) (n int, err error) {
|
||||
c := q.quoter.Replace(string(p))
|
||||
return q.BytesWriter.Builder.WriteString(c)
|
||||
}
|
||||
|
||||
func (statement *Statement) QuoteReplacer(w *builder.BytesWriter) *QuoteReplacer {
|
||||
return &QuoteReplacer{
|
||||
BytesWriter: w,
|
||||
quoter: statement.dialect.Quoter(),
|
||||
}
|
||||
}
|
||||
|
||||
// Where add Where statement
|
||||
func (statement *Statement) Where(query interface{}, args ...interface{}) *Statement {
|
||||
return statement.And(query, args...)
|
||||
}
|
||||
|
||||
// And add Where & and statement
|
||||
func (statement *Statement) And(query interface{}, args ...interface{}) *Statement {
|
||||
switch qr := query.(type) {
|
||||
case string:
|
||||
cond := builder.Expr(qr, args...)
|
||||
statement.cond = statement.cond.And(cond)
|
||||
case map[string]interface{}:
|
||||
cond := make(builder.Eq)
|
||||
for k, v := range qr {
|
||||
cond[statement.quote(k)] = v
|
||||
}
|
||||
statement.cond = statement.cond.And(cond)
|
||||
case builder.Cond:
|
||||
statement.cond = statement.cond.And(qr)
|
||||
for _, v := range args {
|
||||
if vv, ok := v.(builder.Cond); ok {
|
||||
statement.cond = statement.cond.And(vv)
|
||||
}
|
||||
}
|
||||
default:
|
||||
statement.LastError = ErrConditionType
|
||||
}
|
||||
|
||||
return statement
|
||||
}
|
||||
|
||||
// Or add Where & Or statement
|
||||
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
|
||||
switch qr := query.(type) {
|
||||
case string:
|
||||
cond := builder.Expr(qr, args...)
|
||||
statement.cond = statement.cond.Or(cond)
|
||||
case map[string]interface{}:
|
||||
cond := make(builder.Eq)
|
||||
for k, v := range qr {
|
||||
cond[statement.quote(k)] = v
|
||||
}
|
||||
statement.cond = statement.cond.Or(cond)
|
||||
case builder.Cond:
|
||||
statement.cond = statement.cond.Or(qr)
|
||||
for _, v := range args {
|
||||
if vv, ok := v.(builder.Cond); ok {
|
||||
statement.cond = statement.cond.Or(vv)
|
||||
}
|
||||
}
|
||||
default:
|
||||
statement.LastError = ErrConditionType
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// In generate "Where column IN (?) " statement
|
||||
func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
||||
in := builder.In(statement.quote(column), args...)
|
||||
statement.cond = statement.cond.And(in)
|
||||
return statement
|
||||
}
|
||||
|
||||
// NotIn generate "Where column NOT IN (?) " statement
|
||||
func (statement *Statement) NotIn(column string, args ...interface{}) *Statement {
|
||||
notIn := builder.NotIn(statement.quote(column), args...)
|
||||
statement.cond = statement.cond.And(notIn)
|
||||
return statement
|
||||
}
|
||||
|
||||
// SetNoAutoCondition if you do not want convert bean's field as query condition, then use this function
|
||||
func (statement *Statement) SetNoAutoCondition(no ...bool) *Statement {
|
||||
statement.NoAutoCondition = true
|
||||
if len(no) > 0 {
|
||||
statement.NoAutoCondition = no[0]
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// Conds returns condtions
|
||||
func (statement *Statement) Conds() builder.Cond {
|
||||
return statement.cond
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
// Copyright 2023 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package statements
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func (statement *Statement) writeDeleteOrder(w *builder.BytesWriter) error {
|
||||
if err := statement.writeOrderBys(w); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if statement.LimitN != nil && *statement.LimitN > 0 {
|
||||
limitNValue := *statement.LimitN
|
||||
if _, err := fmt.Fprintf(w, " LIMIT %d", limitNValue); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ErrNotImplemented not implemented
|
||||
var ErrNotImplemented = errors.New("Not implemented")
|
||||
|
||||
func (statement *Statement) writeOrderCond(orderCondWriter *builder.BytesWriter, tableName string) error {
|
||||
orderSQLWriter := builder.NewWriter()
|
||||
if err := statement.writeDeleteOrder(orderSQLWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if orderSQLWriter.Len() == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch statement.dialect.URI().DBType {
|
||||
case schemas.POSTGRES:
|
||||
if statement.cond.IsValid() {
|
||||
if _, err := fmt.Fprint(orderCondWriter, " AND "); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := fmt.Fprint(orderCondWriter, " WHERE "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprintf(orderCondWriter, "ctid IN (SELECT ctid FROM %s%s)", tableName, orderSQLWriter.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
orderCondWriter.Append(orderSQLWriter.Args()...)
|
||||
return nil
|
||||
case schemas.SQLITE:
|
||||
if statement.cond.IsValid() {
|
||||
if _, err := fmt.Fprint(orderCondWriter, " AND "); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := fmt.Fprint(orderCondWriter, " WHERE "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprintf(orderCondWriter, "rowid IN (SELECT rowid FROM %s%s)", tableName, orderSQLWriter.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
orderCondWriter.Append(orderSQLWriter.Args()...)
|
||||
return nil
|
||||
// TODO: how to handle delete limit on mssql?
|
||||
case schemas.MSSQL:
|
||||
return ErrNotImplemented
|
||||
default:
|
||||
return utils.WriteBuilder(orderCondWriter, orderSQLWriter)
|
||||
}
|
||||
}
|
||||
|
||||
func (statement *Statement) WriteDelete(realSQLWriter, deleteSQLWriter *builder.BytesWriter, nowTime func(*schemas.Column) (interface{}, time.Time, error)) error {
|
||||
tableNameNoQuote := statement.TableName()
|
||||
tableName := statement.dialect.Quoter().Quote(tableNameNoQuote)
|
||||
table := statement.RefTable
|
||||
if _, err := fmt.Fprint(deleteSQLWriter, "DELETE FROM ", tableName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeWhere(deleteSQLWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
orderCondWriter := builder.NewWriter()
|
||||
if err := statement.writeOrderCond(orderCondWriter, tableName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if statement.GetUnscoped() || table == nil || table.DeletedColumn() == nil { // tag "deleted" is disabled
|
||||
return utils.WriteBuilder(realSQLWriter, deleteSQLWriter, orderCondWriter)
|
||||
}
|
||||
|
||||
deletedColumn := table.DeletedColumn()
|
||||
if _, err := fmt.Fprintf(realSQLWriter, "UPDATE %v SET %v = ?",
|
||||
statement.dialect.Quoter().Quote(statement.TableName()),
|
||||
statement.dialect.Quoter().Quote(deletedColumn.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val, _, err := nowTime(deletedColumn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
realSQLWriter.Append(val)
|
||||
|
||||
if err := statement.writeWhere(realSQLWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utils.WriteBuilder(realSQLWriter, orderCondWriter)
|
||||
}
|
|
@ -43,8 +43,8 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{})
|
|||
return "", nil, err
|
||||
}
|
||||
|
||||
var hasInsertColumns = len(colNames) > 0
|
||||
var needSeq = len(table.AutoIncrement) > 0 && (statement.dialect.URI().DBType == schemas.ORACLE || statement.dialect.URI().DBType == schemas.DAMENG)
|
||||
hasInsertColumns := len(colNames) > 0
|
||||
needSeq := len(table.AutoIncrement) > 0 && (statement.dialect.URI().DBType == schemas.ORACLE || statement.dialect.URI().DBType == schemas.DAMENG)
|
||||
if needSeq {
|
||||
for _, col := range colNames {
|
||||
if strings.EqualFold(col, table.AutoIncrement) {
|
||||
|
@ -124,11 +124,7 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{})
|
|||
return "", nil, err
|
||||
}
|
||||
|
||||
if _, err := buf.WriteString(" WHERE "); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := statement.Conds().WriteTo(buf); err != nil {
|
||||
if err := statement.writeWhere(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
} else {
|
||||
|
@ -297,3 +293,99 @@ func (statement *Statement) GenInsertMultipleMapSQL(columns []string, argss [][]
|
|||
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeColumns(w *builder.BytesWriter, slice []string) error {
|
||||
for i, s := range slice {
|
||||
if i > 0 {
|
||||
if _, err := fmt.Fprint(w, ","); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := statement.dialect.Quoter().QuoteTo(w.Builder, s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeQuestions(w *builder.BytesWriter, length int) error {
|
||||
for i := 0; i < length; i++ {
|
||||
if i > 0 {
|
||||
if _, err := fmt.Fprint(w, ","); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprint(w, "?"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) oracleWriteInsertMultiple(w *builder.BytesWriter, tableName string, colNames []string, colMultiPlaces []string) error {
|
||||
if _, err := fmt.Fprint(w, "INSERT ALL"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, cols := range colMultiPlaces {
|
||||
if _, err := fmt.Fprint(w, " INTO "); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.dialect.Quoter().QuoteTo(w.Builder, tableName); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprint(w, " ("); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeColumns(w, colNames); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprint(w, ") VALUES ("); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprintf(w, cols, ")"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprint(w, " SELECT 1 FROM DUAL"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) WriteInsertMultiple(w *builder.BytesWriter, tableName string, colNames []string, colMultiPlaces []string) error {
|
||||
if statement.dialect.URI().DBType == schemas.ORACLE {
|
||||
return statement.oracleWriteInsertMultiple(w, tableName, colNames, colMultiPlaces)
|
||||
}
|
||||
return statement.plainWriteInsertMultiple(w, tableName, colNames, colMultiPlaces)
|
||||
}
|
||||
|
||||
func (statement *Statement) plainWriteInsertMultiple(w *builder.BytesWriter, tableName string, colNames []string, colMultiPlaces []string) error {
|
||||
if _, err := fmt.Fprint(w, "INSERT INTO "); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.dialect.Quoter().QuoteTo(w.Builder, tableName); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprint(w, " ("); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeColumns(w, colNames); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprint(w, ") VALUES ("); err != nil {
|
||||
return err
|
||||
}
|
||||
for i, cols := range colMultiPlaces {
|
||||
if _, err := fmt.Fprint(w, cols, ")"); err != nil {
|
||||
return err
|
||||
}
|
||||
if i < len(colMultiPlaces)-1 {
|
||||
if _, err := fmt.Fprint(w, ",("); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
// Copyright 2022 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package statements
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/dialects"
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
// Join The joinOP should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
|
||||
func (statement *Statement) Join(joinOP string, joinTable interface{}, condition interface{}, args ...interface{}) *Statement {
|
||||
statement.joins = append(statement.joins, join{
|
||||
op: joinOP,
|
||||
table: joinTable,
|
||||
condition: condition,
|
||||
args: args,
|
||||
})
|
||||
return statement
|
||||
}
|
||||
|
||||
func (statement *Statement) writeJoins(w *builder.BytesWriter) error {
|
||||
for _, join := range statement.joins {
|
||||
if err := statement.writeJoin(w, join); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeJoin(buf *builder.BytesWriter, join join) error {
|
||||
// write join operator
|
||||
if _, err := fmt.Fprint(buf, " ", join.op, " JOIN"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// write join table or subquery
|
||||
switch tp := join.table.(type) {
|
||||
case builder.Builder:
|
||||
if _, err := fmt.Fprintf(buf, " ("); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tp.WriteTo(statement.QuoteReplacer(buf)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fields := strings.Split(tp.TableName(), ".")
|
||||
aliasName := statement.dialect.Quoter().Trim(fields[len(fields)-1])
|
||||
aliasName = schemas.CommonQuoter.Trim(aliasName)
|
||||
|
||||
if _, err := fmt.Fprintf(buf, ") %s", statement.quote(aliasName)); err != nil {
|
||||
return err
|
||||
}
|
||||
case *builder.Builder:
|
||||
if _, err := fmt.Fprintf(buf, " ("); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tp.WriteTo(statement.QuoteReplacer(buf)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fields := strings.Split(tp.TableName(), ".")
|
||||
aliasName := statement.dialect.Quoter().Trim(fields[len(fields)-1])
|
||||
aliasName = schemas.CommonQuoter.Trim(aliasName)
|
||||
|
||||
if _, err := fmt.Fprintf(buf, ") %s", statement.quote(aliasName)); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
tbName := dialects.FullTableName(statement.dialect, statement.tagParser.GetTableMapper(), join.table, true)
|
||||
if !utils.IsSubQuery(tbName) {
|
||||
var sb strings.Builder
|
||||
if err := statement.dialect.Quoter().QuoteTo(&sb, tbName); err != nil {
|
||||
return err
|
||||
}
|
||||
tbName = sb.String()
|
||||
} else {
|
||||
tbName = statement.ReplaceQuote(tbName)
|
||||
}
|
||||
if _, err := fmt.Fprint(buf, " ", tbName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// write on condition
|
||||
if _, err := fmt.Fprint(buf, " ON "); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch condTp := join.condition.(type) {
|
||||
case string:
|
||||
if _, err := fmt.Fprint(buf, statement.ReplaceQuote(condTp)); err != nil {
|
||||
return err
|
||||
}
|
||||
case builder.Cond:
|
||||
if err := condTp.WriteTo(statement.QuoteReplacer(buf)); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unsupported join condition type: %v", condTp)
|
||||
}
|
||||
buf.Append(join.args...)
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
// Copyright 2022 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package statements
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
type orderBy struct {
|
||||
orderStr interface{}
|
||||
orderArgs []interface{}
|
||||
direction string // ASC, DESC or "", "" means raw orderStr
|
||||
}
|
||||
|
||||
func (ob orderBy) CheckValid() error {
|
||||
if ob.orderStr == nil {
|
||||
return fmt.Errorf("order by string is nil")
|
||||
}
|
||||
switch t := ob.orderStr.(type) {
|
||||
case string:
|
||||
if t == "" {
|
||||
return fmt.Errorf("order by string is empty")
|
||||
}
|
||||
return nil
|
||||
case *builder.Expression:
|
||||
if t.Content() == "" {
|
||||
return fmt.Errorf("order by string is empty")
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("order by string is not string or builder.Expression")
|
||||
}
|
||||
}
|
||||
|
||||
func (statement *Statement) HasOrderBy() bool {
|
||||
return len(statement.orderBy) > 0
|
||||
}
|
||||
|
||||
// ResetOrderBy reset ordery conditions
|
||||
func (statement *Statement) ResetOrderBy() {
|
||||
statement.orderBy = []orderBy{}
|
||||
}
|
||||
|
||||
var ErrNoColumnName = errors.New("no column name")
|
||||
|
||||
func (statement *Statement) writeOrderBy(w *builder.BytesWriter, orderBy orderBy) error {
|
||||
switch t := orderBy.orderStr.(type) {
|
||||
case (*builder.Expression):
|
||||
if _, err := fmt.Fprint(w.Builder, statement.dialect.Quoter().Replace(t.Content())); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Append(t.Args()...)
|
||||
return nil
|
||||
case string:
|
||||
if orderBy.direction == "" {
|
||||
if _, err := fmt.Fprint(w.Builder, statement.dialect.Quoter().Replace(t)); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Append(orderBy.orderArgs...)
|
||||
return nil
|
||||
}
|
||||
if err := statement.dialect.Quoter().QuoteTo(w.Builder, t); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprint(w, " ", orderBy.direction)
|
||||
return err
|
||||
default:
|
||||
return ErrUnSupportedSQLType
|
||||
}
|
||||
}
|
||||
|
||||
// WriteOrderBy write order by to writer
|
||||
func (statement *Statement) writeOrderBys(w *builder.BytesWriter) error {
|
||||
if len(statement.orderBy) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprint(w, " ORDER BY "); err != nil {
|
||||
return err
|
||||
}
|
||||
for i, ob := range statement.orderBy {
|
||||
if err := statement.writeOrderBy(w, ob); err != nil {
|
||||
return err
|
||||
}
|
||||
if i < len(statement.orderBy)-1 {
|
||||
if _, err := fmt.Fprint(w, ", "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// OrderBy generate "Order By order" statement
|
||||
func (statement *Statement) OrderBy(order interface{}, args ...interface{}) *Statement {
|
||||
ob := orderBy{order, args, ""}
|
||||
if err := ob.CheckValid(); err != nil {
|
||||
statement.LastError = err
|
||||
return statement
|
||||
}
|
||||
statement.orderBy = append(statement.orderBy, ob)
|
||||
return statement
|
||||
}
|
||||
|
||||
// Desc generate `ORDER BY xx DESC`
|
||||
func (statement *Statement) Desc(colNames ...string) *Statement {
|
||||
if len(colNames) == 0 {
|
||||
statement.LastError = ErrNoColumnName
|
||||
return statement
|
||||
}
|
||||
for _, colName := range colNames {
|
||||
ob := orderBy{colName, nil, "DESC"}
|
||||
statement.orderBy = append(statement.orderBy, ob)
|
||||
if err := ob.CheckValid(); err != nil {
|
||||
statement.LastError = err
|
||||
return statement
|
||||
}
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// Asc provide asc order by query condition, the input parameters are columns.
|
||||
func (statement *Statement) Asc(colNames ...string) *Statement {
|
||||
if len(colNames) == 0 {
|
||||
statement.LastError = ErrNoColumnName
|
||||
return statement
|
||||
}
|
||||
for _, colName := range colNames {
|
||||
ob := orderBy{colName, nil, "ASC"}
|
||||
statement.orderBy = append(statement.orderBy, ob)
|
||||
if err := ob.CheckValid(); err != nil {
|
||||
statement.LastError = err
|
||||
return statement
|
||||
}
|
||||
}
|
||||
return statement
|
||||
}
|
|
@ -7,10 +7,12 @@ package statements
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
|
@ -28,49 +30,15 @@ func (statement *Statement) GenQuerySQL(sqlOrArgs ...interface{}) (string, []int
|
|||
return "", nil, ErrTableNotFound
|
||||
}
|
||||
|
||||
var columnStr = statement.ColumnStr()
|
||||
if len(statement.SelectStr) > 0 {
|
||||
columnStr = statement.SelectStr
|
||||
} else {
|
||||
if statement.JoinStr == "" {
|
||||
if columnStr == "" {
|
||||
if statement.GroupByStr != "" {
|
||||
columnStr = statement.quoteColumnStr(statement.GroupByStr)
|
||||
} else {
|
||||
columnStr = statement.genColumnStr()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if columnStr == "" {
|
||||
if statement.GroupByStr != "" {
|
||||
columnStr = statement.quoteColumnStr(statement.GroupByStr)
|
||||
} else {
|
||||
columnStr = "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
if columnStr == "" {
|
||||
columnStr = "*"
|
||||
}
|
||||
}
|
||||
|
||||
if err := statement.ProcessIDParam(); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
sqlStr, condArgs, err := statement.genSelectSQL(columnStr, true, true)
|
||||
if err != nil {
|
||||
buf := builder.NewWriter()
|
||||
if err := statement.writeSelect(buf, statement.genSelectColumnStr(), true, true); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
args := append(statement.joinArgs, condArgs...)
|
||||
|
||||
// for mssql and use limit
|
||||
qs := strings.Count(sqlStr, "?")
|
||||
if len(args)*2 == qs {
|
||||
args = append(args, args...)
|
||||
}
|
||||
|
||||
return sqlStr, args, nil
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
// GenSumSQL generates sum SQL
|
||||
|
@ -83,7 +51,7 @@ func (statement *Statement) GenSumSQL(bean interface{}, columns ...string) (stri
|
|||
return "", nil, err
|
||||
}
|
||||
|
||||
var sumStrs = make([]string, 0, len(columns))
|
||||
sumStrs := make([]string, 0, len(columns))
|
||||
for _, colName := range columns {
|
||||
if !strings.Contains(colName, " ") && !strings.Contains(colName, "(") {
|
||||
colName = statement.quote(colName)
|
||||
|
@ -92,18 +60,16 @@ func (statement *Statement) GenSumSQL(bean interface{}, columns ...string) (stri
|
|||
}
|
||||
sumStrs = append(sumStrs, fmt.Sprintf("COALESCE(sum(%s),0)", colName))
|
||||
}
|
||||
sumSelect := strings.Join(sumStrs, ", ")
|
||||
|
||||
if err := statement.mergeConds(bean); err != nil {
|
||||
if err := statement.MergeConds(bean); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
sqlStr, condArgs, err := statement.genSelectSQL(sumSelect, true, true)
|
||||
if err != nil {
|
||||
buf := builder.NewWriter()
|
||||
if err := statement.writeSelect(buf, strings.Join(sumStrs, ", "), true, true); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
return sqlStr, append(statement.joinArgs, condArgs...), nil
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
// GenGetSQL generates Get SQL
|
||||
|
@ -119,12 +85,12 @@ func (statement *Statement) GenGetSQL(bean interface{}) (string, []interface{},
|
|||
}
|
||||
}
|
||||
|
||||
var columnStr = statement.ColumnStr()
|
||||
columnStr := statement.ColumnStr()
|
||||
if len(statement.SelectStr) > 0 {
|
||||
columnStr = statement.SelectStr
|
||||
} else {
|
||||
// TODO: always generate column names, not use * even if join
|
||||
if len(statement.JoinStr) == 0 {
|
||||
if len(statement.joins) == 0 {
|
||||
if len(columnStr) == 0 {
|
||||
if len(statement.GroupByStr) > 0 {
|
||||
columnStr = statement.quoteColumnStr(statement.GroupByStr)
|
||||
|
@ -146,7 +112,7 @@ func (statement *Statement) GenGetSQL(bean interface{}) (string, []interface{},
|
|||
}
|
||||
|
||||
if isStruct {
|
||||
if err := statement.mergeConds(bean); err != nil {
|
||||
if err := statement.MergeConds(bean); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
} else {
|
||||
|
@ -155,12 +121,11 @@ func (statement *Statement) GenGetSQL(bean interface{}) (string, []interface{},
|
|||
}
|
||||
}
|
||||
|
||||
sqlStr, condArgs, err := statement.genSelectSQL(columnStr, true, true)
|
||||
if err != nil {
|
||||
buf := builder.NewWriter()
|
||||
if err := statement.writeSelect(buf, columnStr, true, true); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
return sqlStr, append(statement.joinArgs, condArgs...), nil
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
// GenCountSQL generates the SQL for counting
|
||||
|
@ -169,18 +134,16 @@ func (statement *Statement) GenCountSQL(beans ...interface{}) (string, []interfa
|
|||
return statement.GenRawSQL(), statement.RawParams, nil
|
||||
}
|
||||
|
||||
var condArgs []interface{}
|
||||
var err error
|
||||
if len(beans) > 0 {
|
||||
if err := statement.SetRefBean(beans[0]); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.mergeConds(beans[0]); err != nil {
|
||||
if err := statement.MergeConds(beans[0]); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var selectSQL = statement.SelectStr
|
||||
selectSQL := statement.SelectStr
|
||||
if len(selectSQL) <= 0 {
|
||||
if statement.IsDistinct {
|
||||
selectSQL = fmt.Sprintf("count(DISTINCT %s)", statement.ColumnStr())
|
||||
|
@ -190,6 +153,14 @@ func (statement *Statement) GenCountSQL(beans ...interface{}) (string, []interfa
|
|||
selectSQL = "count(*)"
|
||||
}
|
||||
}
|
||||
|
||||
buf := builder.NewWriter()
|
||||
if statement.GroupByStr != "" {
|
||||
if _, err := fmt.Fprintf(buf, "SELECT %s FROM (", selectSQL); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var subQuerySelect string
|
||||
if statement.GroupByStr != "" {
|
||||
subQuerySelect = statement.GroupByStr
|
||||
|
@ -197,160 +168,238 @@ func (statement *Statement) GenCountSQL(beans ...interface{}) (string, []interfa
|
|||
subQuerySelect = selectSQL
|
||||
}
|
||||
|
||||
sqlStr, condArgs, err := statement.genSelectSQL(subQuerySelect, false, false)
|
||||
if err != nil {
|
||||
if err := statement.writeSelect(buf, subQuerySelect, false, false); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if statement.GroupByStr != "" {
|
||||
sqlStr = fmt.Sprintf("SELECT %s FROM (%s) sub", selectSQL, sqlStr)
|
||||
if _, err := fmt.Fprintf(buf, ") sub"); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return sqlStr, append(statement.joinArgs, condArgs...), nil
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
func (statement *Statement) fromBuilder() *strings.Builder {
|
||||
var builder strings.Builder
|
||||
var quote = statement.quote
|
||||
var dialect = statement.dialect
|
||||
func (statement *Statement) writeFrom(w *builder.BytesWriter) error {
|
||||
if _, err := fmt.Fprint(w, " FROM "); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeTableName(w); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeAlias(w); err != nil {
|
||||
return err
|
||||
}
|
||||
return statement.writeJoins(w)
|
||||
}
|
||||
|
||||
builder.WriteString(" FROM ")
|
||||
func (statement *Statement) writeLimitOffset(w builder.Writer) error {
|
||||
if statement.Start > 0 {
|
||||
if statement.LimitN != nil {
|
||||
_, err := fmt.Fprintf(w, " LIMIT %v OFFSET %v", *statement.LimitN, statement.Start)
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprintf(w, " LIMIT 0 OFFSET %v", statement.Start)
|
||||
return err
|
||||
}
|
||||
if statement.LimitN != nil {
|
||||
_, err := fmt.Fprint(w, " LIMIT ", *statement.LimitN)
|
||||
return err
|
||||
}
|
||||
// no limit statement
|
||||
return nil
|
||||
}
|
||||
|
||||
if dialect.URI().DBType == schemas.MSSQL && strings.Contains(statement.TableName(), "..") {
|
||||
builder.WriteString(statement.TableName())
|
||||
func (statement *Statement) writeTop(w builder.Writer) error {
|
||||
if statement.dialect.URI().DBType != schemas.MSSQL {
|
||||
return nil
|
||||
}
|
||||
if statement.LimitN == nil {
|
||||
return nil
|
||||
}
|
||||
_, err := fmt.Fprintf(w, " TOP %d", *statement.LimitN)
|
||||
return err
|
||||
}
|
||||
|
||||
func (statement *Statement) writeDistinct(w builder.Writer) error {
|
||||
if statement.IsDistinct && !strings.HasPrefix(statement.SelectStr, "count(") {
|
||||
_, err := fmt.Fprint(w, " DISTINCT")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeSelectColumns(w *builder.BytesWriter, columnStr string) error {
|
||||
if _, err := fmt.Fprintf(w, "SELECT"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeDistinct(w); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeTop(w); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprint(w, " ", columnStr)
|
||||
return err
|
||||
}
|
||||
|
||||
func (statement *Statement) writeWhereCond(w *builder.BytesWriter, cond builder.Cond) error {
|
||||
if !cond.IsValid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprint(w, " WHERE "); err != nil {
|
||||
return err
|
||||
}
|
||||
return cond.WriteTo(statement.QuoteReplacer(w))
|
||||
}
|
||||
|
||||
func (statement *Statement) writeWhere(w *builder.BytesWriter) error {
|
||||
return statement.writeWhereCond(w, statement.cond)
|
||||
}
|
||||
|
||||
func (statement *Statement) writeWhereWithMssqlPagination(w *builder.BytesWriter) error {
|
||||
if !statement.cond.IsValid() {
|
||||
return statement.writeMssqlPaginationCond(w)
|
||||
}
|
||||
if _, err := fmt.Fprint(w, " WHERE "); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.cond.WriteTo(statement.QuoteReplacer(w)); err != nil {
|
||||
return err
|
||||
}
|
||||
return statement.writeMssqlPaginationCond(w)
|
||||
}
|
||||
|
||||
func (statement *Statement) writeForUpdate(w io.Writer) error {
|
||||
if !statement.IsForUpdate {
|
||||
return nil
|
||||
}
|
||||
|
||||
if statement.dialect.URI().DBType != schemas.MYSQL {
|
||||
return errors.New("only support mysql for update")
|
||||
}
|
||||
_, err := fmt.Fprint(w, " FOR UPDATE")
|
||||
return err
|
||||
}
|
||||
|
||||
func (statement *Statement) writeMssqlPaginationCond(w *builder.BytesWriter) error {
|
||||
if statement.dialect.URI().DBType != schemas.MSSQL || statement.Start <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if statement.RefTable == nil {
|
||||
return errors.New("unsupported query limit without reference table")
|
||||
}
|
||||
|
||||
var column string
|
||||
if len(statement.RefTable.PKColumns()) == 0 {
|
||||
for _, index := range statement.RefTable.Indexes {
|
||||
if len(index.Cols) == 1 {
|
||||
column = index.Cols[0]
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(column) == 0 {
|
||||
column = statement.RefTable.ColumnsSeq()[0]
|
||||
}
|
||||
} else {
|
||||
builder.WriteString(quote(statement.TableName()))
|
||||
column = statement.RefTable.PKColumns()[0].Name
|
||||
}
|
||||
if statement.NeedTableName() {
|
||||
if len(statement.TableAlias) > 0 {
|
||||
column = fmt.Sprintf("%s.%s", statement.TableAlias, column)
|
||||
} else {
|
||||
column = fmt.Sprintf("%s.%s", statement.TableName(), column)
|
||||
}
|
||||
}
|
||||
|
||||
if statement.TableAlias != "" {
|
||||
if dialect.URI().DBType == schemas.ORACLE {
|
||||
builder.WriteString(" ")
|
||||
} else {
|
||||
builder.WriteString(" AS ")
|
||||
subWriter := builder.NewWriter()
|
||||
if _, err := fmt.Fprintf(subWriter, "(%s NOT IN (SELECT TOP %d %s",
|
||||
column, statement.Start, column); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeFrom(subWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeWhere(subWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeOrderBys(subWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeGroupBy(subWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprint(subWriter, "))"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if statement.cond.IsValid() {
|
||||
if _, err := fmt.Fprint(w, " AND "); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := fmt.Fprint(w, " WHERE "); err != nil {
|
||||
return err
|
||||
}
|
||||
builder.WriteString(quote(statement.TableAlias))
|
||||
}
|
||||
if statement.JoinStr != "" {
|
||||
builder.WriteString(" ")
|
||||
builder.WriteString(statement.JoinStr)
|
||||
}
|
||||
return &builder
|
||||
|
||||
return utils.WriteBuilder(w, subWriter)
|
||||
}
|
||||
|
||||
func (statement *Statement) genSelectSQL(columnStr string, needLimit, needOrderBy bool) (string, []interface{}, error) {
|
||||
var (
|
||||
distinct string
|
||||
dialect = statement.dialect
|
||||
fromStr = statement.fromBuilder().String()
|
||||
top, mssqlCondi, whereStr string
|
||||
)
|
||||
|
||||
if statement.IsDistinct && !strings.HasPrefix(columnStr, "count") {
|
||||
distinct = "DISTINCT "
|
||||
func (statement *Statement) writeOracleLimit(w *builder.BytesWriter, columnStr string) error {
|
||||
if statement.LimitN == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
condSQL, condArgs, err := statement.GenCondSQL(statement.cond)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
oldString := w.String()
|
||||
w.Reset()
|
||||
rawColStr := columnStr
|
||||
if rawColStr == "*" {
|
||||
rawColStr = "at.*"
|
||||
}
|
||||
if len(condSQL) > 0 {
|
||||
whereStr = fmt.Sprintf(" WHERE %s", condSQL)
|
||||
_, err := fmt.Fprintf(w, "SELECT %v FROM (SELECT %v,ROWNUM RN FROM (%v) at WHERE ROWNUM <= %d) aat WHERE RN > %d",
|
||||
columnStr, rawColStr, oldString, statement.Start+*statement.LimitN, statement.Start)
|
||||
return err
|
||||
}
|
||||
|
||||
func (statement *Statement) writeSelect(buf *builder.BytesWriter, columnStr string, needLimit, needOrderBy bool) error {
|
||||
if err := statement.writeSelectColumns(buf, columnStr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pLimitN := statement.LimitN
|
||||
if dialect.URI().DBType == schemas.MSSQL {
|
||||
if pLimitN != nil {
|
||||
LimitNValue := *pLimitN
|
||||
top = fmt.Sprintf("TOP %d ", LimitNValue)
|
||||
}
|
||||
if statement.Start > 0 {
|
||||
if statement.RefTable == nil {
|
||||
return "", nil, errors.New("Unsupported query limit without reference table")
|
||||
}
|
||||
var column string
|
||||
if len(statement.RefTable.PKColumns()) == 0 {
|
||||
for _, index := range statement.RefTable.Indexes {
|
||||
if len(index.Cols) == 1 {
|
||||
column = index.Cols[0]
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(column) == 0 {
|
||||
column = statement.RefTable.ColumnsSeq()[0]
|
||||
}
|
||||
} else {
|
||||
column = statement.RefTable.PKColumns()[0].Name
|
||||
}
|
||||
if statement.needTableName() {
|
||||
if len(statement.TableAlias) > 0 {
|
||||
column = fmt.Sprintf("%s.%s", statement.TableAlias, column)
|
||||
} else {
|
||||
column = fmt.Sprintf("%s.%s", statement.TableName(), column)
|
||||
}
|
||||
}
|
||||
|
||||
var orderStr string
|
||||
if needOrderBy && len(statement.OrderStr) > 0 {
|
||||
orderStr = fmt.Sprintf(" ORDER BY %s", statement.OrderStr)
|
||||
}
|
||||
|
||||
var groupStr string
|
||||
if len(statement.GroupByStr) > 0 {
|
||||
groupStr = fmt.Sprintf(" GROUP BY %s", statement.GroupByStr)
|
||||
}
|
||||
mssqlCondi = fmt.Sprintf("(%s NOT IN (SELECT TOP %d %s%s%s%s%s))",
|
||||
column, statement.Start, column, fromStr, whereStr, orderStr, groupStr)
|
||||
if err := statement.writeFrom(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeWhereWithMssqlPagination(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeGroupBy(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeHaving(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
if needOrderBy {
|
||||
if err := statement.writeOrderBys(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var buf strings.Builder
|
||||
fmt.Fprintf(&buf, "SELECT %v%v%v%v%v", distinct, top, columnStr, fromStr, whereStr)
|
||||
if len(mssqlCondi) > 0 {
|
||||
if len(whereStr) > 0 {
|
||||
fmt.Fprint(&buf, " AND ", mssqlCondi)
|
||||
} else {
|
||||
fmt.Fprint(&buf, " WHERE ", mssqlCondi)
|
||||
}
|
||||
}
|
||||
|
||||
if statement.GroupByStr != "" {
|
||||
fmt.Fprint(&buf, " GROUP BY ", statement.GroupByStr)
|
||||
}
|
||||
if statement.HavingStr != "" {
|
||||
fmt.Fprint(&buf, " ", statement.HavingStr)
|
||||
}
|
||||
if needOrderBy && statement.OrderStr != "" {
|
||||
fmt.Fprint(&buf, " ORDER BY ", statement.OrderStr)
|
||||
}
|
||||
dialect := statement.dialect
|
||||
if needLimit {
|
||||
if dialect.URI().DBType != schemas.MSSQL && dialect.URI().DBType != schemas.ORACLE {
|
||||
if statement.Start > 0 {
|
||||
if pLimitN != nil {
|
||||
fmt.Fprintf(&buf, " LIMIT %v OFFSET %v", *pLimitN, statement.Start)
|
||||
} else {
|
||||
fmt.Fprintf(&buf, " LIMIT 0 OFFSET %v", statement.Start)
|
||||
}
|
||||
} else if pLimitN != nil {
|
||||
fmt.Fprint(&buf, " LIMIT ", *pLimitN)
|
||||
if dialect.URI().DBType == schemas.ORACLE {
|
||||
if err := statement.writeOracleLimit(buf, columnStr); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if dialect.URI().DBType == schemas.ORACLE {
|
||||
if pLimitN != nil {
|
||||
oldString := buf.String()
|
||||
buf.Reset()
|
||||
rawColStr := columnStr
|
||||
if rawColStr == "*" {
|
||||
rawColStr = "at.*"
|
||||
}
|
||||
fmt.Fprintf(&buf, "SELECT %v FROM (SELECT %v,ROWNUM RN FROM (%v) at WHERE ROWNUM <= %d) aat WHERE RN > %d",
|
||||
columnStr, rawColStr, oldString, statement.Start+*pLimitN, statement.Start)
|
||||
} else if dialect.URI().DBType != schemas.MSSQL {
|
||||
if err := statement.writeLimitOffset(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if statement.IsForUpdate {
|
||||
return dialect.ForUpdateSQL(buf.String()), condArgs, nil
|
||||
}
|
||||
|
||||
return buf.String(), condArgs, nil
|
||||
return statement.writeForUpdate(buf)
|
||||
}
|
||||
|
||||
// GenExistSQL generates Exist SQL
|
||||
|
@ -359,10 +408,6 @@ func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interfac
|
|||
return statement.GenRawSQL(), statement.RawParams, nil
|
||||
}
|
||||
|
||||
var sqlStr string
|
||||
var args []interface{}
|
||||
var joinStr string
|
||||
var err error
|
||||
var b interface{}
|
||||
if len(bean) > 0 {
|
||||
b = bean[0]
|
||||
|
@ -381,45 +426,87 @@ func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interfac
|
|||
if len(tableName) <= 0 {
|
||||
return "", nil, ErrTableNotFound
|
||||
}
|
||||
if statement.RefTable == nil {
|
||||
tableName = statement.quote(tableName)
|
||||
if len(statement.JoinStr) > 0 {
|
||||
joinStr = statement.JoinStr
|
||||
}
|
||||
if statement.RefTable != nil {
|
||||
return statement.Limit(1).GenGetSQL(b)
|
||||
}
|
||||
|
||||
tableName = statement.quote(tableName)
|
||||
|
||||
buf := builder.NewWriter()
|
||||
if statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
if _, err := fmt.Fprintf(buf, "SELECT TOP 1 * FROM %s", tableName); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.writeJoins(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.writeWhere(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
} else if statement.dialect.URI().DBType == schemas.ORACLE {
|
||||
if _, err := fmt.Fprintf(buf, "SELECT * FROM %s", tableName); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.writeJoins(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if _, err := fmt.Fprintf(buf, " WHERE "); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if statement.Conds().IsValid() {
|
||||
condSQL, condArgs, err := statement.GenCondSQL(statement.Conds())
|
||||
if err != nil {
|
||||
if err := statement.Conds().WriteTo(statement.QuoteReplacer(buf)); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
sqlStr = fmt.Sprintf("SELECT TOP 1 * FROM %s %s WHERE %s", tableName, joinStr, condSQL)
|
||||
} else if statement.dialect.URI().DBType == schemas.ORACLE {
|
||||
sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE (%s) %s AND ROWNUM=1", tableName, joinStr, condSQL)
|
||||
} else {
|
||||
sqlStr = fmt.Sprintf("SELECT 1 FROM %s %s WHERE %s LIMIT 1", tableName, joinStr, condSQL)
|
||||
if _, err := fmt.Fprintf(buf, " AND "); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
args = condArgs
|
||||
} else {
|
||||
if statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
sqlStr = fmt.Sprintf("SELECT TOP 1 * FROM %s %s", tableName, joinStr)
|
||||
} else if statement.dialect.URI().DBType == schemas.ORACLE {
|
||||
sqlStr = fmt.Sprintf("SELECT * FROM %s %s WHERE ROWNUM=1", tableName, joinStr)
|
||||
} else {
|
||||
sqlStr = fmt.Sprintf("SELECT 1 FROM %s %s LIMIT 1", tableName, joinStr)
|
||||
}
|
||||
args = []interface{}{}
|
||||
}
|
||||
if _, err := fmt.Fprintf(buf, "ROWNUM=1"); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
} else {
|
||||
statement.Limit(1)
|
||||
sqlStr, args, err = statement.GenGetSQL(b)
|
||||
if err != nil {
|
||||
if _, err := fmt.Fprintf(buf, "SELECT 1 FROM %s", tableName); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.writeJoins(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.writeWhere(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if _, err := fmt.Fprintf(buf, " LIMIT 1"); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return sqlStr, args, nil
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
func (statement *Statement) genSelectColumnStr() string {
|
||||
// manually select columns
|
||||
if len(statement.SelectStr) > 0 {
|
||||
return statement.SelectStr
|
||||
}
|
||||
|
||||
columnStr := statement.ColumnStr()
|
||||
if columnStr != "" {
|
||||
return columnStr
|
||||
}
|
||||
|
||||
// autodetect columns
|
||||
if statement.GroupByStr != "" {
|
||||
return statement.quoteColumnStr(statement.GroupByStr)
|
||||
}
|
||||
|
||||
if len(statement.joins) != 0 {
|
||||
return "*"
|
||||
}
|
||||
|
||||
columnStr = statement.genColumnStr()
|
||||
if columnStr == "" {
|
||||
columnStr = "*"
|
||||
}
|
||||
return columnStr
|
||||
}
|
||||
|
||||
// GenFindSQL generates Find SQL
|
||||
|
@ -428,52 +515,15 @@ func (statement *Statement) GenFindSQL(autoCond builder.Cond) (string, []interfa
|
|||
return statement.GenRawSQL(), statement.RawParams, nil
|
||||
}
|
||||
|
||||
var sqlStr string
|
||||
var args []interface{}
|
||||
var err error
|
||||
|
||||
if len(statement.TableName()) <= 0 {
|
||||
return "", nil, ErrTableNotFound
|
||||
}
|
||||
|
||||
var columnStr = statement.ColumnStr()
|
||||
if len(statement.SelectStr) > 0 {
|
||||
columnStr = statement.SelectStr
|
||||
} else {
|
||||
if statement.JoinStr == "" {
|
||||
if columnStr == "" {
|
||||
if statement.GroupByStr != "" {
|
||||
columnStr = statement.quoteColumnStr(statement.GroupByStr)
|
||||
} else {
|
||||
columnStr = statement.genColumnStr()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if columnStr == "" {
|
||||
if statement.GroupByStr != "" {
|
||||
columnStr = statement.quoteColumnStr(statement.GroupByStr)
|
||||
} else {
|
||||
columnStr = "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
if columnStr == "" {
|
||||
columnStr = "*"
|
||||
}
|
||||
}
|
||||
|
||||
statement.cond = statement.cond.And(autoCond)
|
||||
|
||||
sqlStr, condArgs, err := statement.genSelectSQL(columnStr, true, true)
|
||||
if err != nil {
|
||||
buf := builder.NewWriter()
|
||||
if err := statement.writeSelect(buf, statement.genSelectColumnStr(), true, true); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
args = append(statement.joinArgs, condArgs...)
|
||||
// for mssql and use limit
|
||||
qs := strings.Count(sqlStr, "?")
|
||||
if len(args)*2 == qs {
|
||||
args = append(args, args...)
|
||||
}
|
||||
|
||||
return sqlStr, args, nil
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
// Copyright 2022 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package statements
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
// Select replace select
|
||||
func (statement *Statement) Select(str string) *Statement {
|
||||
statement.SelectStr = statement.ReplaceQuote(str)
|
||||
return statement
|
||||
}
|
||||
|
||||
func col2NewCols(columns ...string) []string {
|
||||
newColumns := make([]string, 0, len(columns))
|
||||
for _, col := range columns {
|
||||
col = strings.Replace(col, "`", "", -1)
|
||||
col = strings.Replace(col, `"`, "", -1)
|
||||
ccols := strings.Split(col, ",")
|
||||
for _, c := range ccols {
|
||||
newColumns = append(newColumns, strings.TrimSpace(c))
|
||||
}
|
||||
}
|
||||
return newColumns
|
||||
}
|
||||
|
||||
// Cols generate "col1, col2" statement
|
||||
func (statement *Statement) Cols(columns ...string) *Statement {
|
||||
cols := col2NewCols(columns...)
|
||||
for _, nc := range cols {
|
||||
statement.ColumnMap.Add(nc)
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// ColumnStr returns column string
|
||||
func (statement *Statement) ColumnStr() string {
|
||||
return statement.dialect.Quoter().Join(statement.ColumnMap, ", ")
|
||||
}
|
||||
|
||||
// AllCols update use only: update all columns
|
||||
func (statement *Statement) AllCols() *Statement {
|
||||
statement.useAllCols = true
|
||||
return statement
|
||||
}
|
||||
|
||||
// MustCols update use only: must update columns
|
||||
func (statement *Statement) MustCols(columns ...string) *Statement {
|
||||
newColumns := col2NewCols(columns...)
|
||||
for _, nc := range newColumns {
|
||||
statement.MustColumnMap[strings.ToLower(nc)] = true
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// UseBool indicates that use bool fields as update contents and query contiditions
|
||||
func (statement *Statement) UseBool(columns ...string) *Statement {
|
||||
if len(columns) > 0 {
|
||||
statement.MustCols(columns...)
|
||||
} else {
|
||||
statement.allUseBool = true
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// Omit do not use the columns
|
||||
func (statement *Statement) Omit(columns ...string) {
|
||||
newColumns := col2NewCols(columns...)
|
||||
for _, nc := range newColumns {
|
||||
statement.OmitColumnMap = append(statement.OmitColumnMap, nc)
|
||||
}
|
||||
}
|
||||
|
||||
func (statement *Statement) genColumnStr() string {
|
||||
if statement.RefTable == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var buf strings.Builder
|
||||
columns := statement.RefTable.Columns()
|
||||
|
||||
for _, col := range columns {
|
||||
if statement.OmitColumnMap.Contain(col.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(statement.ColumnMap) > 0 && !statement.ColumnMap.Contain(col.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
if col.MapType == schemas.ONLYTODB {
|
||||
continue
|
||||
}
|
||||
|
||||
if buf.Len() != 0 {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
|
||||
if len(statement.joins) > 0 {
|
||||
if statement.TableAlias != "" {
|
||||
buf.WriteString(statement.TableAlias)
|
||||
} else {
|
||||
buf.WriteString(statement.TableName())
|
||||
}
|
||||
|
||||
buf.WriteString(".")
|
||||
}
|
||||
|
||||
statement.dialect.Quoter().QuoteTo(&buf, col.Name)
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (statement *Statement) colName(col *schemas.Column, tableName string) string {
|
||||
if statement.NeedTableName() {
|
||||
nm := tableName
|
||||
if len(statement.TableAlias) > 0 {
|
||||
nm = statement.TableAlias
|
||||
}
|
||||
return fmt.Sprintf("%s.%s", statement.quote(nm), statement.quote(col.Name))
|
||||
}
|
||||
return statement.quote(col.Name)
|
||||
}
|
||||
|
||||
// Distinct generates "DISTINCT col1, col2 " statement
|
||||
func (statement *Statement) Distinct(columns ...string) *Statement {
|
||||
statement.IsDistinct = true
|
||||
statement.Cols(columns...)
|
||||
return statement
|
||||
}
|
|
@ -34,6 +34,13 @@ var (
|
|||
ErrTableNotFound = errors.New("Table not found")
|
||||
)
|
||||
|
||||
type join struct {
|
||||
op string
|
||||
table interface{}
|
||||
condition interface{}
|
||||
args []interface{}
|
||||
}
|
||||
|
||||
// Statement save all the sql info for executing SQL
|
||||
type Statement struct {
|
||||
RefTable *schemas.Table
|
||||
|
@ -43,9 +50,8 @@ type Statement struct {
|
|||
Start int
|
||||
LimitN *int
|
||||
idParam schemas.PK
|
||||
OrderStr string
|
||||
JoinStr string
|
||||
joinArgs []interface{}
|
||||
orderBy []orderBy
|
||||
joins []join
|
||||
GroupByStr string
|
||||
HavingStr string
|
||||
SelectStr string
|
||||
|
@ -101,15 +107,6 @@ func (statement *Statement) GenRawSQL() string {
|
|||
return statement.ReplaceQuote(statement.RawSQL)
|
||||
}
|
||||
|
||||
// GenCondSQL generates condition SQL
|
||||
func (statement *Statement) GenCondSQL(condOrBuilder interface{}) (string, []interface{}, error) {
|
||||
condSQL, condArgs, err := builder.ToSQL(condOrBuilder)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return statement.ReplaceQuote(condSQL), condArgs, nil
|
||||
}
|
||||
|
||||
// ReplaceQuote replace sql key words with quote
|
||||
func (statement *Statement) ReplaceQuote(sql string) string {
|
||||
if sql == "" || statement.dialect.URI().DBType == schemas.MYSQL ||
|
||||
|
@ -129,10 +126,9 @@ func (statement *Statement) Reset() {
|
|||
statement.RefTable = nil
|
||||
statement.Start = 0
|
||||
statement.LimitN = nil
|
||||
statement.OrderStr = ""
|
||||
statement.ResetOrderBy()
|
||||
statement.UseCascade = true
|
||||
statement.JoinStr = ""
|
||||
statement.joinArgs = make([]interface{}, 0)
|
||||
statement.joins = nil
|
||||
statement.GroupByStr = ""
|
||||
statement.HavingStr = ""
|
||||
statement.ColumnMap = columnMap{}
|
||||
|
@ -164,32 +160,17 @@ func (statement *Statement) Reset() {
|
|||
statement.LastError = nil
|
||||
}
|
||||
|
||||
// SetNoAutoCondition if you do not want convert bean's field as query condition, then use this function
|
||||
func (statement *Statement) SetNoAutoCondition(no ...bool) *Statement {
|
||||
statement.NoAutoCondition = true
|
||||
if len(no) > 0 {
|
||||
statement.NoAutoCondition = no[0]
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// Alias set the table alias
|
||||
func (statement *Statement) Alias(alias string) *Statement {
|
||||
statement.TableAlias = alias
|
||||
return statement
|
||||
}
|
||||
|
||||
// SQL adds raw sql statement
|
||||
func (statement *Statement) SQL(query interface{}, args ...interface{}) *Statement {
|
||||
switch query.(type) {
|
||||
switch t := query.(type) {
|
||||
case (*builder.Builder):
|
||||
var err error
|
||||
statement.RawSQL, statement.RawParams, err = query.(*builder.Builder).ToSQL()
|
||||
statement.RawSQL, statement.RawParams, err = t.ToSQL()
|
||||
if err != nil {
|
||||
statement.LastError = err
|
||||
}
|
||||
case string:
|
||||
statement.RawSQL = query.(string)
|
||||
statement.RawSQL = t
|
||||
statement.RawParams = args
|
||||
default:
|
||||
statement.LastError = ErrUnSupportedSQLType
|
||||
|
@ -198,80 +179,10 @@ func (statement *Statement) SQL(query interface{}, args ...interface{}) *Stateme
|
|||
return statement
|
||||
}
|
||||
|
||||
// Where add Where statement
|
||||
func (statement *Statement) Where(query interface{}, args ...interface{}) *Statement {
|
||||
return statement.And(query, args...)
|
||||
}
|
||||
|
||||
func (statement *Statement) quote(s string) string {
|
||||
return statement.dialect.Quoter().Quote(s)
|
||||
}
|
||||
|
||||
// And add Where & and statement
|
||||
func (statement *Statement) And(query interface{}, args ...interface{}) *Statement {
|
||||
switch qr := query.(type) {
|
||||
case string:
|
||||
cond := builder.Expr(qr, args...)
|
||||
statement.cond = statement.cond.And(cond)
|
||||
case map[string]interface{}:
|
||||
cond := make(builder.Eq)
|
||||
for k, v := range qr {
|
||||
cond[statement.quote(k)] = v
|
||||
}
|
||||
statement.cond = statement.cond.And(cond)
|
||||
case builder.Cond:
|
||||
statement.cond = statement.cond.And(qr)
|
||||
for _, v := range args {
|
||||
if vv, ok := v.(builder.Cond); ok {
|
||||
statement.cond = statement.cond.And(vv)
|
||||
}
|
||||
}
|
||||
default:
|
||||
statement.LastError = ErrConditionType
|
||||
}
|
||||
|
||||
return statement
|
||||
}
|
||||
|
||||
// Or add Where & Or statement
|
||||
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
|
||||
switch qr := query.(type) {
|
||||
case string:
|
||||
cond := builder.Expr(qr, args...)
|
||||
statement.cond = statement.cond.Or(cond)
|
||||
case map[string]interface{}:
|
||||
cond := make(builder.Eq)
|
||||
for k, v := range qr {
|
||||
cond[statement.quote(k)] = v
|
||||
}
|
||||
statement.cond = statement.cond.Or(cond)
|
||||
case builder.Cond:
|
||||
statement.cond = statement.cond.Or(qr)
|
||||
for _, v := range args {
|
||||
if vv, ok := v.(builder.Cond); ok {
|
||||
statement.cond = statement.cond.Or(vv)
|
||||
}
|
||||
}
|
||||
default:
|
||||
statement.LastError = ErrConditionType
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// In generate "Where column IN (?) " statement
|
||||
func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
||||
in := builder.In(statement.quote(column), args...)
|
||||
statement.cond = statement.cond.And(in)
|
||||
return statement
|
||||
}
|
||||
|
||||
// NotIn generate "Where column NOT IN (?) " statement
|
||||
func (statement *Statement) NotIn(column string, args ...interface{}) *Statement {
|
||||
notIn := builder.NotIn(statement.quote(column), args...)
|
||||
statement.cond = statement.cond.And(notIn)
|
||||
return statement
|
||||
}
|
||||
|
||||
// SetRefValue set ref value
|
||||
func (statement *Statement) SetRefValue(v reflect.Value) error {
|
||||
var err error
|
||||
|
@ -298,28 +209,8 @@ func (statement *Statement) SetRefBean(bean interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) needTableName() bool {
|
||||
return len(statement.JoinStr) > 0
|
||||
}
|
||||
|
||||
func (statement *Statement) colName(col *schemas.Column, tableName string) string {
|
||||
if statement.needTableName() {
|
||||
var nm = tableName
|
||||
if len(statement.TableAlias) > 0 {
|
||||
nm = statement.TableAlias
|
||||
}
|
||||
return fmt.Sprintf("%s.%s", statement.quote(nm), statement.quote(col.Name))
|
||||
}
|
||||
return statement.quote(col.Name)
|
||||
}
|
||||
|
||||
// TableName return current tableName
|
||||
func (statement *Statement) TableName() string {
|
||||
if statement.AltTableName != "" {
|
||||
return statement.AltTableName
|
||||
}
|
||||
|
||||
return statement.tableName
|
||||
func (statement *Statement) NeedTableName() bool {
|
||||
return len(statement.joins) > 0
|
||||
}
|
||||
|
||||
// Incr Generate "Update ... Set column = column + arg" statement
|
||||
|
@ -352,85 +243,12 @@ func (statement *Statement) SetExpr(column string, expression interface{}) *Stat
|
|||
return statement
|
||||
}
|
||||
|
||||
// Distinct generates "DISTINCT col1, col2 " statement
|
||||
func (statement *Statement) Distinct(columns ...string) *Statement {
|
||||
statement.IsDistinct = true
|
||||
statement.Cols(columns...)
|
||||
return statement
|
||||
}
|
||||
|
||||
// ForUpdate generates "SELECT ... FOR UPDATE" statement
|
||||
func (statement *Statement) ForUpdate() *Statement {
|
||||
statement.IsForUpdate = true
|
||||
return statement
|
||||
}
|
||||
|
||||
// Select replace select
|
||||
func (statement *Statement) Select(str string) *Statement {
|
||||
statement.SelectStr = statement.ReplaceQuote(str)
|
||||
return statement
|
||||
}
|
||||
|
||||
func col2NewCols(columns ...string) []string {
|
||||
newColumns := make([]string, 0, len(columns))
|
||||
for _, col := range columns {
|
||||
col = strings.Replace(col, "`", "", -1)
|
||||
col = strings.Replace(col, `"`, "", -1)
|
||||
ccols := strings.Split(col, ",")
|
||||
for _, c := range ccols {
|
||||
newColumns = append(newColumns, strings.TrimSpace(c))
|
||||
}
|
||||
}
|
||||
return newColumns
|
||||
}
|
||||
|
||||
// Cols generate "col1, col2" statement
|
||||
func (statement *Statement) Cols(columns ...string) *Statement {
|
||||
cols := col2NewCols(columns...)
|
||||
for _, nc := range cols {
|
||||
statement.ColumnMap.Add(nc)
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// ColumnStr returns column string
|
||||
func (statement *Statement) ColumnStr() string {
|
||||
return statement.dialect.Quoter().Join(statement.ColumnMap, ", ")
|
||||
}
|
||||
|
||||
// AllCols update use only: update all columns
|
||||
func (statement *Statement) AllCols() *Statement {
|
||||
statement.useAllCols = true
|
||||
return statement
|
||||
}
|
||||
|
||||
// MustCols update use only: must update columns
|
||||
func (statement *Statement) MustCols(columns ...string) *Statement {
|
||||
newColumns := col2NewCols(columns...)
|
||||
for _, nc := range newColumns {
|
||||
statement.MustColumnMap[strings.ToLower(nc)] = true
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// UseBool indicates that use bool fields as update contents and query contiditions
|
||||
func (statement *Statement) UseBool(columns ...string) *Statement {
|
||||
if len(columns) > 0 {
|
||||
statement.MustCols(columns...)
|
||||
} else {
|
||||
statement.allUseBool = true
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// Omit do not use the columns
|
||||
func (statement *Statement) Omit(columns ...string) {
|
||||
newColumns := col2NewCols(columns...)
|
||||
for _, nc := range newColumns {
|
||||
statement.OmitColumnMap = append(statement.OmitColumnMap, nc)
|
||||
}
|
||||
}
|
||||
|
||||
// Nullable Update use only: update columns to null when value is nullable and zero-value
|
||||
func (statement *Statement) Nullable(columns ...string) {
|
||||
newColumns := col2NewCols(columns...)
|
||||
|
@ -454,54 +272,6 @@ func (statement *Statement) Limit(limit int, start ...int) *Statement {
|
|||
return statement
|
||||
}
|
||||
|
||||
// OrderBy generate "Order By order" statement
|
||||
func (statement *Statement) OrderBy(order string) *Statement {
|
||||
if len(statement.OrderStr) > 0 {
|
||||
statement.OrderStr += ", "
|
||||
}
|
||||
statement.OrderStr += statement.ReplaceQuote(order)
|
||||
return statement
|
||||
}
|
||||
|
||||
// Desc generate `ORDER BY xx DESC`
|
||||
func (statement *Statement) Desc(colNames ...string) *Statement {
|
||||
var buf strings.Builder
|
||||
if len(statement.OrderStr) > 0 {
|
||||
fmt.Fprint(&buf, statement.OrderStr, ", ")
|
||||
}
|
||||
for i, col := range colNames {
|
||||
if i > 0 {
|
||||
fmt.Fprint(&buf, ", ")
|
||||
}
|
||||
_ = statement.dialect.Quoter().QuoteTo(&buf, col)
|
||||
fmt.Fprint(&buf, " DESC")
|
||||
}
|
||||
statement.OrderStr = buf.String()
|
||||
return statement
|
||||
}
|
||||
|
||||
// Asc provide asc order by query condition, the input parameters are columns.
|
||||
func (statement *Statement) Asc(colNames ...string) *Statement {
|
||||
var buf strings.Builder
|
||||
if len(statement.OrderStr) > 0 {
|
||||
fmt.Fprint(&buf, statement.OrderStr, ", ")
|
||||
}
|
||||
for i, col := range colNames {
|
||||
if i > 0 {
|
||||
fmt.Fprint(&buf, ", ")
|
||||
}
|
||||
_ = statement.dialect.Quoter().QuoteTo(&buf, col)
|
||||
fmt.Fprint(&buf, " ASC")
|
||||
}
|
||||
statement.OrderStr = buf.String()
|
||||
return statement
|
||||
}
|
||||
|
||||
// Conds returns condtions
|
||||
func (statement *Statement) Conds() builder.Cond {
|
||||
return statement.cond
|
||||
}
|
||||
|
||||
// SetTable tempororily set table name, the parameter could be a string or a pointer of struct
|
||||
func (statement *Statement) SetTable(tableNameOrBean interface{}) error {
|
||||
v := rValue(tableNameOrBean)
|
||||
|
@ -518,71 +288,34 @@ func (statement *Statement) SetTable(tableNameOrBean interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Join The joinOP should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
|
||||
func (statement *Statement) Join(joinOP string, tablename interface{}, condition string, args ...interface{}) *Statement {
|
||||
var buf strings.Builder
|
||||
if len(statement.JoinStr) > 0 {
|
||||
fmt.Fprintf(&buf, "%v %v JOIN ", statement.JoinStr, joinOP)
|
||||
} else {
|
||||
fmt.Fprintf(&buf, "%v JOIN ", joinOP)
|
||||
}
|
||||
|
||||
switch tp := tablename.(type) {
|
||||
case builder.Builder:
|
||||
subSQL, subQueryArgs, err := tp.ToSQL()
|
||||
if err != nil {
|
||||
statement.LastError = err
|
||||
return statement
|
||||
}
|
||||
|
||||
fields := strings.Split(tp.TableName(), ".")
|
||||
aliasName := statement.dialect.Quoter().Trim(fields[len(fields)-1])
|
||||
aliasName = schemas.CommonQuoter.Trim(aliasName)
|
||||
|
||||
fmt.Fprintf(&buf, "(%s) %s ON %v", statement.ReplaceQuote(subSQL), statement.quote(aliasName), statement.ReplaceQuote(condition))
|
||||
statement.joinArgs = append(statement.joinArgs, subQueryArgs...)
|
||||
case *builder.Builder:
|
||||
subSQL, subQueryArgs, err := tp.ToSQL()
|
||||
if err != nil {
|
||||
statement.LastError = err
|
||||
return statement
|
||||
}
|
||||
|
||||
fields := strings.Split(tp.TableName(), ".")
|
||||
aliasName := statement.dialect.Quoter().Trim(fields[len(fields)-1])
|
||||
aliasName = schemas.CommonQuoter.Trim(aliasName)
|
||||
|
||||
fmt.Fprintf(&buf, "(%s) %s ON %v", statement.ReplaceQuote(subSQL), statement.quote(aliasName), statement.ReplaceQuote(condition))
|
||||
statement.joinArgs = append(statement.joinArgs, subQueryArgs...)
|
||||
default:
|
||||
tbName := dialects.FullTableName(statement.dialect, statement.tagParser.GetTableMapper(), tablename, true)
|
||||
if !utils.IsSubQuery(tbName) {
|
||||
var buf strings.Builder
|
||||
_ = statement.dialect.Quoter().QuoteTo(&buf, tbName)
|
||||
tbName = buf.String()
|
||||
} else {
|
||||
tbName = statement.ReplaceQuote(tbName)
|
||||
}
|
||||
fmt.Fprintf(&buf, "%s ON %v", tbName, statement.ReplaceQuote(condition))
|
||||
}
|
||||
|
||||
statement.JoinStr = buf.String()
|
||||
statement.joinArgs = append(statement.joinArgs, args...)
|
||||
return statement
|
||||
}
|
||||
|
||||
// GroupBy generate "Group By keys" statement
|
||||
func (statement *Statement) GroupBy(keys string) *Statement {
|
||||
statement.GroupByStr = statement.ReplaceQuote(keys)
|
||||
return statement
|
||||
}
|
||||
|
||||
func (statement *Statement) writeGroupBy(w builder.Writer) error {
|
||||
if statement.GroupByStr == "" {
|
||||
return nil
|
||||
}
|
||||
_, err := fmt.Fprint(w, " GROUP BY ", statement.GroupByStr)
|
||||
return err
|
||||
}
|
||||
|
||||
// Having generate "Having conditions" statement
|
||||
func (statement *Statement) Having(conditions string) *Statement {
|
||||
statement.HavingStr = fmt.Sprintf("HAVING %v", statement.ReplaceQuote(conditions))
|
||||
statement.HavingStr = conditions
|
||||
return statement
|
||||
}
|
||||
|
||||
func (statement *Statement) writeHaving(w builder.Writer) error {
|
||||
if statement.HavingStr == "" {
|
||||
return nil
|
||||
}
|
||||
_, err := fmt.Fprint(w, " HAVING ", statement.ReplaceQuote(statement.HavingStr))
|
||||
return err
|
||||
}
|
||||
|
||||
// SetUnscoped always disable struct tag "deleted"
|
||||
func (statement *Statement) SetUnscoped() *Statement {
|
||||
statement.unscoped = true
|
||||
|
@ -594,47 +327,6 @@ func (statement *Statement) GetUnscoped() bool {
|
|||
return statement.unscoped
|
||||
}
|
||||
|
||||
func (statement *Statement) genColumnStr() string {
|
||||
if statement.RefTable == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var buf strings.Builder
|
||||
columns := statement.RefTable.Columns()
|
||||
|
||||
for _, col := range columns {
|
||||
if statement.OmitColumnMap.Contain(col.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(statement.ColumnMap) > 0 && !statement.ColumnMap.Contain(col.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
if col.MapType == schemas.ONLYTODB {
|
||||
continue
|
||||
}
|
||||
|
||||
if buf.Len() != 0 {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
|
||||
if statement.JoinStr != "" {
|
||||
if statement.TableAlias != "" {
|
||||
buf.WriteString(statement.TableAlias)
|
||||
} else {
|
||||
buf.WriteString(statement.TableName())
|
||||
}
|
||||
|
||||
buf.WriteString(".")
|
||||
}
|
||||
|
||||
statement.dialect.Quoter().QuoteTo(&buf, col.Name)
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// GenIndexSQL generated create index SQL
|
||||
func (statement *Statement) GenIndexSQL() []string {
|
||||
var sqls []string
|
||||
|
@ -765,7 +457,7 @@ func (statement *Statement) asDBCond(fieldValue reflect.Value, fieldType reflect
|
|||
if len(table.PrimaryKeys) == 1 {
|
||||
pkField := reflect.Indirect(fieldValue).FieldByName(table.PKColumns()[0].FieldName)
|
||||
// fix non-int pk issues
|
||||
//if pkField.Int() != 0 {
|
||||
// if pkField.Int() != 0 {
|
||||
if pkField.IsValid() && !utils.IsZero(pkField.Interface()) {
|
||||
return pkField.Interface(), true, nil
|
||||
}
|
||||
|
@ -814,7 +506,8 @@ func (statement *Statement) asDBCond(fieldValue reflect.Value, fieldType reflect
|
|||
func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
|
||||
includeVersion bool, includeUpdated bool, includeNil bool,
|
||||
includeAutoIncr bool, allUseBool bool, useAllCols bool, unscoped bool,
|
||||
mustColumnMap map[string]bool, tableName, aliasName string, addedTableName bool) (builder.Cond, error) {
|
||||
mustColumnMap map[string]bool, tableName, aliasName string, addedTableName bool,
|
||||
) (builder.Cond, error) {
|
||||
var conds []builder.Cond
|
||||
for _, col := range table.Columns() {
|
||||
if !includeVersion && col.IsVersion {
|
||||
|
@ -827,17 +520,13 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
|
|||
continue
|
||||
}
|
||||
|
||||
if statement.dialect.URI().DBType == schemas.MSSQL && (col.SQLType.Name == schemas.Text ||
|
||||
col.SQLType.IsBlob() || col.SQLType.Name == schemas.TimeStampz) {
|
||||
continue
|
||||
}
|
||||
if col.IsJSON {
|
||||
continue
|
||||
}
|
||||
|
||||
var colName string
|
||||
if addedTableName {
|
||||
var nm = tableName
|
||||
nm := tableName
|
||||
if len(aliasName) > 0 {
|
||||
nm = aliasName
|
||||
}
|
||||
|
@ -862,6 +551,15 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
|
|||
continue
|
||||
}
|
||||
|
||||
if statement.dialect.URI().DBType == schemas.MSSQL && (col.SQLType.Name == schemas.Text ||
|
||||
col.SQLType.IsBlob() || col.SQLType.Name == schemas.TimeStampz) {
|
||||
if utils.IsValueZero(fieldValue) {
|
||||
continue
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("column %s is a TEXT type with data %#v which cannot be as compare condition", col.Name, fieldValue.Interface())
|
||||
}
|
||||
|
||||
requiredField := useAllCols
|
||||
if b, ok := getFlagForColumn(mustColumnMap, col); ok {
|
||||
if b {
|
||||
|
@ -908,9 +606,10 @@ func (statement *Statement) BuildConds(table *schemas.Table, bean interface{}, i
|
|||
statement.unscoped, statement.MustColumnMap, statement.TableName(), statement.TableAlias, addedTableName)
|
||||
}
|
||||
|
||||
func (statement *Statement) mergeConds(bean interface{}) error {
|
||||
// MergeConds merge conditions from bean and id
|
||||
func (statement *Statement) MergeConds(bean interface{}) error {
|
||||
if !statement.NoAutoCondition && statement.RefTable != nil {
|
||||
var addedTableName = (len(statement.JoinStr) > 0)
|
||||
addedTableName := (len(statement.joins) > 0)
|
||||
autoCond, err := statement.BuildConds(statement.RefTable, bean, true, true, false, true, addedTableName)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -921,15 +620,6 @@ func (statement *Statement) mergeConds(bean interface{}) error {
|
|||
return statement.ProcessIDParam()
|
||||
}
|
||||
|
||||
// GenConds generates conditions
|
||||
func (statement *Statement) GenConds(bean interface{}) (string, []interface{}, error) {
|
||||
if err := statement.mergeConds(bean); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
return statement.GenCondSQL(statement.cond)
|
||||
}
|
||||
|
||||
func (statement *Statement) quoteColumnStr(columnStr string) string {
|
||||
columns := strings.Split(columnStr, ",")
|
||||
return statement.dialect.Quoter().Join(columns, ",")
|
||||
|
@ -948,7 +638,7 @@ func (statement *Statement) convertSQLOrArgs(sqlOrArgs ...interface{}) (string,
|
|||
switch sqlOrArgs[0].(type) {
|
||||
case string:
|
||||
if len(sqlOrArgs) > 1 {
|
||||
var newArgs = make([]interface{}, 0, len(sqlOrArgs)-1)
|
||||
newArgs := make([]interface{}, 0, len(sqlOrArgs)-1)
|
||||
for _, arg := range sqlOrArgs[1:] {
|
||||
if v, ok := arg.(time.Time); ok {
|
||||
newArgs = append(newArgs, v.In(statement.defaultTimeZone).Format("2006-01-02 15:04:05"))
|
||||
|
@ -972,7 +662,7 @@ func (statement *Statement) convertSQLOrArgs(sqlOrArgs ...interface{}) (string,
|
|||
}
|
||||
|
||||
func (statement *Statement) joinColumns(cols []*schemas.Column, includeTableName bool) string {
|
||||
var colnames = make([]string, len(cols))
|
||||
colnames := make([]string, len(cols))
|
||||
for i, col := range cols {
|
||||
if includeTableName {
|
||||
colnames[i] = statement.quote(statement.TableName()) +
|
||||
|
@ -986,8 +676,8 @@ func (statement *Statement) joinColumns(cols []*schemas.Column, includeTableName
|
|||
|
||||
// CondDeleted returns the conditions whether a record is soft deleted.
|
||||
func (statement *Statement) CondDeleted(col *schemas.Column) builder.Cond {
|
||||
var colName = statement.quote(col.Name)
|
||||
if statement.JoinStr != "" {
|
||||
colName := statement.quote(col.Name)
|
||||
if len(statement.joins) > 0 {
|
||||
var prefix string
|
||||
if statement.TableAlias != "" {
|
||||
prefix = statement.TableAlias
|
||||
|
@ -996,7 +686,7 @@ func (statement *Statement) CondDeleted(col *schemas.Column) builder.Cond {
|
|||
}
|
||||
colName = statement.quote(prefix) + "." + statement.quote(col.Name)
|
||||
}
|
||||
var cond = builder.NewCond()
|
||||
cond := builder.NewCond()
|
||||
if col.SQLType.IsNumeric() {
|
||||
cond = builder.Eq{colName: 0}
|
||||
} else {
|
||||
|
|
|
@ -5,78 +5,10 @@
|
|||
package statements
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func quoteNeeded(a interface{}) bool {
|
||||
switch a.(type) {
|
||||
case int, int8, int16, int32, int64:
|
||||
return false
|
||||
case uint, uint8, uint16, uint32, uint64:
|
||||
return false
|
||||
case float32, float64:
|
||||
return false
|
||||
case bool:
|
||||
return false
|
||||
case string:
|
||||
return true
|
||||
case time.Time, *time.Time:
|
||||
return true
|
||||
case builder.Builder, *builder.Builder:
|
||||
return false
|
||||
}
|
||||
|
||||
t := reflect.TypeOf(a)
|
||||
switch t.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return false
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return false
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return false
|
||||
case reflect.Bool:
|
||||
return false
|
||||
case reflect.String:
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func convertStringSingleQuote(arg string) string {
|
||||
return "'" + strings.Replace(arg, "'", "''", -1) + "'"
|
||||
}
|
||||
|
||||
func convertString(arg string) string {
|
||||
var buf strings.Builder
|
||||
buf.WriteRune('\'')
|
||||
for _, c := range arg {
|
||||
if c == '\\' || c == '\'' {
|
||||
buf.WriteRune('\\')
|
||||
}
|
||||
buf.WriteRune(c)
|
||||
}
|
||||
buf.WriteRune('\'')
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func convertArg(arg interface{}, convertFunc func(string) string) string {
|
||||
if quoteNeeded(arg) {
|
||||
argv := fmt.Sprintf("%v", arg)
|
||||
return convertFunc(argv)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v", arg)
|
||||
}
|
||||
|
||||
const insertSelectPlaceHolder = true
|
||||
|
||||
// WriteArg writes an arg
|
||||
func (statement *Statement) WriteArg(w *builder.BytesWriter, arg interface{}) error {
|
||||
switch argv := arg.(type) {
|
||||
|
@ -91,27 +23,17 @@ func (statement *Statement) WriteArg(w *builder.BytesWriter, arg interface{}) er
|
|||
return err
|
||||
}
|
||||
default:
|
||||
if insertSelectPlaceHolder {
|
||||
if err := w.WriteByte('?'); err != nil {
|
||||
return err
|
||||
}
|
||||
if v, ok := arg.(bool); ok && statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
if v {
|
||||
w.Append(1)
|
||||
} else {
|
||||
w.Append(0)
|
||||
}
|
||||
if err := w.WriteByte('?'); err != nil {
|
||||
return err
|
||||
}
|
||||
if v, ok := arg.(bool); ok && statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
if v {
|
||||
w.Append(1)
|
||||
} else {
|
||||
w.Append(arg)
|
||||
w.Append(0)
|
||||
}
|
||||
} else {
|
||||
var convertFunc = convertStringSingleQuote
|
||||
if statement.dialect.URI().DBType == schemas.MYSQL {
|
||||
convertFunc = convertString
|
||||
}
|
||||
if _, err := w.WriteString(convertArg(arg, convertFunc)); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Append(arg)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2022 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package statements
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
// TableName return current tableName
|
||||
func (statement *Statement) TableName() string {
|
||||
if statement.AltTableName != "" {
|
||||
return statement.AltTableName
|
||||
}
|
||||
|
||||
return statement.tableName
|
||||
}
|
||||
|
||||
// Alias set the table alias
|
||||
func (statement *Statement) Alias(alias string) *Statement {
|
||||
statement.TableAlias = alias
|
||||
return statement
|
||||
}
|
||||
|
||||
func (statement *Statement) writeAlias(w builder.Writer) error {
|
||||
if statement.TableAlias != "" {
|
||||
if statement.dialect.URI().DBType == schemas.ORACLE {
|
||||
if _, err := fmt.Fprint(w, " ", statement.quote(statement.TableAlias)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := fmt.Fprint(w, " AS ", statement.quote(statement.TableAlias)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeTableName(w builder.Writer) error {
|
||||
if statement.dialect.URI().DBType == schemas.MSSQL && strings.Contains(statement.TableName(), "..") {
|
||||
if _, err := fmt.Fprint(w, statement.TableName()); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := fmt.Fprint(w, statement.quote(statement.TableName())); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -11,6 +11,7 @@ import (
|
|||
"reflect"
|
||||
"time"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/convert"
|
||||
"xorm.io/xorm/dialects"
|
||||
"xorm.io/xorm/internal/json"
|
||||
|
@ -19,7 +20,8 @@ import (
|
|||
)
|
||||
|
||||
func (statement *Statement) ifAddColUpdate(col *schemas.Column, includeVersion, includeUpdated, includeNil,
|
||||
includeAutoIncr, update bool) (bool, error) {
|
||||
includeAutoIncr, update bool,
|
||||
) (bool, error) {
|
||||
columnMap := statement.ColumnMap
|
||||
omitColumnMap := statement.OmitColumnMap
|
||||
unscoped := statement.unscoped
|
||||
|
@ -64,15 +66,16 @@ func (statement *Statement) ifAddColUpdate(col *schemas.Column, includeVersion,
|
|||
// BuildUpdates auto generating update columnes and values according a struct
|
||||
func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
||||
includeVersion, includeUpdated, includeNil,
|
||||
includeAutoIncr, update bool) ([]string, []interface{}, error) {
|
||||
includeAutoIncr, update bool,
|
||||
) ([]string, []interface{}, error) {
|
||||
table := statement.RefTable
|
||||
allUseBool := statement.allUseBool
|
||||
useAllCols := statement.useAllCols
|
||||
mustColumnMap := statement.MustColumnMap
|
||||
nullableMap := statement.NullableMap
|
||||
|
||||
var colNames = make([]string, 0)
|
||||
var args = make([]interface{}, 0)
|
||||
colNames := make([]string, 0)
|
||||
args := make([]interface{}, 0)
|
||||
|
||||
for _, col := range table.Columns() {
|
||||
ok, err := statement.ifAddColUpdate(col, includeVersion, includeUpdated, includeNil,
|
||||
|
@ -306,3 +309,329 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
|||
|
||||
return colNames, args, nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeUpdateTop(updateWriter *builder.BytesWriter) error {
|
||||
if statement.dialect.URI().DBType != schemas.MSSQL || statement.LimitN == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
table := statement.RefTable
|
||||
if statement.HasOrderBy() && table != nil && len(table.PrimaryKeys) == 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := fmt.Fprintf(updateWriter, " TOP (%d)", *statement.LimitN)
|
||||
return err
|
||||
}
|
||||
|
||||
func (statement *Statement) writeUpdateTableName(updateWriter *builder.BytesWriter) error {
|
||||
tableName := statement.quote(statement.TableName())
|
||||
if statement.TableAlias == "" {
|
||||
_, err := fmt.Fprint(updateWriter, " ", tableName)
|
||||
return err
|
||||
}
|
||||
|
||||
switch statement.dialect.URI().DBType {
|
||||
case schemas.MSSQL:
|
||||
_, err := fmt.Fprint(updateWriter, " ", statement.TableAlias)
|
||||
return err
|
||||
default:
|
||||
_, err := fmt.Fprint(updateWriter, " ", tableName, " AS ", statement.TableAlias)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func (statement *Statement) writeUpdateFrom(updateWriter *builder.BytesWriter) error {
|
||||
if statement.dialect.URI().DBType != schemas.MSSQL || statement.TableAlias == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := fmt.Fprint(updateWriter, " FROM ", statement.quote(statement.TableName()), " ", statement.TableAlias)
|
||||
return err
|
||||
}
|
||||
|
||||
func (statement *Statement) writeUpdateLimit(updateWriter *builder.BytesWriter, cond builder.Cond) error {
|
||||
if statement.LimitN == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
table := statement.RefTable
|
||||
tableName := statement.TableName()
|
||||
|
||||
limitValue := *statement.LimitN
|
||||
switch statement.dialect.URI().DBType {
|
||||
case schemas.MYSQL:
|
||||
_, err := fmt.Fprintf(updateWriter, " LIMIT %d", limitValue)
|
||||
return err
|
||||
case schemas.SQLITE:
|
||||
if cond.IsValid() {
|
||||
if _, err := fmt.Fprint(updateWriter, " AND "); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := fmt.Fprint(updateWriter, " WHERE "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprint(updateWriter, "rowid IN (SELECT rowid FROM ", statement.quote(tableName)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeWhereCond(updateWriter, cond); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeOrderBys(updateWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprintf(updateWriter, " LIMIT %d)", limitValue)
|
||||
return err
|
||||
case schemas.POSTGRES:
|
||||
if cond.IsValid() {
|
||||
if _, err := fmt.Fprint(updateWriter, " AND "); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := fmt.Fprint(updateWriter, " WHERE "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprint(updateWriter, "CTID IN (SELECT CTID FROM ", statement.quote(tableName)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeWhereCond(updateWriter, cond); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeOrderBys(updateWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprintf(updateWriter, " LIMIT %d)", limitValue)
|
||||
return err
|
||||
case schemas.MSSQL:
|
||||
if statement.HasOrderBy() && table != nil && len(table.PrimaryKeys) == 1 {
|
||||
if _, err := fmt.Fprintf(updateWriter, " WHERE %s IN (SELECT TOP (%d) %s FROM %v",
|
||||
table.PrimaryKeys[0], limitValue, table.PrimaryKeys[0],
|
||||
statement.quote(tableName)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeWhereCond(updateWriter, cond); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := statement.writeOrderBys(updateWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprint(updateWriter, ")")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
default: // TODO: Oracle support needed
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func (statement *Statement) GenConditionsFromMap(m interface{}) ([]builder.Cond, error) {
|
||||
switch t := m.(type) {
|
||||
case map[string]interface{}:
|
||||
conds := []builder.Cond{}
|
||||
for k, v := range t {
|
||||
conds = append(conds, builder.Eq{k: v})
|
||||
}
|
||||
return conds, nil
|
||||
case map[string]string:
|
||||
conds := []builder.Cond{}
|
||||
for k, v := range t {
|
||||
conds = append(conds, builder.Eq{k: v})
|
||||
}
|
||||
return conds, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported condition map type %v", t)
|
||||
}
|
||||
}
|
||||
|
||||
func (statement *Statement) writeVersionIncrSet(w builder.Writer, v reflect.Value, hasPreviousSet bool) error {
|
||||
if v.Type().Kind() != reflect.Struct {
|
||||
return nil
|
||||
}
|
||||
|
||||
table := statement.RefTable
|
||||
if !(statement.RefTable != nil && table.Version != "" && statement.CheckVersion) {
|
||||
return nil
|
||||
}
|
||||
|
||||
verValue, err := table.VersionColumn().ValueOfV(&v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if verValue == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if hasPreviousSet {
|
||||
if _, err := fmt.Fprint(w, ", "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprint(w, statement.quote(table.Version), " = ", statement.quote(table.Version), " + 1"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeIncrSets(w builder.Writer, hasPreviousSet bool) error {
|
||||
for i, expr := range statement.IncrColumns {
|
||||
if i > 0 || hasPreviousSet {
|
||||
if _, err := fmt.Fprint(w, ", "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprint(w, statement.quote(expr.ColName), " = ", statement.quote(expr.ColName), " + ?"); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Append(expr.Arg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeDecrSets(w builder.Writer, hasPreviousSet bool) error {
|
||||
// for update action to like "column = column - ?"
|
||||
for i, expr := range statement.DecrColumns {
|
||||
if i > 0 || hasPreviousSet {
|
||||
if _, err := fmt.Fprint(w, ", "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprint(w, statement.quote(expr.ColName), " = ", statement.quote(expr.ColName), " - ?"); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Append(expr.Arg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeExprSets(w *builder.BytesWriter, hasPreviousSet bool) error {
|
||||
// for update action to like "column = expression"
|
||||
for i, expr := range statement.ExprColumns {
|
||||
if i > 0 || hasPreviousSet {
|
||||
if _, err := fmt.Fprint(w, ", "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
switch tp := expr.Arg.(type) {
|
||||
case string:
|
||||
if len(tp) == 0 {
|
||||
tp = "''"
|
||||
}
|
||||
if _, err := fmt.Fprint(w, statement.quote(expr.ColName), " = ", tp); err != nil {
|
||||
return err
|
||||
}
|
||||
case *builder.Builder:
|
||||
if _, err := fmt.Fprint(w, statement.quote(expr.ColName), " = ("); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tp.WriteTo(statement.QuoteReplacer(w)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprint(w, ")"); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
if _, err := fmt.Fprint(w, statement.quote(expr.ColName), " = ?"); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Append(expr.Arg)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeUpdateSets(w *builder.BytesWriter, v reflect.Value, colNames []string, args []interface{}) error {
|
||||
previousLen := w.Len()
|
||||
for i, colName := range colNames {
|
||||
if i > 0 {
|
||||
if _, err := fmt.Fprint(w, ", "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprint(w, colName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
w.Append(args...)
|
||||
|
||||
if err := statement.writeIncrSets(w, w.Len() > previousLen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := statement.writeDecrSets(w, w.Len() > previousLen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := statement.writeExprSets(w, w.Len() > previousLen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := statement.writeVersionIncrSet(w, v, w.Len() > previousLen); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var ErrNoColumnsTobeUpdated = errors.New("no columns found to be updated")
|
||||
|
||||
func (statement *Statement) WriteUpdate(updateWriter *builder.BytesWriter, cond builder.Cond, v reflect.Value, colNames []string, args []interface{}) error {
|
||||
if _, err := fmt.Fprintf(updateWriter, "UPDATE"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := statement.writeUpdateTop(updateWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := statement.writeUpdateTableName(updateWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// write set
|
||||
if _, err := fmt.Fprint(updateWriter, " SET "); err != nil {
|
||||
return err
|
||||
}
|
||||
previousLen := updateWriter.Len()
|
||||
|
||||
if err := statement.writeUpdateSets(updateWriter, v, colNames, args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if no columns to be updated, return error
|
||||
if previousLen == updateWriter.Len() {
|
||||
return ErrNoColumnsTobeUpdated
|
||||
}
|
||||
|
||||
// write from
|
||||
if err := statement.writeUpdateFrom(updateWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
table := statement.RefTable
|
||||
if statement.HasOrderBy() && table != nil && len(table.PrimaryKeys) == 1 {
|
||||
} else {
|
||||
// write where
|
||||
if err := statement.writeWhereCond(updateWriter, cond); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// write where
|
||||
if err := statement.writeWhereCond(updateWriter, cond); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if statement.dialect.URI().DBType == schemas.MYSQL {
|
||||
if err := statement.writeOrderBys(updateWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return statement.writeUpdateLimit(updateWriter, cond)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2022 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
type BuildReader interface {
|
||||
String() string
|
||||
Args() []interface{}
|
||||
}
|
||||
|
||||
// WriteBuilder writes writers to one
|
||||
func WriteBuilder(w *builder.BytesWriter, inputs ...BuildReader) error {
|
||||
for _, input := range inputs {
|
||||
if _, err := fmt.Fprint(w, input.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Append(input.Args()...)
|
||||
}
|
||||
return nil
|
||||
}
|
16
rows.go
16
rows.go
|
@ -46,8 +46,8 @@ func newRows(session *Session, bean interface{}) (*Rows, error) {
|
|||
|
||||
if rows.session.statement.RawSQL == "" {
|
||||
var autoCond builder.Cond
|
||||
var addedTableName = (len(session.statement.JoinStr) > 0)
|
||||
var table = rows.session.statement.RefTable
|
||||
addedTableName := session.statement.NeedTableName()
|
||||
table := rows.session.statement.RefTable
|
||||
|
||||
if !session.statement.NoAutoCondition {
|
||||
var err error
|
||||
|
@ -103,12 +103,12 @@ func (rows *Rows) Scan(beans ...interface{}) error {
|
|||
return rows.Err()
|
||||
}
|
||||
|
||||
var bean = beans[0]
|
||||
var tp = reflect.TypeOf(bean)
|
||||
bean := beans[0]
|
||||
tp := reflect.TypeOf(bean)
|
||||
if tp.Kind() == reflect.Ptr {
|
||||
tp = tp.Elem()
|
||||
}
|
||||
var beanKind = tp.Kind()
|
||||
beanKind := tp.Kind()
|
||||
|
||||
if len(beans) == 1 {
|
||||
if reflect.Indirect(reflect.ValueOf(bean)).Type() != rows.beanType {
|
||||
|
@ -129,7 +129,9 @@ func (rows *Rows) Scan(beans ...interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := rows.session.scan(rows.rows, rows.session.statement.RefTable, beanKind, beans, types, fields); err != nil {
|
||||
columnsSchema := ParseColumnsSchema(fields, types, rows.session.statement.RefTable)
|
||||
|
||||
if err := rows.session.scan(rows.rows, rows.session.statement.RefTable, beanKind, beans, columnsSchema, types, fields); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -142,6 +144,8 @@ func (rows *Rows) Close() error {
|
|||
defer rows.session.Close()
|
||||
}
|
||||
|
||||
defer rows.session.resetStatement()
|
||||
|
||||
if rows.rows != nil {
|
||||
return rows.rows.Close()
|
||||
}
|
||||
|
|
24
scan.go
24
scan.go
|
@ -22,7 +22,7 @@ func genScanResultsByBeanNullable(bean interface{}) (interface{}, bool, error) {
|
|||
switch t := bean.(type) {
|
||||
case *interface{}:
|
||||
return t, false, nil
|
||||
case *sql.NullInt64, *sql.NullBool, *sql.NullFloat64, *sql.NullString, *sql.RawBytes:
|
||||
case *sql.NullInt64, *sql.NullBool, *sql.NullFloat64, *sql.NullString, *sql.RawBytes, *[]byte:
|
||||
return t, false, nil
|
||||
case *time.Time:
|
||||
return &sql.NullString{}, true, nil
|
||||
|
@ -67,7 +67,7 @@ func genScanResultsByBeanNullable(bean interface{}) (interface{}, bool, error) {
|
|||
case reflect.Uint32, reflect.Uint, reflect.Uint16, reflect.Uint8:
|
||||
return &convert.NullUint32{}, true, nil
|
||||
default:
|
||||
return nil, false, fmt.Errorf("unsupported type: %#v", bean)
|
||||
return nil, false, fmt.Errorf("genScanResultsByBeanNullable: unsupported type: %#v", bean)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,12 +125,12 @@ func genScanResultsByBean(bean interface{}) (interface{}, bool, error) {
|
|||
case reflect.Float64:
|
||||
return new(float64), true, nil
|
||||
default:
|
||||
return nil, false, fmt.Errorf("unsupported type: %#v", bean)
|
||||
return nil, false, fmt.Errorf("genScanResultsByBean: unsupported type: %#v", bean)
|
||||
}
|
||||
}
|
||||
|
||||
func (engine *Engine) scanStringInterface(rows *core.Rows, fields []string, types []*sql.ColumnType) ([]interface{}, error) {
|
||||
var scanResults = make([]interface{}, len(types))
|
||||
scanResults := make([]interface{}, len(types))
|
||||
for i := 0; i < len(types); i++ {
|
||||
var s sql.NullString
|
||||
scanResults[i] = &s
|
||||
|
@ -144,8 +144,8 @@ func (engine *Engine) scanStringInterface(rows *core.Rows, fields []string, type
|
|||
|
||||
// scan is a wrap of driver.Scan but will automatically change the input values according requirements
|
||||
func (engine *Engine) scan(rows *core.Rows, fields []string, types []*sql.ColumnType, vv ...interface{}) error {
|
||||
var scanResults = make([]interface{}, 0, len(types))
|
||||
var replaces = make([]bool, 0, len(types))
|
||||
scanResults := make([]interface{}, 0, len(types))
|
||||
replaces := make([]bool, 0, len(types))
|
||||
var err error
|
||||
for _, v := range vv {
|
||||
var replaced bool
|
||||
|
@ -194,7 +194,7 @@ func (engine *Engine) scan(rows *core.Rows, fields []string, types []*sql.Column
|
|||
}
|
||||
|
||||
func (engine *Engine) scanInterfaces(rows *core.Rows, fields []string, types []*sql.ColumnType) ([]interface{}, error) {
|
||||
var scanResultContainers = make([]interface{}, len(types))
|
||||
scanResultContainers := make([]interface{}, len(types))
|
||||
for i := 0; i < len(types); i++ {
|
||||
scanResult, err := engine.driver.GenScanResult(types[i].DatabaseTypeName())
|
||||
if err != nil {
|
||||
|
@ -212,8 +212,8 @@ func (engine *Engine) scanInterfaces(rows *core.Rows, fields []string, types []*
|
|||
// row -> map[string]interface{}
|
||||
|
||||
func (engine *Engine) row2mapInterface(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]interface{}, error) {
|
||||
var resultsMap = make(map[string]interface{}, len(fields))
|
||||
var scanResultContainers = make([]interface{}, len(fields))
|
||||
resultsMap := make(map[string]interface{}, len(fields))
|
||||
scanResultContainers := make([]interface{}, len(fields))
|
||||
for i := 0; i < len(fields); i++ {
|
||||
scanResult, err := engine.driver.GenScanResult(types[i].DatabaseTypeName())
|
||||
if err != nil {
|
||||
|
@ -277,7 +277,7 @@ func (engine *Engine) ScanInterfaceMaps(rows *core.Rows) (resultsSlice []map[str
|
|||
// row -> map[string]string
|
||||
|
||||
func (engine *Engine) row2mapStr(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]string, error) {
|
||||
var scanResults = make([]interface{}, len(fields))
|
||||
scanResults := make([]interface{}, len(fields))
|
||||
for i := 0; i < len(fields); i++ {
|
||||
var s sql.NullString
|
||||
scanResults[i] = &s
|
||||
|
@ -353,7 +353,7 @@ func (engine *Engine) ScanStringMaps(rows *core.Rows) (resultsSlice []map[string
|
|||
// row -> map[string][]byte
|
||||
|
||||
func convertMapStr2Bytes(m map[string]string) map[string][]byte {
|
||||
var r = make(map[string][]byte, len(m))
|
||||
r := make(map[string][]byte, len(m))
|
||||
for k, v := range m {
|
||||
r[k] = []byte(v)
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ func (engine *Engine) row2sliceStr(rows *core.Rows, types []*sql.ColumnType, fie
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var results = make([]string, 0, len(fields))
|
||||
results := make([]string, 0, len(fields))
|
||||
for i := 0; i < len(fields); i++ {
|
||||
results = append(results, scanResults[i].(*sql.NullString).String)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright 2023 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package schemas
|
||||
|
||||
type Collation struct {
|
||||
Name string
|
||||
Column string // blank means it's a table collation
|
||||
}
|
|
@ -26,8 +26,8 @@ type Column struct {
|
|||
FieldIndex []int // Available only when parsed from a struct
|
||||
SQLType SQLType
|
||||
IsJSON bool
|
||||
Length int
|
||||
Length2 int
|
||||
Length int64
|
||||
Length2 int64
|
||||
Nullable bool
|
||||
Default string
|
||||
Indexes map[string]int
|
||||
|
@ -45,10 +45,11 @@ type Column struct {
|
|||
DisableTimeZone bool
|
||||
TimeZone *time.Location // column specified time zone
|
||||
Comment string
|
||||
Collation string
|
||||
}
|
||||
|
||||
// NewColumn creates a new column
|
||||
func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable bool) *Column {
|
||||
func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int64, nullable bool) *Column {
|
||||
return &Column{
|
||||
Name: name,
|
||||
IsJSON: sqlType.IsJson(),
|
||||
|
@ -82,13 +83,15 @@ func (col *Column) ValueOf(bean interface{}) (*reflect.Value, error) {
|
|||
|
||||
// ValueOfV returns column's filed of struct's value accept reflevt value
|
||||
func (col *Column) ValueOfV(dataStruct *reflect.Value) (*reflect.Value, error) {
|
||||
var v = *dataStruct
|
||||
v := *dataStruct
|
||||
for _, i := range col.FieldIndex {
|
||||
if v.Kind() == reflect.Ptr {
|
||||
if v.IsNil() {
|
||||
v.Set(reflect.New(v.Type().Elem()))
|
||||
}
|
||||
v = v.Elem()
|
||||
} else if v.Kind() == reflect.Interface {
|
||||
v = reflect.Indirect(v.Elem())
|
||||
}
|
||||
v = v.FieldByIndex([]int{i})
|
||||
}
|
||||
|
|
|
@ -163,17 +163,18 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error {
|
|||
}
|
||||
|
||||
// QuoteTo quotes the table or column names. i.e. if the quotes are [ and ]
|
||||
// name -> [name]
|
||||
// `name` -> [name]
|
||||
// [name] -> [name]
|
||||
// schema.name -> [schema].[name]
|
||||
// `schema`.`name` -> [schema].[name]
|
||||
// `schema`.name -> [schema].[name]
|
||||
// schema.`name` -> [schema].[name]
|
||||
// [schema].name -> [schema].[name]
|
||||
// schema.[name] -> [schema].[name]
|
||||
// name AS a -> [name] AS a
|
||||
// schema.name AS a -> [schema].[name] AS a
|
||||
//
|
||||
// name -> [name]
|
||||
// `name` -> [name]
|
||||
// [name] -> [name]
|
||||
// schema.name -> [schema].[name]
|
||||
// `schema`.`name` -> [schema].[name]
|
||||
// `schema`.name -> [schema].[name]
|
||||
// schema.`name` -> [schema].[name]
|
||||
// [schema].name -> [schema].[name]
|
||||
// schema.[name] -> [schema].[name]
|
||||
// name AS a -> [name] AS a
|
||||
// schema.name AS a -> [schema].[name] AS a
|
||||
func (q Quoter) QuoteTo(buf *strings.Builder, value string) error {
|
||||
var i int
|
||||
for i < len(value) {
|
||||
|
|
|
@ -27,6 +27,7 @@ type Table struct {
|
|||
StoreEngine string
|
||||
Charset string
|
||||
Comment string
|
||||
Collation string
|
||||
}
|
||||
|
||||
// NewEmptyTable creates an empty table
|
||||
|
@ -36,7 +37,8 @@ func NewEmptyTable() *Table {
|
|||
|
||||
// NewTable creates a new Table object
|
||||
func NewTable(name string, t reflect.Type) *Table {
|
||||
return &Table{Name: name, Type: t,
|
||||
return &Table{
|
||||
Name: name, Type: t,
|
||||
columnsSeq: make([]string, 0),
|
||||
columns: make([]*Column, 0),
|
||||
columnsMap: make(map[string][]*Column),
|
||||
|
|
|
@ -28,8 +28,8 @@ const (
|
|||
// SQLType represents SQL types
|
||||
type SQLType struct {
|
||||
Name string
|
||||
DefaultLength int
|
||||
DefaultLength2 int
|
||||
DefaultLength int64
|
||||
DefaultLength2 int64
|
||||
}
|
||||
|
||||
// enumerates all columns types
|
||||
|
|
104
session.go
104
session.go
|
@ -16,8 +16,6 @@ import (
|
|||
"io"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"xorm.io/xorm/contexts"
|
||||
"xorm.io/xorm/convert"
|
||||
"xorm.io/xorm/core"
|
||||
|
@ -79,7 +77,7 @@ type Session struct {
|
|||
afterClosures []func(interface{})
|
||||
afterProcessors []executedProcessor
|
||||
|
||||
stmtCache map[uint32]*core.Stmt //key: hash.Hash32 of (queryStr, len(queryStr))
|
||||
stmtCache map[uint32]*core.Stmt // key: hash.Hash32 of (queryStr, len(queryStr))
|
||||
txStmtCache map[uint32]*core.Stmt // for tx statement
|
||||
|
||||
lastSQL string
|
||||
|
@ -275,8 +273,8 @@ func (session *Session) Limit(limit int, start ...int) *Session {
|
|||
|
||||
// OrderBy provide order by query condition, the input parameter is the content
|
||||
// after order by on a sql statement.
|
||||
func (session *Session) OrderBy(order string) *Session {
|
||||
session.statement.OrderBy(order)
|
||||
func (session *Session) OrderBy(order interface{}, args ...interface{}) *Session {
|
||||
session.statement.OrderBy(order, args...)
|
||||
return session
|
||||
}
|
||||
|
||||
|
@ -314,7 +312,7 @@ func (session *Session) Cascade(trueOrFalse ...bool) *Session {
|
|||
|
||||
// MustLogSQL means record SQL or not and don't follow engine's setting
|
||||
func (session *Session) MustLogSQL(logs ...bool) *Session {
|
||||
var showSQL = true
|
||||
showSQL := true
|
||||
if len(logs) > 0 {
|
||||
showSQL = logs[0]
|
||||
}
|
||||
|
@ -330,7 +328,7 @@ func (session *Session) NoCache() *Session {
|
|||
}
|
||||
|
||||
// Join join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
|
||||
func (session *Session) Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session {
|
||||
func (session *Session) Join(joinOperator string, tablename interface{}, condition interface{}, args ...interface{}) *Session {
|
||||
session.statement.Join(joinOperator, tablename, condition, args...)
|
||||
return session
|
||||
}
|
||||
|
@ -354,7 +352,7 @@ func (session *Session) DB() *core.DB {
|
|||
|
||||
func (session *Session) canCache() bool {
|
||||
if session.statement.RefTable == nil ||
|
||||
session.statement.JoinStr != "" ||
|
||||
session.statement.NeedTableName() ||
|
||||
session.statement.RawSQL != "" ||
|
||||
!session.statement.UseCache ||
|
||||
session.statement.IsForUpdate ||
|
||||
|
@ -395,10 +393,10 @@ func (session *Session) doPrepareTx(sqlStr string) (stmt *core.Stmt, err error)
|
|||
return
|
||||
}
|
||||
|
||||
func getField(dataStruct *reflect.Value, table *schemas.Table, colName string, idx int) (*schemas.Column, *reflect.Value, error) {
|
||||
var col = table.GetColumnIdx(colName, idx)
|
||||
func getField(dataStruct *reflect.Value, table *schemas.Table, field *QueryedField) (*schemas.Column, *reflect.Value, error) {
|
||||
col := field.ColumnSchema
|
||||
if col == nil {
|
||||
return nil, nil, ErrFieldIsNotExist{colName, table.Name}
|
||||
return nil, nil, ErrFieldIsNotExist{field.FieldName, table.Name}
|
||||
}
|
||||
|
||||
fieldValue, err := col.ValueOfV(dataStruct)
|
||||
|
@ -406,10 +404,10 @@ func getField(dataStruct *reflect.Value, table *schemas.Table, colName string, i
|
|||
return nil, nil, err
|
||||
}
|
||||
if fieldValue == nil {
|
||||
return nil, nil, ErrFieldIsNotValid{colName, table.Name}
|
||||
return nil, nil, ErrFieldIsNotValid{field.FieldName, table.Name}
|
||||
}
|
||||
if !fieldValue.IsValid() || !fieldValue.CanSet() {
|
||||
return nil, nil, ErrFieldIsNotValid{colName, table.Name}
|
||||
return nil, nil, ErrFieldIsNotValid{field.FieldName, table.Name}
|
||||
}
|
||||
|
||||
return col, fieldValue, nil
|
||||
|
@ -418,11 +416,12 @@ func getField(dataStruct *reflect.Value, table *schemas.Table, colName string, i
|
|||
// Cell cell is a result of one column field
|
||||
type Cell *interface{}
|
||||
|
||||
func (session *Session) rows2Beans(rows *core.Rows, fields []string, types []*sql.ColumnType,
|
||||
func (session *Session) rows2Beans(rows *core.Rows, columnsSchema *ColumnsSchema, fields []string, types []*sql.ColumnType,
|
||||
table *schemas.Table, newElemFunc func([]string) reflect.Value,
|
||||
sliceValueSetFunc func(*reflect.Value, schemas.PK) error) error {
|
||||
sliceValueSetFunc func(*reflect.Value, schemas.PK) error,
|
||||
) error {
|
||||
for rows.Next() {
|
||||
var newValue = newElemFunc(fields)
|
||||
newValue := newElemFunc(fields)
|
||||
bean := newValue.Interface()
|
||||
dataStruct := newValue.Elem()
|
||||
|
||||
|
@ -431,7 +430,7 @@ func (session *Session) rows2Beans(rows *core.Rows, fields []string, types []*sq
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pk, err := session.slice2Bean(scanResults, fields, bean, &dataStruct, table)
|
||||
pk, err := session.slice2Bean(scanResults, columnsSchema, fields, bean, &dataStruct, table)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -533,8 +532,11 @@ func asKind(vv reflect.Value, tp reflect.Type) (interface{}, error) {
|
|||
return nil, fmt.Errorf("unsupported primary key type: %v, %v", tp, vv)
|
||||
}
|
||||
|
||||
var uint8ZeroValue = reflect.ValueOf(uint8(0))
|
||||
|
||||
func (session *Session) convertBeanField(col *schemas.Column, fieldValue *reflect.Value,
|
||||
scanResult interface{}, table *schemas.Table) error {
|
||||
scanResult interface{}, table *schemas.Table,
|
||||
) error {
|
||||
v, ok := scanResult.(*interface{})
|
||||
if ok {
|
||||
scanResult = *v
|
||||
|
@ -596,7 +598,7 @@ func (session *Session) convertBeanField(col *schemas.Column, fieldValue *reflec
|
|||
return nil
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
return setJSON(fieldValue, fieldType, scanResult)
|
||||
case reflect.Slice, reflect.Array:
|
||||
case reflect.Slice:
|
||||
bs, ok := convert.AsBytes(scanResult)
|
||||
if ok && fieldType.Elem().Kind() == reflect.Uint8 {
|
||||
if col.SQLType.IsText() {
|
||||
|
@ -607,15 +609,29 @@ func (session *Session) convertBeanField(col *schemas.Column, fieldValue *reflec
|
|||
}
|
||||
fieldValue.Set(x.Elem())
|
||||
} else {
|
||||
if fieldValue.Len() > 0 {
|
||||
for i := 0; i < fieldValue.Len(); i++ {
|
||||
if i < vv.Len() {
|
||||
fieldValue.Index(i).Set(vv.Index(i))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < vv.Len(); i++ {
|
||||
fieldValue.Set(reflect.Append(*fieldValue, vv.Index(i)))
|
||||
fieldValue.Set(reflect.ValueOf(bs))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
case reflect.Array:
|
||||
bs, ok := convert.AsBytes(scanResult)
|
||||
if ok && fieldType.Elem().Kind() == reflect.Uint8 {
|
||||
if col.SQLType.IsText() {
|
||||
x := reflect.New(fieldType)
|
||||
err := json.DefaultJSONHandler.Unmarshal(bs, x.Interface())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fieldValue.Set(x.Elem())
|
||||
} else {
|
||||
if fieldValue.Len() < vv.Len() {
|
||||
return fmt.Errorf("Set field %s[Array] failed because of data too long", col.Name)
|
||||
}
|
||||
for i := 0; i < fieldValue.Len(); i++ {
|
||||
if i < vv.Len() {
|
||||
fieldValue.Index(i).Set(vv.Index(i))
|
||||
} else {
|
||||
fieldValue.Index(i).Set(uint8ZeroValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -659,7 +675,7 @@ func (session *Session) convertBeanField(col *schemas.Column, fieldValue *reflec
|
|||
if len(table.PrimaryKeys) != 1 {
|
||||
return errors.New("unsupported non or composited primary key cascade")
|
||||
}
|
||||
var pk = make(schemas.PK, len(table.PrimaryKeys))
|
||||
pk := make(schemas.PK, len(table.PrimaryKeys))
|
||||
pk[0], err = asKind(vv, reflect.TypeOf(scanResult))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -687,28 +703,16 @@ func (session *Session) convertBeanField(col *schemas.Column, fieldValue *reflec
|
|||
return convert.AssignValue(fieldValue.Addr(), scanResult)
|
||||
}
|
||||
|
||||
func (session *Session) slice2Bean(scanResults []interface{}, fields []string, bean interface{}, dataStruct *reflect.Value, table *schemas.Table) (schemas.PK, error) {
|
||||
func (session *Session) slice2Bean(scanResults []interface{}, columnsSchema *ColumnsSchema, fields []string, bean interface{}, dataStruct *reflect.Value, table *schemas.Table) (schemas.PK, error) {
|
||||
defer func() {
|
||||
executeAfterSet(bean, fields, scanResults)
|
||||
}()
|
||||
|
||||
buildAfterProcessors(session, bean)
|
||||
|
||||
var tempMap = make(map[string]int)
|
||||
var pk schemas.PK
|
||||
for i, colName := range fields {
|
||||
var idx int
|
||||
var lKey = strings.ToLower(colName)
|
||||
var ok bool
|
||||
|
||||
if idx, ok = tempMap[lKey]; !ok {
|
||||
idx = 0
|
||||
} else {
|
||||
idx++
|
||||
}
|
||||
tempMap[lKey] = idx
|
||||
|
||||
col, fieldValue, err := getField(dataStruct, table, colName, idx)
|
||||
for i, field := range columnsSchema.Fields {
|
||||
col, fieldValue, err := getField(dataStruct, table, field)
|
||||
if _, ok := err.(ErrFieldIsNotExist); ok {
|
||||
continue
|
||||
} else if err != nil {
|
||||
|
@ -757,7 +761,7 @@ func (session *Session) incrVersionFieldValue(fieldValue *reflect.Value) {
|
|||
|
||||
// Context sets the context on this session
|
||||
func (session *Session) Context(ctx context.Context) *Session {
|
||||
if session.ctx != nil {
|
||||
if session.engine.logSessionID && session.ctx != nil {
|
||||
ctx = context.WithValue(ctx, log.SessionIDKey, session.ctx.Value(log.SessionIDKey))
|
||||
ctx = context.WithValue(ctx, log.SessionKey, session.ctx.Value(log.SessionKey))
|
||||
ctx = context.WithValue(ctx, log.SessionShowSQLKey, session.ctx.Value(log.SessionShowSQLKey))
|
||||
|
@ -776,3 +780,13 @@ func (session *Session) PingContext(ctx context.Context) error {
|
|||
session.engine.logger.Infof("PING DATABASE %v", session.engine.DriverName())
|
||||
return session.DB().PingContext(ctx)
|
||||
}
|
||||
|
||||
// disable version check
|
||||
func (session *Session) NoVersionCheck() *Session {
|
||||
session.statement.CheckVersion = false
|
||||
return session
|
||||
}
|
||||
|
||||
func SetDefaultJSONHandler(jsonHandler json.Interface) {
|
||||
json.DefaultJSONHandler = jsonHandler
|
||||
}
|
||||
|
|
|
@ -6,20 +6,15 @@ package xorm
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/caches"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrNeedDeletedCond delete needs less one condition error
|
||||
ErrNeedDeletedCond = errors.New("Delete action needs at least one condition")
|
||||
|
||||
// ErrNotImplemented not implemented
|
||||
ErrNotImplemented = errors.New("Not implemented")
|
||||
)
|
||||
// ErrNeedDeletedCond delete needs less one condition error
|
||||
var ErrNeedDeletedCond = errors.New("Delete action needs at least one condition")
|
||||
|
||||
func (session *Session) cacheDelete(table *schemas.Table, tableName, sqlStr string, args ...interface{}) error {
|
||||
if table == nil ||
|
||||
|
@ -28,7 +23,7 @@ func (session *Session) cacheDelete(table *schemas.Table, tableName, sqlStr stri
|
|||
}
|
||||
|
||||
for _, filter := range session.engine.dialect.Filters() {
|
||||
sqlStr = filter.Do(sqlStr)
|
||||
sqlStr = filter.Do(session.ctx, sqlStr)
|
||||
}
|
||||
|
||||
newsql := session.statement.ConvertIDSQL(sqlStr)
|
||||
|
@ -89,7 +84,18 @@ func (session *Session) cacheDelete(table *schemas.Table, tableName, sqlStr stri
|
|||
}
|
||||
|
||||
// Delete records, bean's non-empty fields are conditions
|
||||
// At least one condition must be set.
|
||||
func (session *Session) Delete(beans ...interface{}) (int64, error) {
|
||||
return session.delete(beans, true)
|
||||
}
|
||||
|
||||
// Truncate records, bean's non-empty fields are conditions
|
||||
// In contrast to Delete this method allows deletes without conditions.
|
||||
func (session *Session) Truncate(beans ...interface{}) (int64, error) {
|
||||
return session.delete(beans, false)
|
||||
}
|
||||
|
||||
func (session *Session) delete(beans []interface{}, mustHaveConditions bool) (int64, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
@ -99,10 +105,8 @@ func (session *Session) Delete(beans ...interface{}) (int64, error) {
|
|||
}
|
||||
|
||||
var (
|
||||
condSQL string
|
||||
condArgs []interface{}
|
||||
err error
|
||||
bean interface{}
|
||||
err error
|
||||
bean interface{}
|
||||
)
|
||||
if len(beans) > 0 {
|
||||
bean = beans[0]
|
||||
|
@ -116,127 +120,50 @@ func (session *Session) Delete(beans ...interface{}) (int64, error) {
|
|||
processor.BeforeDelete()
|
||||
}
|
||||
|
||||
condSQL, condArgs, err = session.statement.GenConds(bean)
|
||||
} else {
|
||||
condSQL, condArgs, err = session.statement.GenCondSQL(session.statement.Conds())
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if err = session.statement.MergeConds(bean); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
pLimitN := session.statement.LimitN
|
||||
if len(condSQL) == 0 && (pLimitN == nil || *pLimitN == 0) {
|
||||
if mustHaveConditions && !session.statement.Conds().IsValid() && (pLimitN == nil || *pLimitN == 0) {
|
||||
return 0, ErrNeedDeletedCond
|
||||
}
|
||||
|
||||
var tableNameNoQuote = session.statement.TableName()
|
||||
var tableName = session.engine.Quote(tableNameNoQuote)
|
||||
var table = session.statement.RefTable
|
||||
var deleteSQL string
|
||||
if len(condSQL) > 0 {
|
||||
deleteSQL = fmt.Sprintf("DELETE FROM %v WHERE %v", tableName, condSQL)
|
||||
} else {
|
||||
deleteSQL = fmt.Sprintf("DELETE FROM %v", tableName)
|
||||
tableNameNoQuote := session.statement.TableName()
|
||||
table := session.statement.RefTable
|
||||
|
||||
realSQLWriter := builder.NewWriter()
|
||||
deleteSQLWriter := builder.NewWriter()
|
||||
if err := session.statement.WriteDelete(realSQLWriter, deleteSQLWriter, session.engine.nowTime); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var orderSQL string
|
||||
if len(session.statement.OrderStr) > 0 {
|
||||
orderSQL += fmt.Sprintf(" ORDER BY %s", session.statement.OrderStr)
|
||||
}
|
||||
if pLimitN != nil && *pLimitN > 0 {
|
||||
limitNValue := *pLimitN
|
||||
orderSQL += fmt.Sprintf(" LIMIT %d", limitNValue)
|
||||
}
|
||||
|
||||
if len(orderSQL) > 0 {
|
||||
switch session.engine.dialect.URI().DBType {
|
||||
case schemas.POSTGRES:
|
||||
inSQL := fmt.Sprintf("ctid IN (SELECT ctid FROM %s%s)", tableName, orderSQL)
|
||||
if len(condSQL) > 0 {
|
||||
deleteSQL += " AND " + inSQL
|
||||
} else {
|
||||
deleteSQL += " WHERE " + inSQL
|
||||
}
|
||||
case schemas.SQLITE:
|
||||
inSQL := fmt.Sprintf("rowid IN (SELECT rowid FROM %s%s)", tableName, orderSQL)
|
||||
if len(condSQL) > 0 {
|
||||
deleteSQL += " AND " + inSQL
|
||||
} else {
|
||||
deleteSQL += " WHERE " + inSQL
|
||||
}
|
||||
// TODO: how to handle delete limit on mssql?
|
||||
case schemas.MSSQL:
|
||||
return 0, ErrNotImplemented
|
||||
default:
|
||||
deleteSQL += orderSQL
|
||||
}
|
||||
}
|
||||
|
||||
var realSQL string
|
||||
argsForCache := make([]interface{}, 0, len(condArgs)*2)
|
||||
if session.statement.GetUnscoped() || table == nil || table.DeletedColumn() == nil { // tag "deleted" is disabled
|
||||
realSQL = deleteSQL
|
||||
copy(argsForCache, condArgs)
|
||||
argsForCache = append(condArgs, argsForCache...)
|
||||
} else {
|
||||
// !oinume! sqlStrForCache and argsForCache is needed to behave as executing "DELETE FROM ..." for caches.
|
||||
copy(argsForCache, condArgs)
|
||||
argsForCache = append(condArgs, argsForCache...)
|
||||
|
||||
deletedColumn := table.DeletedColumn()
|
||||
realSQL = fmt.Sprintf("UPDATE %v SET %v = ? WHERE %v",
|
||||
session.engine.Quote(session.statement.TableName()),
|
||||
session.engine.Quote(deletedColumn.Name),
|
||||
condSQL)
|
||||
|
||||
if len(orderSQL) > 0 {
|
||||
switch session.engine.dialect.URI().DBType {
|
||||
case schemas.POSTGRES:
|
||||
inSQL := fmt.Sprintf("ctid IN (SELECT ctid FROM %s%s)", tableName, orderSQL)
|
||||
if len(condSQL) > 0 {
|
||||
realSQL += " AND " + inSQL
|
||||
} else {
|
||||
realSQL += " WHERE " + inSQL
|
||||
}
|
||||
case schemas.SQLITE:
|
||||
inSQL := fmt.Sprintf("rowid IN (SELECT rowid FROM %s%s)", tableName, orderSQL)
|
||||
if len(condSQL) > 0 {
|
||||
realSQL += " AND " + inSQL
|
||||
} else {
|
||||
realSQL += " WHERE " + inSQL
|
||||
}
|
||||
// TODO: how to handle delete limit on mssql?
|
||||
case schemas.MSSQL:
|
||||
return 0, ErrNotImplemented
|
||||
default:
|
||||
realSQL += orderSQL
|
||||
}
|
||||
}
|
||||
|
||||
// !oinume! Insert nowTime to the head of session.statement.Params
|
||||
condArgs = append(condArgs, "")
|
||||
paramsLen := len(condArgs)
|
||||
copy(condArgs[1:paramsLen], condArgs[0:paramsLen-1])
|
||||
|
||||
val, t, err := session.engine.nowTime(deletedColumn)
|
||||
_, t, err := session.engine.nowTime(deletedColumn)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
condArgs[0] = val
|
||||
|
||||
var colName = deletedColumn.Name
|
||||
colName := deletedColumn.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
})
|
||||
}
|
||||
|
||||
argsForCache := make([]interface{}, 0, len(deleteSQLWriter.Args())*2)
|
||||
copy(argsForCache, deleteSQLWriter.Args())
|
||||
argsForCache = append(deleteSQLWriter.Args(), argsForCache...)
|
||||
|
||||
if cacher := session.engine.GetCacher(tableNameNoQuote); cacher != nil && session.statement.UseCache {
|
||||
_ = session.cacheDelete(table, tableNameNoQuote, deleteSQL, argsForCache...)
|
||||
_ = session.cacheDelete(table, tableNameNoQuote, deleteSQLWriter.String(), argsForCache...)
|
||||
}
|
||||
|
||||
session.statement.RefTable = table
|
||||
res, err := session.exec(realSQL, condArgs...)
|
||||
res, err := session.exec(realSQLWriter.String(), realSQLWriter.Args()...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
package xorm
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/caches"
|
||||
|
@ -60,9 +62,7 @@ func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...inte
|
|||
if len(session.statement.ColumnMap) > 0 && !session.statement.IsDistinct {
|
||||
session.statement.ColumnMap = []string{}
|
||||
}
|
||||
if session.statement.OrderStr != "" {
|
||||
session.statement.OrderStr = ""
|
||||
}
|
||||
session.statement.ResetOrderBy()
|
||||
if session.statement.LimitN != nil {
|
||||
session.statement.LimitN = nil
|
||||
}
|
||||
|
@ -85,15 +85,15 @@ func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{})
|
|||
}
|
||||
|
||||
sliceValue := reflect.Indirect(reflect.ValueOf(rowsSlicePtr))
|
||||
var isSlice = sliceValue.Kind() == reflect.Slice
|
||||
var isMap = sliceValue.Kind() == reflect.Map
|
||||
isSlice := sliceValue.Kind() == reflect.Slice
|
||||
isMap := sliceValue.Kind() == reflect.Map
|
||||
if !isSlice && !isMap {
|
||||
return errors.New("needs a pointer to a slice or a map")
|
||||
}
|
||||
|
||||
sliceElementType := sliceValue.Type().Elem()
|
||||
|
||||
var tp = tpStruct
|
||||
tp := tpStruct
|
||||
if session.statement.RefTable == nil {
|
||||
if sliceElementType.Kind() == reflect.Ptr {
|
||||
if sliceElementType.Elem().Kind() == reflect.Struct {
|
||||
|
@ -116,7 +116,7 @@ func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{})
|
|||
|
||||
var (
|
||||
table = session.statement.RefTable
|
||||
addedTableName = (len(session.statement.JoinStr) > 0)
|
||||
addedTableName = session.statement.NeedTableName()
|
||||
autoCond builder.Cond
|
||||
)
|
||||
if tp == tpStruct {
|
||||
|
@ -163,6 +163,64 @@ func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{})
|
|||
return session.noCacheFind(table, sliceValue, sqlStr, args...)
|
||||
}
|
||||
|
||||
type QueryedField struct {
|
||||
FieldName string
|
||||
LowerFieldName string
|
||||
ColumnType *sql.ColumnType
|
||||
TempIndex int
|
||||
ColumnSchema *schemas.Column
|
||||
}
|
||||
|
||||
type ColumnsSchema struct {
|
||||
Fields []*QueryedField
|
||||
FieldNames []string
|
||||
Types []*sql.ColumnType
|
||||
}
|
||||
|
||||
func (columnsSchema *ColumnsSchema) ParseTableSchema(table *schemas.Table) {
|
||||
for _, field := range columnsSchema.Fields {
|
||||
field.ColumnSchema = table.GetColumnIdx(field.FieldName, field.TempIndex)
|
||||
}
|
||||
}
|
||||
|
||||
func ParseColumnsSchema(fieldNames []string, types []*sql.ColumnType, table *schemas.Table) *ColumnsSchema {
|
||||
var columnsSchema ColumnsSchema
|
||||
|
||||
fields := make([]*QueryedField, 0, len(fieldNames))
|
||||
|
||||
for i, fieldName := range fieldNames {
|
||||
field := &QueryedField{
|
||||
FieldName: fieldName,
|
||||
LowerFieldName: strings.ToLower(fieldName),
|
||||
ColumnType: types[i],
|
||||
}
|
||||
fields = append(fields, field)
|
||||
}
|
||||
|
||||
columnsSchema.Fields = fields
|
||||
|
||||
tempMap := make(map[string]int)
|
||||
for _, field := range fields {
|
||||
var idx int
|
||||
var ok bool
|
||||
|
||||
if idx, ok = tempMap[field.LowerFieldName]; !ok {
|
||||
idx = 0
|
||||
} else {
|
||||
idx++
|
||||
}
|
||||
|
||||
tempMap[field.LowerFieldName] = idx
|
||||
field.TempIndex = idx
|
||||
}
|
||||
|
||||
if table != nil {
|
||||
columnsSchema.ParseTableSchema(table)
|
||||
}
|
||||
|
||||
return &columnsSchema
|
||||
}
|
||||
|
||||
func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect.Value, sqlStr string, args ...interface{}) error {
|
||||
elemType := containerValue.Type().Elem()
|
||||
var isPointer bool
|
||||
|
@ -190,7 +248,7 @@ func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect
|
|||
return err
|
||||
}
|
||||
|
||||
var newElemFunc = func(fields []string) reflect.Value {
|
||||
newElemFunc := func(fields []string) reflect.Value {
|
||||
return utils.New(elemType, len(fields), len(fields))
|
||||
}
|
||||
|
||||
|
@ -235,12 +293,15 @@ func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect
|
|||
}
|
||||
|
||||
if elemType.Kind() == reflect.Struct {
|
||||
var newValue = newElemFunc(fields)
|
||||
newValue := newElemFunc(fields)
|
||||
tb, err := session.engine.tagParser.ParseWithCache(newValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = session.rows2Beans(rows, fields, types, tb, newElemFunc, containerValueSetFunc)
|
||||
|
||||
columnsSchema := ParseColumnsSchema(fields, types, tb)
|
||||
|
||||
err = session.rows2Beans(rows, columnsSchema, fields, types, tb, newElemFunc, containerValueSetFunc)
|
||||
rows.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -249,7 +310,7 @@ func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect
|
|||
}
|
||||
|
||||
for rows.Next() {
|
||||
var newValue = newElemFunc(fields)
|
||||
newValue := newElemFunc(fields)
|
||||
bean := newValue.Interface()
|
||||
|
||||
switch elemType.Kind() {
|
||||
|
@ -285,7 +346,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
|
|||
}
|
||||
|
||||
for _, filter := range session.engine.dialect.Filters() {
|
||||
sqlStr = filter.Do(sqlStr)
|
||||
sqlStr = filter.Do(session.ctx, sqlStr)
|
||||
}
|
||||
|
||||
newsql := session.statement.ConvertIDSQL(sqlStr)
|
||||
|
@ -310,7 +371,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
|
|||
session.engine.logger.Debugf("[cacheFind] ids length > 500, no cache")
|
||||
return ErrCacheFailed
|
||||
}
|
||||
var res = make([]string, len(table.PrimaryKeys))
|
||||
res := make([]string, len(table.PrimaryKeys))
|
||||
err = rows.ScanSlice(&res)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -342,7 +403,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
|
|||
|
||||
ididxes := make(map[string]int)
|
||||
var ides []schemas.PK
|
||||
var temps = make([]interface{}, len(ids))
|
||||
temps := make([]interface{}, len(ids))
|
||||
|
||||
for idx, id := range ids {
|
||||
sid, err := id.ToString()
|
||||
|
@ -457,7 +518,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
|
|||
sliceValue.Set(reflect.Append(sliceValue, reflect.Indirect(reflect.ValueOf(bean))))
|
||||
}
|
||||
} else if sliceValue.Kind() == reflect.Map {
|
||||
var key = ids[j]
|
||||
key := ids[j]
|
||||
keyType := sliceValue.Type().Key()
|
||||
keyValue := reflect.New(keyType)
|
||||
var ikey interface{}
|
||||
|
|
|
@ -164,7 +164,9 @@ func (session *Session) nocacheGet(beanKind reflect.Kind, table *schemas.Table,
|
|||
return true, err
|
||||
}
|
||||
|
||||
if err := session.scan(rows, table, beanKind, beans, types, fields); err != nil {
|
||||
columnsSchema := ParseColumnsSchema(fields, types, table)
|
||||
|
||||
if err := session.scan(rows, table, beanKind, beans, columnsSchema, types, fields); err != nil {
|
||||
return true, err
|
||||
}
|
||||
rows.Close()
|
||||
|
@ -172,7 +174,7 @@ func (session *Session) nocacheGet(beanKind reflect.Kind, table *schemas.Table,
|
|||
return true, session.executeProcessors()
|
||||
}
|
||||
|
||||
func (session *Session) scan(rows *core.Rows, table *schemas.Table, firstBeanKind reflect.Kind, beans []interface{}, types []*sql.ColumnType, fields []string) error {
|
||||
func (session *Session) scan(rows *core.Rows, table *schemas.Table, firstBeanKind reflect.Kind, beans []interface{}, columnsSchema *ColumnsSchema, types []*sql.ColumnType, fields []string) error {
|
||||
if len(beans) == 1 {
|
||||
bean := beans[0]
|
||||
switch firstBeanKind {
|
||||
|
@ -186,7 +188,7 @@ func (session *Session) scan(rows *core.Rows, table *schemas.Table, firstBeanKin
|
|||
}
|
||||
|
||||
dataStruct := utils.ReflectValue(bean)
|
||||
_, err = session.slice2Bean(scanResults, fields, bean, &dataStruct, table)
|
||||
_, err = session.slice2Bean(scanResults, columnsSchema, fields, bean, &dataStruct, table)
|
||||
return err
|
||||
case reflect.Slice:
|
||||
return session.getSlice(rows, types, fields, bean)
|
||||
|
@ -278,7 +280,7 @@ func (session *Session) cacheGet(bean interface{}, sqlStr string, args ...interf
|
|||
}
|
||||
|
||||
for _, filter := range session.engine.dialect.Filters() {
|
||||
sqlStr = filter.Do(sqlStr)
|
||||
sqlStr = filter.Do(session.ctx, sqlStr)
|
||||
}
|
||||
newsql := session.statement.ConvertIDSQL(sqlStr)
|
||||
if newsql == "" {
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/convert"
|
||||
"xorm.io/xorm/dialects"
|
||||
"xorm.io/xorm/internal/utils"
|
||||
|
@ -156,14 +157,14 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr interface{}) (int64, e
|
|||
}
|
||||
args = append(args, val)
|
||||
|
||||
var colName = col.Name
|
||||
colName := col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
})
|
||||
} else if col.IsVersion && session.statement.CheckVersion {
|
||||
args = append(args, 1)
|
||||
var colName = col.Name
|
||||
colName := col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnInt(bean, col, 1)
|
||||
|
@ -186,24 +187,12 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr interface{}) (int64, e
|
|||
}
|
||||
cleanupProcessorsClosures(&session.beforeClosures)
|
||||
|
||||
quoter := session.engine.dialect.Quoter()
|
||||
var sql string
|
||||
colStr := quoter.Join(colNames, ",")
|
||||
if session.engine.dialect.URI().DBType == schemas.ORACLE {
|
||||
temp := fmt.Sprintf(") INTO %s (%v) VALUES (",
|
||||
quoter.Quote(tableName),
|
||||
colStr)
|
||||
sql = fmt.Sprintf("INSERT ALL INTO %s (%v) VALUES (%v) SELECT 1 FROM DUAL",
|
||||
quoter.Quote(tableName),
|
||||
colStr,
|
||||
strings.Join(colMultiPlaces, temp))
|
||||
} else {
|
||||
sql = fmt.Sprintf("INSERT INTO %s (%v) VALUES (%v)",
|
||||
quoter.Quote(tableName),
|
||||
colStr,
|
||||
strings.Join(colMultiPlaces, "),("))
|
||||
w := builder.NewWriter()
|
||||
if err := session.statement.WriteInsertMultiple(w, tableName, colNames, colMultiPlaces); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
res, err := session.exec(sql, args...)
|
||||
|
||||
res, err := session.exec(w.String(), args...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -276,7 +265,7 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
|||
processor.BeforeInsert()
|
||||
}
|
||||
|
||||
var tableName = session.statement.TableName()
|
||||
tableName := session.statement.TableName()
|
||||
table := session.statement.RefTable
|
||||
|
||||
colNames, args, err := session.genInsertColumns(bean)
|
||||
|
@ -353,15 +342,15 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
|||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if needCommit {
|
||||
if err := session.Commit(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
if id == 0 {
|
||||
return 0, errors.New("insert successfully but not returned id")
|
||||
}
|
||||
if needCommit {
|
||||
if err := session.Commit(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
if id == 0 {
|
||||
return 0, errors.New("insert successfully but not returned id")
|
||||
}
|
||||
|
||||
defer handleAfterInsertProcessorFunc(bean)
|
||||
|
||||
|
@ -521,7 +510,7 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
|||
}
|
||||
args = append(args, val)
|
||||
|
||||
var colName = col.Name
|
||||
colName := col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
|
@ -551,7 +540,7 @@ func (session *Session) insertMapInterface(m map[string]interface{}) (int64, err
|
|||
return 0, ErrTableNotFound
|
||||
}
|
||||
|
||||
var columns = make([]string, 0, len(m))
|
||||
columns := make([]string, 0, len(m))
|
||||
exprs := session.statement.ExprColumns
|
||||
for k := range m {
|
||||
if !exprs.IsColExist(k) {
|
||||
|
@ -560,7 +549,7 @@ func (session *Session) insertMapInterface(m map[string]interface{}) (int64, err
|
|||
}
|
||||
sort.Strings(columns)
|
||||
|
||||
var args = make([]interface{}, 0, len(m))
|
||||
args := make([]interface{}, 0, len(m))
|
||||
for _, colName := range columns {
|
||||
args = append(args, m[colName])
|
||||
}
|
||||
|
@ -578,7 +567,7 @@ func (session *Session) insertMultipleMapInterface(maps []map[string]interface{}
|
|||
return 0, ErrTableNotFound
|
||||
}
|
||||
|
||||
var columns = make([]string, 0, len(maps[0]))
|
||||
columns := make([]string, 0, len(maps[0]))
|
||||
exprs := session.statement.ExprColumns
|
||||
for k := range maps[0] {
|
||||
if !exprs.IsColExist(k) {
|
||||
|
@ -587,9 +576,9 @@ func (session *Session) insertMultipleMapInterface(maps []map[string]interface{}
|
|||
}
|
||||
sort.Strings(columns)
|
||||
|
||||
var argss = make([][]interface{}, 0, len(maps))
|
||||
argss := make([][]interface{}, 0, len(maps))
|
||||
for _, m := range maps {
|
||||
var args = make([]interface{}, 0, len(m))
|
||||
args := make([]interface{}, 0, len(m))
|
||||
for _, colName := range columns {
|
||||
args = append(args, m[colName])
|
||||
}
|
||||
|
@ -609,7 +598,7 @@ func (session *Session) insertMapString(m map[string]string) (int64, error) {
|
|||
return 0, ErrTableNotFound
|
||||
}
|
||||
|
||||
var columns = make([]string, 0, len(m))
|
||||
columns := make([]string, 0, len(m))
|
||||
exprs := session.statement.ExprColumns
|
||||
for k := range m {
|
||||
if !exprs.IsColExist(k) {
|
||||
|
@ -619,7 +608,7 @@ func (session *Session) insertMapString(m map[string]string) (int64, error) {
|
|||
|
||||
sort.Strings(columns)
|
||||
|
||||
var args = make([]interface{}, 0, len(m))
|
||||
args := make([]interface{}, 0, len(m))
|
||||
for _, colName := range columns {
|
||||
args = append(args, m[colName])
|
||||
}
|
||||
|
@ -637,7 +626,7 @@ func (session *Session) insertMultipleMapString(maps []map[string]string) (int64
|
|||
return 0, ErrTableNotFound
|
||||
}
|
||||
|
||||
var columns = make([]string, 0, len(maps[0]))
|
||||
columns := make([]string, 0, len(maps[0]))
|
||||
exprs := session.statement.ExprColumns
|
||||
for k := range maps[0] {
|
||||
if !exprs.IsColExist(k) {
|
||||
|
@ -646,9 +635,9 @@ func (session *Session) insertMultipleMapString(maps []map[string]string) (int64
|
|||
}
|
||||
sort.Strings(columns)
|
||||
|
||||
var argss = make([][]interface{}, 0, len(maps))
|
||||
argss := make([][]interface{}, 0, len(maps))
|
||||
for _, m := range maps {
|
||||
var args = make([]interface{}, 0, len(m))
|
||||
args := make([]interface{}, 0, len(m))
|
||||
for _, colName := range columns {
|
||||
args = append(args, m[colName])
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
func (session *Session) queryPreprocess(sqlStr *string, paramStr ...interface{}) {
|
||||
for _, filter := range session.engine.dialect.Filters() {
|
||||
*sqlStr = filter.Do(*sqlStr)
|
||||
*sqlStr = filter.Do(session.ctx, *sqlStr)
|
||||
}
|
||||
|
||||
session.lastSQL = *sqlStr
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
|
||||
"xorm.io/xorm/dialects"
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
// Ping test if database is ok
|
||||
|
@ -169,7 +168,7 @@ func (session *Session) dropTable(beanOrTableName interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var seqName = utils.SeqName(tableName)
|
||||
seqName := utils.SeqName(tableName)
|
||||
exist, err := session.engine.dialect.IsSequenceExist(session.ctx, session.getQueryer(), seqName)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -244,228 +243,6 @@ func (session *Session) addUnique(tableName, uqeName string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Sync2 synchronize structs to database tables
|
||||
// Depricated
|
||||
func (session *Session) Sync2(beans ...interface{}) error {
|
||||
return session.Sync(beans...)
|
||||
}
|
||||
|
||||
// Sync synchronize structs to database tables
|
||||
func (session *Session) Sync(beans ...interface{}) error {
|
||||
engine := session.engine
|
||||
|
||||
if session.isAutoClose {
|
||||
session.isAutoClose = false
|
||||
defer session.Close()
|
||||
}
|
||||
|
||||
tables, err := engine.dialect.GetTables(session.getQueryer(), session.ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
session.autoResetStatement = false
|
||||
defer func() {
|
||||
session.autoResetStatement = true
|
||||
session.resetStatement()
|
||||
}()
|
||||
|
||||
for _, bean := range beans {
|
||||
v := utils.ReflectValue(bean)
|
||||
table, err := engine.tagParser.ParseWithCache(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var tbName string
|
||||
if len(session.statement.AltTableName) > 0 {
|
||||
tbName = session.statement.AltTableName
|
||||
} else {
|
||||
tbName = engine.TableName(bean)
|
||||
}
|
||||
tbNameWithSchema := engine.tbNameWithSchema(tbName)
|
||||
|
||||
var oriTable *schemas.Table
|
||||
for _, tb := range tables {
|
||||
if strings.EqualFold(engine.tbNameWithSchema(tb.Name), engine.tbNameWithSchema(tbName)) {
|
||||
oriTable = tb
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// this is a new table
|
||||
if oriTable == nil {
|
||||
err = session.StoreEngine(session.statement.StoreEngine).createTable(bean)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = session.createUniques(bean)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = session.createIndexes(bean)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// this will modify an old table
|
||||
if err = engine.loadTableInfo(oriTable); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// check columns
|
||||
for _, col := range table.Columns() {
|
||||
var oriCol *schemas.Column
|
||||
for _, col2 := range oriTable.Columns() {
|
||||
if strings.EqualFold(col.Name, col2.Name) {
|
||||
oriCol = col2
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// column is not exist on table
|
||||
if oriCol == nil {
|
||||
session.statement.RefTable = table
|
||||
session.statement.SetTableName(tbNameWithSchema)
|
||||
if err = session.addColumn(col.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
err = nil
|
||||
expectedType := engine.dialect.SQLType(col)
|
||||
curType := engine.dialect.SQLType(oriCol)
|
||||
if expectedType != curType {
|
||||
if expectedType == schemas.Text &&
|
||||
strings.HasPrefix(curType, schemas.Varchar) {
|
||||
// currently only support mysql & postgres
|
||||
if engine.dialect.URI().DBType == schemas.MYSQL ||
|
||||
engine.dialect.URI().DBType == schemas.POSTGRES {
|
||||
engine.logger.Infof("Table %s column %s change type from %s to %s\n",
|
||||
tbNameWithSchema, col.Name, curType, expectedType)
|
||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||
} else {
|
||||
engine.logger.Warnf("Table %s column %s db type is %s, struct type is %s\n",
|
||||
tbNameWithSchema, col.Name, curType, expectedType)
|
||||
}
|
||||
} else if strings.HasPrefix(curType, schemas.Varchar) && strings.HasPrefix(expectedType, schemas.Varchar) {
|
||||
if engine.dialect.URI().DBType == schemas.MYSQL {
|
||||
if oriCol.Length < col.Length {
|
||||
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
||||
tbNameWithSchema, col.Name, oriCol.Length, col.Length)
|
||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !(strings.HasPrefix(curType, expectedType) && curType[len(expectedType)] == '(') {
|
||||
if !strings.EqualFold(schemas.SQLTypeName(curType), engine.dialect.Alias(schemas.SQLTypeName(expectedType))) {
|
||||
engine.logger.Warnf("Table %s column %s db type is %s, struct type is %s",
|
||||
tbNameWithSchema, col.Name, curType, expectedType)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if expectedType == schemas.Varchar {
|
||||
if engine.dialect.URI().DBType == schemas.MYSQL {
|
||||
if oriCol.Length < col.Length {
|
||||
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
||||
tbNameWithSchema, col.Name, oriCol.Length, col.Length)
|
||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||
}
|
||||
}
|
||||
} else if col.Comment != oriCol.Comment {
|
||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||
}
|
||||
|
||||
if col.Default != oriCol.Default {
|
||||
switch {
|
||||
case col.IsAutoIncrement: // For autoincrement column, don't check default
|
||||
case (col.SQLType.Name == schemas.Bool || col.SQLType.Name == schemas.Boolean) &&
|
||||
((strings.EqualFold(col.Default, "true") && oriCol.Default == "1") ||
|
||||
(strings.EqualFold(col.Default, "false") && oriCol.Default == "0")):
|
||||
default:
|
||||
engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s",
|
||||
tbName, col.Name, oriCol.Default, col.Default)
|
||||
}
|
||||
}
|
||||
if col.Nullable != oriCol.Nullable {
|
||||
engine.logger.Warnf("Table %s Column %s db nullable is %v, struct nullable is %v",
|
||||
tbName, col.Name, oriCol.Nullable, col.Nullable)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var foundIndexNames = make(map[string]bool)
|
||||
var addedNames = make(map[string]*schemas.Index)
|
||||
|
||||
for name, index := range table.Indexes {
|
||||
var oriIndex *schemas.Index
|
||||
for name2, index2 := range oriTable.Indexes {
|
||||
if index.Equal(index2) {
|
||||
oriIndex = index2
|
||||
foundIndexNames[name2] = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if oriIndex != nil {
|
||||
if oriIndex.Type != index.Type {
|
||||
sql := engine.dialect.DropIndexSQL(tbNameWithSchema, oriIndex)
|
||||
_, err = session.exec(sql)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
oriIndex = nil
|
||||
}
|
||||
}
|
||||
|
||||
if oriIndex == nil {
|
||||
addedNames[name] = index
|
||||
}
|
||||
}
|
||||
|
||||
for name2, index2 := range oriTable.Indexes {
|
||||
if _, ok := foundIndexNames[name2]; !ok {
|
||||
sql := engine.dialect.DropIndexSQL(tbNameWithSchema, index2)
|
||||
_, err = session.exec(sql)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for name, index := range addedNames {
|
||||
if index.Type == schemas.UniqueType {
|
||||
session.statement.RefTable = table
|
||||
session.statement.SetTableName(tbNameWithSchema)
|
||||
err = session.addUnique(tbNameWithSchema, name)
|
||||
} else if index.Type == schemas.IndexType {
|
||||
session.statement.RefTable = table
|
||||
session.statement.SetTableName(tbNameWithSchema)
|
||||
err = session.addIndex(tbNameWithSchema, name)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// check all the columns which removed from struct fields but left on database tables.
|
||||
for _, colName := range oriTable.ColumnsSeq() {
|
||||
if table.GetColumn(colName) == nil {
|
||||
engine.logger.Warnf("Table %s has column %s but struct has not related field", engine.TableName(oriTable.Name, true), colName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ImportFile SQL DDL file
|
||||
func (session *Session) ImportFile(ddlPath string) ([]sql.Result, error) {
|
||||
file, err := os.Open(ddlPath)
|
||||
|
@ -490,7 +267,7 @@ func (session *Session) Import(r io.Reader) ([]sql.Result, error) {
|
|||
if atEOF && len(data) == 0 {
|
||||
return 0, nil, nil
|
||||
}
|
||||
var oriInSingleQuote = inSingleQuote
|
||||
oriInSingleQuote := inSingleQuote
|
||||
for i, b := range data {
|
||||
if startComment {
|
||||
if b == '\n' {
|
||||
|
|
|
@ -24,7 +24,7 @@ func (session *Session) Count(bean ...interface{}) (int64, error) {
|
|||
|
||||
var total int64
|
||||
err = session.queryRow(sqlStr, args...).Scan(&total)
|
||||
if err == sql.ErrNoRows || err == nil {
|
||||
if err == nil {
|
||||
return total, nil
|
||||
}
|
||||
|
||||
|
@ -70,12 +70,12 @@ func (session *Session) SumInt(bean interface{}, columnName string) (res int64,
|
|||
|
||||
// Sums call sum some columns. bean's non-empty fields are conditions.
|
||||
func (session *Session) Sums(bean interface{}, columnNames ...string) ([]float64, error) {
|
||||
var res = make([]float64, len(columnNames))
|
||||
res := make([]float64, len(columnNames))
|
||||
return res, session.sum(&res, bean, columnNames...)
|
||||
}
|
||||
|
||||
// SumsInt sum specify columns and return as []int64 instead of []float64
|
||||
func (session *Session) SumsInt(bean interface{}, columnNames ...string) ([]int64, error) {
|
||||
var res = make([]int64, len(columnNames))
|
||||
res := make([]int64, len(columnNames))
|
||||
return res, session.sum(&res, bean, columnNames...)
|
||||
}
|
||||
|
|
|
@ -5,149 +5,61 @@
|
|||
package xorm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/caches"
|
||||
"xorm.io/xorm/internal/statements"
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
// enumerated all errors
|
||||
var (
|
||||
ErrNoColumnsTobeUpdated = errors.New("no columns found to be updated")
|
||||
ErrNoColumnsTobeUpdated = statements.ErrNoColumnsTobeUpdated
|
||||
)
|
||||
|
||||
//revive:disable
|
||||
func (session *Session) cacheUpdate(table *schemas.Table, tableName, sqlStr string, args ...interface{}) error {
|
||||
if table == nil ||
|
||||
session.tx != nil {
|
||||
return ErrCacheFailed
|
||||
func (session *Session) genAutoCond(condiBean interface{}) (builder.Cond, error) {
|
||||
if session.statement.NoAutoCondition {
|
||||
return builder.NewCond(), nil
|
||||
}
|
||||
|
||||
oldhead, newsql := session.statement.ConvertUpdateSQL(sqlStr)
|
||||
if newsql == "" {
|
||||
return ErrCacheFailed
|
||||
}
|
||||
for _, filter := range session.engine.dialect.Filters() {
|
||||
newsql = filter.Do(newsql)
|
||||
}
|
||||
session.engine.logger.Debugf("[cache] new sql: %v, %v", oldhead, newsql)
|
||||
|
||||
var nStart int
|
||||
if len(args) > 0 {
|
||||
if strings.Contains(sqlStr, "?") {
|
||||
nStart = strings.Count(oldhead, "?")
|
||||
} else {
|
||||
// only for pq, TODO: if any other databse?
|
||||
nStart = strings.Count(oldhead, "$")
|
||||
if c, ok := condiBean.(map[string]interface{}); ok {
|
||||
eq := make(builder.Eq)
|
||||
for k, v := range c {
|
||||
eq[session.engine.Quote(k)] = v
|
||||
}
|
||||
|
||||
if session.statement.RefTable != nil {
|
||||
if col := session.statement.RefTable.DeletedColumn(); col != nil && !session.statement.GetUnscoped() { // tag "deleted" is enabled
|
||||
return eq.And(session.statement.CondDeleted(col)), nil
|
||||
}
|
||||
}
|
||||
return eq, nil
|
||||
}
|
||||
|
||||
cacher := session.engine.GetCacher(tableName)
|
||||
session.engine.logger.Debugf("[cache] get cache sql: %v, %v", newsql, args[nStart:])
|
||||
ids, err := caches.GetCacheSql(cacher, tableName, newsql, args[nStart:])
|
||||
ct := reflect.TypeOf(condiBean)
|
||||
k := ct.Kind()
|
||||
if k == reflect.Ptr {
|
||||
k = ct.Elem().Kind()
|
||||
}
|
||||
if k != reflect.Struct {
|
||||
return nil, ErrConditionType
|
||||
}
|
||||
|
||||
condTable, err := session.engine.TableInfo(condiBean)
|
||||
if err != nil {
|
||||
rows, err := session.NoCache().queryRows(newsql, args[nStart:]...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
ids = make([]schemas.PK, 0)
|
||||
for rows.Next() {
|
||||
var res = make([]string, len(table.PrimaryKeys))
|
||||
err = rows.ScanSlice(&res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var pk schemas.PK = make([]interface{}, len(table.PrimaryKeys))
|
||||
for i, col := range table.PKColumns() {
|
||||
if col.SQLType.IsNumeric() {
|
||||
n, err := strconv.ParseInt(res[i], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pk[i] = n
|
||||
} else if col.SQLType.IsText() {
|
||||
pk[i] = res[i]
|
||||
} else {
|
||||
return errors.New("not supported")
|
||||
}
|
||||
}
|
||||
|
||||
ids = append(ids, pk)
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return rows.Err()
|
||||
}
|
||||
session.engine.logger.Debugf("[cache] find updated id: %v", ids)
|
||||
} /*else {
|
||||
session.engine.LogDebug("[xorm:cacheUpdate] del cached sql:", tableName, newsql, args)
|
||||
cacher.DelIds(tableName, genSqlKey(newsql, args))
|
||||
}*/
|
||||
|
||||
for _, id := range ids {
|
||||
sid, err := id.ToString()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if bean := cacher.GetBean(tableName, sid); bean != nil {
|
||||
sqls := utils.SplitNNoCase(sqlStr, "where", 2)
|
||||
if len(sqls) == 0 || len(sqls) > 2 {
|
||||
return ErrCacheFailed
|
||||
}
|
||||
|
||||
sqls = utils.SplitNNoCase(sqls[0], "set", 2)
|
||||
if len(sqls) != 2 {
|
||||
return ErrCacheFailed
|
||||
}
|
||||
kvs := strings.Split(strings.TrimSpace(sqls[1]), ",")
|
||||
|
||||
for idx, kv := range kvs {
|
||||
sps := strings.SplitN(kv, "=", 2)
|
||||
sps2 := strings.Split(sps[0], ".")
|
||||
colName := sps2[len(sps2)-1]
|
||||
colName = session.engine.dialect.Quoter().Trim(colName)
|
||||
colName = schemas.CommonQuoter.Trim(colName)
|
||||
|
||||
if col := table.GetColumn(colName); col != nil {
|
||||
fieldValue, err := col.ValueOf(bean)
|
||||
if err != nil {
|
||||
session.engine.logger.Errorf("%v", err)
|
||||
} else {
|
||||
session.engine.logger.Debugf("[cache] set bean field: %v, %v, %v", bean, colName, fieldValue.Interface())
|
||||
if col.IsVersion && session.statement.CheckVersion {
|
||||
session.incrVersionFieldValue(fieldValue)
|
||||
} else {
|
||||
fieldValue.Set(reflect.ValueOf(args[idx]))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
session.engine.logger.Errorf("[cache] ERROR: column %v is not table %v's",
|
||||
colName, table.Name)
|
||||
}
|
||||
}
|
||||
|
||||
session.engine.logger.Debugf("[cache] update cache: %v, %v, %v", tableName, id, bean)
|
||||
cacher.PutBean(tableName, sid, bean)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
session.engine.logger.Debugf("[cache] clear cached table sql: %v", tableName)
|
||||
cacher.ClearIds(tableName)
|
||||
return nil
|
||||
return session.statement.BuildConds(condTable, condiBean, true, true, false, true, false)
|
||||
}
|
||||
|
||||
// Update records, bean's non-empty fields are updated contents,
|
||||
// condiBean' non-empty filds are conditions
|
||||
// CAUTION:
|
||||
// 1.bool will defaultly be updated content nor conditions
|
||||
// You should call UseBool if you have bool to use.
|
||||
// 2.float32 & float64 may be not inexact as conditions
|
||||
//
|
||||
// 1.bool will defaultly be updated content nor conditions
|
||||
// You should call UseBool if you have bool to use.
|
||||
// 2.float32 & float64 may be not inexact as conditions
|
||||
func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int64, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
|
@ -162,9 +74,6 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
v := utils.ReflectValue(bean)
|
||||
t := v.Type()
|
||||
|
||||
var colNames []string
|
||||
var args []interface{}
|
||||
|
||||
// handle before update processors
|
||||
for _, closure := range session.beforeClosures {
|
||||
closure(bean)
|
||||
|
@ -175,9 +84,11 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
}
|
||||
// --
|
||||
|
||||
var colNames []string
|
||||
var args []interface{}
|
||||
var err error
|
||||
var isMap = t.Kind() == reflect.Map
|
||||
var isStruct = t.Kind() == reflect.Struct
|
||||
isMap := t.Kind() == reflect.Map
|
||||
isStruct := t.Kind() == reflect.Struct
|
||||
if isStruct {
|
||||
if err := session.statement.SetRefBean(bean); err != nil {
|
||||
return 0, err
|
||||
|
@ -226,7 +137,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
args = append(args, val)
|
||||
}
|
||||
|
||||
var colName = col.Name
|
||||
colName := col.Name
|
||||
if isStruct {
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
col := table.GetColumn(colName)
|
||||
|
@ -236,200 +147,53 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
}
|
||||
}
|
||||
|
||||
// for update action to like "column = column + ?"
|
||||
incColumns := session.statement.IncrColumns
|
||||
for _, expr := range incColumns {
|
||||
colNames = append(colNames, session.engine.Quote(expr.ColName)+" = "+session.engine.Quote(expr.ColName)+" + ?")
|
||||
args = append(args, expr.Arg)
|
||||
}
|
||||
// for update action to like "column = column - ?"
|
||||
decColumns := session.statement.DecrColumns
|
||||
for _, expr := range decColumns {
|
||||
colNames = append(colNames, session.engine.Quote(expr.ColName)+" = "+session.engine.Quote(expr.ColName)+" - ?")
|
||||
args = append(args, expr.Arg)
|
||||
}
|
||||
// for update action to like "column = expression"
|
||||
exprColumns := session.statement.ExprColumns
|
||||
for _, expr := range exprColumns {
|
||||
switch tp := expr.Arg.(type) {
|
||||
case string:
|
||||
if len(tp) == 0 {
|
||||
tp = "''"
|
||||
}
|
||||
colNames = append(colNames, session.engine.Quote(expr.ColName)+"="+tp)
|
||||
case *builder.Builder:
|
||||
subQuery, subArgs, err := session.statement.GenCondSQL(tp)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
colNames = append(colNames, session.engine.Quote(expr.ColName)+"=("+subQuery+")")
|
||||
args = append(args, subArgs...)
|
||||
default:
|
||||
colNames = append(colNames, session.engine.Quote(expr.ColName)+"=?")
|
||||
args = append(args, expr.Arg)
|
||||
}
|
||||
}
|
||||
|
||||
if err = session.statement.ProcessIDParam(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var autoCond builder.Cond
|
||||
if !session.statement.NoAutoCondition {
|
||||
condBeanIsStruct := false
|
||||
if len(condiBean) > 0 {
|
||||
if c, ok := condiBean[0].(map[string]interface{}); ok {
|
||||
var eq = make(builder.Eq)
|
||||
for k, v := range c {
|
||||
eq[session.engine.Quote(k)] = v
|
||||
}
|
||||
autoCond = builder.Eq(eq)
|
||||
} else {
|
||||
ct := reflect.TypeOf(condiBean[0])
|
||||
k := ct.Kind()
|
||||
if k == reflect.Ptr {
|
||||
k = ct.Elem().Kind()
|
||||
}
|
||||
if k == reflect.Struct {
|
||||
condTable, err := session.engine.TableInfo(condiBean[0])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
autoCond, err = session.statement.BuildConds(condTable, condiBean[0], true, true, false, true, false)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
condBeanIsStruct = true
|
||||
} else {
|
||||
return 0, ErrConditionType
|
||||
}
|
||||
}
|
||||
if len(condiBean) > 0 {
|
||||
autoCond, err = session.genAutoCond(condiBean[0])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
} else if table != nil {
|
||||
if col := table.DeletedColumn(); col != nil && !session.statement.GetUnscoped() { // tag "deleted" is enabled
|
||||
autoCond1 := session.statement.CondDeleted(col)
|
||||
|
||||
if !condBeanIsStruct && table != nil {
|
||||
if col := table.DeletedColumn(); col != nil && !session.statement.GetUnscoped() { // tag "deleted" is enabled
|
||||
autoCond1 := session.statement.CondDeleted(col)
|
||||
|
||||
if autoCond == nil {
|
||||
autoCond = autoCond1
|
||||
} else {
|
||||
autoCond = autoCond.And(autoCond1)
|
||||
}
|
||||
if autoCond == nil {
|
||||
autoCond = autoCond1
|
||||
} else {
|
||||
autoCond = autoCond.And(autoCond1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
st := session.statement
|
||||
|
||||
var (
|
||||
sqlStr string
|
||||
condArgs []interface{}
|
||||
condSQL string
|
||||
cond = session.statement.Conds().And(autoCond)
|
||||
|
||||
doIncVer = isStruct && (table != nil && table.Version != "" && session.statement.CheckVersion)
|
||||
verValue *reflect.Value
|
||||
)
|
||||
if doIncVer {
|
||||
verValue, err = table.VersionColumn().ValueOf(bean)
|
||||
verValue, err = table.VersionColumn().ValueOfV(&v)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if verValue != nil {
|
||||
cond = cond.And(builder.Eq{session.engine.Quote(table.Version): verValue.Interface()})
|
||||
colNames = append(colNames, session.engine.Quote(table.Version)+" = "+session.engine.Quote(table.Version)+" + 1")
|
||||
}
|
||||
}
|
||||
|
||||
if len(colNames) == 0 {
|
||||
return 0, ErrNoColumnsTobeUpdated
|
||||
}
|
||||
|
||||
condSQL, condArgs, err = session.statement.GenCondSQL(cond)
|
||||
if err != nil {
|
||||
updateWriter := builder.NewWriter()
|
||||
if err := session.statement.WriteUpdate(updateWriter, cond, v, colNames, args); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if len(condSQL) > 0 {
|
||||
condSQL = "WHERE " + condSQL
|
||||
}
|
||||
tableName := session.statement.TableName() // table name must been get before exec because statement will be reset
|
||||
useCache := session.statement.UseCache
|
||||
|
||||
if st.OrderStr != "" {
|
||||
condSQL += fmt.Sprintf(" ORDER BY %v", st.OrderStr)
|
||||
}
|
||||
|
||||
var tableName = session.statement.TableName()
|
||||
// TODO: Oracle support needed
|
||||
var top string
|
||||
if st.LimitN != nil {
|
||||
limitValue := *st.LimitN
|
||||
switch session.engine.dialect.URI().DBType {
|
||||
case schemas.MYSQL:
|
||||
condSQL += fmt.Sprintf(" LIMIT %d", limitValue)
|
||||
case schemas.SQLITE:
|
||||
tempCondSQL := condSQL + fmt.Sprintf(" LIMIT %d", limitValue)
|
||||
cond = cond.And(builder.Expr(fmt.Sprintf("rowid IN (SELECT rowid FROM %v %v)",
|
||||
session.engine.Quote(tableName), tempCondSQL), condArgs...))
|
||||
condSQL, condArgs, err = session.statement.GenCondSQL(cond)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(condSQL) > 0 {
|
||||
condSQL = "WHERE " + condSQL
|
||||
}
|
||||
case schemas.POSTGRES:
|
||||
tempCondSQL := condSQL + fmt.Sprintf(" LIMIT %d", limitValue)
|
||||
cond = cond.And(builder.Expr(fmt.Sprintf("CTID IN (SELECT CTID FROM %v %v)",
|
||||
session.engine.Quote(tableName), tempCondSQL), condArgs...))
|
||||
condSQL, condArgs, err = session.statement.GenCondSQL(cond)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if len(condSQL) > 0 {
|
||||
condSQL = "WHERE " + condSQL
|
||||
}
|
||||
case schemas.MSSQL:
|
||||
if st.OrderStr != "" && table != nil && len(table.PrimaryKeys) == 1 {
|
||||
cond = builder.Expr(fmt.Sprintf("%s IN (SELECT TOP (%d) %s FROM %v%v)",
|
||||
table.PrimaryKeys[0], limitValue, table.PrimaryKeys[0],
|
||||
session.engine.Quote(tableName), condSQL), condArgs...)
|
||||
|
||||
condSQL, condArgs, err = session.statement.GenCondSQL(cond)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(condSQL) > 0 {
|
||||
condSQL = "WHERE " + condSQL
|
||||
}
|
||||
} else {
|
||||
top = fmt.Sprintf("TOP (%d) ", limitValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var tableAlias = session.engine.Quote(tableName)
|
||||
var fromSQL string
|
||||
if session.statement.TableAlias != "" {
|
||||
switch session.engine.dialect.URI().DBType {
|
||||
case schemas.MSSQL:
|
||||
fromSQL = fmt.Sprintf("FROM %s %s ", tableAlias, session.statement.TableAlias)
|
||||
tableAlias = session.statement.TableAlias
|
||||
default:
|
||||
tableAlias = fmt.Sprintf("%s AS %s", tableAlias, session.statement.TableAlias)
|
||||
}
|
||||
}
|
||||
|
||||
sqlStr = fmt.Sprintf("UPDATE %v%v SET %v %v%v",
|
||||
top,
|
||||
tableAlias,
|
||||
strings.Join(colNames, ", "),
|
||||
fromSQL,
|
||||
condSQL)
|
||||
|
||||
res, err := session.exec(sqlStr, append(args, condArgs...)...)
|
||||
res, err := session.exec(updateWriter.String(), updateWriter.Args()...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else if doIncVer {
|
||||
|
@ -438,8 +202,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
}
|
||||
}
|
||||
|
||||
if cacher := session.engine.GetCacher(tableName); cacher != nil && session.statement.UseCache {
|
||||
// session.cacheUpdate(table, tableName, sqlStr, args...)
|
||||
if cacher := session.engine.GetCacher(tableName); cacher != nil && useCache {
|
||||
session.engine.logger.Debugf("[cache] clear table: %v", tableName)
|
||||
cacher.ClearIds(tableName)
|
||||
cacher.ClearBeans(tableName)
|
||||
|
@ -535,7 +298,7 @@ func (session *Session) genUpdateColumns(bean interface{}) ([]string, []interfac
|
|||
}
|
||||
args = append(args, val)
|
||||
|
||||
var colName = col.Name
|
||||
colName := col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
|
|
|
@ -0,0 +1,276 @@
|
|||
// Copyright 2023 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
type SyncOptions struct {
|
||||
WarnIfDatabaseColumnMissed bool
|
||||
}
|
||||
|
||||
type SyncResult struct{}
|
||||
|
||||
// Sync the new struct changes to database, this method will automatically add
|
||||
// table, column, index, unique. but will not delete or change anything.
|
||||
// If you change some field, you should change the database manually.
|
||||
func (engine *Engine) Sync(beans ...interface{}) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Sync(beans...)
|
||||
}
|
||||
|
||||
// SyncWithOptions sync the database schemas according options and table structs
|
||||
func (engine *Engine) SyncWithOptions(opts SyncOptions, beans ...interface{}) (*SyncResult, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.SyncWithOptions(opts, beans...)
|
||||
}
|
||||
|
||||
// Sync2 synchronize structs to database tables
|
||||
// Depricated
|
||||
func (engine *Engine) Sync2(beans ...interface{}) error {
|
||||
return engine.Sync(beans...)
|
||||
}
|
||||
|
||||
// Sync2 synchronize structs to database tables
|
||||
// Depricated
|
||||
func (session *Session) Sync2(beans ...interface{}) error {
|
||||
return session.Sync(beans...)
|
||||
}
|
||||
|
||||
// Sync synchronize structs to database tables
|
||||
func (session *Session) Sync(beans ...interface{}) error {
|
||||
_, err := session.SyncWithOptions(SyncOptions{
|
||||
WarnIfDatabaseColumnMissed: false,
|
||||
}, beans...)
|
||||
return err
|
||||
}
|
||||
|
||||
func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{}) (*SyncResult, error) {
|
||||
engine := session.engine
|
||||
|
||||
if session.isAutoClose {
|
||||
session.isAutoClose = false
|
||||
defer session.Close()
|
||||
}
|
||||
|
||||
tables, err := engine.dialect.GetTables(session.getQueryer(), session.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
session.autoResetStatement = false
|
||||
defer func() {
|
||||
session.autoResetStatement = true
|
||||
session.resetStatement()
|
||||
}()
|
||||
|
||||
var syncResult SyncResult
|
||||
|
||||
for _, bean := range beans {
|
||||
v := utils.ReflectValue(bean)
|
||||
table, err := engine.tagParser.ParseWithCache(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var tbName string
|
||||
if len(session.statement.AltTableName) > 0 {
|
||||
tbName = session.statement.AltTableName
|
||||
} else {
|
||||
tbName = engine.TableName(bean)
|
||||
}
|
||||
tbNameWithSchema := engine.tbNameWithSchema(tbName)
|
||||
|
||||
var oriTable *schemas.Table
|
||||
for _, tb := range tables {
|
||||
if strings.EqualFold(engine.tbNameWithSchema(tb.Name), engine.tbNameWithSchema(tbName)) {
|
||||
oriTable = tb
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// this is a new table
|
||||
if oriTable == nil {
|
||||
err = session.StoreEngine(session.statement.StoreEngine).createTable(bean)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = session.createUniques(bean)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = session.createIndexes(bean)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// this will modify an old table
|
||||
if err = engine.loadTableInfo(session.ctx, oriTable); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// check columns
|
||||
for _, col := range table.Columns() {
|
||||
var oriCol *schemas.Column
|
||||
for _, col2 := range oriTable.Columns() {
|
||||
if strings.EqualFold(col.Name, col2.Name) {
|
||||
oriCol = col2
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// column is not exist on table
|
||||
if oriCol == nil {
|
||||
session.statement.RefTable = table
|
||||
session.statement.SetTableName(tbNameWithSchema)
|
||||
if err = session.addColumn(col.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
err = nil
|
||||
expectedType := engine.dialect.SQLType(col)
|
||||
curType := engine.dialect.SQLType(oriCol)
|
||||
if expectedType != curType {
|
||||
if expectedType == schemas.Text &&
|
||||
strings.HasPrefix(curType, schemas.Varchar) {
|
||||
// currently only support mysql & postgres
|
||||
if engine.dialect.URI().DBType == schemas.MYSQL ||
|
||||
engine.dialect.URI().DBType == schemas.POSTGRES {
|
||||
engine.logger.Infof("Table %s column %s change type from %s to %s\n",
|
||||
tbNameWithSchema, col.Name, curType, expectedType)
|
||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||
} else {
|
||||
engine.logger.Warnf("Table %s column %s db type is %s, struct type is %s\n",
|
||||
tbNameWithSchema, col.Name, curType, expectedType)
|
||||
}
|
||||
} else if strings.HasPrefix(curType, schemas.Varchar) && strings.HasPrefix(expectedType, schemas.Varchar) {
|
||||
if engine.dialect.URI().DBType == schemas.MYSQL {
|
||||
if oriCol.Length < col.Length {
|
||||
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
||||
tbNameWithSchema, col.Name, oriCol.Length, col.Length)
|
||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !(strings.HasPrefix(curType, expectedType) && curType[len(expectedType)] == '(') {
|
||||
if !strings.EqualFold(schemas.SQLTypeName(curType), engine.dialect.Alias(schemas.SQLTypeName(expectedType))) {
|
||||
engine.logger.Warnf("Table %s column %s db type is %s, struct type is %s",
|
||||
tbNameWithSchema, col.Name, curType, expectedType)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if expectedType == schemas.Varchar {
|
||||
if engine.dialect.URI().DBType == schemas.MYSQL {
|
||||
if oriCol.Length < col.Length {
|
||||
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
||||
tbNameWithSchema, col.Name, oriCol.Length, col.Length)
|
||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||
}
|
||||
}
|
||||
} else if col.Comment != oriCol.Comment {
|
||||
if engine.dialect.URI().DBType == schemas.POSTGRES ||
|
||||
engine.dialect.URI().DBType == schemas.MYSQL {
|
||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||
}
|
||||
}
|
||||
|
||||
if col.Default != oriCol.Default {
|
||||
switch {
|
||||
case col.IsAutoIncrement: // For autoincrement column, don't check default
|
||||
case (col.SQLType.Name == schemas.Bool || col.SQLType.Name == schemas.Boolean) &&
|
||||
((strings.EqualFold(col.Default, "true") && oriCol.Default == "1") ||
|
||||
(strings.EqualFold(col.Default, "false") && oriCol.Default == "0")):
|
||||
default:
|
||||
engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s",
|
||||
tbName, col.Name, oriCol.Default, col.Default)
|
||||
}
|
||||
}
|
||||
if col.Nullable != oriCol.Nullable {
|
||||
engine.logger.Warnf("Table %s Column %s db nullable is %v, struct nullable is %v",
|
||||
tbName, col.Name, oriCol.Nullable, col.Nullable)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
foundIndexNames := make(map[string]bool)
|
||||
addedNames := make(map[string]*schemas.Index)
|
||||
|
||||
for name, index := range table.Indexes {
|
||||
var oriIndex *schemas.Index
|
||||
for name2, index2 := range oriTable.Indexes {
|
||||
if index.Equal(index2) {
|
||||
oriIndex = index2
|
||||
foundIndexNames[name2] = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if oriIndex != nil {
|
||||
if oriIndex.Type != index.Type {
|
||||
sql := engine.dialect.DropIndexSQL(tbNameWithSchema, oriIndex)
|
||||
_, err = session.exec(sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
oriIndex = nil
|
||||
}
|
||||
}
|
||||
|
||||
if oriIndex == nil {
|
||||
addedNames[name] = index
|
||||
}
|
||||
}
|
||||
|
||||
for name2, index2 := range oriTable.Indexes {
|
||||
if _, ok := foundIndexNames[name2]; !ok {
|
||||
sql := engine.dialect.DropIndexSQL(tbNameWithSchema, index2)
|
||||
_, err = session.exec(sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for name, index := range addedNames {
|
||||
if index.Type == schemas.UniqueType {
|
||||
session.statement.RefTable = table
|
||||
session.statement.SetTableName(tbNameWithSchema)
|
||||
err = session.addUnique(tbNameWithSchema, name)
|
||||
} else if index.Type == schemas.IndexType {
|
||||
session.statement.RefTable = table
|
||||
session.statement.SetTableName(tbNameWithSchema)
|
||||
err = session.addIndex(tbNameWithSchema, name)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if opts.WarnIfDatabaseColumnMissed {
|
||||
// check all the columns which removed from struct fields but left on database tables.
|
||||
for _, colName := range oriTable.ColumnsSeq() {
|
||||
if table.GetColumn(colName) == nil {
|
||||
engine.logger.Warnf("Table %s has column %s but struct has not related field", engine.TableName(oriTable.Name, true), colName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &syncResult, nil
|
||||
}
|
|
@ -21,10 +21,21 @@ import (
|
|||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUnsupportedType represents an unsupported type error
|
||||
ErrUnsupportedType = errors.New("unsupported type")
|
||||
)
|
||||
// ErrUnsupportedType represents an unsupported type error
|
||||
var ErrUnsupportedType = errors.New("unsupported type")
|
||||
|
||||
// TableIndices is an interface that describes structs that provide additional index information above that which is automatically parsed
|
||||
type TableIndices interface {
|
||||
TableIndices() []*schemas.Index
|
||||
}
|
||||
|
||||
var tpTableIndices = reflect.TypeOf((*TableIndices)(nil)).Elem()
|
||||
|
||||
type TableCollations interface {
|
||||
TableCollations() []*schemas.Collation
|
||||
}
|
||||
|
||||
var tpTableCollations = reflect.TypeOf((*TableCollations)(nil)).Elem()
|
||||
|
||||
// Parser represents a parser for xorm tag
|
||||
type Parser struct {
|
||||
|
@ -177,7 +188,7 @@ func (parser *Parser) parseFieldWithNoTag(fieldIndex int, field reflect.StructFi
|
|||
}
|
||||
|
||||
func (parser *Parser) parseFieldWithTags(table *schemas.Table, fieldIndex int, field reflect.StructField, fieldValue reflect.Value, tags []tag) (*schemas.Column, error) {
|
||||
var col = &schemas.Column{
|
||||
col := &schemas.Column{
|
||||
FieldName: field.Name,
|
||||
FieldIndex: []int{fieldIndex},
|
||||
Nullable: true,
|
||||
|
@ -188,7 +199,7 @@ func (parser *Parser) parseFieldWithTags(table *schemas.Table, fieldIndex int, f
|
|||
DefaultIsEmpty: true,
|
||||
}
|
||||
|
||||
var ctx = Context{
|
||||
ctx := Context{
|
||||
table: table,
|
||||
col: col,
|
||||
fieldValue: fieldValue,
|
||||
|
@ -329,5 +340,81 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
|
|||
table.AddColumn(col)
|
||||
} // end for
|
||||
|
||||
indices := tableIndices(v)
|
||||
for _, index := range indices {
|
||||
// Override old information
|
||||
if oldIndex, ok := table.Indexes[index.Name]; ok {
|
||||
for _, colName := range oldIndex.Cols {
|
||||
col := table.GetColumn(colName)
|
||||
if col == nil {
|
||||
return nil, ErrUnsupportedType
|
||||
}
|
||||
delete(col.Indexes, index.Name)
|
||||
}
|
||||
}
|
||||
table.AddIndex(index)
|
||||
for _, colName := range index.Cols {
|
||||
col := table.GetColumn(colName)
|
||||
if col == nil {
|
||||
return nil, ErrUnsupportedType
|
||||
}
|
||||
col.Indexes[index.Name] = index.Type
|
||||
}
|
||||
}
|
||||
|
||||
collations := tableCollations(v)
|
||||
for _, collation := range collations {
|
||||
if collation.Name == "" {
|
||||
continue
|
||||
}
|
||||
if collation.Column == "" {
|
||||
table.Collation = collation.Name
|
||||
} else {
|
||||
col := table.GetColumn(collation.Column)
|
||||
if col == nil {
|
||||
return nil, ErrUnsupportedType
|
||||
}
|
||||
col.Collation = collation.Name // this may override definition in struct tag
|
||||
}
|
||||
}
|
||||
|
||||
return table, nil
|
||||
}
|
||||
|
||||
func tableIndices(v reflect.Value) []*schemas.Index {
|
||||
if v.Type().Implements(tpTableIndices) {
|
||||
return v.Interface().(TableIndices).TableIndices()
|
||||
}
|
||||
|
||||
if v.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
if v.Type().Implements(tpTableIndices) {
|
||||
return v.Interface().(TableIndices).TableIndices()
|
||||
}
|
||||
} else if v.CanAddr() {
|
||||
v1 := v.Addr()
|
||||
if v1.Type().Implements(tpTableIndices) {
|
||||
return v1.Interface().(TableIndices).TableIndices()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func tableCollations(v reflect.Value) []*schemas.Collation {
|
||||
if v.Type().Implements(tpTableCollations) {
|
||||
return v.Interface().(TableCollations).TableCollations()
|
||||
}
|
||||
|
||||
if v.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
if v.Type().Implements(tpTableCollations) {
|
||||
return v.Interface().(TableCollations).TableCollations()
|
||||
}
|
||||
} else if v.CanAddr() {
|
||||
v1 := v.Addr()
|
||||
if v1.Type().Implements(tpTableCollations) {
|
||||
return v1.Interface().(TableCollations).TableCollations()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -557,6 +557,29 @@ func TestParseWithJSON(t *testing.T) {
|
|||
assert.True(t, table.Columns()[0].IsJSON)
|
||||
}
|
||||
|
||||
func TestParseWithJSONB(t *testing.T) {
|
||||
parser := NewParser(
|
||||
"db",
|
||||
dialects.QueryDialect("postgres"),
|
||||
names.GonicMapper{
|
||||
"JSONB": true,
|
||||
},
|
||||
names.SnakeMapper{},
|
||||
caches.NewManager(),
|
||||
)
|
||||
|
||||
type StructWithJSONB struct {
|
||||
Default1 []string `db:"jsonb"`
|
||||
}
|
||||
|
||||
table, err := parser.Parse(reflect.ValueOf(new(StructWithJSONB)))
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "struct_with_jsonb", table.Name)
|
||||
assert.EqualValues(t, 1, len(table.Columns()))
|
||||
assert.EqualValues(t, "default1", table.Columns()[0].Name)
|
||||
assert.True(t, table.Columns()[0].IsJSON)
|
||||
}
|
||||
|
||||
func TestParseWithSQLType(t *testing.T) {
|
||||
parser := NewParser(
|
||||
"db",
|
||||
|
|
79
tags/tag.go
79
tags/tag.go
|
@ -99,33 +99,32 @@ type Context struct {
|
|||
// Handler describes tag handler for XORM
|
||||
type Handler func(ctx *Context) error
|
||||
|
||||
var (
|
||||
// defaultTagHandlers enumerates all the default tag handler
|
||||
defaultTagHandlers = map[string]Handler{
|
||||
"-": IgnoreHandler,
|
||||
"<-": OnlyFromDBTagHandler,
|
||||
"->": OnlyToDBTagHandler,
|
||||
"PK": PKTagHandler,
|
||||
"NULL": NULLTagHandler,
|
||||
"NOT": NotTagHandler,
|
||||
"AUTOINCR": AutoIncrTagHandler,
|
||||
"DEFAULT": DefaultTagHandler,
|
||||
"CREATED": CreatedTagHandler,
|
||||
"UPDATED": UpdatedTagHandler,
|
||||
"DELETED": DeletedTagHandler,
|
||||
"VERSION": VersionTagHandler,
|
||||
"UTC": UTCTagHandler,
|
||||
"LOCAL": LocalTagHandler,
|
||||
"NOTNULL": NotNullTagHandler,
|
||||
"INDEX": IndexTagHandler,
|
||||
"UNIQUE": UniqueTagHandler,
|
||||
"CACHE": CacheTagHandler,
|
||||
"NOCACHE": NoCacheTagHandler,
|
||||
"COMMENT": CommentTagHandler,
|
||||
"EXTENDS": ExtendsTagHandler,
|
||||
"UNSIGNED": UnsignedTagHandler,
|
||||
}
|
||||
)
|
||||
// defaultTagHandlers enumerates all the default tag handler
|
||||
var defaultTagHandlers = map[string]Handler{
|
||||
"-": IgnoreHandler,
|
||||
"<-": OnlyFromDBTagHandler,
|
||||
"->": OnlyToDBTagHandler,
|
||||
"PK": PKTagHandler,
|
||||
"NULL": NULLTagHandler,
|
||||
"NOT": NotTagHandler,
|
||||
"AUTOINCR": AutoIncrTagHandler,
|
||||
"DEFAULT": DefaultTagHandler,
|
||||
"CREATED": CreatedTagHandler,
|
||||
"UPDATED": UpdatedTagHandler,
|
||||
"DELETED": DeletedTagHandler,
|
||||
"VERSION": VersionTagHandler,
|
||||
"UTC": UTCTagHandler,
|
||||
"LOCAL": LocalTagHandler,
|
||||
"NOTNULL": NotNullTagHandler,
|
||||
"INDEX": IndexTagHandler,
|
||||
"UNIQUE": UniqueTagHandler,
|
||||
"CACHE": CacheTagHandler,
|
||||
"NOCACHE": NoCacheTagHandler,
|
||||
"COMMENT": CommentTagHandler,
|
||||
"EXTENDS": ExtendsTagHandler,
|
||||
"UNSIGNED": UnsignedTagHandler,
|
||||
"COLLATE": CollateTagHandler,
|
||||
}
|
||||
|
||||
func init() {
|
||||
for k := range schemas.SqlTypes {
|
||||
|
@ -284,10 +283,20 @@ func CommentTagHandler(ctx *Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func CollateTagHandler(ctx *Context) error {
|
||||
if len(ctx.params) > 0 {
|
||||
ctx.col.Collation = ctx.params[0]
|
||||
} else {
|
||||
ctx.col.Collation = ctx.nextTag
|
||||
ctx.ignoreNext = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SQLTypeTagHandler describes SQL Type tag handler
|
||||
func SQLTypeTagHandler(ctx *Context) error {
|
||||
ctx.col.SQLType = schemas.SQLType{Name: ctx.tagUname}
|
||||
if ctx.tagUname == "JSON" {
|
||||
if ctx.tagUname == "JSON" || ctx.tagUname == "JSONB" {
|
||||
ctx.col.IsJSON = true
|
||||
}
|
||||
if len(ctx.params) == 0 {
|
||||
|
@ -312,16 +321,16 @@ func SQLTypeTagHandler(ctx *Context) error {
|
|||
default:
|
||||
var err error
|
||||
if len(ctx.params) == 2 {
|
||||
ctx.col.Length, err = strconv.Atoi(ctx.params[0])
|
||||
ctx.col.Length, err = strconv.ParseInt(ctx.params[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.col.Length2, err = strconv.Atoi(ctx.params[1])
|
||||
ctx.col.Length2, err = strconv.ParseInt(ctx.params[1], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if len(ctx.params) == 1 {
|
||||
ctx.col.Length, err = strconv.Atoi(ctx.params[0])
|
||||
ctx.col.Length, err = strconv.ParseInt(ctx.params[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -332,8 +341,8 @@ func SQLTypeTagHandler(ctx *Context) error {
|
|||
|
||||
// ExtendsTagHandler describes extends tag handler
|
||||
func ExtendsTagHandler(ctx *Context) error {
|
||||
var fieldValue = ctx.fieldValue
|
||||
var isPtr = false
|
||||
fieldValue := ctx.fieldValue
|
||||
isPtr := false
|
||||
switch fieldValue.Kind() {
|
||||
case reflect.Ptr:
|
||||
f := fieldValue.Type().Elem()
|
||||
|
@ -355,7 +364,7 @@ func ExtendsTagHandler(ctx *Context) error {
|
|||
col.FieldName = fmt.Sprintf("%v.%v", ctx.col.FieldName, col.FieldName)
|
||||
col.FieldIndex = append(ctx.col.FieldIndex, col.FieldIndex...)
|
||||
|
||||
var tagPrefix = ctx.col.FieldName
|
||||
tagPrefix := ctx.col.FieldName
|
||||
if len(ctx.params) > 0 {
|
||||
col.Nullable = isPtr
|
||||
tagPrefix = strings.Trim(ctx.params[0], "'")
|
||||
|
@ -378,7 +387,7 @@ func ExtendsTagHandler(ctx *Context) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
//TODO: warning
|
||||
// TODO: warning
|
||||
}
|
||||
return ErrIgnoreField
|
||||
}
|
||||
|
|
118
tags/tag_test.go
118
tags/tag_test.go
|
@ -11,68 +11,84 @@ import (
|
|||
)
|
||||
|
||||
func TestSplitTag(t *testing.T) {
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
tag string
|
||||
tags []tag
|
||||
}{
|
||||
{"not null default '2000-01-01 00:00:00' TIMESTAMP", []tag{
|
||||
{
|
||||
name: "not",
|
||||
},
|
||||
{
|
||||
name: "null",
|
||||
},
|
||||
{
|
||||
name: "default",
|
||||
},
|
||||
{
|
||||
name: "'2000-01-01 00:00:00'",
|
||||
},
|
||||
{
|
||||
name: "TIMESTAMP",
|
||||
},
|
||||
},
|
||||
},
|
||||
{"TEXT", []tag{
|
||||
{
|
||||
name: "TEXT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{"default('2000-01-01 00:00:00')", []tag{
|
||||
{
|
||||
name: "default",
|
||||
params: []string{
|
||||
"'2000-01-01 00:00:00'",
|
||||
{
|
||||
"not null default '2000-01-01 00:00:00' TIMESTAMP", []tag{
|
||||
{
|
||||
name: "not",
|
||||
},
|
||||
{
|
||||
name: "null",
|
||||
},
|
||||
{
|
||||
name: "default",
|
||||
},
|
||||
{
|
||||
name: "'2000-01-01 00:00:00'",
|
||||
},
|
||||
{
|
||||
name: "TIMESTAMP",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{"json binary", []tag{
|
||||
{
|
||||
name: "json",
|
||||
},
|
||||
{
|
||||
name: "binary",
|
||||
{
|
||||
"TEXT", []tag{
|
||||
{
|
||||
name: "TEXT",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{"numeric(10, 2)", []tag{
|
||||
{
|
||||
name: "numeric",
|
||||
params: []string{"10", "2"},
|
||||
{
|
||||
"default('2000-01-01 00:00:00')", []tag{
|
||||
{
|
||||
name: "default",
|
||||
params: []string{
|
||||
"'2000-01-01 00:00:00'",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{"numeric(10, 2) notnull", []tag{
|
||||
{
|
||||
name: "numeric",
|
||||
params: []string{"10", "2"},
|
||||
},
|
||||
{
|
||||
name: "notnull",
|
||||
{
|
||||
"json binary", []tag{
|
||||
{
|
||||
name: "json",
|
||||
},
|
||||
{
|
||||
name: "binary",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"numeric(10, 2)", []tag{
|
||||
{
|
||||
name: "numeric",
|
||||
params: []string{"10", "2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"numeric(10, 2) notnull", []tag{
|
||||
{
|
||||
name: "numeric",
|
||||
params: []string{"10", "2"},
|
||||
},
|
||||
{
|
||||
name: "notnull",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"collate utf8mb4_bin", []tag{
|
||||
{
|
||||
name: "collate",
|
||||
},
|
||||
{
|
||||
name: "utf8mb4_bin",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -82,7 +98,7 @@ func TestSplitTag(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, len(tags), len(kase.tags))
|
||||
for i := 0; i < len(tags); i++ {
|
||||
assert.Equal(t, tags[i], kase.tags[i])
|
||||
assert.Equal(t, kase.tags[i], tags[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue