merge from x/sqlc

r/paopao-ce-xtra
Michael Li 3 years ago
commit 96a9d9bc22
No known key found for this signature in database

@ -69,7 +69,7 @@ windows-x64:
@CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=amd64 go build -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $(RELEASE_WINDOWS_AMD64)/$(basename $(TARGET)).exe
.PHONY: generate
generate: gen-mir gen-grpc gen-yesql
generate: gen-mir gen-grpc gen-sqlc gen-yesql
.PHONY: gen-mir
gen-mir:
@ -87,6 +87,12 @@ gen-grpc:
@buf generate proto
@go fmt ./auto/rpc/...
.PHONY: gen-sqlc
gen-sqlc:
@find internal/dao/slonik/sqlc/postgres -name '*.go' -exec rm -f {} +
@go generate internal/dao/slonik/sqlc/gen.go
@go fmt ./internal/dao/slonik/sqlc/...
.PHONY: proto-mod
proto-mod:
@cd proto/ && buf mod update
@ -112,6 +118,10 @@ test:
pre-commit: fmt
@go mod tidy
.PHONY: install-plugins
install-plugins: install-protobuf-plugins
.PHONY: install-protobuf-plugins
install-protobuf-plugins:
@go install github.com/bufbuild/buf/cmd/buf@v1.15.1
@ -120,6 +130,10 @@ install-protobuf-plugins:
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
.PHONY: install-sqlc-plugins
install-sqlc-plugins:
@go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
help:
@echo "make: make"
@echo "make run: start api server"

@ -48,12 +48,17 @@
#### 数据库:
* `Gorm` + `MySQL`/`Sqlite3`/`PostgreSQL`
使用[gorm](https://github.com/go-gorm/gorm)作为数据库的ORM默认使用 `Grom` + `MySQL`组合(目前状态:稳定,默认,推荐使用)
使用[gorm](https://github.com/go-gorm/gorm)作为数据库的ORM默认使用 `Grom` + `MySQL`组合(目前状态:稳定,默认,推荐使用)
* [ ] 提按文档
* [x] 接口定义
* [x] 业务逻辑实现
* `Sqlx` + `MySQL`/`PostgreSQL`
使用[sqlx](https://github.com/jmoiron/sqlx)作为数据库的ORM(目前状态WIP)
* `Sqlx` + `MySQL`/`Sqlite3`/`PostgreSQL`
使用[sqlx](https://github.com/jmoiron/sqlx)作为数据库的ORM(目前状态WIP)
* [ ] 提按文档
* [ ] 接口定义
* [ ] 业务逻辑实现
* `Sqlc` + `PostgreSQL`
使用[sqlc](https://github.com/kyleconroy/sqlc)自动生成ORM代码(目前状态WIP)
* [ ] 提按文档
* [ ] 接口定义
* [ ] 业务逻辑实现

@ -21,8 +21,10 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-migrate/migrate/v4 v4.15.2
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.3+incompatible
github.com/jackc/pgx/v5 v5.3.1
github.com/jmoiron/sqlx v1.3.5
github.com/json-iterator/go v1.1.12
github.com/kyleconroy/sqlc v1.17.2
github.com/meilisearch/meilisearch-go v0.21.0
github.com/minio/minio-go/v7 v7.0.49
github.com/onsi/ginkgo/v2 v2.9.2
@ -51,8 +53,14 @@ require (
require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220626175859-9abda183db8e // indirect
github.com/benbjohnson/clock v1.1.0 // indirect
github.com/bytecodealliance/wasmtime-go/v5 v5.0.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/cubicdaiya/gonp v1.0.4 // indirect
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
@ -71,18 +79,17 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.3.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lib/pq v1.10.2 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
@ -93,8 +100,12 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mozillazg/go-httpheader v0.3.1 // indirect
github.com/mozillazg/go-httpheader v0.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pganalyze/pg_query_go/v2 v2.2.0 // indirect
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354 // indirect
github.com/pingcap/tidb/parser v0.0.0-20220725134311-c80026e61f00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pyroscope-io/godeltaprof v0.1.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
@ -102,6 +113,7 @@ require (
github.com/smartwalle/crypto4go v1.0.2 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
@ -109,12 +121,16 @@ require (
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 // indirect
golang.org/x/image v0.0.0-20210216034530-4410531fe030 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.1.0 // indirect

@ -136,6 +136,8 @@ github.com/allegro/bigcache/v3 v3.0.2/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpx
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220626175859-9abda183db8e h1:bt6SW1eSSvdmmsG0KqyxYXorcTnFBTX7hfVR1+68+jg=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220626175859-9abda183db8e/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/apache/arrow/go/arrow v0.0.0-20210818145353-234c94e4ce64/go.mod h1:2qMFB56yOP3KzkB3PbYZ4AlUFg3a88F67TIx5lB/WwY=
github.com/apache/arrow/go/arrow v0.0.0-20211013220434-5962184e7a30/go.mod h1:Q7yQnSMnLvcXlZ8RV+jwz/6y1rQTqbX6C82SndT52Zs=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
@ -172,6 +174,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.7.2/go.mod h1:8EzeIqfWt2wWT4rJVu3f21
github.com/aws/smithy-go v1.7.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
@ -192,6 +196,8 @@ github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx2
github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/bytecodealliance/wasmtime-go/v5 v5.0.0 h1:Ue3eBDElMrdzWoUtr7uPr7NeDZriuR5oIivp5EHknQU=
github.com/bytecodealliance/wasmtime-go/v5 v5.0.0/go.mod h1:KcecyOqumZrvLnlaEIMFRbBaQeUYNvsbPjAEVho1Fcs=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.8.5 h1:kjX0/vo5acEQ/sinD/18SkA/lDDUk23F0RcaHvI7omc=
github.com/bytedance/sonic v1.8.5/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
@ -356,12 +362,17 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cubicdaiya/gonp v1.0.4 h1:ky2uIAJh81WiLcGKBVD5R7KsM/36W6IqqTy6Bo6rGws=
github.com/cubicdaiya/gonp v1.0.4/go.mod h1:iWGuP/7+JVTn02OWhRemVbMmG1DOUnmrGTYYACpOI0I=
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM=
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1vaoKsclOGD3ADKpshg3SRtYBbwso=
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM=
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c/go.mod h1:Ct2BUK8SB0YC1SMSibvLzxjeJLnrYEVLULFNiHY9YfQ=
github.com/d2g/dhcp4client v1.0.0/go.mod h1:j0hNfjhrt2SxUOw55nL0ATM/z4Yt3t2Kd1mW34z5W5s=
github.com/d2g/dhcp4server v0.0.0-20181031114812-7d4a0a7f59a5/go.mod h1:Eo87+Kg/IX2hfWJfwxMzLyuSZyxSoAug2nGa1G2QAi8=
@ -728,6 +739,8 @@ github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/intel/goresctrl v0.2.0/go.mod h1:+CZdzouYFn5EsxgqAQTEzMfwKwuc0fVdMrT9FCCAVRQ=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
github.com/j-keck/arping v1.0.2/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw=
@ -772,8 +785,9 @@ github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXg
github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o=
github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg=
github.com/jackc/pgx/v4 v4.10.1/go.mod h1:QlrWebbs3kqEZPHCTGyxecvzG6tvIsYu+A5b1raylkA=
github.com/jackc/pgx/v5 v5.3.0 h1:/NQi8KHMpKWHInxXesC8yD4DhkXPrVhmnwYkjp9AmBA=
github.com/jackc/pgx/v5 v5.3.0/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8=
github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU=
github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8=
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=
@ -849,9 +863,8 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
@ -859,6 +872,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/ktrysmt/go-bitbucket v0.6.4/go.mod h1:9u0v3hsd2rqCHRIpbir1oP7F58uo5dq19sBYvuMoyQ4=
github.com/kyleconroy/sqlc v1.17.2 h1:aFXblbzJTCHy0S8zWgF+6hMwc6ezxtwBfmjxoBCuv/8=
github.com/kyleconroy/sqlc v1.17.2/go.mod h1:tZo5IZRJSjGiQGuFD6nqRcVThyPQ+D5HOzHEXXzOo8M=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
@ -867,8 +882,8 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3/go.mod h1:3r6x7q95whyfWQpmGZTu3gk3v2YkMi05HEzl7Tf7YEo=
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
@ -964,9 +979,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/mozillazg/go-httpheader v0.2.1 h1:geV7TrjbL8KXSyvghnFm+NyTux/hxwueTSrwhe88TQQ=
github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60=
github.com/mozillazg/go-httpheader v0.3.1 h1:IRP+HFrMX2SlwY9riuio7raffXUpzAosHtZu25BSJok=
github.com/mozillazg/go-httpheader v0.3.1/go.mod h1:PuT8h0pw6efvp8ZeUec1Rs7dwjK08bt6gKSReGMqtdA=
github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
@ -1046,10 +1060,19 @@ github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZO
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pganalyze/pg_query_go/v2 v2.2.0 h1:OW+reH+ZY7jdEuPyuLGlf1m7dLbE+fDudKXhLs0Ttpk=
github.com/pganalyze/pg_query_go/v2 v2.2.0/go.mod h1:XAxmVqz1tEGqizcQ3YSdN90vCOHBWjJi8URL1er5+cA=
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4/v4 v4.1.8/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 h1:+FZIDR/D97YOPik4N4lPDaUcLDF/EQPogxtlHB2ZZRM=
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354 h1:SvWCbCPh1YeHd9yQLksvJYAgft6wLTY1aNG81tpyscQ=
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
github.com/pingcap/tidb/parser v0.0.0-20220725134311-c80026e61f00 h1:aDC/yAGx/jPEyrX+UPKV3GWg+4A4yG8ifuP6jBEhDi0=
github.com/pingcap/tidb/parser v0.0.0-20220725134311-c80026e61f00/go.mod h1:wjvp+T3/T9XYt0nKqGX3Kc1AKuyUcfno6LTc6b2A6ew=
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@ -1114,7 +1137,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
@ -1123,6 +1145,7 @@ github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThC
github.com/rueian/rueidis v0.0.97 h1:b3jo3CatMd7Jak+Sbz8sPpasdUY/BziBsSjdzT5GQvc=
github.com/rueian/rueidis v0.0.97/go.mod h1:ivvsRYRtAUcf9OnheuKc5Gpa8IebrkLT1P45Lr2jlXE=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
@ -1174,6 +1197,8 @@ github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKv
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
@ -1317,19 +1342,27 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME=
go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@ -1377,6 +1410,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4=
golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
@ -1386,9 +1421,8 @@ golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+o
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210216034530-4410531fe030 h1:lP9pYkih3DUSC641giIXa2XqfTIbbbRr0w2EOTA7wHA=
golang.org/x/image v0.0.0-20210216034530-4410531fe030/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 h1:LRtI4W37N+KFebI/qV0OFiLUv4GLOWeEW5hn/KEJvxE=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@ -1979,6 +2013,7 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/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 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

@ -0,0 +1,29 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package conf
import (
"context"
"sync"
"github.com/jackc/pgx/v5"
"github.com/sirupsen/logrus"
)
var (
_pgxDB *pgx.Conn
_oncePgx sync.Once
)
func MustPgxDB() *pgx.Conn {
_oncePgx.Do(func() {
conn, err := pgx.Connect(context.Background(), PostgresSetting.Dsn())
if err != nil {
logrus.Fatalf("pgx.Connect occurs error: %s", err)
}
_pgxDB = conn
})
return _pgxDB
}

@ -0,0 +1,55 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.AuthorizationManageService = (*authorizationManageSrv)(nil)
)
type authorizationManageSrv struct {
*pgxSrv
}
func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) bool {
// TODO
debug.NotImplemented()
return false
}
func (s *authorizationManageSrv) MyFriendSet(userId int64) core.FriendSet {
// TODO
debug.NotImplemented()
return nil
}
func (s *authorizationManageSrv) BeFriendFilter(userId int64) core.FriendFilter {
// TODO
debug.NotImplemented()
return nil
}
func (s *authorizationManageSrv) BeFriendIds(userId int64) ([]int64, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *authorizationManageSrv) isFriend(userId int64, friendId int64) bool {
// TODO
debug.NotImplemented()
return false
}
func newAuthorizationManageService(db *pgx.Conn) core.AuthorizationManageService {
return &authorizationManageSrv{
pgxSrv: newPgxSrv(db),
}
}

@ -0,0 +1,102 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.CommentService = (*commentSrv)(nil)
_ core.CommentManageService = (*commentManageSrv)(nil)
)
type commentSrv struct {
*pgxSrv
}
type commentManageSrv struct {
*pgxSrv
}
func (s *commentSrv) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentSrv) GetCommentByID(id int64) (*core.Comment, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentSrv) GetCommentReplyByID(id int64) (*core.CommentReply, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentSrv) GetCommentCount(conditions *core.ConditionsT) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentManageSrv) DeleteComment(comment *core.Comment) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *commentManageSrv) CreateComment(comment *core.Comment) (*core.Comment, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentManageSrv) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentManageSrv) DeleteCommentReply(reply *core.CommentReply) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *commentManageSrv) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func newCommentService(db *pgx.Conn) core.CommentService {
return &commentSrv{
pgxSrv: newPgxSrv(db),
}
}
func newCommentManageService(db *pgx.Conn) core.CommentManageService {
return &commentManageSrv{
pgxSrv: newPgxSrv(db),
}
}

@ -0,0 +1,61 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.ContactManageService = (*contactManageSrv)(nil)
)
type contactManageSrv struct {
*pgxSrv
}
func (s *contactManageSrv) RequestingFriend(userId int64, friendId int64, greetings string) (err error) {
// TODO
debug.NotImplemented()
return nil
}
func (s *contactManageSrv) AddFriend(userId int64, friendId int64) (err error) {
// TODO
debug.NotImplemented()
return nil
}
func (s *contactManageSrv) RejectFriend(userId int64, friendId int64) (err error) {
// TODO
debug.NotImplemented()
return nil
}
func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error) {
// TODO
debug.NotImplemented()
return nil
}
func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *contactManageSrv) IsFriend(userId int64, friendId int64) bool {
// TODO
debug.NotImplemented()
return false
}
func newContactManageService(db *pgx.Conn) core.ContactManageService {
return &contactManageSrv{
pgxSrv: newPgxSrv(db),
}
}

@ -0,0 +1,15 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
//go:build migration
// +build migration
package slonik
import (
"embed"
)
//go:embed sqlc/postgres/schema
var Files embed.FS

@ -0,0 +1,61 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.MessageService = (*messageSrv)(nil)
)
type messageSrv struct {
*pgxSrv
}
func (s *messageSrv) CreateMessage(msg *core.Message) (*core.Message, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *messageSrv) GetUnreadCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *messageSrv) GetMessageByID(id int64) (*core.Message, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *messageSrv) ReadMessage(message *core.Message) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *messageSrv) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *messageSrv) GetMessageCount(conditions *core.ConditionsT) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func newMessageService(db *pgx.Conn) core.MessageService {
return &messageSrv{
pgxSrv: newPgxSrv(db),
}
}

@ -0,0 +1,104 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"context"
"sync"
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/conf"
dbr "github.com/rocboss/paopao-ce/internal/dao/slonik/sqlc/postgres"
)
var (
_pgxDB *pgx.Conn
_oncePgx sync.Once
)
type pgxSrv struct {
db *pgx.Conn
q dbr.Querier
}
func (s *pgxSrv) begin(ctx context.Context) (pgx.Tx, dbr.Querier, error) {
tx, err := s.db.Begin(ctx)
if err != nil {
return nil, nil, err
}
return tx, dbr.New(tx), nil
}
func (s *pgxSrv) beingTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, dbr.Querier, error) {
tx, err := s.db.BeginTx(ctx, txOptions)
if err != nil {
return nil, nil, err
}
return tx, dbr.New(tx), nil
}
func (s *pgxSrv) with(handle func(c context.Context, q dbr.Querier) error) error {
ctx := context.Background()
tx, err := s.db.Begin(ctx)
if err != nil {
return err
}
defer tx.Rollback(ctx)
if err = handle(ctx, dbr.New(tx)); err != nil {
return err
}
return tx.Commit(ctx)
}
func (s *pgxSrv) withTx(txOptions pgx.TxOptions, handle func(ctx context.Context, q dbr.Querier) error) error {
ctx := context.Background()
tx, err := s.db.BeginTx(ctx, txOptions)
if err != nil {
return err
}
defer tx.Rollback(ctx)
if err = handle(ctx, dbr.New(tx)); err != nil {
return err
}
return tx.Commit(ctx)
}
func (s *pgxSrv) withCtx(ctx context.Context, handle func(dbr.Querier) error) error {
tx, err := s.db.Begin(ctx)
if err != nil {
return err
}
defer tx.Rollback(ctx)
if err = handle(dbr.New(tx)); err != nil {
return err
}
return tx.Commit(ctx)
}
func (s *pgxSrv) withTxCtx(ctx context.Context, txOptions pgx.TxOptions, handle func(dbr.Querier) error) error {
tx, err := s.db.BeginTx(ctx, txOptions)
if err != nil {
return err
}
defer tx.Rollback(ctx)
if err = handle(dbr.New(tx)); err != nil {
return err
}
return tx.Commit(ctx)
}
func newPgxSrv(db *pgx.Conn) *pgxSrv {
return &pgxSrv{
db: db,
q: dbr.New(db),
}
}
func pgxDB() *pgx.Conn {
_oncePgx.Do(func() {
_pgxDB = conf.MustPgxDB()
})
return _pgxDB
}

@ -0,0 +1,46 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.SecurityService = (*securitySrv)(nil)
)
type securitySrv struct {
*pgxSrv
}
// GetLatestPhoneCaptcha 获取最新短信验证码
func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
// UsePhoneCaptcha 更新短信验证码
func (s *securitySrv) UsePhoneCaptcha(captcha *core.Captcha) error {
// TODO
debug.NotImplemented()
return nil
}
// SendPhoneCaptcha 发送短信验证码
func (s *securitySrv) SendPhoneCaptcha(phone string) error {
// TODO
debug.NotImplemented()
return nil
}
func newSecurityService(db *pgx.Conn, phoneVerify core.PhoneVerifyService) core.SecurityService {
return &securitySrv{
pgxSrv: newPgxSrv(db),
}
}

@ -1,20 +1,108 @@
// Copyright 2022 ROC. All rights reserved.
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
// Core service implement base sqlx+postgresql. All sub-service
// will declare here and provide initial function.
package slonik
import (
"github.com/Masterminds/semver/v3"
"github.com/alimy/cfg"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/dao/cache"
"github.com/rocboss/paopao-ce/internal/dao/security"
"github.com/sirupsen/logrus"
)
var (
_ core.DataService = (*dataSrv)(nil)
_ core.VersionInfo = (*dataSrv)(nil)
_ core.WebDataServantA = (*webDataSrvA)(nil)
_ core.VersionInfo = (*webDataSrvA)(nil)
)
type dataSrv struct {
core.IndexPostsService
core.WalletService
core.MessageService
core.TopicService
core.TweetService
core.TweetManageService
core.TweetHelpService
core.CommentService
core.CommentManageService
core.UserManageService
core.ContactManageService
core.SecurityService
core.AttachmentCheckService
}
type webDataSrvA struct {
core.TopicServantA
core.TweetServantA
core.TweetManageServantA
core.TweetHelpServantA
}
func NewDataService() (core.DataService, core.VersionInfo) {
logrus.Fatal("not support now")
return nil, nil
var (
v core.VersionInfo
cis core.CacheIndexService
ips core.IndexPostsService
)
db := pgxDB()
pvs := security.NewPhoneVerifyService()
ams := NewAuthorizationManageService()
ths := newTweetHelpService(db)
// initialize core.IndexPostsService
if cfg.If("Friendship") {
ips = newFriendIndexService(db, ams, ths)
} else if cfg.If("Followship") {
ips = newFollowIndexService(db, ths)
} else if cfg.If("Lightship") {
ips = newLightIndexService(db, ths)
} else {
// default use lightship post index service
ips = newLightIndexService(db, ths)
}
// initialize core.CacheIndexService
cfg.On(cfg.Actions{
"SimpleCacheIndex": func() {
// simpleCache use special post index service
ips = newSimpleIndexPostsService(db, ths)
cis, v = cache.NewSimpleCacheIndexService(ips)
},
"BigCacheIndex": func() {
// TODO: make cache index post in different scence like friendship/followship/lightship
cis, v = cache.NewBigCacheIndexService(ips, ams)
},
"RedisCacheIndex": func() {
cis, v = cache.NewRedisCacheIndexService(ips, ams)
},
}, func() {
// defualt no cache
cis, v = cache.NewNoneCacheIndexService(ips)
})
logrus.Infof("use %s as cache index service by version: %s", v.Name(), v.Version())
ds := &dataSrv{
IndexPostsService: cis,
WalletService: newWalletService(db),
MessageService: newMessageService(db),
TopicService: newTopicService(db),
TweetService: newTweetService(db),
TweetManageService: newTweetManageService(db, cis),
TweetHelpService: newTweetHelpService(db),
CommentService: newCommentService(db),
CommentManageService: newCommentManageService(db),
UserManageService: newUserManageService(db),
ContactManageService: newContactManageService(db),
SecurityService: newSecurityService(db, pvs),
AttachmentCheckService: security.NewAttachmentCheckService(),
}
return ds, ds
}
func NewWebDataServantA() (core.WebDataServantA, core.VersionInfo) {
@ -23,6 +111,21 @@ func NewWebDataServantA() (core.WebDataServantA, core.VersionInfo) {
}
func NewAuthorizationManageService() core.AuthorizationManageService {
logrus.Fatal("not support now")
return nil
return newAuthorizationManageService(pgxDB())
}
func (s *dataSrv) Name() string {
return "sqlc/pgx"
}
func (s *dataSrv) Version() *semver.Version {
return semver.MustParse("v0.1.0")
}
func (s *webDataSrvA) Name() string {
return "sqlc/pgx"
}
func (s *webDataSrvA) Version() *semver.Version {
return semver.MustParse("v0.1.0")
}

@ -0,0 +1,15 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package main
import (
"os"
sqlc "github.com/kyleconroy/sqlc/pkg/cli"
)
//go:generate go run $GOFILE generate -x
func main() {
os.Exit(sqlc.Run(os.Args[1:]))
}

@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.17.2
package dbr
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}

@ -0,0 +1,239 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.17.2
package dbr
import (
"github.com/jackc/pgx/v5/pgtype"
)
type PAttachment struct {
ID int64
UserID int64
FileSize int64
ImgWidth int64
ImgHeight int64
Type int16
Content string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PCaptcha struct {
ID int64
Phone pgtype.Text
Captcha pgtype.Text
UseTimes int32
ExpiredOn int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PComment struct {
ID int64
PostID int64
UserID int64
Ip string
IpLoc string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PCommentContent struct {
ID int64
CommentID int64
UserID int64
Content string
Type int16
Sort int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PCommentReply struct {
ID int64
CommentID int64
UserID int64
AtUserID int64
Content string
Ip string
IpLoc string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PContact struct {
ID int64
UserID int64
FriendID int64
GroupID int64
Remark string
Status int16
IsTop int16
IsBlack int16
IsDel int16
NoticeEnable int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PContactGroup struct {
ID int64
UserID int32
Name string
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PMessage struct {
ID int64
SenderUserID int64
ReceiverUserID int64
Type int16
Brief string
Content string
PostID int64
CommentID int64
ReplyID int64
IsRead int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PPost struct {
ID int64
UserID int64
CommentCount int64
CollectionCount int64
UpvoteCount int64
IsTop int16
IsEssence int16
IsLock int16
LatestRepliedOn int64
Tags string
AttachmentPrice int64
Ip string
IpLoc string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
Visibility int16
}
type PPostAttachmentBill struct {
ID int64
PostID int64
UserID int64
PaidAmount int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PPostCollection struct {
ID int64
PostID int64
UserID int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PPostContent struct {
ID int64
PostID int64
UserID int64
Content string
Type int16
Sort int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PPostStar struct {
ID int64
PostID int64
UserID int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PTag struct {
ID int64
UserID int64
Tag string
QuoteNum int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
// 用户
type PUser struct {
ID int64
Nickname string
Username string
Phone string
// MD5密码
Password string
Salt string
// 状态, 1正常, 2停用
Status int16
Avatar string
// 用户余额(分)
Balance int64
IsAdmin bool
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PWalletRecharge struct {
ID int64
UserID int64
Amount int64
TradeNo string
TradeStatus string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PWalletStatement struct {
ID int64
UserID int64
ChangeAmount int64
BalanceSnapshot int64
Reason string
PostID int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}

@ -0,0 +1,21 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.17.2
package dbr
import (
"context"
)
type Querier interface {
DecrTagsById(ctx context.Context, arg *DecrTagsByIdParams) error
HotTags(ctx context.Context, arg *HotTagsParams) ([]*HotTagsRow, error)
IncrTags(ctx context.Context, arg *IncrTagsParams) ([]*IncrTagsRow, error)
InsertTags(ctx context.Context, arg *InsertTagsParams) (int64, error)
NewestTags(ctx context.Context, arg *NewestTagsParams) ([]*NewestTagsRow, error)
TagsByKeywordA(ctx context.Context) ([]*TagsByKeywordARow, error)
TagsByKeywordB(ctx context.Context, tag string) ([]*TagsByKeywordBRow, error)
}
var _ Querier = (*Queries)(nil)

@ -0,0 +1,54 @@
-- name: NewestTags :many
SELECT t.id, t.tag, t.quote_num, u.id user_id, u.nickname, u.username, u.status, u.avatar, u.is_admin
FROM p_tag t JOIN p_user u ON t.user_id = u.id
WHERE t.is_del = false AND t.quote_num > 0
ORDER BY t.id DESC
OFFSET $1 LIMIT $2;
-- name: HotTags :many
SELECT t.id, t.tag, t.quote_num, u.id user_id, u.nickname, u.username, u.status, u.avatar, u.is_admin
FROM p_tag t JOIN p_user u ON t.user_id = u.id
WHERE t.is_del = false AND t.quote_num > 0
ORDER BY quote_num DESC
OFFSET $1 LIMIT $2;
-- name: TagsByKeywordA :many
SELECT id, user_id, tag, quote_num
FROM p_tag
WHERE is_del AND quote_num > 0
ORDER BY quote_num DESC
OFFSET 0 LIMIT 6;
-- name: TagsByKeywordB :many
SELECT id, user_id, tag, quote_num
FROM p_tag
WHERE is_del = false AND tag LIKE $1
ORDER BY quote_num DESC
OFFSET 0 LIMIT 6;
-- name: InsertTags :one
INSERT INTO p_tag (user_id, tag, created_on, modified_on, quote_num)
VALUES ($1, $2, $3, $3, 1)
RETURNING id;
-- name: DecrTagsById :exec
UPDATE p_tag
SET quote_num = quote_num-1,
modified_on=$1
WHERE id IN (
SELECT id
FROM p_tag
WHERE id = ANY(@ids::BIGINT[]) AND is_del = false AND quote_num >= 1
);
-- name: IncrTags :many
UPDATE p_tag
SET quote_num = quote_num+1,
modified_on = $1,
id_del = false
WHERE id IN (
SELECT id
FROM p_tag
WHERE tag = ANY(@tags::VARCHAR[])
)
RETURNING id, user_id, tag, quote_num;

@ -0,0 +1,17 @@
DROP TABLE IF EXISTS p_attachment;
DROP TABLE IF EXISTS p_captcha;
DROP TABLE IF EXISTS p_comment;
DROP TABLE IF EXISTS p_comment_content;
DROP TABLE IF EXISTS p_comment_reply;
DROP TABLE IF EXISTS p_message;
DROP TABLE IF EXISTS p_post;
DROP TABLE IF EXISTS p_post_attachment_bill;
DROP TABLE IF EXISTS p_post_collection;
DROP TABLE IF EXISTS p_post_content;
DROP TABLE IF EXISTS p_post_star;
DROP TABLE IF EXISTS p_tag;
DROP TABLE IF EXISTS p_user;
DROP TABLE IF EXISTS p_wallet_recharge;
DROP TABLE IF EXISTS p_wallet_statement;
DROP SEQUENCE IF EXISTS post_id_seq;

@ -0,0 +1,236 @@
CREATE TABLE p_attachment (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL DEFAULT 0,
file_size BIGINT NOT NULL,
img_width BIGINT NOT NULL DEFAULT 0,
img_height BIGINT NOT NULL DEFAULT 0,
"type" SMALLINT NOT NULL DEFAULT 1, -- 1图片、2视频、3其他附件
content VARCHAR(255) NOT NULL DEFAULT '',
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0 -- 是否删除 0为未删除、1为已删除
);
CREATE INDEX idx_attachment_user_id ON p_attachment USING btree (id);
CREATE TABLE p_captcha (
id BIGSERIAL PRIMARY KEY,
phone VARCHAR(16),
captcha VARCHAR(16),
use_times INTEGER NOT NULL DEFAULT 0,
expired_on BIGINT NOT NULL DEFAULT 0,
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0 -- 是否删除 0为未删除、1为已删除'
);
CREATE INDEX idx_captcha_phone ON p_captcha USING btree (phone);
CREATE INDEX idx_captcha_expired_on ON p_captcha USING btree (expired_on);
CREATE INDEX idx_captcha_use_times ON p_captcha USING btree (use_times);
CREATE TABLE p_comment (
id BIGSERIAL PRIMARY KEY,
post_id BIGINT NOT NULL DEFAULT 0,
user_id BIGINT NOT NULL DEFAULT 0,
ip VARCHAR(64) NOT NULL DEFAULT '',
ip_loc VARCHAR(64) NOT NULL DEFAULT '',
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_comment_post_id ON p_comment USING btree (post_id);
CREATE INDEX idx_comment_user_id ON p_comment USING btree (user_id);
CREATE TABLE p_comment_content (
id BIGSERIAL PRIMARY KEY,
comment_id BIGINT NOT NULL DEFAULT 0,
user_id BIGINT NOT NULL DEFAULT 0,
content VARCHAR(255) NOT NULL DEFAULT '',
"type" SMALLINT NOT NULL DEFAULT 2, -- 类型1标题2文字段落3图片地址4视频地址5语音地址6链接地址,
sort BIGINT NOT NULL DEFAULT 100,
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_comment_content_comment_id ON p_comment_content USING btree (comment_id);
CREATE INDEX idx_comment_content_user_id ON p_comment_content USING btree (user_id);
CREATE INDEX idx_comment_content_type ON p_comment_content USING btree ("type");
CREATE INDEX idx_comment_content_sort ON p_comment_content USING btree (sort);
CREATE TABLE p_comment_reply (
id BIGSERIAL PRIMARY KEY,
comment_id BIGINT NOT NULL DEFAULT 0,
user_id BIGINT NOT NULL DEFAULT 0,
at_user_id BIGINT NOT NULL DEFAULT 0,
content VARCHAR(255) NOT NULL DEFAULT '',
ip VARCHAR(64) NOT NULL DEFAULT '',
ip_loc VARCHAR(64) NOT NULL DEFAULT '',
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_comment_reply_comment_id ON p_comment_reply USING btree (comment_id);
CREATE TABLE p_message (
id BIGSERIAL PRIMARY KEY,
sender_user_id BIGINT NOT NULL DEFAULT 0,
receiver_user_id BIGINT NOT NULL DEFAULT 0,
type SMALLINT NOT NULL DEFAULT 1,
brief VARCHAR(255) NOT NULL DEFAULT '',
content VARCHAR(255) NOT NULL DEFAULT '',
post_id BIGINT NOT NULL DEFAULT 0,
comment_id BIGINT NOT NULL DEFAULT 0,
reply_id BIGINT NOT NULL DEFAULT 0,
is_read SMALLINT NOT NULL DEFAULT 0,
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_message_receiver_user_id ON p_message USING btree (receiver_user_id);
CREATE INDEX idx_message_is_read ON p_message USING btree (is_read);
CREATE INDEX idx_message_type ON p_message USING btree ("type");
CREATE SEQUENCE IF NOT EXISTS post_id_seq AS BIGINT MINVALUE 1080017989 NO MAXVALUE;
CREATE TABLE p_post (
id BIGINT NOT NULL DEFAULT nextval('post_id_seq'::regclass),
user_id BIGINT NOT NULL DEFAULT 0,
comment_count BIGINT NOT NULL DEFAULT 0,
collection_count BIGINT NOT NULL DEFAULT 0,
upvote_count BIGINT NOT NULL DEFAULT 0,
is_top SMALLINT NOT NULL DEFAULT 0, -- 是否置顶
is_essence SMALLINT NOT NULL DEFAULT 0, -- 是否精华
is_lock SMALLINT NOT NULL DEFAULT 0, -- 是否锁定
latest_replied_on BIGINT NOT NULL DEFAULT 0, -- 最新回复时间
tags VARCHAR(255) NOT NULL DEFAULT '',
attachment_price BIGINT NOT NULL DEFAULT 0, -- 附件价格(分)
ip VARCHAR(64) NOT NULL DEFAULT '', -- IP地址
ip_loc VARCHAR(64) NOT NULL DEFAULT '', -- IP城市地址
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);
CREATE INDEX idx_post_user_id ON p_post USING btree (user_id);
CREATE TABLE p_post_attachment_bill (
id BIGSERIAL PRIMARY KEY,
post_id BIGINT NOT NULL DEFAULT 0,
user_id BIGINT NOT NULL DEFAULT 0,
paid_amount BIGINT NOT NULL DEFAULT 0, -- 支付金额
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_post_attachment_bill_post_id ON p_post_attachment_bill USING btree (post_id);
CREATE INDEX idx_post_attachment_bill_user_id ON p_post_attachment_bill USING btree (user_id);
CREATE TABLE p_post_collection (
id BIGSERIAL PRIMARY KEY,
post_id BIGINT NOT NULL DEFAULT 0,
user_id BIGINT NOT NULL DEFAULT 0,
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_post_collection_post_id ON p_post_collection USING btree (post_id);
CREATE INDEX idx_post_collection_user_id ON p_post_collection USING btree (user_id);
CREATE TABLE p_post_content (
id BIGSERIAL PRIMARY KEY,
post_id BIGINT NOT NULL DEFAULT 0,
user_id BIGINT NOT NULL DEFAULT 0,
content VARCHAR(2000) NOT NULL DEFAULT '',
"type" SMALLINT NOT NULL DEFAULT 2, -- 类型1标题2文字段落3图片地址4视频地址5语音地址6链接地址7附件资源8收费资源
sort SMALLINT NOT NULL DEFAULT 100,
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_post_content_post_id ON p_post_content USING btree (post_id);
CREATE INDEX idx_post_content_user_id ON p_post_content USING btree (user_id);
CREATE TABLE p_post_star (
id BIGSERIAL PRIMARY KEY,
post_id BIGINT NOT NULL DEFAULT 0,
user_id BIGINT NOT NULL DEFAULT 0,
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_post_star_post_id ON p_post_star USING btree (post_id);
CREATE INDEX idx_post_star_user_id ON p_post_star USING btree (user_id);
CREATE TABLE p_tag (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL DEFAULT 0,
tag VARCHAR(255) NOT NULL,
quote_num BIGINT NOT NULL DEFAULT 0, -- 引用数
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE UNIQUE INDEX idx_tag_tag ON p_tag USING btree (tag);
CREATE INDEX idx_tag_user_id ON p_tag USING btree (user_id);
CREATE INDEX idx_tag_quote_num ON p_tag USING btree (quote_num);
CREATE TABLE p_user (
id BIGSERIAL PRIMARY KEY,
nickname VARCHAR(32) NOT NULL DEFAULT '',
username VARCHAR(32) NOT NULL DEFAULT '',
phone VARCHAR(16) NOT NULL DEFAULT '', -- 手机号
password VARCHAR(32) NOT NULL DEFAULT '', -- MD5密码
salt VARCHAR(16) NOT NULL DEFAULT '', -- 盐值
status SMALLINT NOT NULL DEFAULT 1, -- 状态1正常2停用
avatar VARCHAR(255) NOT NULL DEFAULT '',
balance BIGINT NOT NULL, -- 用户余额(分)
is_admin BOOLEAN NOT NULL DEFAULT false, -- 是否管理员
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
COMMENT ON TABLE p_user IS '用户';
COMMENT ON COLUMN p_user.password IS 'MD5密码';
COMMENT ON COLUMN p_user.status IS '状态, 1正常, 2停用';
COMMENT ON COLUMN p_user.balance IS '用户余额(分)';
CREATE UNIQUE INDEX idx_user_username ON p_user USING btree (username);
CREATE INDEX idx_user_phone ON p_user USING btree (phone);
CREATE TABLE p_wallet_recharge (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL DEFAULT 0,
amount BIGINT NOT NULL DEFAULT 0, -- 充值金额
trade_no VARCHAR(64) NOT NULL DEFAULT '', -- 支付宝订单号
trade_status VARCHAR(32) NOT NULL DEFAULT '', -- 交易状态
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0 -- 是否删除 0 为未删除、1 为已删除
);
CREATE INDEX idx_wallet_recharge_user_id ON p_wallet_recharge USING btree (user_id);
CREATE INDEX idx_wallet_recharge_trade_no ON p_wallet_recharge USING btree (trade_no);
CREATE INDEX idx_wallet_recharge_trade_status ON p_wallet_recharge USING btree (trade_status);
CREATE TABLE p_wallet_statement (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL DEFAULT 0,
change_amount BIGINT NOT NULL DEFAULT 0, -- 变动金额
balance_snapshot BIGINT NOT NULL DEFAULT 0, -- 资金快照
reason VARCHAR(255) NOT NULL, -- 变动原因
post_id BIGINT NOT NULL DEFAULT 0, -- 关联动态
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_wallet_statement_user_id ON p_wallet_statement USING btree (user_id);

@ -0,0 +1 @@
ALTER TABLE p_post ADD COLUMN visibility SMALLINT NOT NULL DEFAULT 0; -- 可见性 0公开 1私密 2好友可见

@ -0,0 +1,2 @@
DROP TABLE IF EXISTS p_contact;
DROP TABLE IF EXISTS p_contact_group;

@ -0,0 +1,27 @@
CREATE TABLE p_contact (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL,
friend_id BIGINT NOT NULL,
group_id BIGINT NOT NULL DEFAULT 0, -- 好友分组ID:默认为0无分组
remark VARCHAR(32) NOT NULL DEFAULT '', -- 好友备注
status SMALLINT NOT NULL DEFAULT 0, -- 好友状态: 1请求好友, 2已好友, 3拒绝好友, 4已删好友
is_top SMALLINT NOT NULL DEFAULT 0, -- 是否置顶, 0否, 1是
is_black SMALLINT NOT NULL DEFAULT 0, -- 是否为黑名单, 0否, 1是
is_del SMALLINT NOT NULL DEFAULT 0, -- 否删除好友, 0否, 1是
notice_enable SMALLINT NOT NULL DEFAULT 0, -- 是否有消息提醒, 0否, 1是
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0
);
CREATE UNIQUE INDEX idx_contact_user_friend ON p_contact USING btree (user_id,friend_id);
CREATE INDEX idx_contact_user_friend_status ON p_contact USING btree (user_id, friend_id, status);
CREATE TABLE p_contact_group (
id BIGSERIAL PRIMARY KEY,
user_id int NOT NULL DEFAULT 0,
name VARCHAR(32) NOT NULL DEFAULT '', -- 分组名称
is_del SMALLINT NOT NULL DEFAULT 1, -- 是否删除, 0否, 1是
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0
);

@ -0,0 +1,290 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.17.2
// source: topic.sql
package dbr
import (
"context"
)
const decrTagsById = `-- name: DecrTagsById :exec
UPDATE p_tag
SET quote_num = quote_num-1,
modified_on=$1
WHERE id IN (
SELECT id
FROM p_tag
WHERE id = ANY($2::BIGINT[]) AND is_del = false AND quote_num >= 1
)
`
type DecrTagsByIdParams struct {
ModifiedOn int64
Ids []int64
}
func (q *Queries) DecrTagsById(ctx context.Context, arg *DecrTagsByIdParams) error {
_, err := q.db.Exec(ctx, decrTagsById, arg.ModifiedOn, arg.Ids)
return err
}
const hotTags = `-- name: HotTags :many
SELECT t.id, t.tag, t.quote_num, u.id user_id, u.nickname, u.username, u.status, u.avatar, u.is_admin
FROM p_tag t JOIN p_user u ON t.user_id = u.id
WHERE t.is_del = false AND t.quote_num > 0
ORDER BY quote_num DESC
OFFSET $1 LIMIT $2
`
type HotTagsParams struct {
Offset int32
Limit int32
}
type HotTagsRow struct {
ID int64
Tag string
QuoteNum int64
UserID int64
Nickname string
Username string
Status int16
Avatar string
IsAdmin bool
}
func (q *Queries) HotTags(ctx context.Context, arg *HotTagsParams) ([]*HotTagsRow, error) {
rows, err := q.db.Query(ctx, hotTags, arg.Offset, arg.Limit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*HotTagsRow
for rows.Next() {
var i HotTagsRow
if err := rows.Scan(
&i.ID,
&i.Tag,
&i.QuoteNum,
&i.UserID,
&i.Nickname,
&i.Username,
&i.Status,
&i.Avatar,
&i.IsAdmin,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const incrTags = `-- name: IncrTags :many
UPDATE p_tag
SET quote_num = quote_num+1,
modified_on = $1,
id_del = false
WHERE id IN (
SELECT id
FROM p_tag
WHERE tag = ANY($2::VARCHAR[])
)
RETURNING id, user_id, tag, quote_num
`
type IncrTagsParams struct {
ModifiedOn int64
Tags []string
}
type IncrTagsRow struct {
ID int64
UserID int64
Tag string
QuoteNum int64
}
func (q *Queries) IncrTags(ctx context.Context, arg *IncrTagsParams) ([]*IncrTagsRow, error) {
rows, err := q.db.Query(ctx, incrTags, arg.ModifiedOn, arg.Tags)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*IncrTagsRow
for rows.Next() {
var i IncrTagsRow
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Tag,
&i.QuoteNum,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const insertTags = `-- name: InsertTags :one
INSERT INTO p_tag (user_id, tag, created_on, modified_on, quote_num)
VALUES ($1, $2, $3, $3, 1)
RETURNING id
`
type InsertTagsParams struct {
UserID int64
Tag string
CreatedOn int64
}
func (q *Queries) InsertTags(ctx context.Context, arg *InsertTagsParams) (int64, error) {
row := q.db.QueryRow(ctx, insertTags, arg.UserID, arg.Tag, arg.CreatedOn)
var id int64
err := row.Scan(&id)
return id, err
}
const newestTags = `-- name: NewestTags :many
SELECT t.id, t.tag, t.quote_num, u.id user_id, u.nickname, u.username, u.status, u.avatar, u.is_admin
FROM p_tag t JOIN p_user u ON t.user_id = u.id
WHERE t.is_del = false AND t.quote_num > 0
ORDER BY t.id DESC
OFFSET $1 LIMIT $2
`
type NewestTagsParams struct {
Offset int32
Limit int32
}
type NewestTagsRow struct {
ID int64
Tag string
QuoteNum int64
UserID int64
Nickname string
Username string
Status int16
Avatar string
IsAdmin bool
}
func (q *Queries) NewestTags(ctx context.Context, arg *NewestTagsParams) ([]*NewestTagsRow, error) {
rows, err := q.db.Query(ctx, newestTags, arg.Offset, arg.Limit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*NewestTagsRow
for rows.Next() {
var i NewestTagsRow
if err := rows.Scan(
&i.ID,
&i.Tag,
&i.QuoteNum,
&i.UserID,
&i.Nickname,
&i.Username,
&i.Status,
&i.Avatar,
&i.IsAdmin,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const tagsByKeywordA = `-- name: TagsByKeywordA :many
SELECT id, user_id, tag, quote_num
FROM p_tag
WHERE is_del AND quote_num > 0
ORDER BY quote_num DESC
OFFSET 0 LIMIT 6
`
type TagsByKeywordARow struct {
ID int64
UserID int64
Tag string
QuoteNum int64
}
func (q *Queries) TagsByKeywordA(ctx context.Context) ([]*TagsByKeywordARow, error) {
rows, err := q.db.Query(ctx, tagsByKeywordA)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*TagsByKeywordARow
for rows.Next() {
var i TagsByKeywordARow
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Tag,
&i.QuoteNum,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const tagsByKeywordB = `-- name: TagsByKeywordB :many
SELECT id, user_id, tag, quote_num
FROM p_tag
WHERE is_del = false AND tag LIKE $1
ORDER BY quote_num DESC
OFFSET 0 LIMIT 6
`
type TagsByKeywordBRow struct {
ID int64
UserID int64
Tag string
QuoteNum int64
}
func (q *Queries) TagsByKeywordB(ctx context.Context, tag string) ([]*TagsByKeywordBRow, error) {
rows, err := q.db.Query(ctx, tagsByKeywordB, tag)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*TagsByKeywordBRow
for rows.Next() {
var i TagsByKeywordBRow
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Tag,
&i.QuoteNum,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

@ -0,0 +1,14 @@
version: '2'
sql:
- schema: postgres/schema
queries: postgres/query
engine: postgresql
gen:
go:
package: dbr
out: postgres
sql_package: 'pgx/v5'
emit_prepared_queries: true
emit_interface: true
emit_result_struct_pointers: true
emit_params_struct_pointers: true

@ -0,0 +1,112 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.IndexPostsService = (*friendIndexSrv)(nil)
_ core.IndexPostsService = (*followIndexSrv)(nil)
_ core.IndexPostsService = (*lightIndexSrv)(nil)
_ core.IndexPostsService = (*simpleIndexPostsSrv)(nil)
)
type friendIndexSrv struct {
*pgxSrv
ams core.AuthorizationManageService
ths core.TweetHelpService
}
type followIndexSrv struct {
*pgxSrv
ths core.TweetHelpService
}
type lightIndexSrv struct {
*pgxSrv
ths core.TweetHelpService
}
type simpleIndexPostsSrv struct {
*pgxSrv
ths core.TweetHelpService
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *friendIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *friendIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *followIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *followIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *lightIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数
func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *simpleIndexPostsSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func newFriendIndexService(db *pgx.Conn, ams core.AuthorizationManageService, ths core.TweetHelpService) core.IndexPostsService {
return &friendIndexSrv{
ams: ams,
pgxSrv: newPgxSrv(db),
}
}
func newFollowIndexService(db *pgx.Conn, ths core.TweetHelpService) core.IndexPostsService {
return &followIndexSrv{
ths: ths,
pgxSrv: newPgxSrv(db),
}
}
func newLightIndexService(db *pgx.Conn, ths core.TweetHelpService) core.IndexPostsService {
return &lightIndexSrv{
ths: ths,
pgxSrv: newPgxSrv(db),
}
}
func newSimpleIndexPostsService(db *pgx.Conn, ths core.TweetHelpService) core.IndexPostsService {
return &simpleIndexPostsSrv{
ths: ths,
pgxSrv: newPgxSrv(db),
}
}

@ -0,0 +1,170 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"context"
"strings"
"time"
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
dbr "github.com/rocboss/paopao-ce/internal/dao/slonik/sqlc/postgres"
)
var (
_ core.TopicService = (*topicSrv)(nil)
)
type topicSrv struct {
*pgxSrv
}
// UpsertTags update/insert tags info.
// Assume tags slice is distinct elements.
func (s *topicSrv) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, err error) {
err = s.with(func(c context.Context, q dbr.Querier) error {
now := time.Now().Unix()
upTags, err := q.IncrTags(c, &dbr.IncrTagsParams{
Tags: tags,
ModifiedOn: now,
})
if err != nil {
return err
}
if len(upTags) > 0 {
for _, t := range upTags {
for i := 0; i < len(tags); {
if tags[i] == t.Tag {
latestIdx := len(tags) - 1
tags[i] = tags[latestIdx]
tags = tags[:latestIdx]
break
}
}
res = append(res, &cs.TagInfo{
ID: t.ID,
UserID: t.UserID,
Tag: t.Tag,
QuoteNum: t.QuoteNum,
})
}
}
for _, tag := range tags {
id, err := q.InsertTags(c, &dbr.InsertTagsParams{
UserID: userId,
Tag: tag,
CreatedOn: now,
})
if err != nil {
return err
}
res = append(res, &cs.TagInfo{
ID: id,
UserID: userId,
Tag: tag,
QuoteNum: 1,
})
}
return nil
})
return
}
func (s *topicSrv) DecrTagsById(ids []int64) error {
return s.q.DecrTagsById(context.Background(), &dbr.DecrTagsByIdParams{
Ids: ids,
ModifiedOn: time.Now().Unix(),
})
}
func (s *topicSrv) ListTags(typ cs.TagType, limit int, offset int) (res cs.TagList, _ error) {
ctx := context.Background()
switch typ {
case cs.TagTypeHot:
tags, err := s.q.HotTags(ctx, &dbr.HotTagsParams{Limit: int32(limit), Offset: int32(offset)})
if err != nil {
return nil, err
}
for _, tag := range tags {
res = append(res, &cs.TagItem{
ID: tag.ID,
UserID: tag.UserID,
Tag: tag.Tag,
QuoteNum: tag.QuoteNum,
User: &cs.UserInfo{
ID: tag.UserID,
Nickname: tag.Nickname,
Username: tag.Username,
Status: int(tag.Status),
Avatar: tag.Avatar,
IsAdmin: tag.IsAdmin,
},
})
}
case cs.TagTypeNew:
tags, err := s.q.NewestTags(ctx, &dbr.NewestTagsParams{Limit: int32(limit), Offset: int32(offset)})
if err != nil {
return nil, err
}
for _, tag := range tags {
res = append(res, &cs.TagItem{
ID: tag.ID,
UserID: tag.UserID,
Tag: tag.Tag,
QuoteNum: tag.QuoteNum,
User: &cs.UserInfo{
ID: tag.UserID,
Nickname: tag.Nickname,
Username: tag.Username,
Status: int(tag.Status),
Avatar: tag.Avatar,
IsAdmin: tag.IsAdmin,
},
})
}
}
return
}
func (s *topicSrv) TagsByKeyword(keyword string) (res cs.TagInfoList, _ error) {
ctx := context.Background()
keyword = "%" + strings.Trim(keyword, " ") + "%"
if keyword == "%%" {
tags, err := s.q.TagsByKeywordA(ctx)
if err != nil {
return nil, err
}
for _, tag := range tags {
res = append(res, &cs.TagInfo{
ID: tag.ID,
UserID: tag.UserID,
Tag: tag.Tag,
QuoteNum: tag.QuoteNum,
})
}
} else {
tags, err := s.q.TagsByKeywordB(ctx, keyword)
if err != nil {
return nil, err
}
for _, tag := range tags {
res = append(res, &cs.TagInfo{
ID: tag.ID,
UserID: tag.UserID,
Tag: tag.Tag,
QuoteNum: tag.QuoteNum,
})
}
}
return
}
func newTopicService(db *pgx.Conn) core.TopicService {
return &topicSrv{
pgxSrv: newPgxSrv(db),
}
}

@ -0,0 +1,331 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/pkg/debug"
"gorm.io/gorm"
)
var (
_ core.TweetService = (*tweetSrv)(nil)
_ core.TweetManageService = (*tweetManageSrv)(nil)
_ core.TweetHelpService = (*tweetHelpSrv)(nil)
)
type tweetSrv struct {
*pgxSrv
}
type tweetManageSrv struct {
*pgxSrv
}
type tweetHelpSrv struct {
*pgxSrv
}
// MergePosts post数据整合
func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
// RevampPosts post数据整形修复
func (s *tweetHelpSrv) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetHelpSrv) RevampTweets(tweets cs.TweetList) (cs.TweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetHelpSrv) MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) ([]*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageSrv) DeletePostCollection(p *core.PostCollection) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageSrv) CreatePostContent(content *core.PostContent) (*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageSrv) CreatePost(post *core.Post) (*core.Post, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageSrv) DeletePost(post *core.Post) ([]string, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageSrv) deleteCommentByPostId(db *gorm.DB, postId int64) ([]string, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageSrv) LockPost(post *core.Post) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageSrv) StickPost(post *core.Post) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageSrv) VisiblePost(post *core.Post, visibility core.PostVisibleT) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageSrv) UpdatePost(post *core.Post) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*core.PostStar, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageSrv) DeletePostStar(p *core.PostStar) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageSrv) CreateAttachment(obj *cs.Attachment) (int64, error) {
// TODO
return 0, debug.ErrNotImplemented
}
func (s *tweetManageSrv) CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetManageSrv) DeleteTweet(userId int64, tweetId int64) ([]string, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetManageSrv) LockTweet(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrv) StickTweet(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrv) VisibleTweet(userId int64, visibility cs.TweetVisibleType) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrv) CreateReaction(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrv) DeleteReaction(userId int64, reactionId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrv) CreateFavorite(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrv) DeleteFavorite(userId int64, favoriteId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) GetPosts(conditions *core.ConditionsT, limit int, offset int) ([]*core.Post, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) GetPostCount(conditions *core.ConditionsT) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*core.PostStar, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) GetUserPostStars(userID int64, limit int, offset int) ([]*core.PostStar, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) GetUserPostStarCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) GetUserPostCollections(userID int64, limit int, offset int) ([]*core.PostCollection, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *tweetSrv) GetUserWalletBills(userID int64, limit int, offset int) ([]*core.WalletStatement, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) GetUserWalletBillCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) GetPostContentByID(id int64) (*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetSrv) TweetInfoById(id int64) (*cs.TweetInfo, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrv) TweetItemById(id int64) (*cs.TweetItem, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrv) UserTweets(visitorId, userId int64) (cs.TweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrv) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrv) UserReactions(userId int64, limit int, offset int) (cs.ReactionList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrv) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrv) UserFavorites(userId int64, limit int, offset int) (cs.FavoriteList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrv) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func newTweetService(db *pgx.Conn) core.TweetService {
return &tweetSrv{
pgxSrv: newPgxSrv(db),
}
}
func newTweetManageService(db *pgx.Conn, cacheIndex core.CacheIndexService) core.TweetManageService {
return &tweetManageSrv{
pgxSrv: newPgxSrv(db),
}
}
func newTweetHelpService(db *pgx.Conn) core.TweetHelpService {
return &tweetHelpSrv{
pgxSrv: newPgxSrv(db),
}
}

@ -0,0 +1,67 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.UserManageService = (*userManageSrv)(nil)
)
type userManageSrv struct {
*pgxSrv
}
func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageSrv) GetUserByUsername(username string) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageSrv) GetUserByPhone(phone string) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageSrv) CreateUser(user *core.User) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageSrv) UpdateUser(user *core.User) error {
// TODO
debug.NotImplemented()
return nil
}
func newUserManageService(db *pgx.Conn) core.UserManageService {
return &userManageSrv{
pgxSrv: newPgxSrv(db),
}
}

@ -0,0 +1,60 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package slonik
import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.WalletService = (*walletSrv)(nil)
)
type walletSrv struct {
*pgxSrv
}
func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *walletSrv) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *walletSrv) GetUserWalletBillCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *walletSrv) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *walletSrv) HandlePostAttachmentBought(post *core.Post, user *core.User) error {
// TODO
debug.NotImplemented()
return nil
}
func newWalletService(db *pgx.Conn) core.WalletService {
return &walletSrv{
pgxSrv: newPgxSrv(db),
}
}

@ -19,6 +19,7 @@ import (
"github.com/golang-migrate/migrate/v4/source"
"github.com/golang-migrate/migrate/v4/source/iofs"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/dao/slonik"
"github.com/rocboss/paopao-ce/scripts/migration"
"github.com/sirupsen/logrus"
)
@ -55,18 +56,25 @@ func Run() {
}
migrationsTable := conf.DatabaseSetting.TablePrefix + "schema_migrations"
if cfg.If("MySQL") {
srcDriver, err = iofs.New(migration.Files, "mysql")
dbDriver, err2 = mysql.WithInstance(db, &mysql.Config{MigrationsTable: migrationsTable})
} else if cfg.If("PostgreSQL") || cfg.If("Postgres") {
srcDriver, err = iofs.New(migration.Files, "postgres")
dbDriver, err2 = postgres.WithInstance(db, &postgres.Config{MigrationsTable: migrationsTable})
} else if cfg.If("Sqlite3") {
srcDriver, err = iofs.New(migration.Files, "sqlite3")
dbDriver, err2 = sqlite3.WithInstance(db, &sqlite3.Config{MigrationsTable: migrationsTable})
} else {
srcDriver, err = iofs.New(migration.Files, "mysql")
dbDriver, err2 = mysql.WithInstance(db, &mysql.Config{MigrationsTable: migrationsTable})
if cfg.If("Gorm") || cfg.If("Sqlx") {
if cfg.If("MySQL") {
srcDriver, err = iofs.New(migration.Files, "mysql")
dbDriver, err2 = mysql.WithInstance(db, &mysql.Config{MigrationsTable: migrationsTable})
} else if cfg.If("PostgreSQL") || cfg.If("Postgres") {
srcDriver, err = iofs.New(migration.Files, "postgres")
dbDriver, err2 = postgres.WithInstance(db, &postgres.Config{MigrationsTable: migrationsTable})
} else if cfg.If("Sqlite3") {
srcDriver, err = iofs.New(migration.Files, "sqlite3")
dbDriver, err2 = sqlite3.WithInstance(db, &sqlite3.Config{MigrationsTable: migrationsTable})
} else {
srcDriver, err = iofs.New(migration.Files, "mysql")
dbDriver, err2 = mysql.WithInstance(db, &mysql.Config{MigrationsTable: migrationsTable})
}
} else if cfg.If("Sqlc") {
if cfg.If("PostgreSQL") || cfg.If("Postgres") {
srcDriver, err = iofs.New(slonik.Files, "sqlc/postgres/schema")
dbDriver, err2 = postgres.WithInstance(db, &postgres.Config{MigrationsTable: migrationsTable})
}
}
if err2 != nil {

@ -0,0 +1,18 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package types
import (
"github.com/jackc/pgx/v5/pgtype"
)
// PgxArray returns an object usable by pg drivers for passing a []T slice
// into a database as type T[].
func PgxArray[T any](elements []T) pgtype.Array[T] {
return pgtype.Array[T]{
Elements: elements,
Dims: []pgtype.ArrayDimension{{Length: int32(len(elements)), LowerBound: 1}},
}
}
Loading…
Cancel
Save