chore: 更新依赖并添加对SQLite的支持
- 在.gitignore中添加了对.idea和.vscode的忽略 - 更新了sqlboiler依赖至v4.18.0 - 添加了多个间接依赖,包括goutils、semver、sprig等 - 在wrtcsgl.go中实现了对SQLite数据库的支持,允许通过sqlite://前缀指定SQLite URL,并相应调整数据库持久化逻辑
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,4 @@
|
||||
out
|
||||
.specstory
|
||||
.idea
|
||||
.vscode
|
||||
|
4
configs/sql-migrate-sqlite/communities.yaml
Normal file
4
configs/sql-migrate-sqlite/communities.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
sqlite3:
|
||||
dialect: sqlite3
|
||||
datasource: weron_communities.db
|
||||
dir: db/sqlite/migrations/communities/
|
3
configs/sqlboiler-sqlite/communities.yaml
Normal file
3
configs/sqlboiler-sqlite/communities.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
no-tests: true
|
||||
sqlite3:
|
||||
dbname: weron_communities.db
|
9
db/sqlite/migrations/communities/1646780237.sql
Normal file
9
db/sqlite/migrations/communities/1646780237.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- +migrate Up
|
||||
create table communities (
|
||||
id text primary key not null,
|
||||
password text not null,
|
||||
clients integer not null,
|
||||
persistent boolean not null
|
||||
);
|
||||
-- +migrate Down
|
||||
drop table communities;
|
11
go.mod
11
go.mod
@@ -25,13 +25,16 @@ require (
|
||||
github.com/teivah/broadcast v0.1.0
|
||||
github.com/vishvananda/netlink v1.3.0
|
||||
github.com/volatiletech/null/v8 v8.1.2
|
||||
github.com/volatiletech/sqlboiler/v4 v4.16.2
|
||||
github.com/volatiletech/sqlboiler/v4 v4.18.0
|
||||
github.com/volatiletech/strmangle v0.0.6
|
||||
golang.org/x/crypto v0.26.0
|
||||
golang.org/x/sync v0.8.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/Masterminds/semver/v3 v3.2.0 // indirect
|
||||
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/coreos/go-oidc/v3 v3.11.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
@@ -41,10 +44,15 @@ require (
|
||||
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
|
||||
github.com/gofrs/uuid v4.4.0+incompatible // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/huandu/xstrings v1.4.0 // indirect
|
||||
github.com/imdario/mergo v0.3.13 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.24 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||
@@ -66,6 +74,7 @@ require (
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/sagikazarmark/locafero v0.6.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
github.com/shopspring/decimal v1.3.1 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/cast v1.7.0 // indirect
|
||||
|
20
go.sum
20
go.sum
@@ -63,9 +63,14 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
|
||||
github.com/DATA-DOG/go-sqlmock v1.4.1 h1:ThlnYciV1iM/V0OSF/dtkqWb6xo5qITT1TJBG1MRDJM=
|
||||
github.com/DATA-DOG/go-sqlmock v1.4.1/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
|
||||
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
||||
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||
github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g=
|
||||
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk=
|
||||
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
|
||||
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
@@ -297,9 +302,13 @@ github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpT
|
||||
github.com/hashicorp/serf v0.9.7/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
|
||||
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
|
||||
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
|
||||
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
@@ -361,12 +370,15 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
|
||||
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
|
||||
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
|
||||
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/microsoft/go-mssqldb v0.17.0/go.mod h1:OkoNGhGEs8EZqchVTtochlXruEhEOaO4S0d2sB5aeGQ=
|
||||
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
|
||||
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
|
||||
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
|
||||
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
|
||||
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
|
||||
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||
@@ -376,6 +388,7 @@ github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
||||
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
||||
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
@@ -497,6 +510,7 @@ github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWR
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
|
||||
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
@@ -560,6 +574,8 @@ github.com/volatiletech/randomize v0.0.1 h1:eE5yajattWqTB2/eN8df4dw+8jwAzBtbdo5s
|
||||
github.com/volatiletech/randomize v0.0.1/go.mod h1:GN3U0QYqfZ9FOJ67bzax1cqZ5q2xuj2mXrXBjWaRTlY=
|
||||
github.com/volatiletech/sqlboiler/v4 v4.16.2 h1:PcV2bxjE+S+GwPKCyX7/AjlY3aiTKsOEjciLhpWQImc=
|
||||
github.com/volatiletech/sqlboiler/v4 v4.16.2/go.mod h1:B14BPBGTrJ2X6l7lwnvV/iXgYR48+ozGSlzHI3frl6U=
|
||||
github.com/volatiletech/sqlboiler/v4 v4.18.0 h1:ISz4w94NmJrGAIO3FnYqzD76yYL54Ll61PIfM/c5cdM=
|
||||
github.com/volatiletech/sqlboiler/v4 v4.18.0/go.mod h1:e4TAZHRyiLwKrHzKS9OuOfc9SJy/AprEMbn+ZrAohO8=
|
||||
github.com/volatiletech/strmangle v0.0.1/go.mod h1:F6RA6IkB5vq0yTG4GQ0UsbbRcl3ni9P76i+JrTBKFFg=
|
||||
github.com/volatiletech/strmangle v0.0.6 h1:AdOYE3B2ygRDq4rXDij/MMwq6KVK/pWAYxpC7CLrkKQ=
|
||||
github.com/volatiletech/strmangle v0.0.6/go.mod h1:ycDvbDkjDvhC0NUU8w3fWwl5JEMTV56vTKXzR3GeR+0=
|
||||
@@ -603,6 +619,7 @@ golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5y
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
|
||||
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||
@@ -696,6 +713,7 @@ golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
@@ -838,6 +856,7 @@ golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
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.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
@@ -852,6 +871,7 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/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.4.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.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
|
1
internal/db/sqlite/migrations/communities/.keep
Normal file
1
internal/db/sqlite/migrations/communities/.keep
Normal file
@@ -0,0 +1 @@
|
||||
# This file is used to keep the directory in git
|
243
internal/db/sqlite/migrations/communities/migrations.go
Normal file
243
internal/db/sqlite/migrations/communities/migrations.go
Normal file
@@ -0,0 +1,243 @@
|
||||
// Code generated by go-bindata.
|
||||
// sources:
|
||||
// db/sqlite/migrations/communities/1646780237.sql
|
||||
// DO NOT EDIT!
|
||||
|
||||
package communities
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func bindataRead(data []byte, name string) ([]byte, error) {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
clErr := gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
if clErr != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
type asset struct {
|
||||
bytes []byte
|
||||
info os.FileInfo
|
||||
}
|
||||
|
||||
type bindataFileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
modTime time.Time
|
||||
}
|
||||
|
||||
func (fi bindataFileInfo) Name() string {
|
||||
return fi.name
|
||||
}
|
||||
func (fi bindataFileInfo) Size() int64 {
|
||||
return fi.size
|
||||
}
|
||||
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||
return fi.mode
|
||||
}
|
||||
func (fi bindataFileInfo) ModTime() time.Time {
|
||||
return fi.modTime
|
||||
}
|
||||
func (fi bindataFileInfo) IsDir() bool {
|
||||
return false
|
||||
}
|
||||
func (fi bindataFileInfo) Sys() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _dbSqliteMigrationsCommunities1646780237Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\xce\x4b\xaa\xc3\x30\x0c\x85\xe1\xb9\x57\x71\x86\xf7\xd2\x66\x05\x99\x76\x0b\x5d\x80\xe3\x88\x20\x6a\x4b\x46\x52\x48\xb3\xfb\xd2\x52\x4a\x1f\x33\x81\xbe\x03\xff\x30\xe0\xd0\x78\xb1\x1c\x84\x73\x4f\xc5\xe8\x7e\x45\x9e\x2a\xa1\x68\x6b\xab\x70\x30\x39\xfe\x12\x00\xf0\x8c\xa0\x6b\xa0\x1b\xb7\x6c\x3b\x2e\xb4\x43\x34\x20\x6b\xad\xc7\x87\xe8\xd9\x7d\x53\x7b\xba\xcf\x5f\xa9\x4c\x12\x0e\x96\xa0\x85\xec\x7b\x49\xe6\xec\x41\x12\x98\x54\x2b\x65\x79\x81\xf4\x3f\xa6\xf7\xd0\x93\x6e\x92\x66\xd3\xfe\x1b\x3a\xe2\x16\x00\x00\xff\xff\x05\x05\x2f\xa9\xd2\x00\x00\x00")
|
||||
|
||||
func dbSqliteMigrationsCommunities1646780237SqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_dbSqliteMigrationsCommunities1646780237Sql,
|
||||
"db/sqlite/migrations/communities/1646780237.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func dbSqliteMigrationsCommunities1646780237Sql() (*asset, error) {
|
||||
bytes, err := dbSqliteMigrationsCommunities1646780237SqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "db/sqlite/migrations/communities/1646780237.sql", size: 210, mode: os.FileMode(420), modTime: time.Unix(1743177866, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func Asset(name string) ([]byte, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.bytes, nil
|
||||
}
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
|
||||
// MustAsset is like Asset but panics when Asset would return an error.
|
||||
// It simplifies safe initialization of global variables.
|
||||
func MustAsset(name string) []byte {
|
||||
a, err := Asset(name)
|
||||
if err != nil {
|
||||
panic("asset: Asset(" + name + "): " + err.Error())
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// AssetInfo loads and returns the asset info for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func AssetInfo(name string) (os.FileInfo, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.info, nil
|
||||
}
|
||||
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||
}
|
||||
|
||||
// AssetNames returns the names of the assets.
|
||||
func AssetNames() []string {
|
||||
names := make([]string, 0, len(_bindata))
|
||||
for name := range _bindata {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"db/sqlite/migrations/communities/1646780237.sql": dbSqliteMigrationsCommunities1646780237Sql,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
// directory embedded in the file by go-bindata.
|
||||
// For example if you run go-bindata on data/... and data contains the
|
||||
// following hierarchy:
|
||||
// data/
|
||||
// foo.txt
|
||||
// img/
|
||||
// a.png
|
||||
// b.png
|
||||
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||
// AssetDir("") will return []string{"data"}.
|
||||
func AssetDir(name string) ([]string, error) {
|
||||
node := _bintree
|
||||
if len(name) != 0 {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
pathList := strings.Split(cannonicalName, "/")
|
||||
for _, p := range pathList {
|
||||
node = node.Children[p]
|
||||
if node == nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.Func != nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
rv := make([]string, 0, len(node.Children))
|
||||
for childName := range node.Children {
|
||||
rv = append(rv, childName)
|
||||
}
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
type bintree struct {
|
||||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"db": &bintree{nil, map[string]*bintree{
|
||||
"sqlite": &bintree{nil, map[string]*bintree{
|
||||
"migrations": &bintree{nil, map[string]*bintree{
|
||||
"communities": &bintree{nil, map[string]*bintree{
|
||||
"1646780237.sql": &bintree{dbSqliteMigrationsCommunities1646780237Sql, map[string]*bintree{}},
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
}}
|
||||
|
||||
// RestoreAsset restores an asset under the given directory
|
||||
func RestoreAsset(dir, name string) error {
|
||||
data, err := Asset(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info, err := AssetInfo(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RestoreAssets restores an asset under the given directory recursively
|
||||
func RestoreAssets(dir, name string) error {
|
||||
children, err := AssetDir(name)
|
||||
// File
|
||||
if err != nil {
|
||||
return RestoreAsset(dir, name)
|
||||
}
|
||||
// Dir
|
||||
for _, child := range children {
|
||||
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _filePath(dir, name string) string {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||
}
|
||||
|
38
internal/db/sqlite/models/communities/boil_queries.go
Normal file
38
internal/db/sqlite/models/communities/boil_queries.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Code generated by SQLBoiler 4.18.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/volatiletech/sqlboiler/v4/drivers"
|
||||
"github.com/volatiletech/sqlboiler/v4/queries"
|
||||
"github.com/volatiletech/sqlboiler/v4/queries/qm"
|
||||
)
|
||||
|
||||
var dialect = drivers.Dialect{
|
||||
LQ: 0x22,
|
||||
RQ: 0x22,
|
||||
|
||||
UseIndexPlaceholders: false,
|
||||
UseLastInsertID: false,
|
||||
UseSchema: false,
|
||||
UseDefaultKeyword: true,
|
||||
UseAutoColumns: false,
|
||||
UseTopClause: false,
|
||||
UseOutputClause: false,
|
||||
UseCaseWhenExistsClause: false,
|
||||
}
|
||||
|
||||
// This is a dummy variable to prevent unused regexp import error
|
||||
var _ = ®exp.Regexp{}
|
||||
|
||||
// NewQuery initializes a new Query using the passed in QueryMods
|
||||
func NewQuery(mods ...qm.QueryMod) *queries.Query {
|
||||
q := &queries.Query{}
|
||||
queries.SetDialect(q, &dialect)
|
||||
qm.Apply(q, mods...)
|
||||
|
||||
return q
|
||||
}
|
10
internal/db/sqlite/models/communities/boil_table_names.go
Normal file
10
internal/db/sqlite/models/communities/boil_table_names.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// Code generated by SQLBoiler 4.18.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
var TableNames = struct {
|
||||
Communities string
|
||||
}{
|
||||
Communities: "communities",
|
||||
}
|
52
internal/db/sqlite/models/communities/boil_types.go
Normal file
52
internal/db/sqlite/models/communities/boil_types.go
Normal file
@@ -0,0 +1,52 @@
|
||||
// Code generated by SQLBoiler 4.18.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/friendsofgo/errors"
|
||||
"github.com/volatiletech/sqlboiler/v4/boil"
|
||||
"github.com/volatiletech/strmangle"
|
||||
)
|
||||
|
||||
// M type is for providing columns and column values to UpdateAll.
|
||||
type M map[string]interface{}
|
||||
|
||||
// ErrSyncFail occurs during insert when the record could not be retrieved in
|
||||
// order to populate default value information. This usually happens when LastInsertId
|
||||
// fails or there was a primary key configuration that was not resolvable.
|
||||
var ErrSyncFail = errors.New("models: failed to synchronize data after insert")
|
||||
|
||||
type insertCache struct {
|
||||
query string
|
||||
retQuery string
|
||||
valueMapping []uint64
|
||||
retMapping []uint64
|
||||
}
|
||||
|
||||
type updateCache struct {
|
||||
query string
|
||||
valueMapping []uint64
|
||||
}
|
||||
|
||||
func makeCacheKey(cols boil.Columns, nzDefaults []string) string {
|
||||
buf := strmangle.GetBuffer()
|
||||
|
||||
buf.WriteString(strconv.Itoa(cols.Kind))
|
||||
for _, w := range cols.Cols {
|
||||
buf.WriteString(w)
|
||||
}
|
||||
|
||||
if len(nzDefaults) != 0 {
|
||||
buf.WriteByte('.')
|
||||
}
|
||||
for _, nz := range nzDefaults {
|
||||
buf.WriteString(nz)
|
||||
}
|
||||
|
||||
str := buf.String()
|
||||
strmangle.PutBuffer(buf)
|
||||
return str
|
||||
}
|
7
internal/db/sqlite/models/communities/boil_view_names.go
Normal file
7
internal/db/sqlite/models/communities/boil_view_names.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// Code generated by SQLBoiler 4.18.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
var ViewNames = struct {
|
||||
}{}
|
994
internal/db/sqlite/models/communities/communities.go
Normal file
994
internal/db/sqlite/models/communities/communities.go
Normal file
@@ -0,0 +1,994 @@
|
||||
// Code generated by SQLBoiler 4.18.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/friendsofgo/errors"
|
||||
"github.com/volatiletech/sqlboiler/v4/boil"
|
||||
"github.com/volatiletech/sqlboiler/v4/queries"
|
||||
"github.com/volatiletech/sqlboiler/v4/queries/qm"
|
||||
"github.com/volatiletech/sqlboiler/v4/queries/qmhelper"
|
||||
"github.com/volatiletech/strmangle"
|
||||
)
|
||||
|
||||
// Community is an object representing the database table.
|
||||
type Community struct {
|
||||
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
|
||||
Password string `boil:"password" json:"password" toml:"password" yaml:"password"`
|
||||
Clients int64 `boil:"clients" json:"clients" toml:"clients" yaml:"clients"`
|
||||
Persistent bool `boil:"persistent" json:"persistent" toml:"persistent" yaml:"persistent"`
|
||||
|
||||
R *communityR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L communityL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var CommunityColumns = struct {
|
||||
ID string
|
||||
Password string
|
||||
Clients string
|
||||
Persistent string
|
||||
}{
|
||||
ID: "id",
|
||||
Password: "password",
|
||||
Clients: "clients",
|
||||
Persistent: "persistent",
|
||||
}
|
||||
|
||||
var CommunityTableColumns = struct {
|
||||
ID string
|
||||
Password string
|
||||
Clients string
|
||||
Persistent string
|
||||
}{
|
||||
ID: "communities.id",
|
||||
Password: "communities.password",
|
||||
Clients: "communities.clients",
|
||||
Persistent: "communities.persistent",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
type whereHelperstring struct{ field string }
|
||||
|
||||
func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
|
||||
func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) }
|
||||
func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
|
||||
func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) }
|
||||
func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
|
||||
func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) }
|
||||
func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) }
|
||||
func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) }
|
||||
func (w whereHelperstring) IN(slice []string) qm.QueryMod {
|
||||
values := make([]interface{}, 0, len(slice))
|
||||
for _, value := range slice {
|
||||
values = append(values, value)
|
||||
}
|
||||
return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...)
|
||||
}
|
||||
func (w whereHelperstring) NIN(slice []string) qm.QueryMod {
|
||||
values := make([]interface{}, 0, len(slice))
|
||||
for _, value := range slice {
|
||||
values = append(values, value)
|
||||
}
|
||||
return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...)
|
||||
}
|
||||
|
||||
type whereHelperint64 struct{ field string }
|
||||
|
||||
func (w whereHelperint64) EQ(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
|
||||
func (w whereHelperint64) NEQ(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) }
|
||||
func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
|
||||
func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) }
|
||||
func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
|
||||
func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) }
|
||||
func (w whereHelperint64) IN(slice []int64) qm.QueryMod {
|
||||
values := make([]interface{}, 0, len(slice))
|
||||
for _, value := range slice {
|
||||
values = append(values, value)
|
||||
}
|
||||
return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...)
|
||||
}
|
||||
func (w whereHelperint64) NIN(slice []int64) qm.QueryMod {
|
||||
values := make([]interface{}, 0, len(slice))
|
||||
for _, value := range slice {
|
||||
values = append(values, value)
|
||||
}
|
||||
return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...)
|
||||
}
|
||||
|
||||
type whereHelperbool struct{ field string }
|
||||
|
||||
func (w whereHelperbool) EQ(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
|
||||
func (w whereHelperbool) NEQ(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) }
|
||||
func (w whereHelperbool) LT(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
|
||||
func (w whereHelperbool) LTE(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) }
|
||||
func (w whereHelperbool) GT(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
|
||||
func (w whereHelperbool) GTE(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) }
|
||||
|
||||
var CommunityWhere = struct {
|
||||
ID whereHelperstring
|
||||
Password whereHelperstring
|
||||
Clients whereHelperint64
|
||||
Persistent whereHelperbool
|
||||
}{
|
||||
ID: whereHelperstring{field: "\"communities\".\"id\""},
|
||||
Password: whereHelperstring{field: "\"communities\".\"password\""},
|
||||
Clients: whereHelperint64{field: "\"communities\".\"clients\""},
|
||||
Persistent: whereHelperbool{field: "\"communities\".\"persistent\""},
|
||||
}
|
||||
|
||||
// CommunityRels is where relationship names are stored.
|
||||
var CommunityRels = struct {
|
||||
}{}
|
||||
|
||||
// communityR is where relationships are stored.
|
||||
type communityR struct {
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*communityR) NewStruct() *communityR {
|
||||
return &communityR{}
|
||||
}
|
||||
|
||||
// communityL is where Load methods for each relationship are stored.
|
||||
type communityL struct{}
|
||||
|
||||
var (
|
||||
communityAllColumns = []string{"id", "password", "clients", "persistent"}
|
||||
communityColumnsWithoutDefault = []string{"id", "password", "clients", "persistent"}
|
||||
communityColumnsWithDefault = []string{}
|
||||
communityPrimaryKeyColumns = []string{"id"}
|
||||
communityGeneratedColumns = []string{}
|
||||
)
|
||||
|
||||
type (
|
||||
// CommunitySlice is an alias for a slice of pointers to Community.
|
||||
// This should almost always be used instead of []Community.
|
||||
CommunitySlice []*Community
|
||||
// CommunityHook is the signature for custom Community hook methods
|
||||
CommunityHook func(context.Context, boil.ContextExecutor, *Community) error
|
||||
|
||||
communityQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
communityType = reflect.TypeOf(&Community{})
|
||||
communityMapping = queries.MakeStructMapping(communityType)
|
||||
communityPrimaryKeyMapping, _ = queries.BindMapping(communityType, communityMapping, communityPrimaryKeyColumns)
|
||||
communityInsertCacheMut sync.RWMutex
|
||||
communityInsertCache = make(map[string]insertCache)
|
||||
communityUpdateCacheMut sync.RWMutex
|
||||
communityUpdateCache = make(map[string]updateCache)
|
||||
communityUpsertCacheMut sync.RWMutex
|
||||
communityUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
var communityAfterSelectMu sync.Mutex
|
||||
var communityAfterSelectHooks []CommunityHook
|
||||
|
||||
var communityBeforeInsertMu sync.Mutex
|
||||
var communityBeforeInsertHooks []CommunityHook
|
||||
var communityAfterInsertMu sync.Mutex
|
||||
var communityAfterInsertHooks []CommunityHook
|
||||
|
||||
var communityBeforeUpdateMu sync.Mutex
|
||||
var communityBeforeUpdateHooks []CommunityHook
|
||||
var communityAfterUpdateMu sync.Mutex
|
||||
var communityAfterUpdateHooks []CommunityHook
|
||||
|
||||
var communityBeforeDeleteMu sync.Mutex
|
||||
var communityBeforeDeleteHooks []CommunityHook
|
||||
var communityAfterDeleteMu sync.Mutex
|
||||
var communityAfterDeleteHooks []CommunityHook
|
||||
|
||||
var communityBeforeUpsertMu sync.Mutex
|
||||
var communityBeforeUpsertHooks []CommunityHook
|
||||
var communityAfterUpsertMu sync.Mutex
|
||||
var communityAfterUpsertHooks []CommunityHook
|
||||
|
||||
// doAfterSelectHooks executes all "after Select" hooks.
|
||||
func (o *Community) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range communityAfterSelectHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeInsertHooks executes all "before insert" hooks.
|
||||
func (o *Community) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range communityBeforeInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterInsertHooks executes all "after Insert" hooks.
|
||||
func (o *Community) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range communityAfterInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpdateHooks executes all "before Update" hooks.
|
||||
func (o *Community) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range communityBeforeUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpdateHooks executes all "after Update" hooks.
|
||||
func (o *Community) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range communityAfterUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeDeleteHooks executes all "before Delete" hooks.
|
||||
func (o *Community) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range communityBeforeDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterDeleteHooks executes all "after Delete" hooks.
|
||||
func (o *Community) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range communityAfterDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpsertHooks executes all "before Upsert" hooks.
|
||||
func (o *Community) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range communityBeforeUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpsertHooks executes all "after Upsert" hooks.
|
||||
func (o *Community) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range communityAfterUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddCommunityHook registers your hook function for all future operations.
|
||||
func AddCommunityHook(hookPoint boil.HookPoint, communityHook CommunityHook) {
|
||||
switch hookPoint {
|
||||
case boil.AfterSelectHook:
|
||||
communityAfterSelectMu.Lock()
|
||||
communityAfterSelectHooks = append(communityAfterSelectHooks, communityHook)
|
||||
communityAfterSelectMu.Unlock()
|
||||
case boil.BeforeInsertHook:
|
||||
communityBeforeInsertMu.Lock()
|
||||
communityBeforeInsertHooks = append(communityBeforeInsertHooks, communityHook)
|
||||
communityBeforeInsertMu.Unlock()
|
||||
case boil.AfterInsertHook:
|
||||
communityAfterInsertMu.Lock()
|
||||
communityAfterInsertHooks = append(communityAfterInsertHooks, communityHook)
|
||||
communityAfterInsertMu.Unlock()
|
||||
case boil.BeforeUpdateHook:
|
||||
communityBeforeUpdateMu.Lock()
|
||||
communityBeforeUpdateHooks = append(communityBeforeUpdateHooks, communityHook)
|
||||
communityBeforeUpdateMu.Unlock()
|
||||
case boil.AfterUpdateHook:
|
||||
communityAfterUpdateMu.Lock()
|
||||
communityAfterUpdateHooks = append(communityAfterUpdateHooks, communityHook)
|
||||
communityAfterUpdateMu.Unlock()
|
||||
case boil.BeforeDeleteHook:
|
||||
communityBeforeDeleteMu.Lock()
|
||||
communityBeforeDeleteHooks = append(communityBeforeDeleteHooks, communityHook)
|
||||
communityBeforeDeleteMu.Unlock()
|
||||
case boil.AfterDeleteHook:
|
||||
communityAfterDeleteMu.Lock()
|
||||
communityAfterDeleteHooks = append(communityAfterDeleteHooks, communityHook)
|
||||
communityAfterDeleteMu.Unlock()
|
||||
case boil.BeforeUpsertHook:
|
||||
communityBeforeUpsertMu.Lock()
|
||||
communityBeforeUpsertHooks = append(communityBeforeUpsertHooks, communityHook)
|
||||
communityBeforeUpsertMu.Unlock()
|
||||
case boil.AfterUpsertHook:
|
||||
communityAfterUpsertMu.Lock()
|
||||
communityAfterUpsertHooks = append(communityAfterUpsertHooks, communityHook)
|
||||
communityAfterUpsertMu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// One returns a single community record from the query.
|
||||
func (q communityQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Community, error) {
|
||||
o := &Community{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: failed to execute a one query for communities")
|
||||
}
|
||||
|
||||
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all Community records from the query.
|
||||
func (q communityQuery) All(ctx context.Context, exec boil.ContextExecutor) (CommunitySlice, error) {
|
||||
var o []*Community
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "models: failed to assign all query results to Community slice")
|
||||
}
|
||||
|
||||
if len(communityAfterSelectHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all Community records in the query.
|
||||
func (q communityQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to count communities rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q communityQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: failed to check if communities exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// Communities retrieves all the records using an executor.
|
||||
func Communities(mods ...qm.QueryMod) communityQuery {
|
||||
mods = append(mods, qm.From("\"communities\""))
|
||||
q := NewQuery(mods...)
|
||||
if len(queries.GetSelect(q)) == 0 {
|
||||
queries.SetSelect(q, []string{"\"communities\".*"})
|
||||
}
|
||||
|
||||
return communityQuery{q}
|
||||
}
|
||||
|
||||
// FindCommunity retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindCommunity(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*Community, error) {
|
||||
communityObj := &Community{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"communities\" where \"id\"=?", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, iD)
|
||||
|
||||
err := q.Bind(ctx, exec, communityObj)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: unable to select from communities")
|
||||
}
|
||||
|
||||
if err = communityObj.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return communityObj, err
|
||||
}
|
||||
|
||||
return communityObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *Community) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no communities provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(communityColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
communityInsertCacheMut.RLock()
|
||||
cache, cached := communityInsertCache[key]
|
||||
communityInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
communityAllColumns,
|
||||
communityColumnsWithDefault,
|
||||
communityColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(communityType, communityMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(communityType, communityMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"communities\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"communities\" %sDEFAULT VALUES%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to insert into communities")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
communityInsertCacheMut.Lock()
|
||||
communityInsertCache[key] = cache
|
||||
communityInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return o.doAfterInsertHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// Update uses an executor to update the Community.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *Community) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
var err error
|
||||
if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
key := makeCacheKey(columns, nil)
|
||||
communityUpdateCacheMut.RLock()
|
||||
cache, cached := communityUpdateCache[key]
|
||||
communityUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
communityAllColumns,
|
||||
communityPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if !columns.IsWhitelist() {
|
||||
wl = strmangle.SetComplement(wl, []string{"created_at"})
|
||||
}
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("models: unable to update communities, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"communities\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, wl),
|
||||
strmangle.WhereClause("\"", "\"", 0, communityPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(communityType, communityMapping, append(wl, communityPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update communities row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by update for communities")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
communityUpdateCacheMut.Lock()
|
||||
communityUpdateCache[key] = cache
|
||||
communityUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q communityQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all for communities")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for communities")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o CommunitySlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("models: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), communityPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"communities\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, communityPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all in community slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all community")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
|
||||
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
|
||||
func (o *Community) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no communities provided for upsert")
|
||||
}
|
||||
|
||||
if err := o.doBeforeUpsertHooks(ctx, exec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(communityColumnsWithDefault, o)
|
||||
|
||||
// Build cache key in-line uglily - mysql vs psql problems
|
||||
buf := strmangle.GetBuffer()
|
||||
if updateOnConflict {
|
||||
buf.WriteByte('t')
|
||||
} else {
|
||||
buf.WriteByte('f')
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range conflictColumns {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(updateColumns.Kind))
|
||||
for _, c := range updateColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(insertColumns.Kind))
|
||||
for _, c := range insertColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range nzDefaults {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
key := buf.String()
|
||||
strmangle.PutBuffer(buf)
|
||||
|
||||
communityUpsertCacheMut.RLock()
|
||||
cache, cached := communityUpsertCache[key]
|
||||
communityUpsertCacheMut.RUnlock()
|
||||
|
||||
var err error
|
||||
|
||||
if !cached {
|
||||
insert, _ := insertColumns.InsertColumnSet(
|
||||
communityAllColumns,
|
||||
communityColumnsWithDefault,
|
||||
communityColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
update := updateColumns.UpdateColumnSet(
|
||||
communityAllColumns,
|
||||
communityPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if updateOnConflict && len(update) == 0 {
|
||||
return errors.New("models: unable to upsert communities, could not build update column list")
|
||||
}
|
||||
|
||||
ret := strmangle.SetComplement(communityAllColumns, strmangle.SetIntersect(insert, update))
|
||||
|
||||
conflict := conflictColumns
|
||||
if len(conflict) == 0 {
|
||||
conflict = make([]string, len(communityPrimaryKeyColumns))
|
||||
copy(conflict, communityPrimaryKeyColumns)
|
||||
}
|
||||
cache.query = buildUpsertQuerySQLite(dialect, "\"communities\"", updateOnConflict, ret, update, conflict, insert)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(communityType, communityMapping, insert)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(ret) != 0 {
|
||||
cache.retMapping, err = queries.BindMapping(communityType, communityMapping, ret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
var returns []interface{}
|
||||
if len(cache.retMapping) != 0 {
|
||||
returns = queries.PtrsFromMapping(value, cache.retMapping)
|
||||
}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil // Postgres doesn't return anything when there's no update
|
||||
}
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to upsert communities")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
communityUpsertCacheMut.Lock()
|
||||
communityUpsertCache[key] = cache
|
||||
communityUpsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return o.doAfterUpsertHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// Delete deletes a single Community record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *Community) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("models: no Community provided for delete")
|
||||
}
|
||||
|
||||
if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), communityPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"communities\" WHERE \"id\"=?"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete from communities")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for communities")
|
||||
}
|
||||
|
||||
if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q communityQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("models: no communityQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from communities")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for communities")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o CommunitySlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(communityBeforeDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), communityPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"communities\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, communityPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from community slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for communities")
|
||||
}
|
||||
|
||||
if len(communityAfterDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *Community) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindCommunity(ctx, exec, o.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *CommunitySlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := CommunitySlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), communityPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"communities\".* FROM \"communities\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, communityPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to reload all in CommunitySlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CommunityExists checks if the Community row exists.
|
||||
func CommunityExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"communities\" where \"id\"=? limit 1)"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, iD)
|
||||
}
|
||||
row := exec.QueryRowContext(ctx, sql, iD)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: unable to check if communities exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// Exists checks if the Community row exists.
|
||||
func (o *Community) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
return CommunityExists(ctx, exec, o.ID)
|
||||
}
|
61
internal/db/sqlite/models/communities/sqlite_upsert.go
Normal file
61
internal/db/sqlite/models/communities/sqlite_upsert.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Code generated by SQLBoiler 4.18.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/volatiletech/sqlboiler/v4/drivers"
|
||||
"github.com/volatiletech/strmangle"
|
||||
)
|
||||
|
||||
// buildUpsertQuerySQLite builds a SQL statement string using the upsertData provided.
|
||||
func buildUpsertQuerySQLite(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string {
|
||||
conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict)
|
||||
whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist)
|
||||
ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret)
|
||||
|
||||
buf := strmangle.GetBuffer()
|
||||
defer strmangle.PutBuffer(buf)
|
||||
|
||||
columns := "DEFAULT VALUES"
|
||||
if len(whitelist) != 0 {
|
||||
columns = fmt.Sprintf("(%s) VALUES (%s)",
|
||||
strings.Join(whitelist, ", "),
|
||||
strmangle.Placeholders(dia.UseIndexPlaceholders, len(whitelist), 1, 1))
|
||||
}
|
||||
|
||||
fmt.Fprintf(
|
||||
buf,
|
||||
"INSERT INTO %s %s ON CONFLICT ",
|
||||
tableName,
|
||||
columns,
|
||||
)
|
||||
|
||||
if !updateOnConflict || len(update) == 0 {
|
||||
buf.WriteString("DO NOTHING")
|
||||
} else {
|
||||
buf.WriteByte('(')
|
||||
buf.WriteString(strings.Join(conflict, ", "))
|
||||
buf.WriteString(") DO UPDATE SET ")
|
||||
|
||||
for i, v := range update {
|
||||
if i != 0 {
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v)
|
||||
buf.WriteString(quoted)
|
||||
buf.WriteString(" = EXCLUDED.")
|
||||
buf.WriteString(quoted)
|
||||
}
|
||||
}
|
||||
|
||||
if len(ret) != 0 {
|
||||
buf.WriteString(" RETURNING ")
|
||||
buf.WriteString(strings.Join(ret, ", "))
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
291
internal/persisters/sqlite/communities.go
Normal file
291
internal/persisters/sqlite/communities.go
Normal file
@@ -0,0 +1,291 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/pojntfx/go-auth-utils/pkg/authn"
|
||||
"github.com/pojntfx/weron/internal/db/sqlite/migrations/communities"
|
||||
models "github.com/pojntfx/weron/internal/db/sqlite/models/communities"
|
||||
"github.com/pojntfx/weron/internal/persisters"
|
||||
migrate "github.com/rubenv/sql-migrate"
|
||||
"github.com/volatiletech/sqlboiler/v4/boil"
|
||||
"github.com/volatiletech/sqlboiler/v4/queries/qm"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
//go:generate sqlboiler sqlite3 -o ../../../internal/db/sqlite/models/communities -c ../../../configs/sqlboiler-sqlite/communities.yaml
|
||||
//go:generate go-bindata -pkg communities -o ../../../internal/db/sqlite/migrations/communities/migrations.go ../../../db/sqlite/migrations/communities
|
||||
|
||||
type CommunitiesPersister struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewCommunitiesPersister() *CommunitiesPersister {
|
||||
return &CommunitiesPersister{}
|
||||
}
|
||||
|
||||
func (p *CommunitiesPersister) Open(dbURL string) error {
|
||||
// 确保SQLite数据库文件的目录存在
|
||||
if dbURL != ":memory:" {
|
||||
dir := filepath.Dir(dbURL)
|
||||
if dir != "." {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 连接到数据库
|
||||
db, err := sql.Open("sqlite3", dbURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 配置数据库
|
||||
db.SetMaxOpenConns(1) // 防止"database locked"错误
|
||||
|
||||
// 运行迁移
|
||||
if _, err := migrate.Exec(db, "sqlite3", migrate.AssetMigrationSource{
|
||||
Asset: communities.Asset,
|
||||
AssetDir: communities.AssetDir,
|
||||
Dir: "../../../db/sqlite/migrations/communities",
|
||||
}, migrate.Up); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.db = db
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *CommunitiesPersister) AddClientsToCommunity(
|
||||
ctx context.Context,
|
||||
community string,
|
||||
password string,
|
||||
upsert bool,
|
||||
) error {
|
||||
tx, err := p.db.BeginTx(ctx, &sql.TxOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := models.FindCommunity(ctx, tx, community)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if !upsert {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return persisters.ErrEphemeralCommunitiesDisabled
|
||||
}
|
||||
|
||||
c = &models.Community{
|
||||
ID: community,
|
||||
Password: string(hashedPassword),
|
||||
Clients: 1,
|
||||
Persistent: false,
|
||||
}
|
||||
|
||||
if err := c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
} else {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if bcrypt.CompareHashAndPassword([]byte(c.Password), []byte(password)) != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return authn.ErrWrongPassword
|
||||
}
|
||||
|
||||
c.Clients += 1
|
||||
|
||||
if _, err := c.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (p *CommunitiesPersister) RemoveClientFromCommunity(
|
||||
ctx context.Context,
|
||||
community string,
|
||||
) error {
|
||||
tx, err := p.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := models.FindCommunity(ctx, tx, community)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil // No-op
|
||||
}
|
||||
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
c.Clients -= 1
|
||||
if c.Clients <= 0 {
|
||||
if !c.Persistent {
|
||||
if _, err := c.Delete(ctx, tx); err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
c.Clients = 0
|
||||
}
|
||||
|
||||
if _, err := c.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (p *CommunitiesPersister) Cleanup(
|
||||
ctx context.Context,
|
||||
) error {
|
||||
tx, err := p.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 删除所有临时社区
|
||||
if _, err := models.Communities(qm.Where(models.CommunityColumns.Persistent+"= ?", false)).DeleteAll(ctx, tx); err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// 将所有持久社区的客户端计数设置为0
|
||||
if _, err := models.Communities(qm.Where(models.CommunityColumns.Persistent+"= ?", true)).UpdateAll(ctx, tx, models.M{models.CommunityColumns.Clients: 0}); err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (p *CommunitiesPersister) GetCommunities(
|
||||
ctx context.Context,
|
||||
) ([]persisters.Community, error) {
|
||||
c, err := models.Communities().All(ctx, p.db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cc := []persisters.Community{}
|
||||
for _, community := range c {
|
||||
cc = append(cc, persisters.Community{
|
||||
ID: community.ID,
|
||||
Clients: int(community.Clients),
|
||||
Persistent: community.Persistent,
|
||||
})
|
||||
}
|
||||
|
||||
return cc, nil
|
||||
}
|
||||
|
||||
func (p *CommunitiesPersister) CreatePersistentCommunity(
|
||||
ctx context.Context,
|
||||
community string,
|
||||
password string,
|
||||
) (*persisters.Community, error) {
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c := &models.Community{
|
||||
ID: community,
|
||||
Password: string(hashedPassword),
|
||||
Clients: 0,
|
||||
Persistent: true,
|
||||
}
|
||||
|
||||
if err := c.Insert(ctx, p.db, boil.Infer()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cc := &persisters.Community{
|
||||
ID: c.ID,
|
||||
Clients: int(c.Clients),
|
||||
Persistent: c.Persistent,
|
||||
}
|
||||
|
||||
return cc, nil
|
||||
}
|
||||
|
||||
func (p *CommunitiesPersister) DeleteCommunity(
|
||||
ctx context.Context,
|
||||
community string,
|
||||
) error {
|
||||
n, err := models.Communities(
|
||||
qm.Where(models.CommunityColumns.ID+"= ?", community),
|
||||
).DeleteAll(ctx, p.db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if n <= 0 {
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/pojntfx/weron/internal/persisters"
|
||||
"github.com/pojntfx/weron/internal/persisters/memory"
|
||||
"github.com/pojntfx/weron/internal/persisters/psql"
|
||||
"github.com/pojntfx/weron/internal/persisters/sqlite"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -60,6 +61,7 @@ type SignalerConfig struct {
|
||||
type Signaler struct {
|
||||
laddr string
|
||||
postgresURL string
|
||||
sqliteURL string
|
||||
redisURL string
|
||||
config *SignalerConfig
|
||||
ctx context.Context
|
||||
@@ -85,9 +87,19 @@ func NewSignaler(
|
||||
config = &SignalerConfig{}
|
||||
}
|
||||
|
||||
// 检测是否为SQLite URL
|
||||
sqliteURL := ""
|
||||
postgresURL := dbURL
|
||||
|
||||
if strings.HasPrefix(dbURL, "sqlite://") {
|
||||
sqliteURL = strings.TrimPrefix(dbURL, "sqlite://")
|
||||
postgresURL = ""
|
||||
}
|
||||
|
||||
return &Signaler{
|
||||
laddr: laddr,
|
||||
postgresURL: dbURL,
|
||||
postgresURL: postgresURL,
|
||||
sqliteURL: sqliteURL,
|
||||
redisURL: brokerURL,
|
||||
config: config,
|
||||
ctx: ctx,
|
||||
@@ -112,14 +124,25 @@ func (s *Signaler) Open() error {
|
||||
log.Debug().Msg("API password not set, disabling management API")
|
||||
}
|
||||
|
||||
if strings.TrimSpace(s.postgresURL) == "" {
|
||||
if strings.TrimSpace(s.postgresURL) == "" && strings.TrimSpace(s.sqliteURL) == "" {
|
||||
s.db = memory.NewCommunitiesPersister()
|
||||
log.Debug().Msg("Using in-memory database")
|
||||
} else if strings.TrimSpace(s.sqliteURL) != "" {
|
||||
s.db = sqlite.NewCommunitiesPersister()
|
||||
log.Debug().Msg("Using SQLite database")
|
||||
} else {
|
||||
s.db = psql.NewCommunitiesPersister()
|
||||
log.Debug().Msg("Using PostgreSQL database")
|
||||
}
|
||||
|
||||
if err := s.db.Open(s.postgresURL); err != nil {
|
||||
return err
|
||||
if strings.TrimSpace(s.sqliteURL) != "" {
|
||||
if err := s.db.Open(s.sqliteURL); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := s.db.Open(s.postgresURL); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if s.config.Cleanup {
|
||||
|
BIN
weron_communities.db
Normal file
BIN
weron_communities.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user