This commit is contained in:
parent
2b59dca9a6
commit
c73decb38a
12
go.mod
12
go.mod
@ -1,6 +1,6 @@
|
||||
module git.paulbsd.com/paulbsd/qrz
|
||||
|
||||
go 1.20
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/antchfx/htmlquery v1.3.0
|
||||
@ -13,13 +13,13 @@ require (
|
||||
github.com/onsi/ginkgo v1.16.5 // indirect
|
||||
github.com/onsi/gomega v1.23.0 // indirect
|
||||
github.com/robfig/cron v1.2.0
|
||||
golang.org/x/crypto v0.12.0 // indirect
|
||||
golang.org/x/net v0.14.0
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
golang.org/x/text v0.12.0 // indirect
|
||||
golang.org/x/crypto v0.13.0 // indirect
|
||||
golang.org/x/net v0.15.0
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0
|
||||
xorm.io/builder v0.3.13 // indirect
|
||||
xorm.io/xorm v1.3.2
|
||||
xorm.io/xorm v1.3.3
|
||||
)
|
||||
|
||||
require (
|
||||
|
83
go.sum
83
go.sum
@ -3,6 +3,9 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
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/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/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||
@ -36,6 +39,9 @@ github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n
|
||||
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/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/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/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
|
||||
@ -52,7 +58,9 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
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/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||
github.com/denisenkom/go-mssqldb v0.12.3/go.mod h1:k0mtMFOnU+AihqFxPMiF05rtiDrorD1Vrm1KEz5hxDo=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
|
||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
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=
|
||||
@ -72,12 +80,14 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
|
||||
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-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
||||
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-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/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/goccy/go-json v0.8.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
@ -92,6 +102,7 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
|
||||
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/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
|
||||
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=
|
||||
@ -119,7 +130,9 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
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/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=
|
||||
@ -154,6 +167,7 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
|
||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
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/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
|
||||
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/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
|
||||
@ -168,9 +182,12 @@ github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853/go.mod h1:QeD3lBfpT
|
||||
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/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/go.mod h1:9mBNlny0UvkgJdCDvdVHYSjI+8tD2rnKK69Wz8ti++E=
|
||||
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/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c=
|
||||
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
|
||||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
|
||||
@ -180,8 +197,10 @@ github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:
|
||||
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/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgproto3/v2 v2.3.2/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/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
||||
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=
|
||||
@ -190,6 +209,8 @@ github.com/jackc/pgtype v1.3.1-0.20200510190516-8cd94a14c75a/go.mod h1:vaogEUkAL
|
||||
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/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/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=
|
||||
@ -198,11 +219,14 @@ github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6
|
||||
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/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/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/jackc/puddle v1.3.0/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=
|
||||
@ -265,6 +289,8 @@ github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APP
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
@ -283,6 +309,7 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
|
||||
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/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
|
||||
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=
|
||||
@ -322,6 +349,7 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP
|
||||
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/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||
@ -362,6 +390,7 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
|
||||
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/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shopspring/decimal v1.3.1/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/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
@ -378,12 +407,17 @@ github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5J
|
||||
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/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=
|
||||
@ -427,10 +461,14 @@ golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8U
|
||||
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/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
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/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
|
||||
@ -439,6 +477,8 @@ golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
|
||||
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
|
||||
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
|
||||
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
||||
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
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=
|
||||
@ -469,8 +509,11 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
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.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
@ -479,6 +522,8 @@ golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
|
||||
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
||||
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
|
||||
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
||||
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
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/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@ -518,16 +563,19 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
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-20210112080510-489259a85091/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-20210630005230-0f9fa26af87c/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-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/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.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
@ -536,10 +584,13 @@ golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.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.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
|
||||
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=
|
||||
@ -547,6 +598,7 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||
@ -555,6 +607,8 @@ golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
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=
|
||||
@ -625,16 +679,20 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
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=
|
||||
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.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=
|
||||
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=
|
||||
lukechampine.com/uint128 v1.2.0/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=
|
||||
@ -650,6 +708,11 @@ 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/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/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.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=
|
||||
@ -686,7 +749,10 @@ modernc.org/ccgo/v3 v3.12.73/go.mod h1:hngkB+nUUqzOf3iqsM48Gf1FZhY599qzVg1iX+BT3
|
||||
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/ccgo/v3 v3.16.13-0.20221017192402-261537637ce8/go.mod h1:fUB3Vn0nVPReA+7IG7yZDfjv1TMWjhQP8gCxrFAtL5g=
|
||||
modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY=
|
||||
modernc.org/ccorpus v1.11.1/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ=
|
||||
modernc.org/ccorpus v1.11.6/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ=
|
||||
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=
|
||||
@ -724,24 +790,39 @@ 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/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/go.mod h1:uvQavJ1pZ0hIoC/jfqNoMLURIMhKzINIWypNM17puug=
|
||||
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/mathutil v1.5.0/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/memory v1.3.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
|
||||
modernc.org/memory v1.4.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
|
||||
modernc.org/opt v0.1.1 h1:/0RX92k9vwVeDXj+Xn23DKp2VJubL7k8qNffND6qn3A=
|
||||
modernc.org/opt v0.1.1/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/opt v0.1.3/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/sqlite v1.20.4/go.mod h1:zKcGyrICaxNTMEHSr1HQ2GUraP0j+845GYw37+EyT6A=
|
||||
modernc.org/strutil v1.1.1 h1:xv+J1BXY3Opl2ALrBwyfEikFAj8pmqcpnfmuwUwcozs=
|
||||
modernc.org/strutil v1.1.1/go.mod h1:DE+MQQ/hjKBZS2zNInV5hhcipt5rLPWkmpbGeW5mmdw=
|
||||
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
|
||||
modernc.org/tcl v1.8.13/go.mod h1:V+q/Ef0IJaNUSECieLU4o+8IScapxnMyFV6i/7uQlAY=
|
||||
modernc.org/tcl v1.15.0/go.mod h1:xRoGotBZ6dU+Zo2tca+2EqVEeMmOUBzHnhIwq4YrVnE=
|
||||
modernc.org/token v1.0.0 h1:a0jaWiNMDhDUtqOj09wvjWWAqd3q7WpBulmL9H2egsk=
|
||||
modernc.org/token v1.0.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
modernc.org/z v1.2.19/go.mod h1:+ZpP0pc4zz97eukOzW3xagV/lS82IpPN9NGG5pNF9vY=
|
||||
modernc.org/z v1.7.0/go.mod h1:hVdgNMh8ggTuRG1rGU8x+xGRFfiQUIAw0ZqlPy8+HyQ=
|
||||
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.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||
@ -751,3 +832,5 @@ xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
|
||||
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||
xorm.io/xorm v1.3.2 h1:uTRRKF2jYzbZ5nsofXVUx6ncMaek+SHjWYtCXyZo1oM=
|
||||
xorm.io/xorm v1.3.2/go.mod h1:9NbjqdnjX6eyjRRhh01GHm64r6N9shTb/8Ak3YRt8Nw=
|
||||
xorm.io/xorm v1.3.3 h1:L5/GOhvgMcwJYYRjzPf3lTTTf6JcaTd1Mb9A/Iqvccw=
|
||||
xorm.io/xorm v1.3.3/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
|
||||
|
51
vendor/golang.org/x/net/http2/Dockerfile
generated
vendored
51
vendor/golang.org/x/net/http2/Dockerfile
generated
vendored
@ -1,51 +0,0 @@
|
||||
#
|
||||
# This Dockerfile builds a recent curl with HTTP/2 client support, using
|
||||
# a recent nghttp2 build.
|
||||
#
|
||||
# See the Makefile for how to tag it. If Docker and that image is found, the
|
||||
# Go tests use this curl binary for integration tests.
|
||||
#
|
||||
|
||||
FROM ubuntu:trusty
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get upgrade -y && \
|
||||
apt-get install -y git-core build-essential wget
|
||||
|
||||
RUN apt-get install -y --no-install-recommends \
|
||||
autotools-dev libtool pkg-config zlib1g-dev \
|
||||
libcunit1-dev libssl-dev libxml2-dev libevent-dev \
|
||||
automake autoconf
|
||||
|
||||
# The list of packages nghttp2 recommends for h2load:
|
||||
RUN apt-get install -y --no-install-recommends make binutils \
|
||||
autoconf automake autotools-dev \
|
||||
libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev \
|
||||
libev-dev libevent-dev libjansson-dev libjemalloc-dev \
|
||||
cython python3.4-dev python-setuptools
|
||||
|
||||
# Note: setting NGHTTP2_VER before the git clone, so an old git clone isn't cached:
|
||||
ENV NGHTTP2_VER 895da9a
|
||||
RUN cd /root && git clone https://github.com/tatsuhiro-t/nghttp2.git
|
||||
|
||||
WORKDIR /root/nghttp2
|
||||
RUN git reset --hard $NGHTTP2_VER
|
||||
RUN autoreconf -i
|
||||
RUN automake
|
||||
RUN autoconf
|
||||
RUN ./configure
|
||||
RUN make
|
||||
RUN make install
|
||||
|
||||
WORKDIR /root
|
||||
RUN wget https://curl.se/download/curl-7.45.0.tar.gz
|
||||
RUN tar -zxvf curl-7.45.0.tar.gz
|
||||
WORKDIR /root/curl-7.45.0
|
||||
RUN ./configure --with-ssl --with-nghttp2=/usr/local
|
||||
RUN make
|
||||
RUN make install
|
||||
RUN ldconfig
|
||||
|
||||
CMD ["-h"]
|
||||
ENTRYPOINT ["/usr/local/bin/curl"]
|
||||
|
3
vendor/golang.org/x/net/http2/Makefile
generated
vendored
3
vendor/golang.org/x/net/http2/Makefile
generated
vendored
@ -1,3 +0,0 @@
|
||||
curlimage:
|
||||
docker build -t gohttp2/curl .
|
||||
|
8
vendor/golang.org/x/net/http2/server.go
generated
vendored
8
vendor/golang.org/x/net/http2/server.go
generated
vendored
@ -1012,14 +1012,6 @@ func (sc *serverConn) serve() {
|
||||
}
|
||||
}
|
||||
|
||||
func (sc *serverConn) awaitGracefulShutdown(sharedCh <-chan struct{}, privateCh chan struct{}) {
|
||||
select {
|
||||
case <-sc.doneServing:
|
||||
case <-sharedCh:
|
||||
close(privateCh)
|
||||
}
|
||||
}
|
||||
|
||||
type serverMessage int
|
||||
|
||||
// Message values sent to serveMsgCh.
|
||||
|
1
vendor/golang.org/x/net/http2/transport.go
generated
vendored
1
vendor/golang.org/x/net/http2/transport.go
generated
vendored
@ -292,7 +292,6 @@ func (t *Transport) initConnPool() {
|
||||
type ClientConn struct {
|
||||
t *Transport
|
||||
tconn net.Conn // usually *tls.Conn, except specialized impls
|
||||
tconnClosed bool
|
||||
tlsState *tls.ConnectionState // nil only for specialized impls
|
||||
reused uint32 // whether conn is being reused; atomic
|
||||
singleUse bool // whether being used for a single http.Request
|
||||
|
1
vendor/golang.org/x/sys/unix/mkerrors.sh
generated
vendored
1
vendor/golang.org/x/sys/unix/mkerrors.sh
generated
vendored
@ -583,6 +583,7 @@ ccflags="$@"
|
||||
$2 ~ /^PERF_/ ||
|
||||
$2 ~ /^SECCOMP_MODE_/ ||
|
||||
$2 ~ /^SEEK_/ ||
|
||||
$2 ~ /^SCHED_/ ||
|
||||
$2 ~ /^SPLICE_/ ||
|
||||
$2 ~ /^SYNC_FILE_RANGE_/ ||
|
||||
$2 !~ /IOC_MAGIC/ &&
|
||||
|
23
vendor/golang.org/x/sys/unix/syscall_linux.go
generated
vendored
23
vendor/golang.org/x/sys/unix/syscall_linux.go
generated
vendored
@ -2471,6 +2471,29 @@ func Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *
|
||||
return pselect6(nfd, r, w, e, mutableTimeout, kernelMask)
|
||||
}
|
||||
|
||||
//sys schedSetattr(pid int, attr *SchedAttr, flags uint) (err error)
|
||||
//sys schedGetattr(pid int, attr *SchedAttr, size uint, flags uint) (err error)
|
||||
|
||||
// SchedSetAttr is a wrapper for sched_setattr(2) syscall.
|
||||
// https://man7.org/linux/man-pages/man2/sched_setattr.2.html
|
||||
func SchedSetAttr(pid int, attr *SchedAttr, flags uint) error {
|
||||
if attr == nil {
|
||||
return EINVAL
|
||||
}
|
||||
attr.Size = SizeofSchedAttr
|
||||
return schedSetattr(pid, attr, flags)
|
||||
}
|
||||
|
||||
// SchedGetAttr is a wrapper for sched_getattr(2) syscall.
|
||||
// https://man7.org/linux/man-pages/man2/sched_getattr.2.html
|
||||
func SchedGetAttr(pid int, flags uint) (*SchedAttr, error) {
|
||||
attr := &SchedAttr{}
|
||||
if err := schedGetattr(pid, attr, SizeofSchedAttr, flags); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return attr, nil
|
||||
}
|
||||
|
||||
/*
|
||||
* Unimplemented
|
||||
*/
|
||||
|
3
vendor/golang.org/x/sys/unix/syscall_unix.go
generated
vendored
3
vendor/golang.org/x/sys/unix/syscall_unix.go
generated
vendored
@ -549,6 +549,9 @@ func SetNonblock(fd int, nonblocking bool) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (flag&O_NONBLOCK != 0) == nonblocking {
|
||||
return nil
|
||||
}
|
||||
if nonblocking {
|
||||
flag |= O_NONBLOCK
|
||||
} else {
|
||||
|
17
vendor/golang.org/x/sys/unix/zerrors_linux.go
generated
vendored
17
vendor/golang.org/x/sys/unix/zerrors_linux.go
generated
vendored
@ -2821,6 +2821,23 @@ const (
|
||||
RWF_SUPPORTED = 0x1f
|
||||
RWF_SYNC = 0x4
|
||||
RWF_WRITE_LIFE_NOT_SET = 0x0
|
||||
SCHED_BATCH = 0x3
|
||||
SCHED_DEADLINE = 0x6
|
||||
SCHED_FIFO = 0x1
|
||||
SCHED_FLAG_ALL = 0x7f
|
||||
SCHED_FLAG_DL_OVERRUN = 0x4
|
||||
SCHED_FLAG_KEEP_ALL = 0x18
|
||||
SCHED_FLAG_KEEP_PARAMS = 0x10
|
||||
SCHED_FLAG_KEEP_POLICY = 0x8
|
||||
SCHED_FLAG_RECLAIM = 0x2
|
||||
SCHED_FLAG_RESET_ON_FORK = 0x1
|
||||
SCHED_FLAG_UTIL_CLAMP = 0x60
|
||||
SCHED_FLAG_UTIL_CLAMP_MAX = 0x40
|
||||
SCHED_FLAG_UTIL_CLAMP_MIN = 0x20
|
||||
SCHED_IDLE = 0x5
|
||||
SCHED_NORMAL = 0x0
|
||||
SCHED_RESET_ON_FORK = 0x40000000
|
||||
SCHED_RR = 0x2
|
||||
SCM_CREDENTIALS = 0x2
|
||||
SCM_RIGHTS = 0x1
|
||||
SCM_TIMESTAMP = 0x1d
|
||||
|
20
vendor/golang.org/x/sys/unix/zsyscall_linux.go
generated
vendored
20
vendor/golang.org/x/sys/unix/zsyscall_linux.go
generated
vendored
@ -2197,3 +2197,23 @@ func getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) {
|
||||
RawSyscallNoError(SYS_GETRESGID, uintptr(unsafe.Pointer(rgid)), uintptr(unsafe.Pointer(egid)), uintptr(unsafe.Pointer(sgid)))
|
||||
return
|
||||
}
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func schedSetattr(pid int, attr *SchedAttr, flags uint) (err error) {
|
||||
_, _, e1 := Syscall(SYS_SCHED_SETATTR, uintptr(pid), uintptr(unsafe.Pointer(attr)), uintptr(flags))
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func schedGetattr(pid int, attr *SchedAttr, size uint, flags uint) (err error) {
|
||||
_, _, e1 := Syscall6(SYS_SCHED_GETATTR, uintptr(pid), uintptr(unsafe.Pointer(attr)), uintptr(size), uintptr(flags), 0, 0)
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
15
vendor/golang.org/x/sys/unix/ztypes_linux.go
generated
vendored
15
vendor/golang.org/x/sys/unix/ztypes_linux.go
generated
vendored
@ -5868,3 +5868,18 @@ const (
|
||||
VIRTIO_NET_HDR_GSO_UDP_L4 = 0x5
|
||||
VIRTIO_NET_HDR_GSO_ECN = 0x80
|
||||
)
|
||||
|
||||
type SchedAttr struct {
|
||||
Size uint32
|
||||
Policy uint32
|
||||
Flags uint64
|
||||
Nice int32
|
||||
Priority uint32
|
||||
Runtime uint64
|
||||
Deadline uint64
|
||||
Period uint64
|
||||
Util_min uint32
|
||||
Util_max uint32
|
||||
}
|
||||
|
||||
const SizeofSchedAttr = 0x38
|
||||
|
2
vendor/golang.org/x/text/unicode/norm/trie.go
generated
vendored
2
vendor/golang.org/x/text/unicode/norm/trie.go
generated
vendored
@ -29,7 +29,7 @@ var (
|
||||
nfkcData = newNfkcTrie(0)
|
||||
)
|
||||
|
||||
// lookupValue determines the type of block n and looks up the value for b.
|
||||
// lookup determines the type of block n and looks up the value for b.
|
||||
// For n < t.cutoff, the block is a simple lookup table. Otherwise, the block
|
||||
// is a list of ranges with an accompanying value. Given a matching range r,
|
||||
// the value for b is by r.value + (b - r.lo) * stride.
|
||||
|
12
vendor/modules.txt
vendored
12
vendor/modules.txt
vendored
@ -77,11 +77,11 @@ github.com/valyala/bytebufferpool
|
||||
# github.com/valyala/fasttemplate v1.2.2
|
||||
## explicit; go 1.12
|
||||
github.com/valyala/fasttemplate
|
||||
# golang.org/x/crypto v0.12.0
|
||||
# golang.org/x/crypto v0.13.0
|
||||
## explicit; go 1.17
|
||||
golang.org/x/crypto/acme
|
||||
golang.org/x/crypto/acme/autocert
|
||||
# golang.org/x/net v0.14.0
|
||||
# golang.org/x/net v0.15.0
|
||||
## explicit; go 1.17
|
||||
golang.org/x/net/html
|
||||
golang.org/x/net/html/atom
|
||||
@ -91,10 +91,10 @@ golang.org/x/net/http2
|
||||
golang.org/x/net/http2/h2c
|
||||
golang.org/x/net/http2/hpack
|
||||
golang.org/x/net/idna
|
||||
# golang.org/x/sys v0.11.0
|
||||
# golang.org/x/sys v0.12.0
|
||||
## explicit; go 1.17
|
||||
golang.org/x/sys/unix
|
||||
# golang.org/x/text v0.12.0
|
||||
# golang.org/x/text v0.13.0
|
||||
## explicit; go 1.17
|
||||
golang.org/x/text/encoding
|
||||
golang.org/x/text/encoding/charmap
|
||||
@ -122,8 +122,8 @@ gopkg.in/ini.v1
|
||||
# xorm.io/builder v0.3.13
|
||||
## explicit; go 1.11
|
||||
xorm.io/builder
|
||||
# xorm.io/xorm v1.3.2
|
||||
## explicit; go 1.13
|
||||
# xorm.io/xorm v1.3.3
|
||||
## explicit; go 1.16
|
||||
xorm.io/xorm
|
||||
xorm.io/xorm/caches
|
||||
xorm.io/xorm/contexts
|
||||
|
437
vendor/xorm.io/xorm/.drone.yml
generated
vendored
437
vendor/xorm.io/xorm/.drone.yml
generated
vendored
@ -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
|
5
vendor/xorm.io/xorm/.gitignore
generated
vendored
5
vendor/xorm.io/xorm/.gitignore
generated
vendored
@ -35,6 +35,7 @@ test.db.sql
|
||||
|
||||
*coverage.out
|
||||
test.db
|
||||
integrations/*.sql
|
||||
integrations/test_sqlite*
|
||||
tests/*.sql
|
||||
tests/test_sqlite*
|
||||
cover.out
|
||||
cover.html
|
||||
|
7
vendor/xorm.io/xorm/Makefile
generated
vendored
7
vendor/xorm.io/xorm/Makefile
generated
vendored
@ -9,7 +9,7 @@ SED_INPLACE := sed -i
|
||||
GO_DIRS := caches contexts integrations core dialects internal log migrate names schemas tags
|
||||
GOFILES := $(wildcard *.go)
|
||||
GOFILES += $(shell find $(GO_DIRS) -name "*.go" -type f)
|
||||
INTEGRATION_PACKAGES := xorm.io/xorm/integrations
|
||||
INTEGRATION_PACKAGES := xorm.io/xorm/tests
|
||||
PACKAGES ?= $(filter-out $(INTEGRATION_PACKAGES),$(shell $(GO) list ./...))
|
||||
|
||||
TEST_COCKROACH_HOST ?= cockroach:26257
|
||||
@ -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
|
||||
|
3
vendor/xorm.io/xorm/README.md
generated
vendored
3
vendor/xorm.io/xorm/README.md
generated
vendored
@ -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
|
||||
|
||||
|
3
vendor/xorm.io/xorm/README_CN.md
generated
vendored
3
vendor/xorm.io/xorm/README_CN.md
generated
vendored
@ -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) (试验性支持)
|
||||
|
||||
## 安装
|
||||
|
||||
|
14
vendor/xorm.io/xorm/convert/conversion.go
generated
vendored
14
vendor/xorm.io/xorm/convert/conversion.go
generated
vendored
@ -16,11 +16,21 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ConversionFrom is an inteface to allow retrieve data from database
|
||||
type ConversionFrom interface {
|
||||
FromDB([]byte) error
|
||||
}
|
||||
|
||||
// ConversionTo is an interface to allow store data to database
|
||||
type ConversionTo interface {
|
||||
ToDB() ([]byte, error)
|
||||
}
|
||||
|
||||
// Conversion is an interface. A type implements Conversion will according
|
||||
// the custom method to fill into database and retrieve from database.
|
||||
type Conversion interface {
|
||||
FromDB([]byte) error
|
||||
ToDB() ([]byte, error)
|
||||
ConversionFrom
|
||||
ConversionTo
|
||||
}
|
||||
|
||||
// ErrNilPtr represents an error
|
||||
|
58
vendor/xorm.io/xorm/convert/int.go
generated
vendored
58
vendor/xorm.io/xorm/convert/int.go
generated
vendored
@ -35,6 +35,56 @@ func AsInt64(src interface{}) (int64, error) {
|
||||
return int64(v), nil
|
||||
case uint64:
|
||||
return int64(v), nil
|
||||
case *int:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return int64(*v), nil
|
||||
case *int16:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return int64(*v), nil
|
||||
case *int32:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return int64(*v), nil
|
||||
case *int8:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return int64(*v), nil
|
||||
case *int64:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return *v, nil
|
||||
case *uint:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return int64(*v), nil
|
||||
case *uint8:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return int64(*v), nil
|
||||
case *uint16:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return int64(*v), nil
|
||||
case *uint32:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return int64(*v), nil
|
||||
case *uint64:
|
||||
if v == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return int64(*v), nil
|
||||
case []byte:
|
||||
return strconv.ParseInt(string(v), 10, 64)
|
||||
case string:
|
||||
@ -110,9 +160,7 @@ func AsUint64(src interface{}) (uint64, error) {
|
||||
return 0, fmt.Errorf("unsupported value %T as uint64", src)
|
||||
}
|
||||
|
||||
var (
|
||||
_ sql.Scanner = &NullUint64{}
|
||||
)
|
||||
var _ sql.Scanner = &NullUint64{}
|
||||
|
||||
// NullUint64 represents an uint64 that may be null.
|
||||
// NullUint64 implements the Scanner interface so
|
||||
@ -142,9 +190,7 @@ func (n NullUint64) Value() (driver.Value, error) {
|
||||
return n.Uint64, nil
|
||||
}
|
||||
|
||||
var (
|
||||
_ sql.Scanner = &NullUint32{}
|
||||
)
|
||||
var _ sql.Scanner = &NullUint32{}
|
||||
|
||||
// NullUint32 represents an uint32 that may be null.
|
||||
// NullUint32 implements the Scanner interface so
|
||||
|
5
vendor/xorm.io/xorm/convert/interface.go
generated
vendored
5
vendor/xorm.io/xorm/convert/interface.go
generated
vendored
@ -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:
|
||||
|
57
vendor/xorm.io/xorm/convert/time.go
generated
vendored
57
vendor/xorm.io/xorm/convert/time.go
generated
vendored
@ -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 {
|
||||
@ -27,6 +28,9 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
||||
dt = dt.In(convertedLocation)
|
||||
return &dt, nil
|
||||
} else if len(s) == 20 && s[10] == 'T' && s[19] == 'Z' {
|
||||
if strings.HasPrefix(s, "0000-00-00T00:00:00") || strings.HasPrefix(s, "0001-01-01T00:00:00") {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
dt, err := time.ParseInLocation("2006-01-02T15:04:05", s[:19], originalLocation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -34,14 +38,32 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
||||
dt = dt.In(convertedLocation)
|
||||
return &dt, nil
|
||||
} else if len(s) == 25 && s[10] == 'T' && s[19] == '+' && s[22] == ':' {
|
||||
if strings.HasPrefix(s, "0000-00-00T00:00:00") || strings.HasPrefix(s, "0001-01-01T00:00:00") {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
dt, err := time.Parse(time.RFC3339, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dt = dt.In(convertedLocation)
|
||||
return &dt, nil
|
||||
} else if len(s) >= 21 && s[10] == 'T' && s[19] == '.' {
|
||||
if strings.HasPrefix(s, "0000-00-00T00:00:00."+strings.Repeat("0", len(s)-20)) ||
|
||||
strings.HasPrefix(s, "0001-01-01T00:00:00."+strings.Repeat("0", len(s)-20)) {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
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)
|
||||
if strings.HasPrefix(s, "0000-00-00T00:00:00."+strings.Repeat("0", len(s)-20)) ||
|
||||
strings.HasPrefix(s, "0001-01-01T00:00:00."+strings.Repeat("0", len(s)-20)) {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
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,9 +80,24 @@ 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] == ':' {
|
||||
dt, err := time.ParseInLocation("15:04:05", s, originalLocation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
currentDate := time.Now()
|
||||
// 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 {
|
||||
if i == 0 {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
tm := time.Unix(i, 0).In(convertedLocation)
|
||||
return &tm, nil
|
||||
}
|
||||
@ -87,6 +124,9 @@ func AsTime(src interface{}, dbLoc *time.Location, uiLoc *time.Location) (*time.
|
||||
if !t.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
if utils.IsTimeZero(t.Time) {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
z, _ := t.Time.Zone()
|
||||
if len(z) == 0 || t.Time.Year() == 0 || t.Time.Location().String() != dbLoc.String() {
|
||||
tm := time.Date(t.Time.Year(), t.Time.Month(), t.Time.Day(), t.Time.Hour(),
|
||||
@ -96,6 +136,9 @@ func AsTime(src interface{}, dbLoc *time.Location, uiLoc *time.Location) (*time.
|
||||
tm := t.Time.In(uiLoc)
|
||||
return &tm, nil
|
||||
case *time.Time:
|
||||
if utils.IsTimeZero(*t) {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
z, _ := t.Zone()
|
||||
if len(z) == 0 || t.Year() == 0 || t.Location().String() != dbLoc.String() {
|
||||
tm := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(),
|
||||
@ -105,6 +148,9 @@ func AsTime(src interface{}, dbLoc *time.Location, uiLoc *time.Location) (*time.
|
||||
tm := t.In(uiLoc)
|
||||
return &tm, nil
|
||||
case time.Time:
|
||||
if utils.IsTimeZero(t) {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
z, _ := t.Zone()
|
||||
if len(z) == 0 || t.Year() == 0 || t.Location().String() != dbLoc.String() {
|
||||
tm := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(),
|
||||
@ -114,12 +160,21 @@ func AsTime(src interface{}, dbLoc *time.Location, uiLoc *time.Location) (*time.
|
||||
tm := t.In(uiLoc)
|
||||
return &tm, nil
|
||||
case int:
|
||||
if t == 0 {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
tm := time.Unix(int64(t), 0).In(uiLoc)
|
||||
return &tm, nil
|
||||
case int64:
|
||||
if t == 0 {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
tm := time.Unix(t, 0).In(uiLoc)
|
||||
return &tm, nil
|
||||
case *sql.NullInt64:
|
||||
if t.Int64 == 0 {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
tm := time.Unix(t.Int64, 0).In(uiLoc)
|
||||
return &tm, nil
|
||||
}
|
||||
|
18
vendor/xorm.io/xorm/dialects/dameng.go
generated
vendored
18
vendor/xorm.io/xorm/dialects/dameng.go
generated
vendored
@ -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 {
|
||||
@ -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) {
|
||||
|
29
vendor/xorm.io/xorm/dialects/dialect.go
generated
vendored
29
vendor/xorm.io/xorm/dialects/dialect.go
generated
vendored
@ -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
|
||||
|
85
vendor/xorm.io/xorm/dialects/filter.go
generated
vendored
85
vendor/xorm.io/xorm/dialects/filter.go
generated
vendored
@ -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)
|
||||
}
|
||||
|
22
vendor/xorm.io/xorm/dialects/mssql.go
generated
vendored
22
vendor/xorm.io/xorm/dialects/mssql.go
generated
vendored
@ -320,11 +320,7 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
||||
res += "(MAX)"
|
||||
}
|
||||
case schemas.TimeStamp, schemas.DateTime:
|
||||
if c.Length > 3 {
|
||||
res = "DATETIME2"
|
||||
} else {
|
||||
return schemas.DateTime
|
||||
}
|
||||
return "DATETIME2"
|
||||
case schemas.TimeStampz:
|
||||
res = "DATETIMEOFFSET"
|
||||
c.Length = 7
|
||||
@ -428,7 +424,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 +450,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 +471,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 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 +496,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 +646,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 +665,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{}
|
||||
}
|
||||
|
46
vendor/xorm.io/xorm/dialects/mysql.go
generated
vendored
46
vendor/xorm.io/xorm/dialects/mysql.go
generated
vendored
@ -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,
|
||||
@ -380,12 +382,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) {
|
||||
@ -398,7 +415,7 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
||||
"SUBSTRING_INDEX(SUBSTRING(VERSION(), 6), '-', 1) >= 7)))))"
|
||||
s := "SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`," +
|
||||
" `COLUMN_KEY`, `EXTRA`, `COLUMN_COMMENT`, `CHARACTER_MAXIMUM_LENGTH`, " +
|
||||
alreadyQuoted + " AS NEEDS_QUOTE " +
|
||||
alreadyQuoted + " AS NEEDS_QUOTE, `COLLATION_NAME` " +
|
||||
"FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?" +
|
||||
" ORDER BY `COLUMNS`.ORDINAL_POSITION ASC"
|
||||
|
||||
@ -416,8 +433,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, maxLength *string
|
||||
err = rows.Scan(&columnName, &nullableStr, &colDefault, &colType, &colKey, &extra, &comment, &maxLength, &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
|
||||
}
|
||||
@ -433,6 +450,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" {
|
||||
@ -525,7 +545,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...)
|
||||
@ -537,9 +557,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
|
||||
}
|
||||
@ -549,6 +569,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 {
|
||||
@ -640,7 +661,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 {
|
||||
@ -738,8 +759,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":
|
||||
|
23
vendor/xorm.io/xorm/dialects/oracle.go
generated
vendored
23
vendor/xorm.io/xorm/dialects/oracle.go
generated
vendored
@ -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
|
||||
@ -602,7 +609,7 @@ 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) {
|
||||
@ -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,6 +645,10 @@ 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:
|
||||
@ -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
|
||||
}
|
||||
|
10
vendor/xorm.io/xorm/dialects/postgres.go
generated
vendored
10
vendor/xorm.io/xorm/dialects/postgres.go
generated
vendored
@ -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 := ""
|
||||
@ -1078,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 != "" {
|
||||
@ -1343,14 +1343,14 @@ 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)
|
||||
commentSQL += fmt.Sprintf("COMMENT ON COLUMN %s.%s IS '%s'; ", quoter.Quote(tableName), quoter.Quote(col.Name), col.Comment)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1358,7 +1358,7 @@ func (db *postgres) CreateTableSQL(ctx context.Context, queryer core.Queryer, ta
|
||||
}
|
||||
|
||||
func (db *postgres) Filters() []Filter {
|
||||
return []Filter{&SeqFilter{Prefix: "$", Start: 1}}
|
||||
return []Filter{&postgresSeqFilter{Prefix: "$", Start: 1}}
|
||||
}
|
||||
|
||||
type pqDriver struct {
|
||||
|
10
vendor/xorm.io/xorm/dialects/sqlite3.go
generated
vendored
10
vendor/xorm.io/xorm/dialects/sqlite3.go
generated
vendored
@ -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 {
|
||||
|
13
vendor/xorm.io/xorm/doc.go
generated
vendored
13
vendor/xorm.io/xorm/doc.go
generated
vendored
@ -3,16 +3,15 @@
|
||||
// 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
|
||||
|
||||
Create Engine
|
||||
# Create Engine
|
||||
|
||||
Firstly, we should create an engine for a database
|
||||
|
||||
@ -21,7 +20,7 @@ Firstly, we should create an engine for a database
|
||||
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:
|
||||
|
||||
@ -41,7 +40,7 @@ XORM supports raw SQL execution:
|
||||
|
||||
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.
|
||||
|
||||
@ -142,7 +141,7 @@ or
|
||||
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.
|
||||
@ -204,7 +203,7 @@ Notice: the above 8 methods should be the last chainable method.
|
||||
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.
|
||||
|
||||
|
44
vendor/xorm.io/xorm/engine.go
generated
vendored
44
vendor/xorm.io/xorm/engine.go
generated
vendored
@ -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)
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
@ -998,7 +1006,6 @@ func (engine *Engine) Desc(colNames ...string) *Session {
|
||||
//
|
||||
// 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
|
||||
@ -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,6 +1212,7 @@ 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
|
||||
@ -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) {
|
||||
|
4
vendor/xorm.io/xorm/interface.go
generated
vendored
4
vendor/xorm.io/xorm/interface.go
generated
vendored
@ -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,7 +53,7 @@ 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 interface{}, args ...interface{}) *Session
|
||||
Ping() error
|
||||
@ -120,6 +121,7 @@ type EngineInterface interface {
|
||||
ShowSQL(show ...bool)
|
||||
Sync(...interface{}) error
|
||||
Sync2(...interface{}) error
|
||||
SyncWithOptions(SyncOptions, ...interface{}) (*SyncResult, error)
|
||||
StoreEngine(storeEngine string) *Session
|
||||
TableInfo(bean interface{}) (*schemas.Table, error)
|
||||
TableName(interface{}, ...bool) string
|
||||
|
1
vendor/xorm.io/xorm/internal/json/gojson.go
generated
vendored
1
vendor/xorm.io/xorm/internal/json/gojson.go
generated
vendored
@ -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
|
||||
|
1
vendor/xorm.io/xorm/internal/json/jsoniter.go
generated
vendored
1
vendor/xorm.io/xorm/internal/json/jsoniter.go
generated
vendored
@ -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
|
||||
|
16
vendor/xorm.io/xorm/internal/statements/cache.go
generated
vendored
16
vendor/xorm.io/xorm/internal/statements/cache.go
generated
vendored
@ -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
|
||||
|
125
vendor/xorm.io/xorm/internal/statements/delete.go
generated
vendored
Normal file
125
vendor/xorm.io/xorm/internal/statements/delete.go
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
// 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 {
|
||||
if statement.Start > 0 {
|
||||
return fmt.Errorf("Delete with Limit start is unsupported")
|
||||
}
|
||||
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)
|
||||
}
|
106
vendor/xorm.io/xorm/internal/statements/insert.go
generated
vendored
106
vendor/xorm.io/xorm/internal/statements/insert.go
generated
vendored
@ -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
|
||||
}
|
||||
|
139
vendor/xorm.io/xorm/internal/statements/join.go
generated
vendored
139
vendor/xorm.io/xorm/internal/statements/join.go
generated
vendored
@ -15,64 +15,97 @@ import (
|
||||
)
|
||||
|
||||
// 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...)
|
||||
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) writeJoin(w builder.Writer) error {
|
||||
if statement.JoinStr != "" {
|
||||
if _, err := fmt.Fprint(w, " ", statement.JoinStr); err != nil {
|
||||
func (statement *Statement) writeJoins(w *builder.BytesWriter) error {
|
||||
for _, join := range statement.joins {
|
||||
if err := statement.writeJoin(w, join); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Append(statement.joinArgs...)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
136
vendor/xorm.io/xorm/internal/statements/order_by.go
generated
vendored
136
vendor/xorm.io/xorm/internal/statements/order_by.go
generated
vendored
@ -5,86 +5,138 @@
|
||||
package statements
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"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 statement.orderStr != ""
|
||||
return len(statement.orderBy) > 0
|
||||
}
|
||||
|
||||
// ResetOrderBy reset ordery conditions
|
||||
func (statement *Statement) ResetOrderBy() {
|
||||
statement.orderStr = ""
|
||||
statement.orderArgs = nil
|
||||
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) WriteOrderBy(w builder.Writer) error {
|
||||
if len(statement.orderStr) > 0 {
|
||||
if _, err := fmt.Fprintf(w, " ORDER BY %s", statement.orderStr); err != nil {
|
||||
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
|
||||
}
|
||||
w.Append(statement.orderArgs...)
|
||||
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 {
|
||||
if len(statement.orderStr) > 0 {
|
||||
statement.orderStr += ", "
|
||||
}
|
||||
var rawOrder string
|
||||
switch t := order.(type) {
|
||||
case (*builder.Expression):
|
||||
rawOrder = t.Content()
|
||||
args = t.Args()
|
||||
case string:
|
||||
rawOrder = t
|
||||
default:
|
||||
statement.LastError = ErrUnSupportedSQLType
|
||||
ob := orderBy{order, args, ""}
|
||||
if err := ob.CheckValid(); err != nil {
|
||||
statement.LastError = err
|
||||
return statement
|
||||
}
|
||||
statement.orderStr += statement.ReplaceQuote(rawOrder)
|
||||
if len(args) > 0 {
|
||||
statement.orderArgs = append(statement.orderArgs, args...)
|
||||
}
|
||||
statement.orderBy = append(statement.orderBy, ob)
|
||||
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, ", ")
|
||||
if len(colNames) == 0 {
|
||||
statement.LastError = ErrNoColumnName
|
||||
return statement
|
||||
}
|
||||
for i, col := range colNames {
|
||||
if i > 0 {
|
||||
fmt.Fprint(&buf, ", ")
|
||||
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
|
||||
}
|
||||
_ = 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, ", ")
|
||||
if len(colNames) == 0 {
|
||||
statement.LastError = ErrNoColumnName
|
||||
return statement
|
||||
}
|
||||
for i, col := range colNames {
|
||||
if i > 0 {
|
||||
fmt.Fprint(&buf, ", ")
|
||||
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
|
||||
}
|
||||
_ = statement.dialect.Quoter().QuoteTo(&buf, col)
|
||||
fmt.Fprint(&buf, " ASC")
|
||||
}
|
||||
statement.orderStr = buf.String()
|
||||
return statement
|
||||
}
|
||||
|
378
vendor/xorm.io/xorm/internal/statements/query.go
generated
vendored
378
vendor/xorm.io/xorm/internal/statements/query.go
generated
vendored
@ -7,6 +7,7 @@ package statements
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@ -29,37 +30,15 @@ func (statement *Statement) GenQuerySQL(sqlOrArgs ...interface{}) (string, []int
|
||||
return "", nil, ErrTableNotFound
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
return statement.genSelectSQL(columnStr, true, true)
|
||||
buf := builder.NewWriter()
|
||||
if err := statement.writeSelect(buf, statement.genSelectColumnStr(), true, true); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
// GenSumSQL generates sum SQL
|
||||
@ -81,13 +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 {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
return statement.genSelectSQL(sumSelect, true, true)
|
||||
buf := builder.NewWriter()
|
||||
if err := statement.writeSelect(buf, strings.Join(sumStrs, ", "), true, true); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
// GenGetSQL generates Get SQL
|
||||
@ -108,7 +90,7 @@ func (statement *Statement) GenGetSQL(bean interface{}) (string, []interface{},
|
||||
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)
|
||||
@ -139,7 +121,11 @@ func (statement *Statement) GenGetSQL(bean interface{}) (string, []interface{},
|
||||
}
|
||||
}
|
||||
|
||||
return statement.genSelectSQL(columnStr, true, true)
|
||||
buf := builder.NewWriter()
|
||||
if err := statement.writeSelect(buf, columnStr, true, true); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
// GenCountSQL generates the SQL for counting
|
||||
@ -148,8 +134,6 @@ 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
|
||||
@ -169,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
|
||||
@ -176,19 +168,20 @@ 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, condArgs, nil
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeFrom(w builder.Writer) error {
|
||||
func (statement *Statement) writeFrom(w *builder.BytesWriter) error {
|
||||
if _, err := fmt.Fprint(w, " FROM "); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -198,7 +191,7 @@ func (statement *Statement) writeFrom(w builder.Writer) error {
|
||||
if err := statement.writeAlias(w); err != nil {
|
||||
return err
|
||||
}
|
||||
return statement.writeJoin(w)
|
||||
return statement.writeJoins(w)
|
||||
}
|
||||
|
||||
func (statement *Statement) writeLimitOffset(w builder.Writer) error {
|
||||
@ -218,37 +211,88 @@ func (statement *Statement) writeLimitOffset(w builder.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) genSelectSQL(columnStr string, needLimit, needOrderBy bool) (string, []interface{}, error) {
|
||||
var (
|
||||
distinct string
|
||||
dialect = statement.dialect
|
||||
top, whereStr string
|
||||
mssqlCondi = builder.NewWriter()
|
||||
)
|
||||
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
|
||||
}
|
||||
|
||||
if statement.IsDistinct && !strings.HasPrefix(columnStr, "count") {
|
||||
distinct = "DISTINCT "
|
||||
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
|
||||
}
|
||||
|
||||
condWriter := builder.NewWriter()
|
||||
if err := statement.cond.WriteTo(statement.QuoteReplacer(condWriter)); err != nil {
|
||||
return "", nil, err
|
||||
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 condWriter.Len() > 0 {
|
||||
whereStr = " WHERE "
|
||||
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
|
||||
}
|
||||
|
||||
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")
|
||||
return errors.New("unsupported query limit without reference table")
|
||||
}
|
||||
|
||||
var column string
|
||||
if len(statement.RefTable.PKColumns()) == 0 {
|
||||
for _, index := range statement.RefTable.Indexes {
|
||||
@ -263,7 +307,7 @@ func (statement *Statement) genSelectSQL(columnStr string, needLimit, needOrderB
|
||||
} else {
|
||||
column = statement.RefTable.PKColumns()[0].Name
|
||||
}
|
||||
if statement.needTableName() {
|
||||
if statement.NeedTableName() {
|
||||
if len(statement.TableAlias) > 0 {
|
||||
column = fmt.Sprintf("%s.%s", statement.TableAlias, column)
|
||||
} else {
|
||||
@ -271,100 +315,91 @@ func (statement *Statement) genSelectSQL(columnStr string, needLimit, needOrderB
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprintf(mssqlCondi, "(%s NOT IN (SELECT TOP %d %s",
|
||||
subWriter := builder.NewWriter()
|
||||
if _, err := fmt.Fprintf(subWriter, "(%s NOT IN (SELECT TOP %d %s",
|
||||
column, statement.Start, column); err != nil {
|
||||
return "", nil, err
|
||||
return err
|
||||
}
|
||||
if err := statement.writeFrom(mssqlCondi); err != nil {
|
||||
return "", nil, err
|
||||
if err := statement.writeFrom(subWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
if whereStr != "" {
|
||||
if _, err := fmt.Fprint(mssqlCondi, whereStr); err != nil {
|
||||
return "", nil, err
|
||||
if err := statement.writeWhere(subWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := utils.WriteBuilder(mssqlCondi, statement.QuoteReplacer(condWriter)); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
if needOrderBy {
|
||||
if err := statement.WriteOrderBy(mssqlCondi); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
if err := statement.WriteGroupBy(mssqlCondi); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if _, err := fmt.Fprint(mssqlCondi, "))"); err != nil {
|
||||
return "", nil, 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
|
||||
}
|
||||
|
||||
buf := builder.NewWriter()
|
||||
if _, err := fmt.Fprintf(buf, "SELECT %v%v%v", distinct, top, columnStr); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.writeFrom(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if whereStr != "" {
|
||||
if _, err := fmt.Fprint(buf, whereStr); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := utils.WriteBuilder(buf, statement.QuoteReplacer(condWriter)); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
if mssqlCondi.Len() > 0 {
|
||||
if len(whereStr) > 0 {
|
||||
if _, err := fmt.Fprint(buf, " AND "); err != nil {
|
||||
return "", nil, err
|
||||
if statement.cond.IsValid() {
|
||||
if _, err := fmt.Fprint(w, " AND "); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := fmt.Fprint(buf, " WHERE "); err != nil {
|
||||
return "", nil, err
|
||||
if _, err := fmt.Fprint(w, " WHERE "); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := utils.WriteBuilder(buf, mssqlCondi); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return utils.WriteBuilder(w, subWriter)
|
||||
}
|
||||
|
||||
func (statement *Statement) writeOracleLimit(w *builder.BytesWriter, columnStr string) error {
|
||||
if statement.LimitN == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := statement.WriteGroupBy(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.writeHaving(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if needOrderBy {
|
||||
if err := statement.WriteOrderBy(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
if needLimit {
|
||||
if dialect.URI().DBType != schemas.MSSQL && dialect.URI().DBType != schemas.ORACLE {
|
||||
if err := statement.writeLimitOffset(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
} else if dialect.URI().DBType == schemas.ORACLE {
|
||||
if pLimitN != nil {
|
||||
oldString := buf.String()
|
||||
buf.Reset()
|
||||
oldString := w.String()
|
||||
w.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)
|
||||
_, 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
|
||||
}
|
||||
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
|
||||
}
|
||||
if statement.IsForUpdate {
|
||||
return dialect.ForUpdateSQL(buf.String()), buf.Args(), nil
|
||||
}
|
||||
|
||||
return buf.String(), buf.Args(), nil
|
||||
dialect := statement.dialect
|
||||
if needLimit {
|
||||
if dialect.URI().DBType == schemas.ORACLE {
|
||||
if err := statement.writeOracleLimit(buf, columnStr); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if dialect.URI().DBType != schemas.MSSQL {
|
||||
if err := statement.writeLimitOffset(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return statement.writeForUpdate(buf)
|
||||
}
|
||||
|
||||
// GenExistSQL generates Exist SQL
|
||||
@ -402,22 +437,17 @@ func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interfac
|
||||
if _, err := fmt.Fprintf(buf, "SELECT TOP 1 * FROM %s", tableName); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.writeJoin(buf); err != nil {
|
||||
if err := statement.writeJoins(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if statement.Conds().IsValid() {
|
||||
if _, err := fmt.Fprintf(buf, " WHERE "); err != nil {
|
||||
if err := statement.writeWhere(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.Conds().WriteTo(statement.QuoteReplacer(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.writeJoin(buf); err != nil {
|
||||
if err := statement.writeJoins(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if _, err := fmt.Fprintf(buf, " WHERE "); err != nil {
|
||||
@ -438,17 +468,12 @@ func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interfac
|
||||
if _, err := fmt.Fprintf(buf, "SELECT 1 FROM %s", tableName); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.writeJoin(buf); err != nil {
|
||||
if err := statement.writeJoins(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if statement.Conds().IsValid() {
|
||||
if _, err := fmt.Fprintf(buf, " WHERE "); err != nil {
|
||||
if err := statement.writeWhere(buf); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := statement.Conds().WriteTo(statement.QuoteReplacer(buf)); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprintf(buf, " LIMIT 1"); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
@ -457,6 +482,33 @@ func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interfac
|
||||
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
|
||||
func (statement *Statement) GenFindSQL(autoCond builder.Cond) (string, []interface{}, error) {
|
||||
if statement.RawSQL != "" {
|
||||
@ -467,33 +519,11 @@ func (statement *Statement) GenFindSQL(autoCond builder.Cond) (string, []interfa
|
||||
return "", nil, ErrTableNotFound
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
return statement.genSelectSQL(columnStr, true, true)
|
||||
buf := builder.NewWriter()
|
||||
if err := statement.writeSelect(buf, statement.genSelectColumnStr(), true, true); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
4
vendor/xorm.io/xorm/internal/statements/select.go
generated
vendored
4
vendor/xorm.io/xorm/internal/statements/select.go
generated
vendored
@ -102,7 +102,7 @@ func (statement *Statement) genColumnStr() string {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
|
||||
if statement.JoinStr != "" {
|
||||
if len(statement.joins) > 0 {
|
||||
if statement.TableAlias != "" {
|
||||
buf.WriteString(statement.TableAlias)
|
||||
} else {
|
||||
@ -119,7 +119,7 @@ func (statement *Statement) genColumnStr() string {
|
||||
}
|
||||
|
||||
func (statement *Statement) colName(col *schemas.Column, tableName string) string {
|
||||
if statement.needTableName() {
|
||||
if statement.NeedTableName() {
|
||||
nm := tableName
|
||||
if len(statement.TableAlias) > 0 {
|
||||
nm = statement.TableAlias
|
||||
|
58
vendor/xorm.io/xorm/internal/statements/statement.go
generated
vendored
58
vendor/xorm.io/xorm/internal/statements/statement.go
generated
vendored
@ -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,10 +50,8 @@ type Statement struct {
|
||||
Start int
|
||||
LimitN *int
|
||||
idParam schemas.PK
|
||||
orderStr string
|
||||
orderArgs []interface{}
|
||||
JoinStr string
|
||||
joinArgs []interface{}
|
||||
orderBy []orderBy
|
||||
joins []join
|
||||
GroupByStr string
|
||||
HavingStr string
|
||||
SelectStr string
|
||||
@ -123,8 +128,7 @@ func (statement *Statement) Reset() {
|
||||
statement.LimitN = nil
|
||||
statement.ResetOrderBy()
|
||||
statement.UseCascade = true
|
||||
statement.JoinStr = ""
|
||||
statement.joinArgs = make([]interface{}, 0)
|
||||
statement.joins = nil
|
||||
statement.GroupByStr = ""
|
||||
statement.HavingStr = ""
|
||||
statement.ColumnMap = columnMap{}
|
||||
@ -158,15 +162,15 @@ func (statement *Statement) Reset() {
|
||||
|
||||
// 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
|
||||
@ -205,8 +209,8 @@ func (statement *Statement) SetRefBean(bean interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) needTableName() bool {
|
||||
return len(statement.JoinStr) > 0
|
||||
func (statement *Statement) NeedTableName() bool {
|
||||
return len(statement.joins) > 0
|
||||
}
|
||||
|
||||
// Incr Generate "Update ... Set column = column + arg" statement
|
||||
@ -290,17 +294,17 @@ func (statement *Statement) GroupBy(keys string) *Statement {
|
||||
return statement
|
||||
}
|
||||
|
||||
func (statement *Statement) WriteGroupBy(w builder.Writer) error {
|
||||
func (statement *Statement) writeGroupBy(w builder.Writer) error {
|
||||
if statement.GroupByStr == "" {
|
||||
return nil
|
||||
}
|
||||
_, err := fmt.Fprintf(w, " GROUP BY %s", statement.GroupByStr)
|
||||
_, 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
|
||||
}
|
||||
|
||||
@ -308,7 +312,7 @@ func (statement *Statement) writeHaving(w builder.Writer) error {
|
||||
if statement.HavingStr == "" {
|
||||
return nil
|
||||
}
|
||||
_, err := fmt.Fprint(w, " ", statement.HavingStr)
|
||||
_, err := fmt.Fprint(w, " HAVING ", statement.ReplaceQuote(statement.HavingStr))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -605,7 +609,7 @@ func (statement *Statement) BuildConds(table *schemas.Table, bean interface{}, i
|
||||
// MergeConds merge conditions from bean and id
|
||||
func (statement *Statement) MergeConds(bean interface{}) error {
|
||||
if !statement.NoAutoCondition && statement.RefTable != nil {
|
||||
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
|
||||
@ -640,6 +644,23 @@ func (statement *Statement) convertSQLOrArgs(sqlOrArgs ...interface{}) (string,
|
||||
newArgs = append(newArgs, v.In(statement.defaultTimeZone).Format("2006-01-02 15:04:05"))
|
||||
} else if v, ok := arg.(*time.Time); ok && v != nil {
|
||||
newArgs = append(newArgs, v.In(statement.defaultTimeZone).Format("2006-01-02 15:04:05"))
|
||||
} else if v, ok := arg.(convert.ConversionTo); ok {
|
||||
r, err := v.ToDB()
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if r != nil {
|
||||
// for nvarchar column on mssql, bytes have to be converted as ucs-2 external of driver
|
||||
// for binary column, a string will be converted as bytes directly. So we have to
|
||||
// convert bytes as string
|
||||
if statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
newArgs = append(newArgs, string(r))
|
||||
} else {
|
||||
newArgs = append(newArgs, r)
|
||||
}
|
||||
} else {
|
||||
newArgs = append(newArgs, nil)
|
||||
}
|
||||
} else {
|
||||
newArgs = append(newArgs, arg)
|
||||
}
|
||||
@ -673,7 +694,7 @@ 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 {
|
||||
colName := statement.quote(col.Name)
|
||||
if statement.JoinStr != "" {
|
||||
if len(statement.joins) > 0 {
|
||||
var prefix string
|
||||
if statement.TableAlias != "" {
|
||||
prefix = statement.TableAlias
|
||||
@ -686,11 +707,8 @@ func (statement *Statement) CondDeleted(col *schemas.Column) builder.Cond {
|
||||
if col.SQLType.IsNumeric() {
|
||||
cond = builder.Eq{colName: 0}
|
||||
} else {
|
||||
// FIXME: mssql: The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
|
||||
if statement.dialect.URI().DBType != schemas.MSSQL {
|
||||
cond = builder.Eq{colName: utils.ZeroTime1}
|
||||
}
|
||||
}
|
||||
|
||||
if col.Nullable {
|
||||
cond = cond.Or(builder.IsNull{colName})
|
||||
|
337
vendor/xorm.io/xorm/internal/statements/update.go
generated
vendored
337
vendor/xorm.io/xorm/internal/statements/update.go
generated
vendored
@ -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)
|
||||
}
|
||||
|
16
vendor/xorm.io/xorm/rows.go
generated
vendored
16
vendor/xorm.io/xorm/rows.go
generated
vendored
@ -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()
|
||||
}
|
||||
|
10
vendor/xorm.io/xorm/schemas/collation.go
generated
vendored
Normal file
10
vendor/xorm.io/xorm/schemas/collation.go
generated
vendored
Normal file
@ -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
|
||||
}
|
3
vendor/xorm.io/xorm/schemas/column.go
generated
vendored
3
vendor/xorm.io/xorm/schemas/column.go
generated
vendored
@ -45,6 +45,7 @@ type Column struct {
|
||||
DisableTimeZone bool
|
||||
TimeZone *time.Location // column specified time zone
|
||||
Comment string
|
||||
Collation string
|
||||
}
|
||||
|
||||
// NewColumn creates a new column
|
||||
@ -89,6 +90,8 @@ func (col *Column) ValueOfV(dataStruct *reflect.Value) (*reflect.Value, error) {
|
||||
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})
|
||||
}
|
||||
|
1
vendor/xorm.io/xorm/schemas/quote.go
generated
vendored
1
vendor/xorm.io/xorm/schemas/quote.go
generated
vendored
@ -163,6 +163,7 @@ 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]
|
||||
|
4
vendor/xorm.io/xorm/schemas/table.go
generated
vendored
4
vendor/xorm.io/xorm/schemas/table.go
generated
vendored
@ -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),
|
||||
|
48
vendor/xorm.io/xorm/session.go
generated
vendored
48
vendor/xorm.io/xorm/session.go
generated
vendored
@ -16,8 +16,6 @@ import (
|
||||
"io"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"xorm.io/xorm/contexts"
|
||||
"xorm.io/xorm/convert"
|
||||
"xorm.io/xorm/core"
|
||||
@ -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) {
|
||||
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,7 +416,7 @@ 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 {
|
||||
@ -432,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
|
||||
}
|
||||
@ -705,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)
|
||||
|
||||
tempMap := make(map[string]int)
|
||||
var pk schemas.PK
|
||||
for i, colName := range fields {
|
||||
var idx int
|
||||
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 {
|
||||
@ -794,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
|
||||
}
|
||||
|
104
vendor/xorm.io/xorm/session_delete.go
generated
vendored
104
vendor/xorm.io/xorm/session_delete.go
generated
vendored
@ -6,22 +6,15 @@ package xorm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/caches"
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"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 ||
|
||||
@ -30,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)
|
||||
@ -91,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()
|
||||
}
|
||||
@ -101,7 +105,6 @@ func (session *Session) Delete(beans ...interface{}) (int64, error) {
|
||||
}
|
||||
|
||||
var (
|
||||
condWriter = builder.NewWriter()
|
||||
err error
|
||||
bean interface{}
|
||||
)
|
||||
@ -122,90 +125,27 @@ func (session *Session) Delete(beans ...interface{}) (int64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if err = session.statement.Conds().WriteTo(session.statement.QuoteReplacer(condWriter)); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
pLimitN := session.statement.LimitN
|
||||
if condWriter.Len() == 0 && (pLimitN == nil || *pLimitN == 0) {
|
||||
if mustHaveConditions && !session.statement.Conds().IsValid() && (pLimitN == nil || *pLimitN == 0) {
|
||||
return 0, ErrNeedDeletedCond
|
||||
}
|
||||
|
||||
tableNameNoQuote := session.statement.TableName()
|
||||
tableName := session.engine.Quote(tableNameNoQuote)
|
||||
table := session.statement.RefTable
|
||||
deleteSQLWriter := builder.NewWriter()
|
||||
fmt.Fprintf(deleteSQLWriter, "DELETE FROM %v", tableName)
|
||||
if condWriter.Len() > 0 {
|
||||
fmt.Fprintf(deleteSQLWriter, " WHERE %v", condWriter.String())
|
||||
deleteSQLWriter.Append(condWriter.Args()...)
|
||||
}
|
||||
|
||||
orderSQLWriter := builder.NewWriter()
|
||||
if err := session.statement.WriteOrderBy(orderSQLWriter); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if pLimitN != nil && *pLimitN > 0 {
|
||||
limitNValue := *pLimitN
|
||||
if _, err := fmt.Fprintf(orderSQLWriter, " LIMIT %d", limitNValue); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
orderCondWriter := builder.NewWriter()
|
||||
if orderSQLWriter.Len() > 0 {
|
||||
switch session.engine.dialect.URI().DBType {
|
||||
case schemas.POSTGRES:
|
||||
if condWriter.Len() > 0 {
|
||||
fmt.Fprintf(orderCondWriter, " AND ")
|
||||
} else {
|
||||
fmt.Fprintf(orderCondWriter, " WHERE ")
|
||||
}
|
||||
fmt.Fprintf(orderCondWriter, "ctid IN (SELECT ctid FROM %s%s)", tableName, orderSQLWriter.String())
|
||||
orderCondWriter.Append(orderSQLWriter.Args()...)
|
||||
case schemas.SQLITE:
|
||||
if condWriter.Len() > 0 {
|
||||
fmt.Fprintf(orderCondWriter, " AND ")
|
||||
} else {
|
||||
fmt.Fprintf(orderCondWriter, " WHERE ")
|
||||
}
|
||||
fmt.Fprintf(orderCondWriter, "rowid IN (SELECT rowid FROM %s%s)", tableName, orderSQLWriter.String())
|
||||
// TODO: how to handle delete limit on mssql?
|
||||
case schemas.MSSQL:
|
||||
return 0, ErrNotImplemented
|
||||
default:
|
||||
fmt.Fprint(orderCondWriter, orderSQLWriter.String())
|
||||
orderCondWriter.Append(orderSQLWriter.Args()...)
|
||||
}
|
||||
}
|
||||
|
||||
realSQLWriter := builder.NewWriter()
|
||||
argsForCache := make([]interface{}, 0, len(deleteSQLWriter.Args())*2)
|
||||
copy(argsForCache, deleteSQLWriter.Args())
|
||||
argsForCache = append(deleteSQLWriter.Args(), argsForCache...)
|
||||
if session.statement.GetUnscoped() || table == nil || table.DeletedColumn() == nil { // tag "deleted" is disabled
|
||||
if err := utils.WriteBuilder(realSQLWriter, deleteSQLWriter, orderCondWriter); err != nil {
|
||||
deleteSQLWriter := builder.NewWriter()
|
||||
if err := session.statement.WriteDelete(realSQLWriter, deleteSQLWriter, session.engine.nowTime); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if session.statement.GetUnscoped() || table == nil || table.DeletedColumn() == nil { // tag "deleted" is disabled
|
||||
} else {
|
||||
deletedColumn := table.DeletedColumn()
|
||||
if _, err := fmt.Fprintf(realSQLWriter, "UPDATE %v SET %v = ? WHERE %v",
|
||||
session.engine.Quote(session.statement.TableName()),
|
||||
session.engine.Quote(deletedColumn.Name),
|
||||
condWriter.String()); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, t, err := session.engine.nowTime(deletedColumn)
|
||||
_, t, err := session.engine.nowTime(deletedColumn)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
realSQLWriter.Append(val)
|
||||
realSQLWriter.Append(condWriter.Args()...)
|
||||
|
||||
if err := utils.WriteBuilder(realSQLWriter, orderCondWriter); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
colName := deletedColumn.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
@ -214,6 +154,10 @@ func (session *Session) Delete(beans ...interface{}) (int64, error) {
|
||||
})
|
||||
}
|
||||
|
||||
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, deleteSQLWriter.String(), argsForCache...)
|
||||
}
|
||||
|
69
vendor/xorm.io/xorm/session_find.go
generated
vendored
69
vendor/xorm.io/xorm/session_find.go
generated
vendored
@ -5,8 +5,10 @@
|
||||
package xorm
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/caches"
|
||||
@ -114,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 {
|
||||
@ -161,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
|
||||
@ -238,7 +298,10 @@ func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect
|
||||
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
|
||||
@ -283,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)
|
||||
|
10
vendor/xorm.io/xorm/session_get.go
generated
vendored
10
vendor/xorm.io/xorm/session_get.go
generated
vendored
@ -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 == "" {
|
||||
|
56
vendor/xorm.io/xorm/session_insert.go
generated
vendored
56
vendor/xorm.io/xorm/session_insert.go
generated
vendored
@ -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,6 +342,7 @@ 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
|
||||
@ -361,7 +351,6 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
||||
if id == 0 {
|
||||
return 0, errors.New("insert successfully but not returned id")
|
||||
}
|
||||
}
|
||||
|
||||
defer handleAfterInsertProcessorFunc(bean)
|
||||
|
||||
@ -482,7 +471,8 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
||||
}
|
||||
|
||||
if col.IsDeleted {
|
||||
arg, err := dialects.FormatColumnTime(session.engine.dialect, session.engine.DatabaseTZ, col, time.Time{})
|
||||
zeroTime := time.Date(1, 1, 1, 0, 0, 0, 0, session.engine.DatabaseTZ)
|
||||
arg, err := dialects.FormatColumnTime(session.engine.dialect, session.engine.DatabaseTZ, col, zeroTime)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -517,7 +507,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)
|
||||
@ -547,7 +537,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) {
|
||||
@ -556,7 +546,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])
|
||||
}
|
||||
@ -574,7 +564,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) {
|
||||
@ -583,9 +573,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])
|
||||
}
|
||||
@ -605,7 +595,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) {
|
||||
@ -615,7 +605,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])
|
||||
}
|
||||
@ -633,7 +623,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) {
|
||||
@ -642,9 +632,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])
|
||||
}
|
||||
|
2
vendor/xorm.io/xorm/session_raw.go
generated
vendored
2
vendor/xorm.io/xorm/session_raw.go
generated
vendored
@ -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
|
||||
|
227
vendor/xorm.io/xorm/session_schema.go
generated
vendored
227
vendor/xorm.io/xorm/session_schema.go
generated
vendored
@ -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' {
|
||||
|
6
vendor/xorm.io/xorm/session_stats.go
generated
vendored
6
vendor/xorm.io/xorm/session_stats.go
generated
vendored
@ -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...)
|
||||
}
|
||||
|
316
vendor/xorm.io/xorm/session_update.go
generated
vendored
316
vendor/xorm.io/xorm/session_update.go
generated
vendored
@ -5,146 +5,58 @@
|
||||
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
|
||||
}
|
||||
|
||||
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:])
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
ids = make([]schemas.PK, 0)
|
||||
for rows.Next() {
|
||||
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)
|
||||
}
|
||||
}
|
||||
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
|
||||
@ -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,6 +84,8 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||
}
|
||||
// --
|
||||
|
||||
var colNames []string
|
||||
var args []interface{}
|
||||
var err error
|
||||
isMap := t.Kind() == reflect.Map
|
||||
isStruct := t.Kind() == reflect.Struct
|
||||
@ -236,79 +147,17 @@ 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 := builder.ToSQL(tp)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
subQuery = session.statement.ReplaceQuote(subQuery)
|
||||
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 {
|
||||
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])
|
||||
autoCond, err = session.genAutoCond(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 !condBeanIsStruct && table != nil {
|
||||
} else if table != nil {
|
||||
if col := table.DeletedColumn(); col != nil && !session.statement.GetUnscoped() { // tag "deleted" is enabled
|
||||
autoCond1 := session.statement.CondDeleted(col)
|
||||
|
||||
@ -319,9 +168,6 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
st := session.statement
|
||||
|
||||
var (
|
||||
cond = session.statement.Conds().And(autoCond)
|
||||
@ -329,104 +175,25 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||
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
|
||||
}
|
||||
|
||||
whereWriter := builder.NewWriter()
|
||||
if cond.IsValid() {
|
||||
fmt.Fprint(whereWriter, "WHERE ")
|
||||
}
|
||||
if err := cond.WriteTo(st.QuoteReplacer(whereWriter)); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err := st.WriteOrderBy(whereWriter); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
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:
|
||||
fmt.Fprintf(whereWriter, " LIMIT %d", limitValue)
|
||||
case schemas.SQLITE:
|
||||
fmt.Fprintf(whereWriter, " LIMIT %d", limitValue)
|
||||
|
||||
cond = cond.And(builder.Expr(fmt.Sprintf("rowid IN (SELECT rowid FROM %v %v)",
|
||||
session.engine.Quote(tableName), whereWriter.String()), whereWriter.Args()...))
|
||||
|
||||
whereWriter = builder.NewWriter()
|
||||
fmt.Fprint(whereWriter, "WHERE ")
|
||||
if err := cond.WriteTo(st.QuoteReplacer(whereWriter)); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
case schemas.POSTGRES:
|
||||
fmt.Fprintf(whereWriter, " LIMIT %d", limitValue)
|
||||
|
||||
cond = cond.And(builder.Expr(fmt.Sprintf("CTID IN (SELECT CTID FROM %v %v)",
|
||||
session.engine.Quote(tableName), whereWriter.String()), whereWriter.Args()...))
|
||||
|
||||
whereWriter = builder.NewWriter()
|
||||
fmt.Fprint(whereWriter, "WHERE ")
|
||||
if err := cond.WriteTo(st.QuoteReplacer(whereWriter)); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
case schemas.MSSQL:
|
||||
if st.HasOrderBy() && 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), whereWriter.String()), whereWriter.Args()...)
|
||||
|
||||
whereWriter = builder.NewWriter()
|
||||
fmt.Fprint(whereWriter, "WHERE ")
|
||||
if err := cond.WriteTo(whereWriter); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
} else {
|
||||
top = fmt.Sprintf("TOP (%d) ", limitValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
updateWriter := builder.NewWriter()
|
||||
if _, err := fmt.Fprintf(updateWriter, "UPDATE %v%v SET %v %v",
|
||||
top,
|
||||
tableAlias,
|
||||
strings.Join(colNames, ", "),
|
||||
fromSQL); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err := utils.WriteBuilder(updateWriter, whereWriter); err != nil {
|
||||
if err := session.statement.WriteUpdate(updateWriter, cond, v, colNames, args); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
res, err := session.exec(updateWriter.String(), append(args, updateWriter.Args()...)...)
|
||||
tableName := session.statement.TableName() // table name must been get before exec because statement will be reset
|
||||
useCache := session.statement.UseCache
|
||||
|
||||
res, err := session.exec(updateWriter.String(), updateWriter.Args()...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else if doIncVer {
|
||||
@ -435,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)
|
||||
|
298
vendor/xorm.io/xorm/sync.go
generated
vendored
Normal file
298
vendor/xorm.io/xorm/sync.go
generated
vendored
Normal file
@ -0,0 +1,298 @@
|
||||
// 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
|
||||
// IgnoreConstrains will not add, delete or update unique constrains
|
||||
IgnoreConstrains bool
|
||||
// IgnoreIndices will not add or delete indices
|
||||
IgnoreIndices 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,
|
||||
IgnoreConstrains: false,
|
||||
IgnoreIndices: 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
|
||||
}
|
||||
|
||||
if !opts.IgnoreConstrains {
|
||||
err = session.createUniques(bean)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if !opts.IgnoreIndices {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// indices found in orig table
|
||||
foundIndexNames := make(map[string]bool)
|
||||
// indices to be added
|
||||
addedNames := make(map[string]*schemas.Index)
|
||||
|
||||
// drop indices that exist in orig and new table schema but are not equal
|
||||
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 && 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
|
||||
}
|
||||
}
|
||||
|
||||
// drop all indices that do not exist in new schema or have changed
|
||||
for name2, index2 := range oriTable.Indexes {
|
||||
if _, ok := foundIndexNames[name2]; !ok {
|
||||
// ignore based on there type
|
||||
if (index2.Type == schemas.IndexType && opts.IgnoreIndices) ||
|
||||
(index2.Type == schemas.UniqueType && opts.IgnoreConstrains) {
|
||||
// make sure we do not add a index with same name later
|
||||
delete(addedNames, name2)
|
||||
continue
|
||||
}
|
||||
|
||||
sql := engine.dialect.DropIndexSQL(tbNameWithSchema, index2)
|
||||
_, err = session.exec(sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add new indices because either they did not exist before or were dropped to update them
|
||||
for name, index := range addedNames {
|
||||
if index.Type == schemas.UniqueType && !opts.IgnoreConstrains {
|
||||
session.statement.RefTable = table
|
||||
session.statement.SetTableName(tbNameWithSchema)
|
||||
err = session.addUnique(tbNameWithSchema, name)
|
||||
} else if index.Type == schemas.IndexType && !opts.IgnoreIndices {
|
||||
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
|
||||
}
|
41
vendor/xorm.io/xorm/tags/parser.go
generated
vendored
41
vendor/xorm.io/xorm/tags/parser.go
generated
vendored
@ -31,6 +31,12 @@ type TableIndices interface {
|
||||
|
||||
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 {
|
||||
identifier string
|
||||
@ -356,6 +362,22 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -377,3 +399,22 @@ func tableIndices(v reflect.Value) []*schemas.Index {
|
||||
}
|
||||
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
|
||||
}
|
||||
|
13
vendor/xorm.io/xorm/tags/tag.go
generated
vendored
13
vendor/xorm.io/xorm/tags/tag.go
generated
vendored
@ -123,6 +123,7 @@ var defaultTagHandlers = map[string]Handler{
|
||||
"COMMENT": CommentTagHandler,
|
||||
"EXTENDS": ExtendsTagHandler,
|
||||
"UNSIGNED": UnsignedTagHandler,
|
||||
"COLLATE": CollateTagHandler,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -282,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 {
|
||||
|
Loading…
Reference in New Issue
Block a user