cjovs commited on
Commit
8059bf0
·
verified ·
1 Parent(s): be5a45d

Deploy Sub2API HF Space with embedded Postgres/Redis backup runtime

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .dockerignore +74 -0
  2. .gitattributes +24 -35
  3. .github/audit-exceptions.yml +16 -0
  4. .github/workflows/backend-ci.yml +47 -0
  5. .github/workflows/release.yml +306 -0
  6. .github/workflows/security-scan.yml +58 -0
  7. .gitignore +135 -0
  8. .goreleaser.simple.yaml +88 -0
  9. .goreleaser.yaml +208 -0
  10. DEV_GUIDE.md +346 -0
  11. Dockerfile +133 -0
  12. Dockerfile.goreleaser +62 -0
  13. LICENSE +21 -0
  14. Makefile +32 -0
  15. README.md +620 -5
  16. README_CN.md +646 -0
  17. assets/partners/logos/pincc-logo.png +3 -0
  18. backend/.dockerignore +2 -0
  19. backend/.golangci.yml +139 -0
  20. backend/Dockerfile +24 -0
  21. backend/Makefile +27 -0
  22. backend/cmd/jwtgen/main.go +57 -0
  23. backend/cmd/server/VERSION +1 -0
  24. backend/cmd/server/main.go +178 -0
  25. backend/cmd/server/wire.go +296 -0
  26. backend/cmd/server/wire_gen.go +491 -0
  27. backend/cmd/server/wire_gen_test.go +84 -0
  28. backend/ent/account.go +536 -0
  29. backend/ent/account/account.go +416 -0
  30. backend/ent/account/where.go +1603 -0
  31. backend/ent/account_create.go +2550 -0
  32. backend/ent/account_delete.go +88 -0
  33. backend/ent/account_query.go +900 -0
  34. backend/ent/account_update.go +1911 -0
  35. backend/ent/accountgroup.go +176 -0
  36. backend/ent/accountgroup/accountgroup.go +123 -0
  37. backend/ent/accountgroup/where.go +212 -0
  38. backend/ent/accountgroup_create.go +653 -0
  39. backend/ent/accountgroup_delete.go +87 -0
  40. backend/ent/accountgroup_query.go +640 -0
  41. backend/ent/accountgroup_update.go +477 -0
  42. backend/ent/announcement.go +260 -0
  43. backend/ent/announcement/announcement.go +176 -0
  44. backend/ent/announcement/where.go +694 -0
  45. backend/ent/announcement_create.go +1229 -0
  46. backend/ent/announcement_delete.go +88 -0
  47. backend/ent/announcement_query.go +643 -0
  48. backend/ent/announcement_update.go +868 -0
  49. backend/ent/announcementread.go +185 -0
  50. backend/ent/announcementread/announcementread.go +127 -0
.dockerignore ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # =============================================================================
2
+ # Docker Ignore File for Sub2API
3
+ # =============================================================================
4
+
5
+ # Git
6
+ .git
7
+ .gitignore
8
+ .gitattributes
9
+
10
+ # Documentation
11
+ *.md
12
+ !deploy/DOCKER.md
13
+ docs/
14
+
15
+ # IDE
16
+ .idea/
17
+ .vscode/
18
+ *.swp
19
+ *.swo
20
+
21
+ # OS files
22
+ .DS_Store
23
+ Thumbs.db
24
+
25
+ # Build artifacts
26
+ dist/
27
+ build/
28
+
29
+ # Node modules (will be installed in container)
30
+ frontend/node_modules/
31
+ node_modules/
32
+
33
+ # Go build cache (will be built in container)
34
+ backend/vendor/
35
+
36
+ # Test files
37
+ *_test.go
38
+ **/*.test.js
39
+ coverage/
40
+ .nyc_output/
41
+
42
+ # Environment files
43
+ .env
44
+ .env.*
45
+ !.env.example
46
+
47
+ # Local config
48
+ config.yaml
49
+ config.local.yaml
50
+
51
+ # Logs
52
+ *.log
53
+ logs/
54
+
55
+ # Temporary files
56
+ tmp/
57
+ temp/
58
+ *.tmp
59
+
60
+ # Deploy files (not needed in image)
61
+ deploy/install.sh
62
+ deploy/sub2api.service
63
+ deploy/sub2api-sudoers
64
+
65
+ # GoReleaser
66
+ .goreleaser.yaml
67
+
68
+ # GitHub
69
+ .github/
70
+
71
+ # Claude files
72
+ .claude/
73
+ issues/
74
+ CLAUDE.md
.gitattributes CHANGED
@@ -1,35 +1,24 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ # 确保所有 SQL 迁移文件使用 LF 换行符
2
+ backend/migrations/*.sql text eol=lf
3
+
4
+ # Go 源代码文件
5
+ *.go text eol=lf
6
+
7
+ # 前端 源代码文件
8
+ *.ts text eol=lf
9
+ *.tsx text eol=lf
10
+ *.js text eol=lf
11
+ *.jsx text eol=lf
12
+ *.vue text eol=lf
13
+
14
+ # Shell 脚本
15
+ *.sh text eol=lf
16
+
17
+ # YAML/YML 配置文件
18
+ *.yaml text eol=lf
19
+ *.yml text eol=lf
20
+
21
+ # Dockerfile
22
+ Dockerfile text eol=lf
23
+ assets/partners/logos/pincc-logo.png filter=lfs diff=lfs merge=lfs -text
24
+ frontend/public/logo.png filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
.github/audit-exceptions.yml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: 1
2
+ exceptions:
3
+ - package: xlsx
4
+ advisory: "GHSA-4r6h-8v6p-xvw6"
5
+ severity: high
6
+ reason: "Admin export only; switched to dynamic import to reduce exposure (CVE-2023-30533)"
7
+ mitigation: "Load only on export; restrict export permissions and data scope"
8
+ expires_on: "2026-04-05"
9
+ owner: "security@your-domain"
10
+ - package: xlsx
11
+ advisory: "GHSA-5pgg-2g8v-p4x9"
12
+ severity: high
13
+ reason: "Admin export only; switched to dynamic import to reduce exposure (CVE-2024-22363)"
14
+ mitigation: "Load only on export; restrict export permissions and data scope"
15
+ expires_on: "2026-04-05"
16
+ owner: "security@your-domain"
.github/workflows/backend-ci.yml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v6
15
+ - uses: actions/setup-go@v6
16
+ with:
17
+ go-version-file: backend/go.mod
18
+ check-latest: false
19
+ cache: true
20
+ - name: Verify Go version
21
+ run: |
22
+ go version | grep -q 'go1.26.1'
23
+ - name: Unit tests
24
+ working-directory: backend
25
+ run: make test-unit
26
+ - name: Integration tests
27
+ working-directory: backend
28
+ run: make test-integration
29
+
30
+ golangci-lint:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v6
34
+ - uses: actions/setup-go@v6
35
+ with:
36
+ go-version-file: backend/go.mod
37
+ check-latest: false
38
+ cache: true
39
+ - name: Verify Go version
40
+ run: |
41
+ go version | grep -q 'go1.26.1'
42
+ - name: golangci-lint
43
+ uses: golangci/golangci-lint-action@v9
44
+ with:
45
+ version: v2.9
46
+ args: --timeout=30m
47
+ working-directory: backend
.github/workflows/release.yml ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+ workflow_dispatch:
8
+ inputs:
9
+ tag:
10
+ description: 'Tag to release (e.g., v1.0.0)'
11
+ required: true
12
+ type: string
13
+ simple_release:
14
+ description: 'Simple release: only x86_64 GHCR image, skip other artifacts'
15
+ required: false
16
+ type: boolean
17
+ default: false
18
+
19
+ # 环境变量:合并 workflow_dispatch 输入和 repository variable
20
+ # tag push 触发时读取 vars.SIMPLE_RELEASE,workflow_dispatch 时使用输入参数
21
+ env:
22
+ SIMPLE_RELEASE: ${{ github.event.inputs.simple_release == 'true' || vars.SIMPLE_RELEASE == 'true' }}
23
+
24
+ permissions:
25
+ contents: write
26
+ packages: write
27
+
28
+ jobs:
29
+ # Update VERSION file with tag version
30
+ update-version:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - name: Checkout
34
+ uses: actions/checkout@v6
35
+
36
+ - name: Update VERSION file
37
+ run: |
38
+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
39
+ VERSION=${{ github.event.inputs.tag }}
40
+ VERSION=${VERSION#v}
41
+ else
42
+ VERSION=${GITHUB_REF#refs/tags/v}
43
+ fi
44
+ echo "$VERSION" > backend/cmd/server/VERSION
45
+ echo "Updated VERSION file to: $VERSION"
46
+
47
+ - name: Upload VERSION artifact
48
+ uses: actions/upload-artifact@v7
49
+ with:
50
+ name: version-file
51
+ path: backend/cmd/server/VERSION
52
+ retention-days: 1
53
+
54
+ build-frontend:
55
+ runs-on: ubuntu-latest
56
+ steps:
57
+ - name: Checkout
58
+ uses: actions/checkout@v6
59
+
60
+ - name: Setup pnpm
61
+ uses: pnpm/action-setup@v4
62
+ with:
63
+ version: 9
64
+
65
+ - name: Setup Node.js
66
+ uses: actions/setup-node@v6
67
+ with:
68
+ node-version: '20'
69
+ cache: 'pnpm'
70
+ cache-dependency-path: frontend/pnpm-lock.yaml
71
+
72
+ - name: Install dependencies
73
+ run: pnpm install --frozen-lockfile
74
+ working-directory: frontend
75
+
76
+ - name: Build frontend
77
+ run: pnpm run build
78
+ working-directory: frontend
79
+
80
+ - name: Upload frontend artifact
81
+ uses: actions/upload-artifact@v7
82
+ with:
83
+ name: frontend-dist
84
+ path: backend/internal/web/dist/
85
+ retention-days: 1
86
+
87
+ release:
88
+ needs: [update-version, build-frontend]
89
+ runs-on: ubuntu-latest
90
+ steps:
91
+ - name: Checkout
92
+ uses: actions/checkout@v6
93
+ with:
94
+ fetch-depth: 0
95
+ ref: ${{ github.event.inputs.tag || github.ref }}
96
+
97
+ - name: Download VERSION artifact
98
+ uses: actions/download-artifact@v8
99
+ with:
100
+ name: version-file
101
+ path: backend/cmd/server/
102
+
103
+ - name: Download frontend artifact
104
+ uses: actions/download-artifact@v8
105
+ with:
106
+ name: frontend-dist
107
+ path: backend/internal/web/dist/
108
+
109
+ - name: Setup Go
110
+ uses: actions/setup-go@v6
111
+ with:
112
+ go-version-file: backend/go.mod
113
+ check-latest: false
114
+ cache-dependency-path: backend/go.sum
115
+
116
+ - name: Verify Go version
117
+ run: |
118
+ go version | grep -q 'go1.26.1'
119
+
120
+ # Docker setup for GoReleaser
121
+ - name: Set up QEMU
122
+ uses: docker/setup-qemu-action@v3
123
+
124
+ - name: Set up Docker Buildx
125
+ uses: docker/setup-buildx-action@v3
126
+
127
+ - name: Login to DockerHub
128
+ if: ${{ env.DOCKERHUB_USERNAME != '' }}
129
+ uses: docker/login-action@v3
130
+ env:
131
+ DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
132
+ with:
133
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
134
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
135
+
136
+ - name: Login to GitHub Container Registry
137
+ uses: docker/login-action@v3
138
+ with:
139
+ registry: ghcr.io
140
+ username: ${{ github.repository_owner }}
141
+ password: ${{ secrets.GITHUB_TOKEN }}
142
+
143
+ - name: Fetch tags with annotations
144
+ run: |
145
+ # 确保获取完整的 annotated tag 信息
146
+ git fetch --tags --force
147
+
148
+ - name: Get tag message
149
+ id: tag_message
150
+ run: |
151
+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
152
+ TAG_NAME=${{ github.event.inputs.tag }}
153
+ else
154
+ TAG_NAME=${GITHUB_REF#refs/tags/}
155
+ fi
156
+ echo "Processing tag: $TAG_NAME"
157
+
158
+ # 获取完整的 tag message(跳过第一行标题)
159
+ TAG_MESSAGE=$(git tag -l --format='%(contents:body)' "$TAG_NAME")
160
+
161
+ # 调试输出
162
+ echo "Tag message length: ${#TAG_MESSAGE}"
163
+ echo "Tag message preview:"
164
+ echo "$TAG_MESSAGE" | head -10
165
+
166
+ # 使用 EOF 分隔符处理多行内容
167
+ echo "message<<EOF" >> $GITHUB_OUTPUT
168
+ echo "$TAG_MESSAGE" >> $GITHUB_OUTPUT
169
+ echo "EOF" >> $GITHUB_OUTPUT
170
+
171
+ - name: Set lowercase owner for GHCR
172
+ id: lowercase
173
+ run: echo "owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
174
+
175
+ - name: Run GoReleaser
176
+ uses: goreleaser/goreleaser-action@v7
177
+ with:
178
+ version: '~> v2'
179
+ args: release --clean --skip=validate ${{ env.SIMPLE_RELEASE == 'true' && '--config=.goreleaser.simple.yaml' || '' }}
180
+ env:
181
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
182
+ TAG_MESSAGE: ${{ steps.tag_message.outputs.message }}
183
+ GITHUB_REPO_OWNER: ${{ github.repository_owner }}
184
+ GITHUB_REPO_OWNER_LOWER: ${{ steps.lowercase.outputs.owner }}
185
+ GITHUB_REPO_NAME: ${{ github.event.repository.name }}
186
+ DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME || 'skip' }}
187
+
188
+ # Update DockerHub description
189
+ - name: Update DockerHub description
190
+ if: ${{ env.SIMPLE_RELEASE != 'true' && env.DOCKERHUB_USERNAME != '' }}
191
+ uses: peter-evans/dockerhub-description@v5
192
+ env:
193
+ DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
194
+ with:
195
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
196
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
197
+ repository: ${{ secrets.DOCKERHUB_USERNAME }}/sub2api
198
+ short-description: "Sub2API - AI API Gateway Platform"
199
+ readme-filepath: ./deploy/DOCKER.md
200
+
201
+ # Send Telegram notification
202
+ - name: Send Telegram Notification
203
+ if: ${{ env.SIMPLE_RELEASE != 'true' }}
204
+ env:
205
+ TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
206
+ TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
207
+ DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
208
+ continue-on-error: true
209
+ run: |
210
+ # 检查必要的环境变量
211
+ if [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then
212
+ echo "Telegram credentials not configured, skipping notification"
213
+ exit 0
214
+ fi
215
+
216
+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
217
+ TAG_NAME=${{ github.event.inputs.tag }}
218
+ else
219
+ TAG_NAME=${GITHUB_REF#refs/tags/}
220
+ fi
221
+ VERSION=${TAG_NAME#v}
222
+ REPO="${{ github.repository }}"
223
+ GHCR_IMAGE="ghcr.io/${REPO,,}" # ${,,} converts to lowercase
224
+
225
+ # 获取 tag message 内容并转义 Markdown 特殊字符
226
+ TAG_MESSAGE='${{ steps.tag_message.outputs.message }}'
227
+ TAG_MESSAGE=$(echo "$TAG_MESSAGE" | sed 's/\([_*`\[]\)/\\\1/g')
228
+
229
+ # 限制消息长度(Telegram 消息限制 4096 字符,预留空间给头尾固定内容)
230
+ if [ ${#TAG_MESSAGE} -gt 3500 ]; then
231
+ TAG_MESSAGE="${TAG_MESSAGE:0:3500}..."
232
+ fi
233
+
234
+ # 构建消息内容
235
+ MESSAGE="🚀 *Sub2API 新版本发布!*"$'\n'$'\n'
236
+ MESSAGE+="📦 版本号: \`${VERSION}\`"$'\n'$'\n'
237
+
238
+ # 添加更新内容
239
+ if [ -n "$TAG_MESSAGE" ]; then
240
+ MESSAGE+="${TAG_MESSAGE}"$'\n'$'\n'
241
+ fi
242
+
243
+ MESSAGE+="🐳 *Docker 部署:*"$'\n'
244
+ MESSAGE+="\`\`\`bash"$'\n'
245
+ # 根据是否配置 DockerHub 动态生成
246
+ if [ -n "$DOCKERHUB_USERNAME" ]; then
247
+ DOCKER_IMAGE="${DOCKERHUB_USERNAME}/sub2api"
248
+ MESSAGE+="# Docker Hub"$'\n'
249
+ MESSAGE+="docker pull ${DOCKER_IMAGE}:${TAG_NAME}"$'\n'
250
+ MESSAGE+="# GitHub Container Registry"$'\n'
251
+ fi
252
+ MESSAGE+="docker pull ${GHCR_IMAGE}:${TAG_NAME}"$'\n'
253
+ MESSAGE+="\`\`\`"$'\n'$'\n'
254
+ MESSAGE+="🔗 *相关链接:*"$'\n'
255
+ MESSAGE+="• [GitHub Release](https://github.com/${REPO}/releases/tag/${TAG_NAME})"$'\n'
256
+ if [ -n "$DOCKERHUB_USERNAME" ]; then
257
+ MESSAGE+="• [Docker Hub](https://hub.docker.com/r/${DOCKER_IMAGE})"$'\n'
258
+ fi
259
+ MESSAGE+="• [GitHub Packages](https://github.com/${REPO}/pkgs/container/sub2api)"$'\n'$'\n'
260
+ MESSAGE+="#Sub2API #Release #${TAG_NAME//./_}"
261
+
262
+ # 发送消息
263
+ curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
264
+ -H "Content-Type: application/json" \
265
+ -d "$(jq -n \
266
+ --arg chat_id "${TELEGRAM_CHAT_ID}" \
267
+ --arg text "${MESSAGE}" \
268
+ '{
269
+ chat_id: $chat_id,
270
+ text: $text,
271
+ parse_mode: "Markdown",
272
+ disable_web_page_preview: true
273
+ }')"
274
+
275
+ sync-version-file:
276
+ needs: [release]
277
+ if: ${{ needs.release.result == 'success' }}
278
+ runs-on: ubuntu-latest
279
+ steps:
280
+ - name: Checkout default branch
281
+ uses: actions/checkout@v6
282
+ with:
283
+ ref: ${{ github.event.repository.default_branch }}
284
+
285
+ - name: Sync VERSION file to released tag
286
+ run: |
287
+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
288
+ VERSION=${{ github.event.inputs.tag }}
289
+ VERSION=${VERSION#v}
290
+ else
291
+ VERSION=${GITHUB_REF#refs/tags/v}
292
+ fi
293
+
294
+ CURRENT_VERSION=$(tr -d '\r\n' < backend/cmd/server/VERSION || true)
295
+ if [ "$CURRENT_VERSION" = "$VERSION" ]; then
296
+ echo "VERSION file already matches $VERSION"
297
+ exit 0
298
+ fi
299
+
300
+ echo "$VERSION" > backend/cmd/server/VERSION
301
+
302
+ git config user.name "github-actions[bot]"
303
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
304
+ git add backend/cmd/server/VERSION
305
+ git commit -m "chore: sync VERSION to ${VERSION} [skip ci]"
306
+ git push origin HEAD:${{ github.event.repository.default_branch }}
.github/workflows/security-scan.yml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Security Scan
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ schedule:
7
+ - cron: '0 3 * * 1'
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ backend-security:
14
+ runs-on: ubuntu-latest
15
+ timeout-minutes: 15
16
+ steps:
17
+ - uses: actions/checkout@v6
18
+ - name: Set up Go
19
+ uses: actions/setup-go@v6
20
+ with:
21
+ go-version-file: backend/go.mod
22
+ check-latest: false
23
+ cache-dependency-path: backend/go.sum
24
+ - name: Verify Go version
25
+ run: |
26
+ go version | grep -q 'go1.26.1'
27
+ - name: Run govulncheck
28
+ working-directory: backend
29
+ run: |
30
+ go install golang.org/x/vuln/cmd/govulncheck@latest
31
+ govulncheck ./...
32
+
33
+ frontend-security:
34
+ runs-on: ubuntu-latest
35
+ steps:
36
+ - uses: actions/checkout@v6
37
+ - name: Set up pnpm
38
+ uses: pnpm/action-setup@v4
39
+ with:
40
+ version: 9
41
+ - name: Set up Node.js
42
+ uses: actions/setup-node@v6
43
+ with:
44
+ node-version: '20'
45
+ cache: 'pnpm'
46
+ cache-dependency-path: frontend/pnpm-lock.yaml
47
+ - name: Install dependencies
48
+ working-directory: frontend
49
+ run: pnpm install --frozen-lockfile
50
+ - name: Run pnpm audit
51
+ working-directory: frontend
52
+ run: |
53
+ pnpm audit --prod --audit-level=high --json > audit.json || true
54
+ - name: Check audit exceptions
55
+ run: |
56
+ python tools/check_pnpm_audit_exceptions.py \
57
+ --audit frontend/audit.json \
58
+ --exceptions .github/audit-exceptions.yml
.gitignore ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ docs/claude-relay-service/
2
+
3
+ # ===================
4
+ # Go 后端
5
+ # ===================
6
+ # 二进制文件
7
+ *.exe
8
+ *.exe~
9
+ *.dll
10
+ *.so
11
+ *.dylib
12
+ backend/bin/
13
+ backend/server
14
+ backend/sub2api
15
+ backend/main
16
+
17
+ # Go 测试二进制
18
+ *.test
19
+
20
+ # 测试覆盖率
21
+ *.out
22
+ coverage.html
23
+
24
+ # 依赖(使用 go mod)
25
+ vendor/
26
+
27
+ # Go 编译缓存
28
+ backend/.gocache/
29
+
30
+ # ===================
31
+ # Node.js / Vue 前端
32
+ # ===================
33
+ node_modules/
34
+ frontend/node_modules/
35
+ frontend/dist/
36
+ *.local
37
+ *.tsbuildinfo
38
+ vite.config.d.ts
39
+ vite.config.js.timestamp-*
40
+
41
+ # 日志
42
+ npm-debug.log*
43
+ yarn-debug.log*
44
+ yarn-error.log*
45
+ pnpm-debug.log*
46
+
47
+ # ===================
48
+ # 环境配置
49
+ # ===================
50
+ .env
51
+ .env.local
52
+ .env.*.local
53
+ *.env
54
+ !.env.example
55
+ docker-compose.override.yml
56
+
57
+ # ===================
58
+ # IDE / 编辑器
59
+ # ===================
60
+ .idea/
61
+ .vscode/
62
+ *.swp
63
+ *.swo
64
+ *~
65
+ .project
66
+ .settings/
67
+ .classpath
68
+
69
+ # ===================
70
+ # 操作系统
71
+ # ===================
72
+ .DS_Store
73
+ Thumbs.db
74
+ Desktop.ini
75
+
76
+ # ===================
77
+ # 临时文件
78
+ # ===================
79
+ tmp/
80
+ temp/
81
+ *.tmp
82
+ *.temp
83
+ *.log
84
+ *.bak
85
+ .cache/
86
+ .dev/
87
+ .serena/
88
+
89
+ # ===================
90
+ # 构建产物
91
+ # ===================
92
+ dist/
93
+ build/
94
+ release/
95
+
96
+ # 后端嵌入的前端构建产物
97
+ # Keep a placeholder file so `//go:embed all:dist` always has a match in CI/lint,
98
+ # while still ignoring generated frontend build outputs.
99
+ backend/internal/web/dist/
100
+ !backend/internal/web/dist/
101
+ backend/internal/web/dist/*
102
+ !backend/internal/web/dist/.keep
103
+
104
+ # 后端运行时缓存数据
105
+ backend/data/
106
+
107
+ # ===================
108
+ # 本地配置文件(包含敏感信息)
109
+ # ===================
110
+ backend/config.yaml
111
+ deploy/config.yaml
112
+ backend/.installed
113
+
114
+ # ===================
115
+ # 其他
116
+ # ===================
117
+ tests
118
+ CLAUDE.md
119
+ .claude
120
+ scripts
121
+ .code-review-state
122
+ #openspec/
123
+ code-reviews/
124
+ #AGENTS.md
125
+ backend/cmd/server/server
126
+ deploy/docker-compose.override.yml
127
+ .gocache/
128
+ vite.config.js
129
+ docs/*
130
+ .serena/
131
+ .codex/
132
+ frontend/coverage/
133
+ aicodex
134
+ output/
135
+
.goreleaser.simple.yaml ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 简化版 GoReleaser 配置 - 仅发布 x86_64 GHCR 镜像
2
+ version: 2
3
+
4
+ project_name: sub2api
5
+
6
+ before:
7
+ hooks:
8
+ - go mod tidy -C backend
9
+
10
+ builds:
11
+ - id: sub2api
12
+ dir: backend
13
+ main: ./cmd/server
14
+ binary: sub2api
15
+ flags:
16
+ - -tags=embed
17
+ env:
18
+ - CGO_ENABLED=0
19
+ goos:
20
+ - linux
21
+ goarch:
22
+ - amd64
23
+ ldflags:
24
+ - -s -w
25
+ - -X main.Commit={{.Commit}}
26
+ - -X main.Date={{.Date}}
27
+ - -X main.BuildType=release
28
+
29
+ # 跳过 archives
30
+ archives: []
31
+
32
+ # 跳过 checksum
33
+ checksum:
34
+ disable: true
35
+
36
+ changelog:
37
+ disable: true
38
+
39
+ # 仅 GHCR x86_64 镜像
40
+ dockers:
41
+ - id: ghcr-amd64
42
+ goos: linux
43
+ goarch: amd64
44
+ image_templates:
45
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
46
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}"
47
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:latest"
48
+ dockerfile: Dockerfile.goreleaser
49
+ use: buildx
50
+ extra_files:
51
+ - deploy/docker-entrypoint.sh
52
+ build_flag_templates:
53
+ - "--platform=linux/amd64"
54
+ - "--label=org.opencontainers.image.version={{ .Version }}"
55
+ - "--label=org.opencontainers.image.revision={{ .Commit }}"
56
+ - "--label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}"
57
+
58
+ # 跳过 manifests(单架构不需要)
59
+ docker_manifests: []
60
+
61
+ release:
62
+ github:
63
+ owner: "{{ .Env.GITHUB_REPO_OWNER }}"
64
+ name: "{{ .Env.GITHUB_REPO_NAME }}"
65
+ draft: false
66
+ prerelease: auto
67
+ name_template: "Sub2API {{.Version}} (Simple)"
68
+ # 跳过上传二进制包
69
+ skip_upload: true
70
+ header: |
71
+ > AI API Gateway Platform - 将 AI 订阅配额分发和管理
72
+ > ⚡ Simple Release: 仅包含 x86_64 GHCR 镜像
73
+
74
+ {{ .Env.TAG_MESSAGE }}
75
+
76
+ footer: |
77
+ ---
78
+
79
+ ## 📥 Installation
80
+
81
+ **Docker (x86_64 only):**
82
+ ```bash
83
+ docker pull ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}
84
+ ```
85
+
86
+ ## 📚 Documentation
87
+
88
+ - [GitHub Repository](https://github.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }})
.goreleaser.yaml ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: 2
2
+
3
+ project_name: sub2api
4
+
5
+ before:
6
+ hooks:
7
+ - go mod tidy -C backend
8
+
9
+ builds:
10
+ - id: sub2api
11
+ dir: backend
12
+ main: ./cmd/server
13
+ binary: sub2api
14
+ flags:
15
+ - -tags=embed
16
+ env:
17
+ - CGO_ENABLED=0
18
+ goos:
19
+ - linux
20
+ - windows
21
+ - darwin
22
+ goarch:
23
+ - amd64
24
+ - arm64
25
+ ignore:
26
+ - goos: windows
27
+ goarch: arm64
28
+ ldflags:
29
+ - -s -w
30
+ - -X main.Commit={{.Commit}}
31
+ - -X main.Date={{.Date}}
32
+ - -X main.BuildType=release
33
+
34
+ archives:
35
+ - id: default
36
+ format: tar.gz
37
+ name_template: >-
38
+ {{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}
39
+ format_overrides:
40
+ - goos: windows
41
+ format: zip
42
+ files:
43
+ - LICENSE*
44
+ - README*
45
+ - deploy/*
46
+
47
+ checksum:
48
+ name_template: 'checksums.txt'
49
+ algorithm: sha256
50
+
51
+ changelog:
52
+ # 禁用自动 changelog,完全使用 tag 消息
53
+ disable: true
54
+
55
+ # Docker images
56
+ dockers:
57
+ # DockerHub images (skipped if DOCKERHUB_USERNAME is 'skip')
58
+ - id: amd64
59
+ goos: linux
60
+ goarch: amd64
61
+ skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
62
+ image_templates:
63
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
64
+ dockerfile: Dockerfile.goreleaser
65
+ use: buildx
66
+ extra_files:
67
+ - deploy/docker-entrypoint.sh
68
+ build_flag_templates:
69
+ - "--platform=linux/amd64"
70
+ - "--label=org.opencontainers.image.version={{ .Version }}"
71
+ - "--label=org.opencontainers.image.revision={{ .Commit }}"
72
+
73
+ - id: arm64
74
+ goos: linux
75
+ goarch: arm64
76
+ skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
77
+ image_templates:
78
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
79
+ dockerfile: Dockerfile.goreleaser
80
+ use: buildx
81
+ extra_files:
82
+ - deploy/docker-entrypoint.sh
83
+ build_flag_templates:
84
+ - "--platform=linux/arm64"
85
+ - "--label=org.opencontainers.image.version={{ .Version }}"
86
+ - "--label=org.opencontainers.image.revision={{ .Commit }}"
87
+
88
+ # GHCR images (owner must be lowercase)
89
+ - id: ghcr-amd64
90
+ goos: linux
91
+ goarch: amd64
92
+ image_templates:
93
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
94
+ dockerfile: Dockerfile.goreleaser
95
+ use: buildx
96
+ extra_files:
97
+ - deploy/docker-entrypoint.sh
98
+ build_flag_templates:
99
+ - "--platform=linux/amd64"
100
+ - "--label=org.opencontainers.image.version={{ .Version }}"
101
+ - "--label=org.opencontainers.image.revision={{ .Commit }}"
102
+ - "--label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}"
103
+
104
+ - id: ghcr-arm64
105
+ goos: linux
106
+ goarch: arm64
107
+ image_templates:
108
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
109
+ dockerfile: Dockerfile.goreleaser
110
+ use: buildx
111
+ extra_files:
112
+ - deploy/docker-entrypoint.sh
113
+ build_flag_templates:
114
+ - "--platform=linux/arm64"
115
+ - "--label=org.opencontainers.image.version={{ .Version }}"
116
+ - "--label=org.opencontainers.image.revision={{ .Commit }}"
117
+ - "--label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}"
118
+
119
+ # Docker manifests for multi-arch support
120
+ docker_manifests:
121
+ # DockerHub manifests (skipped if DOCKERHUB_USERNAME is 'skip')
122
+ - name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}"
123
+ skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
124
+ image_templates:
125
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
126
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
127
+
128
+ - name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:latest"
129
+ skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
130
+ image_templates:
131
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
132
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
133
+
134
+ - name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Major }}.{{ .Minor }}"
135
+ skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
136
+ image_templates:
137
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
138
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
139
+
140
+ - name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Major }}"
141
+ skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
142
+ image_templates:
143
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
144
+ - "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
145
+
146
+ # GHCR manifests (owner must be lowercase)
147
+ - name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}"
148
+ image_templates:
149
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
150
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
151
+
152
+ - name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:latest"
153
+ image_templates:
154
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
155
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
156
+
157
+ - name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Major }}.{{ .Minor }}"
158
+ image_templates:
159
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
160
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
161
+
162
+ - name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Major }}"
163
+ image_templates:
164
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
165
+ - "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
166
+
167
+ release:
168
+ github:
169
+ owner: "{{ .Env.GITHUB_REPO_OWNER }}"
170
+ name: "{{ .Env.GITHUB_REPO_NAME }}"
171
+ draft: false
172
+ prerelease: auto
173
+ name_template: "Sub2API {{.Version}}"
174
+ # 完全使用 tag 消息作为 release 内容(通过环境变量传入)
175
+ header: |
176
+ > AI API Gateway Platform - 将 AI 订阅配额分发和管理
177
+
178
+ {{ .Env.TAG_MESSAGE }}
179
+
180
+ footer: |
181
+
182
+ ---
183
+
184
+ ## 📥 Installation
185
+
186
+ **Docker:**
187
+ ```bash
188
+ {{ if ne .Env.DOCKERHUB_USERNAME "skip" -}}
189
+ # Docker Hub
190
+ docker pull {{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}
191
+
192
+ {{ end -}}
193
+ # GitHub Container Registry
194
+ docker pull ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}
195
+ ```
196
+
197
+ **One-line install (Linux):**
198
+ ```bash
199
+ curl -sSL https://raw.githubusercontent.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}/main/deploy/install.sh | sudo bash
200
+ ```
201
+
202
+ **Manual download:**
203
+ Download the appropriate archive for your platform from the assets below.
204
+
205
+ ## 📚 Documentation
206
+
207
+ - [GitHub Repository](https://github.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }})
208
+ - [Installation Guide](https://github.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}/blob/main/deploy/README.md)
DEV_GUIDE.md ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # sub2api 项目开发指南
2
+
3
+ > 本文档记录项目环境配置、常见坑点和注意事项,供 Claude Code 和团队成员参考。
4
+
5
+ ## 一、项目基本信息
6
+
7
+ | 项目 | 说明 |
8
+ |------|------|
9
+ | **上游仓库** | Wei-Shaw/sub2api |
10
+ | **Fork 仓库** | bayma888/sub2api-bmai |
11
+ | **技术栈** | Go 后端 (Ent ORM + Gin) + Vue3 前端 (pnpm) |
12
+ | **数据库** | PostgreSQL 16 + Redis |
13
+ | **包管理** | 后端: go modules, 前端: **pnpm**(不是 npm) |
14
+
15
+ ## 二、本地环境配置
16
+
17
+ ### PostgreSQL 16 (Windows 服务)
18
+
19
+ | 配置项 | 值 |
20
+ |--------|-----|
21
+ | 端口 | 5432 |
22
+ | psql 路径 | `C:\Program Files\PostgreSQL\16\bin\psql.exe` |
23
+ | pg_hba.conf | `C:\Program Files\PostgreSQL\16\data\pg_hba.conf` |
24
+ | 数据库凭据 | user=`sub2api`, password=`sub2api`, dbname=`sub2api` |
25
+ | 超级用户 | user=`postgres`, password=`postgres` |
26
+
27
+ ### Redis
28
+
29
+ | 配置项 | 值 |
30
+ |--------|-----|
31
+ | 端口 | 6379 |
32
+ | 密码 | 无 |
33
+
34
+ ### 开发工具
35
+
36
+ ```bash
37
+ # golangci-lint v2.7
38
+ go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7
39
+
40
+ # pnpm (前端包管理)
41
+ npm install -g pnpm
42
+ ```
43
+
44
+ ## 三、CI/CD 流水线
45
+
46
+ ### GitHub Actions Workflows
47
+
48
+ | Workflow | 触发条件 | 检查内容 |
49
+ |----------|----------|----------|
50
+ | **backend-ci.yml** | push, pull_request | 单元测试 + 集成测试 + golangci-lint v2.7 |
51
+ | **security-scan.yml** | push, pull_request, 每周一 | govulncheck + gosec + pnpm audit |
52
+ | **release.yml** | tag `v*` | 构建发布(PR 不触发) |
53
+
54
+ ### CI 要求
55
+
56
+ - Go 版本必须是 **1.25.7**
57
+ - 前端使用 `pnpm install --frozen-lockfile`,必须提交 `pnpm-lock.yaml`
58
+
59
+ ### 本地测试命令
60
+
61
+ ```bash
62
+ # 后端单元测试
63
+ cd backend && go test -tags=unit ./...
64
+
65
+ # 后端集成测试
66
+ cd backend && go test -tags=integration ./...
67
+
68
+ # 代码质量检查
69
+ cd backend && golangci-lint run ./...
70
+
71
+ # 前端依赖安装(必须用 pnpm)
72
+ cd frontend && pnpm install
73
+ ```
74
+
75
+ ## 四、常见坑点 & 解决方案
76
+
77
+ ### 坑 1:pnpm-lock.yaml 必须同步提交
78
+
79
+ **问题**:`package.json` 新增依赖后,CI 的 `pnpm install --frozen-lockfile` 失败。
80
+
81
+ **原因**:上游 CI 使用 pnpm,lock 文件不同步会报错。
82
+
83
+ **解决**:
84
+ ```bash
85
+ cd frontend
86
+ pnpm install # 更新 pnpm-lock.yaml
87
+ git add pnpm-lock.yaml
88
+ git commit -m "chore: update pnpm-lock.yaml"
89
+ ```
90
+
91
+ ---
92
+
93
+ ### 坑 2:npm 和 pnpm 的 node_modules 冲突
94
+
95
+ **问题**:之前用 npm 装过 `node_modules`,pnpm install 报 `EPERM` 错误。
96
+
97
+ **解决**:
98
+ ```bash
99
+ cd frontend
100
+ rm -rf node_modules # 或 PowerShell: Remove-Item -Recurse -Force node_modules
101
+ pnpm install
102
+ ```
103
+
104
+ ---
105
+
106
+ ### 坑 3:PowerShell 中 bcrypt hash 的 `$` 被转义
107
+
108
+ **问题**:bcrypt hash 格式如 `$2a$10$xxx...`,PowerShell 把 `$2a` 当变量解析,导致数据丢失。
109
+
110
+ **解决**:将 SQL 写入文件,用 `psql -f` 执行:
111
+ ```bash
112
+ # 错误示范(PowerShell 会吃掉 $)
113
+ psql -c "INSERT INTO users ... VALUES ('$2a$10$...')"
114
+
115
+ # 正确做法
116
+ echo "INSERT INTO users ... VALUES ('\$2a\$10\$...')" > temp.sql
117
+ psql -U sub2api -h 127.0.0.1 -d sub2api -f temp.sql
118
+ ```
119
+
120
+ ---
121
+
122
+ ### 坑 4:psql 不支持中文路径
123
+
124
+ **问题**:`psql -f "D:\中文路径\file.sql"` 报错找不到文件。
125
+
126
+ **解决**:复制到纯英文路径再执行:
127
+ ```bash
128
+ cp "D:\中文路径\file.sql" "C:\temp.sql"
129
+ psql -f "C:\temp.sql"
130
+ ```
131
+
132
+ ---
133
+
134
+ ### 坑 5:PostgreSQL 密码重置流程
135
+
136
+ **场景**:忘记 PostgreSQL 密码。
137
+
138
+ **步骤**:
139
+ 1. 修改 `C:\Program Files\PostgreSQL\16\data\pg_hba.conf`
140
+ ```
141
+ # 将 scram-sha-256 改为 trust
142
+ host all all 127.0.0.1/32 trust
143
+ ```
144
+ 2. 重启 PostgreSQL 服务
145
+ ```powershell
146
+ Restart-Service postgresql-x64-16
147
+ ```
148
+ 3. 无密码登录并重置
149
+ ```bash
150
+ psql -U postgres -h 127.0.0.1
151
+ ALTER USER sub2api WITH PASSWORD 'sub2api';
152
+ ALTER USER postgres WITH PASSWORD 'postgres';
153
+ ```
154
+ 4. 改回 `scram-sha-256` 并重启
155
+
156
+ ---
157
+
158
+ ### 坑 6:Go interface 新增方法后 test stub 必须补全
159
+
160
+ **问题**:给 interface 新增方法后,编译报错 `does not implement interface (missing method XXX)`。
161
+
162
+ **原因**:所有测试文件中实现该 interface 的 stub/mock 都必须补上新方法。
163
+
164
+ **解决**:
165
+ ```bash
166
+ # 搜索所有实现该 interface 的 struct
167
+ cd backend
168
+ grep -r "type.*Stub.*struct" internal/
169
+ grep -r "type.*Mock.*struct" internal/
170
+
171
+ # 逐一补全新方法
172
+ ```
173
+
174
+ ---
175
+
176
+ ### 坑 7:Windows 上 psql 连 localhost 的 IPv6 问题
177
+
178
+ **问题**:psql 连 `localhost` 先尝试 IPv6 (::1),可能报错后再回退 IPv4。
179
+
180
+ **建议**:直接用 `127.0.0.1` 代替 `localhost`。
181
+
182
+ ---
183
+
184
+ ### 坑 8:Windows 没有 make 命令
185
+
186
+ **问题**:CI 里用 `make test-unit`,本地 Windows 没有 make。
187
+
188
+ **解决**:直接用 Makefile 里的原始命令:
189
+ ```bash
190
+ # 代替 make test-unit
191
+ go test -tags=unit ./...
192
+
193
+ # 代替 make test-integration
194
+ go test -tags=integration ./...
195
+ ```
196
+
197
+ ---
198
+
199
+ ### 坑 9:Ent Schema 修改后必须重新生成
200
+
201
+ **问题**:修改 `ent/schema/*.go` 后,代码不生效。
202
+
203
+ **解决**:
204
+ ```bash
205
+ cd backend
206
+ go generate ./ent # 重新生成 ent 代码
207
+ git add ent/ # 生成的文件也要提交
208
+ ```
209
+
210
+ ---
211
+
212
+ ### 坑 10:前端测试看似正常,但后端调用失败(模型映射被批量误改)
213
+
214
+ **典型现象**:
215
+ - 前端按钮点测看起来正常;
216
+ - 实际通过 API/客户端调用时返回 `Service temporarily unavailable` 或提示无可用账号;
217
+ - 常见于 OpenAI 账号(例如 Codex 模型)在批量修改后突然不可用。
218
+
219
+ **根因**:
220
+ - OpenAI 账号编辑页默认不显式展示映射规则,容易让人误以为“没映射也没关系”;
221
+ - 但在**批量修改同时选中不同平台账号**(OpenAI + Antigravity/Gemini)时,模型白名单/映射可能被跨平台策略覆盖;
222
+ - 结果是 OpenAI 账号的关键模型映射丢失或被改坏,后端选不到可用账号。
223
+
224
+ **修复方案(按优先级)**:
225
+ 1. **快速修复(推荐)**:在批量修改中补回正确的透传映射(例如 `gpt-5.3-codex -> gpt-5.3-codex-spark`)。
226
+ 2. **彻底重建**:删除并重新添加全部相关账号(最稳但成本高)。
227
+
228
+ **关键经验**:
229
+ - 如果某模型已被软件内置默认映射覆盖,通常不需要额外再加透传;
230
+ - 但当上游模型更新快于本仓库默认映射时,**手动批量添加透传映射**是最简单、最低风险的临时兜底方案;
231
+ - 批量操作前尽量按平台分组,不要混选不同平台账号。
232
+
233
+ ---
234
+
235
+ ### 坑 11:PR 提交前检查清单
236
+
237
+ 提交 PR 前务必本地验证:
238
+
239
+ - [ ] `go test -tags=unit ./...` 通过
240
+ - [ ] `go test -tags=integration ./...` 通过
241
+ - [ ] `golangci-lint run ./...` 无新增问题
242
+ - [ ] `pnpm-lock.yaml` 已同步(如果改了 package.json)
243
+ - [ ] 所有 test stub 补全新接口方法(如果改了 interface)
244
+ - [ ] Ent 生成的代码已提交(如果改了 schema)
245
+
246
+ ## 五、常用命令速查
247
+
248
+ ### 数据库操作
249
+
250
+ ```bash
251
+ # 连接数据库
252
+ psql -U sub2api -h 127.0.0.1 -d sub2api
253
+
254
+ # 查看所有用户
255
+ psql -U postgres -h 127.0.0.1 -c "\du"
256
+
257
+ # 查看所有数据库
258
+ psql -U postgres -h 127.0.0.1 -c "\l"
259
+
260
+ # 执行 SQL 文件
261
+ psql -U sub2api -h 127.0.0.1 -d sub2api -f migration.sql
262
+ ```
263
+
264
+ ### Git 操作
265
+
266
+ ```bash
267
+ # 同步上游
268
+ git fetch upstream
269
+ git checkout main
270
+ git merge upstream/main
271
+ git push origin main
272
+
273
+ # 创建功能分支
274
+ git checkout -b feature/xxx
275
+
276
+ # Rebase 到最新 main
277
+ git fetch upstream
278
+ git rebase upstream/main
279
+ ```
280
+
281
+ ### 前端操作
282
+
283
+ ```bash
284
+ # 安装依赖(必须用 pnpm)
285
+ cd frontend
286
+ pnpm install
287
+
288
+ # 开发服务器
289
+ pnpm dev
290
+
291
+ # 构建
292
+ pnpm build
293
+ ```
294
+
295
+ ### 后端操作
296
+
297
+ ```bash
298
+ # 运行服务器
299
+ cd backend
300
+ go run ./cmd/server/
301
+
302
+ # 生成 Ent 代码
303
+ go generate ./ent
304
+
305
+ # 运行测试
306
+ go test -tags=unit ./...
307
+ go test -tags=integration ./...
308
+
309
+ # Lint 检查
310
+ golangci-lint run ./...
311
+ ```
312
+
313
+ ## 六、项目结构速览
314
+
315
+ ```
316
+ sub2api-bmai/
317
+ ├── backend/
318
+ │ ├── cmd/server/ # 主程序入口
319
+ │ ├── ent/ # Ent ORM 生成代码
320
+ │ │ └── schema/ # 数据库 Schema 定义
321
+ │ ├── internal/
322
+ │ │ ├── handler/ # HTTP 处理器
323
+ │ │ ├── service/ # 业务逻辑
324
+ │ │ ├── repository/ # 数据访问层
325
+ │ │ └── server/ # 服务器配置
326
+ │ ├── migrations/ # 数据库迁移脚本
327
+ │ └── config.yaml # 配置文件
328
+ ├── frontend/
329
+ │ ├── src/
330
+ │ │ ├── api/ # API 调用
331
+ │ │ ├── components/ # Vue 组件
332
+ │ │ ├── views/ # 页面视图
333
+ │ │ ├── types/ # TypeScript 类型
334
+ │ │ └── i18n/ # 国际化
335
+ │ ├── package.json # 依赖配置
336
+ │ └── pnpm-lock.yaml # pnpm 锁文件(必须提交)
337
+ └── .claude/
338
+ └── CLAUDE.md # 本文档
339
+ ```
340
+
341
+ ## 七、参考资源
342
+
343
+ - [上游仓库](https://github.com/Wei-Shaw/sub2api)
344
+ - [Ent 文档](https://entgo.io/docs/getting-started)
345
+ - [Vue3 文档](https://vuejs.org/)
346
+ - [pnpm 文档](https://pnpm.io/)
Dockerfile ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # =============================================================================
2
+ # Sub2API Multi-Stage Dockerfile
3
+ # =============================================================================
4
+ # Stage 1: Build frontend
5
+ # Stage 2: Build Go backend with embedded frontend
6
+ # Stage 3: Final minimal image
7
+ # =============================================================================
8
+
9
+ ARG NODE_IMAGE=node:24-alpine
10
+ ARG GOLANG_IMAGE=golang:1.26.1-alpine
11
+ ARG PYTHON_IMAGE=python:3.12-alpine3.20
12
+ ARG GOPROXY=https://goproxy.cn,direct
13
+ ARG GOSUMDB=sum.golang.google.cn
14
+
15
+ # -----------------------------------------------------------------------------
16
+ # Stage 1: Frontend Builder
17
+ # -----------------------------------------------------------------------------
18
+ FROM ${NODE_IMAGE} AS frontend-builder
19
+
20
+ WORKDIR /app/frontend
21
+
22
+ # Install pnpm
23
+ RUN corepack enable && corepack prepare pnpm@latest --activate
24
+
25
+ # Install dependencies first (better caching)
26
+ COPY frontend/package.json frontend/pnpm-lock.yaml ./
27
+ RUN pnpm install --frozen-lockfile
28
+
29
+ # Copy frontend source and build
30
+ COPY frontend/ ./
31
+ RUN pnpm run build
32
+
33
+ # -----------------------------------------------------------------------------
34
+ # Stage 2: Backend Builder
35
+ # -----------------------------------------------------------------------------
36
+ FROM ${GOLANG_IMAGE} AS backend-builder
37
+
38
+ # Build arguments for version info (set by CI)
39
+ ARG VERSION=
40
+ ARG COMMIT=docker
41
+ ARG DATE
42
+ ARG GOPROXY
43
+ ARG GOSUMDB
44
+
45
+ ENV GOPROXY=${GOPROXY}
46
+ ENV GOSUMDB=${GOSUMDB}
47
+
48
+ # Install build dependencies
49
+ RUN apk add --no-cache git ca-certificates tzdata
50
+
51
+ WORKDIR /app/backend
52
+
53
+ # Copy go mod files first (better caching)
54
+ COPY backend/go.mod backend/go.sum ./
55
+ RUN go mod download
56
+
57
+ # Copy backend source first
58
+ COPY backend/ ./
59
+
60
+ # Copy frontend dist from previous stage (must be after backend copy to avoid being overwritten)
61
+ COPY --from=frontend-builder /app/backend/internal/web/dist ./internal/web/dist
62
+
63
+ # Build the binary (BuildType=release for CI builds, embed frontend)
64
+ # Version precedence: build arg VERSION > cmd/server/VERSION
65
+ RUN VERSION_VALUE="${VERSION}" && \
66
+ if [ -z "${VERSION_VALUE}" ]; then VERSION_VALUE="$(tr -d '\r\n' < ./cmd/server/VERSION)"; fi && \
67
+ DATE_VALUE="${DATE:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}" && \
68
+ CGO_ENABLED=0 GOOS=linux go build \
69
+ -tags embed \
70
+ -ldflags="-s -w -X main.Version=${VERSION_VALUE} -X main.Commit=${COMMIT} -X main.Date=${DATE_VALUE} -X main.BuildType=release" \
71
+ -trimpath \
72
+ -o /app/sub2api \
73
+ ./cmd/server
74
+
75
+ # -----------------------------------------------------------------------------
76
+ # Stage 3: Final Runtime Image
77
+ # -----------------------------------------------------------------------------
78
+ FROM ${PYTHON_IMAGE}
79
+
80
+ # Labels
81
+ LABEL maintainer="Wei-Shaw <github.com/Wei-Shaw>"
82
+ LABEL description="Sub2API - AI API Gateway Platform"
83
+ LABEL org.opencontainers.image.source="https://github.com/Wei-Shaw/sub2api"
84
+
85
+ ENV PATH="/usr/lib/postgresql16/bin:${PATH}" \
86
+ PIP_DISABLE_PIP_VERSION_CHECK=1 \
87
+ PYTHONDONTWRITEBYTECODE=1
88
+
89
+ # Install runtime dependencies
90
+ RUN apk add --no-cache \
91
+ ca-certificates \
92
+ tzdata \
93
+ curl \
94
+ su-exec \
95
+ bash \
96
+ redis \
97
+ postgresql16 \
98
+ postgresql16-client \
99
+ wget \
100
+ && rm -rf /var/cache/apk/*
101
+
102
+ # Create non-root user
103
+ RUN addgroup -g 1000 sub2api && \
104
+ adduser -u 1000 -G sub2api -s /bin/sh -D sub2api
105
+
106
+ # Set working directory
107
+ WORKDIR /app
108
+
109
+ # Copy binary/resources with ownership to avoid extra full-layer chown copy
110
+ COPY --from=backend-builder --chown=sub2api:sub2api /app/sub2api /app/sub2api
111
+ COPY --from=backend-builder --chown=sub2api:sub2api /app/backend/resources /app/resources
112
+
113
+ # Install Hugging Face backup helper dependencies
114
+ COPY deploy/huggingface/requirements.txt /tmp/hf-requirements.txt
115
+ RUN pip install --no-cache-dir -r /tmp/hf-requirements.txt && rm -f /tmp/hf-requirements.txt
116
+
117
+ # Copy deployment helpers
118
+ COPY deploy/huggingface/ /app/deploy/huggingface/
119
+
120
+ # Create data directory
121
+ RUN mkdir -p /app/data /data && \
122
+ chmod +x /app/deploy/huggingface/start.sh /app/deploy/huggingface/backup.sh && \
123
+ chown -R sub2api:sub2api /app /data
124
+
125
+ # Expose port (can be overridden by SERVER_PORT env var)
126
+ EXPOSE 8080
127
+
128
+ # Health check
129
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
130
+ CMD wget -q -T 5 -O /dev/null http://localhost:${SERVER_PORT:-8080}/health || exit 1
131
+
132
+ # Run the Hugging Face startup orchestrator
133
+ ENTRYPOINT ["/app/deploy/huggingface/start.sh"]
Dockerfile.goreleaser ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # =============================================================================
2
+ # Sub2API Dockerfile for GoReleaser
3
+ # =============================================================================
4
+ # This Dockerfile is used by GoReleaser to build Docker images.
5
+ # It only packages the pre-built binary, no compilation needed.
6
+ # =============================================================================
7
+
8
+ ARG ALPINE_IMAGE=alpine:3.21
9
+ ARG POSTGRES_IMAGE=postgres:18-alpine
10
+
11
+ FROM ${POSTGRES_IMAGE} AS pg-client
12
+
13
+ FROM ${ALPINE_IMAGE}
14
+
15
+ LABEL maintainer="Wei-Shaw <github.com/Wei-Shaw>"
16
+ LABEL description="Sub2API - AI API Gateway Platform"
17
+ LABEL org.opencontainers.image.source="https://github.com/Wei-Shaw/sub2api"
18
+
19
+ # Install runtime dependencies
20
+ RUN apk add --no-cache \
21
+ ca-certificates \
22
+ tzdata \
23
+ curl \
24
+ su-exec \
25
+ libpq \
26
+ zstd-libs \
27
+ lz4-libs \
28
+ krb5-libs \
29
+ libldap \
30
+ libedit \
31
+ && rm -rf /var/cache/apk/*
32
+
33
+ # Copy pg_dump and psql from a version-matched PostgreSQL image so backup and
34
+ # restore work in the runtime container without requiring Docker socket access.
35
+ COPY --from=pg-client /usr/local/bin/pg_dump /usr/local/bin/pg_dump
36
+ COPY --from=pg-client /usr/local/bin/psql /usr/local/bin/psql
37
+ COPY --from=pg-client /usr/local/lib/libpq.so.5* /usr/local/lib/
38
+
39
+ # Create non-root user
40
+ RUN addgroup -g 1000 sub2api && \
41
+ adduser -u 1000 -G sub2api -s /bin/sh -D sub2api
42
+
43
+ WORKDIR /app
44
+
45
+ # Copy pre-built binary from GoReleaser
46
+ COPY sub2api /app/sub2api
47
+
48
+ # Create data directory
49
+ RUN mkdir -p /app/data && chown -R sub2api:sub2api /app
50
+
51
+ # Copy entrypoint script (fixes volume permissions then drops to sub2api)
52
+ COPY deploy/docker-entrypoint.sh /app/docker-entrypoint.sh
53
+ RUN chmod +x /app/docker-entrypoint.sh
54
+
55
+ EXPOSE 8080
56
+
57
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
58
+ CMD curl -f http://localhost:${SERVER_PORT:-8080}/health || exit 1
59
+
60
+ # Run the application (entrypoint fixes /app/data ownership then execs as sub2api)
61
+ ENTRYPOINT ["/app/docker-entrypoint.sh"]
62
+ CMD ["/app/sub2api"]
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Wesley Liddick
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Makefile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .PHONY: build build-backend build-frontend build-datamanagementd test test-backend test-frontend test-datamanagementd secret-scan
2
+
3
+ # 一键编译前后端
4
+ build: build-backend build-frontend
5
+
6
+ # 编译后端(复用 backend/Makefile)
7
+ build-backend:
8
+ @$(MAKE) -C backend build
9
+
10
+ # 编译前端(需要已安装依赖)
11
+ build-frontend:
12
+ @pnpm --dir frontend run build
13
+
14
+ # 编译 datamanagementd(宿主机数据管理进程)
15
+ build-datamanagementd:
16
+ @cd datamanagement && go build -o datamanagementd ./cmd/datamanagementd
17
+
18
+ # 运行测试(后端 + 前端)
19
+ test: test-backend test-frontend
20
+
21
+ test-backend:
22
+ @$(MAKE) -C backend test
23
+
24
+ test-frontend:
25
+ @pnpm --dir frontend run lint:check
26
+ @pnpm --dir frontend run typecheck
27
+
28
+ test-datamanagementd:
29
+ @cd datamanagement && go test ./...
30
+
31
+ secret-scan:
32
+ @python3 tools/secret_scan.py
README.md CHANGED
@@ -1,10 +1,625 @@
1
  ---
2
- title: Sub2api
3
- emoji: 🦀
4
- colorFrom: green
5
- colorTo: purple
6
  sdk: docker
 
7
  pinned: false
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Sub2API
3
+ emoji: "🚀"
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: docker
7
+ app_port: 8080
8
  pinned: false
9
+ license: mit
10
  ---
11
 
12
+ # Sub2API
13
+
14
+ <div align="center">
15
+
16
+ [![Go](https://img.shields.io/badge/Go-1.25.7-00ADD8.svg)](https://golang.org/)
17
+ [![Vue](https://img.shields.io/badge/Vue-3.4+-4FC08D.svg)](https://vuejs.org/)
18
+ [![PostgreSQL](https://img.shields.io/badge/PostgreSQL-15+-336791.svg)](https://www.postgresql.org/)
19
+ [![Redis](https://img.shields.io/badge/Redis-7+-DC382D.svg)](https://redis.io/)
20
+ [![Docker](https://img.shields.io/badge/Docker-Ready-2496ED.svg)](https://www.docker.com/)
21
+
22
+ <a href="https://trendshift.io/repositories/21823" target="_blank"><img src="https://trendshift.io/api/badge/repositories/21823" alt="Wei-Shaw%2Fsub2api | Trendshift" width="250" height="55"/></a>
23
+
24
+ **AI API Gateway Platform for Subscription Quota Distribution**
25
+
26
+ English | [中文](README_CN.md)
27
+
28
+ </div>
29
+
30
+ > **Sub2API officially uses only the domains `sub2api.org` and `pincc.ai`. Other websites using the Sub2API name may be third-party deployments or services and are not affiliated with this project. Please verify and exercise your own judgment.**
31
+
32
+ ---
33
+
34
+ ## Demo
35
+
36
+ Try Sub2API online: **[https://demo.sub2api.org/](https://demo.sub2api.org/)**
37
+
38
+ Demo credentials (shared demo environment; **not** created automatically for self-hosted installs):
39
+
40
+ | Email | Password |
41
+ |-------|----------|
42
+ | admin@sub2api.org | admin123 |
43
+
44
+ ## Overview
45
+
46
+ Sub2API is an AI API gateway platform designed to distribute and manage API quotas from AI product subscriptions. Users can access upstream AI services through platform-generated API Keys, while the platform handles authentication, billing, load balancing, and request forwarding.
47
+
48
+ ## Features
49
+
50
+ - **Multi-Account Management** - Support multiple upstream account types (OAuth, API Key)
51
+ - **API Key Distribution** - Generate and manage API Keys for users
52
+ - **Precise Billing** - Token-level usage tracking and cost calculation
53
+ - **Smart Scheduling** - Intelligent account selection with sticky sessions
54
+ - **Concurrency Control** - Per-user and per-account concurrency limits
55
+ - **Rate Limiting** - Configurable request and token rate limits
56
+ - **Admin Dashboard** - Web interface for monitoring and management
57
+ - **External System Integration** - Embed external systems (e.g. payment, ticketing) via iframe to extend the admin dashboard
58
+
59
+ ## Don't Want to Self-Host?
60
+
61
+ <table>
62
+ <tr>
63
+ <td width="180" align="center" valign="middle"><a href="https://shop.pincc.ai/"><img src="assets/partners/logos/pincc-logo.png" alt="pincc" width="120"></a></td>
64
+ <td valign="middle"><b><a href="https://shop.pincc.ai/">PinCC</a></b> is the official relay service built on Sub2API, offering stable access to Claude Code, Codex, Gemini and other popular models — ready to use, no deployment or maintenance required.</td>
65
+ </tr>
66
+ </table>
67
+
68
+ ## Ecosystem
69
+
70
+ Community projects that extend or integrate with Sub2API:
71
+
72
+ | Project | Description | Features |
73
+ |---------|-------------|----------|
74
+ | [Sub2ApiPay](https://github.com/touwaeriol/sub2apipay) | Self-service payment system | Self-service top-up and subscription purchase; supports YiPay protocol, WeChat Pay, Alipay, Stripe; embeddable via iframe |
75
+ | [sub2api-mobile](https://github.com/ckken/sub2api-mobile) | Mobile admin console | Cross-platform app (iOS/Android/Web) for user management, account management, monitoring dashboard, and multi-backend switching; built with Expo + React Native |
76
+
77
+ ## Tech Stack
78
+
79
+ | Component | Technology |
80
+ |-----------|------------|
81
+ | Backend | Go 1.25.7, Gin, Ent |
82
+ | Frontend | Vue 3.4+, Vite 5+, TailwindCSS |
83
+ | Database | PostgreSQL 15+ |
84
+ | Cache/Queue | Redis 7+ |
85
+
86
+ ---
87
+
88
+ ## Nginx Reverse Proxy Note
89
+
90
+ When using Nginx as a reverse proxy for Sub2API (or CRS) with Codex CLI, add the following to the `http` block in your Nginx configuration:
91
+
92
+ ```nginx
93
+ underscores_in_headers on;
94
+ ```
95
+
96
+ Nginx drops headers containing underscores by default (e.g. `session_id`), which breaks sticky session routing in multi-account setups.
97
+
98
+ ---
99
+
100
+ ## Deployment
101
+
102
+ ### Method 0: Hugging Face Docker Space
103
+
104
+ Sub2API can run in a single Hugging Face Docker Space using the deployment helpers under `deploy/huggingface/`.
105
+
106
+ - The Space should stay **public** if you want end users to call your API endpoints directly.
107
+ - Keep backups in a **private dataset repo** (for example `your-name/sub2api-data`).
108
+ - The Space runtime starts a local PostgreSQL server, a local Redis server, restores the latest backup if available, and then launches `sub2api`.
109
+
110
+ Recommended Space secrets:
111
+
112
+ ```bash
113
+ HF_TOKEN=hf_xxx
114
+ HF_BACKUP_REPO=your-name/sub2api-data
115
+ POSTGRES_PASSWORD=...
116
+ JWT_SECRET=...
117
+ TOTP_ENCRYPTION_KEY=...
118
+ ADMIN_EMAIL=admin@example.com
119
+ ADMIN_PASSWORD=...
120
+ ```
121
+
122
+ Useful optional variables:
123
+
124
+ ```bash
125
+ BACKUP_INTERVAL_SECONDS=1800
126
+ OPS_ENABLED=false
127
+ DASHBOARD_AGGREGATION_ENABLED=false
128
+ TZ=Asia/Shanghai
129
+ ```
130
+
131
+ ### Method 1: Script Installation (Recommended)
132
+
133
+ One-click installation script that downloads pre-built binaries from GitHub Releases.
134
+
135
+ #### Prerequisites
136
+
137
+ - Linux server (amd64 or arm64)
138
+ - PostgreSQL 15+ (installed and running)
139
+ - Redis 7+ (installed and running)
140
+ - Root privileges
141
+
142
+ #### Installation Steps
143
+
144
+ ```bash
145
+ curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash
146
+ ```
147
+
148
+ The script will:
149
+ 1. Detect your system architecture
150
+ 2. Download the latest release
151
+ 3. Install binary to `/opt/sub2api`
152
+ 4. Create systemd service
153
+ 5. Configure system user and permissions
154
+
155
+ #### Post-Installation
156
+
157
+ ```bash
158
+ # 1. Start the service
159
+ sudo systemctl start sub2api
160
+
161
+ # 2. Enable auto-start on boot
162
+ sudo systemctl enable sub2api
163
+
164
+ # 3. Open Setup Wizard in browser
165
+ # http://YOUR_SERVER_IP:8080
166
+ ```
167
+
168
+ The Setup Wizard will guide you through:
169
+ - Database configuration
170
+ - Redis configuration
171
+ - Admin account creation
172
+
173
+ #### Upgrade
174
+
175
+ You can upgrade directly from the **Admin Dashboard** by clicking the **Check for Updates** button in the top-left corner.
176
+
177
+ The web interface will:
178
+ - Check for new versions automatically
179
+ - Download and apply updates with one click
180
+ - Support rollback if needed
181
+
182
+ #### Useful Commands
183
+
184
+ ```bash
185
+ # Check status
186
+ sudo systemctl status sub2api
187
+
188
+ # View logs
189
+ sudo journalctl -u sub2api -f
190
+
191
+ # Restart service
192
+ sudo systemctl restart sub2api
193
+
194
+ # Uninstall
195
+ curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash -s -- uninstall -y
196
+ ```
197
+
198
+ ---
199
+
200
+ ### Method 2: Docker Compose (Recommended)
201
+
202
+ Deploy with Docker Compose, including PostgreSQL and Redis containers.
203
+
204
+ #### Prerequisites
205
+
206
+ - Docker 20.10+
207
+ - Docker Compose v2+
208
+
209
+ #### Quick Start (One-Click Deployment)
210
+
211
+ Use the automated deployment script for easy setup:
212
+
213
+ ```bash
214
+ # Create deployment directory
215
+ mkdir -p sub2api-deploy && cd sub2api-deploy
216
+
217
+ # Download and run deployment preparation script
218
+ curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/docker-deploy.sh | bash
219
+
220
+ # Start services
221
+ docker compose up -d
222
+
223
+ # View logs
224
+ docker compose logs -f sub2api
225
+ ```
226
+
227
+ **What the script does:**
228
+ - Downloads `docker-compose.local.yml` (saved as `docker-compose.yml`) and `.env.example`
229
+ - Generates secure credentials (JWT_SECRET, TOTP_ENCRYPTION_KEY, POSTGRES_PASSWORD)
230
+ - Creates `.env` file with auto-generated secrets
231
+ - Creates data directories (uses local directories for easy backup/migration)
232
+ - Displays generated credentials for your reference
233
+
234
+ #### Manual Deployment
235
+
236
+ If you prefer manual setup:
237
+
238
+ ```bash
239
+ # 1. Clone the repository
240
+ git clone https://github.com/Wei-Shaw/sub2api.git
241
+ cd sub2api/deploy
242
+
243
+ # 2. Copy environment configuration
244
+ cp .env.example .env
245
+
246
+ # 3. Edit configuration (generate secure passwords)
247
+ nano .env
248
+ ```
249
+
250
+ **Required configuration in `.env`:**
251
+
252
+ ```bash
253
+ # PostgreSQL password (REQUIRED)
254
+ POSTGRES_PASSWORD=your_secure_password_here
255
+
256
+ # JWT Secret (RECOMMENDED - keeps users logged in after restart)
257
+ JWT_SECRET=your_jwt_secret_here
258
+
259
+ # TOTP Encryption Key (RECOMMENDED - preserves 2FA after restart)
260
+ TOTP_ENCRYPTION_KEY=your_totp_key_here
261
+
262
+ # Optional: Admin account
263
+ ADMIN_EMAIL=admin@example.com
264
+ ADMIN_PASSWORD=your_admin_password
265
+
266
+ # Optional: Custom port
267
+ SERVER_PORT=8080
268
+ ```
269
+
270
+ **Generate secure secrets:**
271
+ ```bash
272
+ # Generate JWT_SECRET
273
+ openssl rand -hex 32
274
+
275
+ # Generate TOTP_ENCRYPTION_KEY
276
+ openssl rand -hex 32
277
+
278
+ # Generate POSTGRES_PASSWORD
279
+ openssl rand -hex 32
280
+ ```
281
+
282
+ ```bash
283
+ # 4. Create data directories (for local version)
284
+ mkdir -p data postgres_data redis_data
285
+
286
+ # 5. Start all services
287
+ # Option A: Local directory version (recommended - easy migration)
288
+ docker compose -f docker-compose.local.yml up -d
289
+
290
+ # Option B: Named volumes version (simple setup)
291
+ docker compose up -d
292
+
293
+ # 6. Check status
294
+ docker compose -f docker-compose.local.yml ps
295
+
296
+ # 7. View logs
297
+ docker compose -f docker-compose.local.yml logs -f sub2api
298
+ ```
299
+
300
+ #### Deployment Versions
301
+
302
+ | Version | Data Storage | Migration | Best For |
303
+ |---------|-------------|-----------|----------|
304
+ | **docker-compose.local.yml** | Local directories | ✅ Easy (tar entire directory) | Production, frequent backups |
305
+ | **docker-compose.yml** | Named volumes | ⚠️ Requires docker commands | Simple setup |
306
+
307
+ **Recommendation:** Use `docker-compose.local.yml` (deployed by script) for easier data management.
308
+
309
+ #### Access
310
+
311
+ Open `http://YOUR_SERVER_IP:8080` in your browser.
312
+
313
+ If admin password was auto-generated, find it in logs:
314
+ ```bash
315
+ docker compose -f docker-compose.local.yml logs sub2api | grep "admin password"
316
+ ```
317
+
318
+ #### Upgrade
319
+
320
+ ```bash
321
+ # Pull latest image and recreate container
322
+ docker compose -f docker-compose.local.yml pull
323
+ docker compose -f docker-compose.local.yml up -d
324
+ ```
325
+
326
+ #### Easy Migration (Local Directory Version)
327
+
328
+ When using `docker-compose.local.yml`, migrate to a new server easily:
329
+
330
+ ```bash
331
+ # On source server
332
+ docker compose -f docker-compose.local.yml down
333
+ cd ..
334
+ tar czf sub2api-complete.tar.gz sub2api-deploy/
335
+
336
+ # Transfer to new server
337
+ scp sub2api-complete.tar.gz user@new-server:/path/
338
+
339
+ # On new server
340
+ tar xzf sub2api-complete.tar.gz
341
+ cd sub2api-deploy/
342
+ docker compose -f docker-compose.local.yml up -d
343
+ ```
344
+
345
+ #### Useful Commands
346
+
347
+ ```bash
348
+ # Stop all services
349
+ docker compose -f docker-compose.local.yml down
350
+
351
+ # Restart
352
+ docker compose -f docker-compose.local.yml restart
353
+
354
+ # View all logs
355
+ docker compose -f docker-compose.local.yml logs -f
356
+
357
+ # Remove all data (caution!)
358
+ docker compose -f docker-compose.local.yml down
359
+ rm -rf data/ postgres_data/ redis_data/
360
+ ```
361
+
362
+ ---
363
+
364
+ ### Method 3: Build from Source
365
+
366
+ Build and run from source code for development or customization.
367
+
368
+ #### Prerequisites
369
+
370
+ - Go 1.21+
371
+ - Node.js 18+
372
+ - PostgreSQL 15+
373
+ - Redis 7+
374
+
375
+ #### Build Steps
376
+
377
+ ```bash
378
+ # 1. Clone the repository
379
+ git clone https://github.com/Wei-Shaw/sub2api.git
380
+ cd sub2api
381
+
382
+ # 2. Install pnpm (if not already installed)
383
+ npm install -g pnpm
384
+
385
+ # 3. Build frontend
386
+ cd frontend
387
+ pnpm install
388
+ pnpm run build
389
+ # Output will be in ../backend/internal/web/dist/
390
+
391
+ # 4. Build backend with embedded frontend
392
+ cd ../backend
393
+ go build -tags embed -o sub2api ./cmd/server
394
+
395
+ # 5. Create configuration file
396
+ cp ../deploy/config.example.yaml ./config.yaml
397
+
398
+ # 6. Edit configuration
399
+ nano config.yaml
400
+ ```
401
+
402
+ > **Note:** The `-tags embed` flag embeds the frontend into the binary. Without this flag, the binary will not serve the frontend UI.
403
+
404
+ **Key configuration in `config.yaml`:**
405
+
406
+ ```yaml
407
+ server:
408
+ host: "0.0.0.0"
409
+ port: 8080
410
+ mode: "release"
411
+
412
+ database:
413
+ host: "localhost"
414
+ port: 5432
415
+ user: "postgres"
416
+ password: "your_password"
417
+ dbname: "sub2api"
418
+
419
+ redis:
420
+ host: "localhost"
421
+ port: 6379
422
+ password: ""
423
+
424
+ jwt:
425
+ secret: "change-this-to-a-secure-random-string"
426
+ expire_hour: 24
427
+
428
+ default:
429
+ user_concurrency: 5
430
+ user_balance: 0
431
+ api_key_prefix: "sk-"
432
+ rate_multiplier: 1.0
433
+ ```
434
+
435
+ ### Sora Status (Temporarily Unavailable)
436
+
437
+ > ⚠️ Sora-related features are temporarily unavailable due to technical issues in upstream integration and media delivery.
438
+ > Please do not rely on Sora in production at this time.
439
+ > Existing `gateway.sora_*` configuration keys are reserved and may not take effect until these issues are resolved.
440
+
441
+ Additional security-related options are available in `config.yaml`:
442
+
443
+ - `cors.allowed_origins` for CORS allowlist
444
+ - `security.url_allowlist` for upstream/pricing/CRS host allowlists
445
+ - `security.url_allowlist.enabled` to disable URL validation (use with caution)
446
+ - `security.url_allowlist.allow_insecure_http` to allow HTTP URLs when validation is disabled
447
+ - `security.url_allowlist.allow_private_hosts` to allow private/local IP addresses
448
+ - `security.response_headers.enabled` to enable configurable response header filtering (disabled uses default allowlist)
449
+ - `security.csp` to control Content-Security-Policy headers
450
+ - `billing.circuit_breaker` to fail closed on billing errors
451
+ - `server.trusted_proxies` to enable X-Forwarded-For parsing
452
+ - `turnstile.required` to require Turnstile in release mode
453
+
454
+ **⚠️ Security Warning: HTTP URL Configuration**
455
+
456
+ When `security.url_allowlist.enabled=false`, the system performs minimal URL validation by default, **rejecting HTTP URLs** and only allowing HTTPS. To allow HTTP URLs (e.g., for development or internal testing), you must explicitly set:
457
+
458
+ ```yaml
459
+ security:
460
+ url_allowlist:
461
+ enabled: false # Disable allowlist checks
462
+ allow_insecure_http: true # Allow HTTP URLs (⚠️ INSECURE)
463
+ ```
464
+
465
+ **Or via environment variable:**
466
+
467
+ ```bash
468
+ SECURITY_URL_ALLOWLIST_ENABLED=false
469
+ SECURITY_URL_ALLOWLIST_ALLOW_INSECURE_HTTP=true
470
+ ```
471
+
472
+ **Risks of allowing HTTP:**
473
+ - API keys and data transmitted in **plaintext** (vulnerable to interception)
474
+ - Susceptible to **man-in-the-middle (MITM) attacks**
475
+ - **NOT suitable for production** environments
476
+
477
+ **When to use HTTP:**
478
+ - ✅ Development/testing with local servers (http://localhost)
479
+ - ✅ Internal networks with trusted endpoints
480
+ - ✅ Testing account connectivity before obtaining HTTPS
481
+ - ❌ Production environments (use HTTPS only)
482
+
483
+ **Example error without this setting:**
484
+ ```
485
+ Invalid base URL: invalid url scheme: http
486
+ ```
487
+
488
+ If you disable URL validation or response header filtering, harden your network layer:
489
+ - Enforce an egress allowlist for upstream domains/IPs
490
+ - Block private/loopback/link-local ranges
491
+ - Enforce TLS-only outbound traffic
492
+ - Strip sensitive upstream response headers at the proxy
493
+
494
+ ```bash
495
+ # 6. Run the application
496
+ ./sub2api
497
+ ```
498
+
499
+ #### Development Mode
500
+
501
+ ```bash
502
+ # Backend (with hot reload)
503
+ cd backend
504
+ go run ./cmd/server
505
+
506
+ # Frontend (with hot reload)
507
+ cd frontend
508
+ pnpm run dev
509
+ ```
510
+
511
+ #### Code Generation
512
+
513
+ When editing `backend/ent/schema`, regenerate Ent + Wire:
514
+
515
+ ```bash
516
+ cd backend
517
+ go generate ./ent
518
+ go generate ./cmd/server
519
+ ```
520
+
521
+ ---
522
+
523
+ ## Simple Mode
524
+
525
+ Simple Mode is designed for individual developers or internal teams who want quick access without full SaaS features.
526
+
527
+ - Enable: Set environment variable `RUN_MODE=simple`
528
+ - Difference: Hides SaaS-related features and skips billing process
529
+ - Security note: In production, you must also set `SIMPLE_MODE_CONFIRM=true` to allow startup
530
+
531
+ ---
532
+
533
+ ## Antigravity Support
534
+
535
+ Sub2API supports [Antigravity](https://antigravity.so/) accounts. After authorization, dedicated endpoints are available for Claude and Gemini models.
536
+
537
+ ### Dedicated Endpoints
538
+
539
+ | Endpoint | Model |
540
+ |----------|-------|
541
+ | `/antigravity/v1/messages` | Claude models |
542
+ | `/antigravity/v1beta/` | Gemini models |
543
+
544
+ ### Claude Code Configuration
545
+
546
+ ```bash
547
+ export ANTHROPIC_BASE_URL="http://localhost:8080/antigravity"
548
+ export ANTHROPIC_AUTH_TOKEN="sk-xxx"
549
+ ```
550
+
551
+ ### Hybrid Scheduling Mode
552
+
553
+ Antigravity accounts support optional **hybrid scheduling**. When enabled, the general endpoints `/v1/messages` and `/v1beta/` will also route requests to Antigravity accounts.
554
+
555
+ > **⚠️ Warning**: Anthropic Claude and Antigravity Claude **cannot be mixed within the same conversation context**. Use groups to isolate them properly.
556
+
557
+ ### Known Issues
558
+
559
+ In Claude Code, Plan Mode cannot exit automatically. (Normally when using the native Claude API, after planning is complete, Claude Code will pop up options for users to approve or reject the plan.)
560
+
561
+ **Workaround**: Press `Shift + Tab` to manually exit Plan Mode, then type your response to approve or reject the plan.
562
+
563
+ ---
564
+
565
+ ## Project Structure
566
+
567
+ ```
568
+ sub2api/
569
+ ├── backend/ # Go backend service
570
+ │ ├── cmd/server/ # Application entry
571
+ │ ├── internal/ # Internal modules
572
+ │ │ ├── config/ # Configuration
573
+ │ │ ├── model/ # Data models
574
+ │ │ ├── service/ # Business logic
575
+ │ │ ├── handler/ # HTTP handlers
576
+ │ │ └── gateway/ # API gateway core
577
+ │ └── resources/ # Static resources
578
+
579
+ ├── frontend/ # Vue 3 frontend
580
+ │ └── src/
581
+ │ ├── api/ # API calls
582
+ │ ├── stores/ # State management
583
+ │ ├── views/ # Page components
584
+ │ └── components/ # Reusable components
585
+
586
+ └── deploy/ # Deployment files
587
+ ├── docker-compose.yml # Docker Compose configuration
588
+ ├── .env.example # Environment variables for Docker Compose
589
+ ├── config.example.yaml # Full config file for binary deployment
590
+ └── install.sh # One-click installation script
591
+ ```
592
+
593
+ ## Disclaimer
594
+
595
+ > **Please read carefully before using this project:**
596
+ >
597
+ > :rotating_light: **Terms of Service Risk**: Using this project may violate Anthropic's Terms of Service. Please read Anthropic's user agreement carefully before use. All risks arising from the use of this project are borne solely by the user.
598
+ >
599
+ > :book: **Disclaimer**: This project is for technical learning and research purposes only. The author assumes no responsibility for account suspension, service interruption, or any other losses caused by the use of this project.
600
+
601
+ ---
602
+
603
+ ## Star History
604
+
605
+ <a href="https://star-history.com/#Wei-Shaw/sub2api&Date">
606
+ <picture>
607
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Wei-Shaw/sub2api&type=Date&theme=dark" />
608
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Wei-Shaw/sub2api&type=Date" />
609
+ <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=Wei-Shaw/sub2api&type=Date" />
610
+ </picture>
611
+ </a>
612
+
613
+ ---
614
+
615
+ ## License
616
+
617
+ MIT License
618
+
619
+ ---
620
+
621
+ <div align="center">
622
+
623
+ **If you find this project useful, please give it a star!**
624
+
625
+ </div>
README_CN.md ADDED
@@ -0,0 +1,646 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Sub2API
2
+
3
+ <div align="center">
4
+
5
+ [![Go](https://img.shields.io/badge/Go-1.25.7-00ADD8.svg)](https://golang.org/)
6
+ [![Vue](https://img.shields.io/badge/Vue-3.4+-4FC08D.svg)](https://vuejs.org/)
7
+ [![PostgreSQL](https://img.shields.io/badge/PostgreSQL-15+-336791.svg)](https://www.postgresql.org/)
8
+ [![Redis](https://img.shields.io/badge/Redis-7+-DC382D.svg)](https://redis.io/)
9
+ [![Docker](https://img.shields.io/badge/Docker-Ready-2496ED.svg)](https://www.docker.com/)
10
+
11
+ <a href="https://trendshift.io/repositories/21823" target="_blank"><img src="https://trendshift.io/api/badge/repositories/21823" alt="Wei-Shaw%2Fsub2api | Trendshift" width="250" height="55"/></a>
12
+
13
+ **AI API 网关平台 - 订阅配额分发管理**
14
+
15
+ [English](README.md) | 中文
16
+
17
+ </div>
18
+
19
+ > **Sub2API 官方仅使用 `sub2api.org` 与 `pincc.ai` 两个域名。其他使用 Sub2API 名义的网站可能为第三方部署或服务,与本项目无关,请自行甄别。**
20
+ ---
21
+
22
+ ## 在线体验
23
+
24
+ 体验地址:**[https://demo.sub2api.org/](https://demo.sub2api.org/)**
25
+
26
+ 演示账号(共享演示环境;自建部署不会自动创建该账号):
27
+
28
+ | 邮箱 | 密码 |
29
+ |------|------|
30
+ | admin@sub2api.org | admin123 |
31
+
32
+ ## 项目概述
33
+
34
+ Sub2API 是一个 AI API 网关平台,用于分发和管理 AI 产品订阅的 API 配额。用户通过平台生成的 API Key 调用上游 AI 服务,平台负责鉴权、计费、负载均衡和请求转发。
35
+
36
+ ## 核心功能
37
+
38
+ - **多账号管理** - 支持多种上游账号类型(OAuth、API Key)
39
+ - **API Key 分发** - 为用户生成和管理 API Key
40
+ - **精确计费** - Token 级别的用量追踪和成本计算
41
+ - **智能调度** - 智能账号选择,支持粘性会话
42
+ - **并发控制** - 用户级和账号级并发限制
43
+ - **速率限制** - 可配置的请求和 Token 速率限制
44
+ - **管理后台** - Web 界面进行监控和管理
45
+ - **外部系统集成** - 支持通过 iframe 嵌入外部系统(如支付、工单等),扩展管理后台功能
46
+
47
+ ## 不想自建?试试官方中转
48
+
49
+ <table>
50
+ <tr>
51
+ <td width="180" align="center" valign="middle"><a href="https://shop.pincc.ai/"><img src="assets/partners/logos/pincc-logo.png" alt="pincc" width="120"></a></td>
52
+ <td valign="middle"><b><a href="https://shop.pincc.ai/">PinCC</a></b> 是基于 Sub2API 搭建的官方中转服务,提供 Claude Code、Codex、Gemini 等主流模型的稳定中转,开箱即用,免去自建部署与运维烦恼。</td>
53
+ </tr>
54
+ </table>
55
+
56
+ ## 生态项目
57
+
58
+ 围绕 Sub2API 的社区扩展与集成项目:
59
+
60
+ | 项目 | 说明 | 功能 |
61
+ |------|------|------|
62
+ | [Sub2ApiPay](https://github.com/touwaeriol/sub2apipay) | 自助支付系统 | 用户自助充值、自助订阅购买;兼容易支付协议、微信官方支付、支付宝官方支付、Stripe;支持 iframe 嵌入管理后台 |
63
+ | [sub2api-mobile](https://github.com/ckken/sub2api-mobile) | 移动端管理控制台 | 跨平台应用(iOS/Android/Web),支持用户管理、账号管理、监控看板、多后端切换;基于 Expo + React Native 构建 |
64
+
65
+ ## 技术栈
66
+
67
+ | 组件 | 技术 |
68
+ |------|------|
69
+ | 后端 | Go 1.25.7, Gin, Ent |
70
+ | 前端 | Vue 3.4+, Vite 5+, TailwindCSS |
71
+ | 数据库 | PostgreSQL 15+ |
72
+ | 缓存/队列 | Redis 7+ |
73
+
74
+ ---
75
+
76
+ ## Nginx 反向代理注意事项
77
+
78
+ 通过 Nginx 反向代理 Sub2API(或 CRS 服务)并搭配 Codex CLI 使用时,需要在 Nginx 配置的 `http` 块中添加:
79
+
80
+ ```nginx
81
+ underscores_in_headers on;
82
+ ```
83
+
84
+ Nginx 默认会丢弃名称中含下划线的请求头(如 `session_id`),这会导致多账号环境下的粘性会话功能失效。
85
+
86
+ ---
87
+
88
+ ## 部署方式
89
+
90
+ ### 方式一:脚本安装(推荐)
91
+
92
+ 一键安装脚本,自动从 GitHub Releases 下载预编译的二进制文件。
93
+
94
+ #### 前置条件
95
+
96
+ - Linux 服务器(amd64 或 arm64)
97
+ - PostgreSQL 15+(已安装并运行)
98
+ - Redis 7+(已安装并运行)
99
+ - Root 权限
100
+
101
+ #### 安装步骤
102
+
103
+ ```bash
104
+ curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash
105
+ ```
106
+
107
+ 脚本会自动:
108
+ 1. 检测系统架构
109
+ 2. 下载最新版本
110
+ 3. 安装二进制文件到 `/opt/sub2api`
111
+ 4. 创建 systemd 服务
112
+ 5. 配置系统用户和权限
113
+
114
+ #### 安装后配置
115
+
116
+ ```bash
117
+ # 1. 启动服务
118
+ sudo systemctl start sub2api
119
+
120
+ # 2. 设置开机自启
121
+ sudo systemctl enable sub2api
122
+
123
+ # 3. 在浏览器中打开设置向导
124
+ # http://你的服务器IP:8080
125
+ ```
126
+
127
+ 设置向导将引导你完成:
128
+ - 数据库配置
129
+ - Redis 配置
130
+ - 管理员账号创建
131
+
132
+ #### 升级
133
+
134
+ 可以直接在 **管理后台** 左上角点击 **检测更新** 按钮进行在线升级。
135
+
136
+ 网页升级功能支持:
137
+ - 自动检测新版本
138
+ - 一键下载并应用更新
139
+ - 支持回滚
140
+
141
+ #### 常用命令
142
+
143
+ ```bash
144
+ # 查看状态
145
+ sudo systemctl status sub2api
146
+
147
+ # 查看日志
148
+ sudo journalctl -u sub2api -f
149
+
150
+ # 重启服务
151
+ sudo systemctl restart sub2api
152
+
153
+ # 卸载
154
+ curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash -s -- uninstall -y
155
+ ```
156
+
157
+ ---
158
+
159
+ ### 方式二:Docker Compose(推荐)
160
+
161
+ 使用 Docker Compose 部署,包含 PostgreSQL 和 Redis 容器。
162
+
163
+ #### 前置条件
164
+
165
+ - Docker 20.10+
166
+ - Docker Compose v2+
167
+
168
+ #### 快速开始(一键部署)
169
+
170
+ 使用自动化部署脚本快速搭建:
171
+
172
+ ```bash
173
+ # 创建部署目录
174
+ mkdir -p sub2api-deploy && cd sub2api-deploy
175
+
176
+ # 下载并运行部署准备脚本
177
+ curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/docker-deploy.sh | bash
178
+
179
+ # 启动服务
180
+ docker compose up -d
181
+
182
+ # 查看日志
183
+ docker compose logs -f sub2api
184
+ ```
185
+
186
+ **脚本功能:**
187
+ - 下载 `docker-compose.local.yml`(本地保存为 `docker-compose.yml`)和 `.env.example`
188
+ - 自动生成安全凭证(JWT_SECRET、TOTP_ENCRYPTION_KEY、POSTGRES_PASSWORD)
189
+ - 创建 `.env` 文件并填充自动生成的密钥
190
+ - 创建数据目录(使用本地目录,便于备份和迁移)
191
+ - 显示生成的凭证供你记录
192
+
193
+ #### 手动部署
194
+
195
+ 如果你希望手动配置:
196
+
197
+ ```bash
198
+ # 1. 克隆仓库
199
+ git clone https://github.com/Wei-Shaw/sub2api.git
200
+ cd sub2api/deploy
201
+
202
+ # 2. 复制环境配置文件
203
+ cp .env.example .env
204
+
205
+ # 3. 编辑配置(生成安全密码)
206
+ nano .env
207
+ ```
208
+
209
+ **`.env` 必须配置项:**
210
+
211
+ ```bash
212
+ # PostgreSQL 密码(必需)
213
+ POSTGRES_PASSWORD=your_secure_password_here
214
+
215
+ # JWT 密钥(推荐 - 重启后保持用户登录状态)
216
+ JWT_SECRET=your_jwt_secret_here
217
+
218
+ # TOTP 加密密钥(推荐 - 重启后保留双因素认证)
219
+ TOTP_ENCRYPTION_KEY=your_totp_key_here
220
+
221
+ # 可选:管理员账号
222
+ ADMIN_EMAIL=admin@example.com
223
+ ADMIN_PASSWORD=your_admin_password
224
+
225
+ # 可选:自定义端口
226
+ SERVER_PORT=8080
227
+ ```
228
+
229
+ **生成安全密钥:**
230
+ ```bash
231
+ # 生成 JWT_SECRET
232
+ openssl rand -hex 32
233
+
234
+ # 生成 TOTP_ENCRYPTION_KEY
235
+ openssl rand -hex 32
236
+
237
+ # 生成 POSTGRES_PASSWORD
238
+ openssl rand -hex 32
239
+ ```
240
+
241
+ ```bash
242
+ # 4. 创建数据目录(本地版)
243
+ mkdir -p data postgres_data redis_data
244
+
245
+ # 5. 启动所有服务
246
+ # 选项 A:本地目录版(推荐 - 易于迁移)
247
+ docker compose -f docker-compose.local.yml up -d
248
+
249
+ # 选项 B:命名卷版(简单设置)
250
+ docker compose up -d
251
+
252
+ # 6. 查看状态
253
+ docker compose -f docker-compose.local.yml ps
254
+
255
+ # 7. 查看日志
256
+ docker compose -f docker-compose.local.yml logs -f sub2api
257
+ ```
258
+
259
+ #### 部署版本对比
260
+
261
+ | 版本 | 数据存储 | 迁移便利性 | 适用场景 |
262
+ |------|---------|-----------|---------|
263
+ | **docker-compose.local.yml** | 本地目录 | ✅ 简单(打包整个目录) | 生产环境、频繁备份 |
264
+ | **docker-compose.yml** | 命名卷 | ⚠️ 需要 docker 命令 | 简单设置 |
265
+
266
+ **推荐:** 使用 `docker-compose.local.yml`(脚本部署)以便更轻松地管理数据。
267
+
268
+ #### 启用“数据管理”功能(datamanagementd)
269
+
270
+ 如需启用管理后台“数据管理”,需要额外部署宿主机数据管理进程 `datamanagementd`。
271
+
272
+ 关键点:
273
+
274
+ - 主进程固定探测:`/tmp/sub2api-datamanagement.sock`
275
+ - 只有该 Socket 可连通时,数据管理功能才会开启
276
+ - Docker 场景需将宿主机 Socket 挂载到容器同路径
277
+
278
+ 详细部署步骤见:`deploy/DATAMANAGEMENTD_CN.md`
279
+
280
+ #### 访问
281
+
282
+ 在浏览器中打开 `http://你的服务器IP:8080`
283
+
284
+ 如果管理员密码是自动生成的,在日志中查找:
285
+ ```bash
286
+ docker compose -f docker-compose.local.yml logs sub2api | grep "admin password"
287
+ ```
288
+
289
+ #### 升级
290
+
291
+ ```bash
292
+ # 拉取最新镜像并重建容器
293
+ docker compose -f docker-compose.local.yml pull
294
+ docker compose -f docker-compose.local.yml up -d
295
+ ```
296
+
297
+ #### 轻松迁移(本地目录版)
298
+
299
+ 使用 `docker-compose.local.yml` 时,可以轻松迁移到新服务器:
300
+
301
+ ```bash
302
+ # 源服务器
303
+ docker compose -f docker-compose.local.yml down
304
+ cd ..
305
+ tar czf sub2api-complete.tar.gz sub2api-deploy/
306
+
307
+ # 传输到新服务器
308
+ scp sub2api-complete.tar.gz user@new-server:/path/
309
+
310
+ # 新服务器
311
+ tar xzf sub2api-complete.tar.gz
312
+ cd sub2api-deploy/
313
+ docker compose -f docker-compose.local.yml up -d
314
+ ```
315
+
316
+ #### 常用命令
317
+
318
+ ```bash
319
+ # 停止所有服务
320
+ docker compose -f docker-compose.local.yml down
321
+
322
+ # 重启
323
+ docker compose -f docker-compose.local.yml restart
324
+
325
+ # 查看所有日志
326
+ docker compose -f docker-compose.local.yml logs -f
327
+
328
+ # 删除所有数据(谨慎!)
329
+ docker compose -f docker-compose.local.yml down
330
+ rm -rf data/ postgres_data/ redis_data/
331
+ ```
332
+
333
+ ---
334
+
335
+ ### 方式三:源码编译
336
+
337
+ 从源码编译安装,适合开发或定制需求。
338
+
339
+ #### 前置条件
340
+
341
+ - Go 1.21+
342
+ - Node.js 18+
343
+ - PostgreSQL 15+
344
+ - Redis 7+
345
+
346
+ #### 编译步骤
347
+
348
+ ```bash
349
+ # 1. 克隆仓库
350
+ git clone https://github.com/Wei-Shaw/sub2api.git
351
+ cd sub2api
352
+
353
+ # 2. 安装 pnpm(如果还没有安装)
354
+ npm install -g pnpm
355
+
356
+ # 3. 编译前端
357
+ cd frontend
358
+ pnpm install
359
+ pnpm run build
360
+ # 构建产物输出到 ../backend/internal/web/dist/
361
+
362
+ # 4. 编译后端(嵌入前端)
363
+ cd ../backend
364
+ go build -tags embed -o sub2api ./cmd/server
365
+
366
+ # 5. 创建配置文件
367
+ cp ../deploy/config.example.yaml ./config.yaml
368
+
369
+ # 6. 编辑配置
370
+ nano config.yaml
371
+ ```
372
+
373
+ > **注意:** `-tags embed` 参数会将前端嵌入到二进制文件中。不使用此参数编译的程序将不包含前端界面。
374
+
375
+ **`config.yaml` 关键配置:**
376
+
377
+ ```yaml
378
+ server:
379
+ host: "0.0.0.0"
380
+ port: 8080
381
+ mode: "release"
382
+
383
+ database:
384
+ host: "localhost"
385
+ port: 5432
386
+ user: "postgres"
387
+ password: "your_password"
388
+ dbname: "sub2api"
389
+
390
+ redis:
391
+ host: "localhost"
392
+ port: 6379
393
+ password: ""
394
+
395
+ jwt:
396
+ secret: "change-this-to-a-secure-random-string"
397
+ expire_hour: 24
398
+
399
+ default:
400
+ user_concurrency: 5
401
+ user_balance: 0
402
+ api_key_prefix: "sk-"
403
+ rate_multiplier: 1.0
404
+ ```
405
+
406
+ ### Sora 功能状态(暂不可用)
407
+
408
+ > ⚠️ 当前 Sora 相关功能因上游接入与媒体链路存在技术问题,暂时不可用。
409
+ > 现阶段请勿在生产环境依赖 Sora 能力。
410
+ > 文档中的 `gateway.sora_*` 配置仅作预留,待技术问题修复后再恢复可用。
411
+
412
+ ### Sora 媒体签名 URL(功能恢复后可选)
413
+
414
+ 当配置 `gateway.sora_media_signing_key` 且 `gateway.sora_media_signed_url_ttl_seconds > 0` 时,网关会将 Sora 输出的媒体地址改写为临时签名 URL(`/sora/media-signed/...`)。这样无需 API Key 即可在浏览器中直接访问,且具备过期控制与防篡改能力(签名包含 path + query)。
415
+
416
+ ```yaml
417
+ gateway:
418
+ # /sora/media 是否强制要求 API Key(默认 false)
419
+ sora_media_require_api_key: false
420
+ # 媒体临时签名密钥(为空则禁用签名)
421
+ sora_media_signing_key: "your-signing-key"
422
+ # 临时签名 URL 有效期(秒)
423
+ sora_media_signed_url_ttl_seconds: 900
424
+ ```
425
+
426
+ > 若未配置签名密钥,`/sora/media-signed` 将返回 503。
427
+ > 如需更严格的访问控制,可将 `sora_media_require_api_key` 设为 true,仅允许携带 API Key 的 `/sora/media` 访问。
428
+
429
+ 访问策略说明:
430
+ - `/sora/media`:内部调用或客户端携带 API Key 才能下载
431
+ - `/sora/media-signed`:外部可访问,但有签名 + 过期控制
432
+
433
+ `config.yaml` 还支持以下安全相关配置:
434
+
435
+ - `cors.allowed_origins` 配置 CORS 白名单
436
+ - `security.url_allowlist` 配置上游/价格数据/CRS 主机白名单
437
+ - `security.url_allowlist.enabled` 可关闭 URL 校验(慎用)
438
+ - `security.url_allowlist.allow_insecure_http` 关闭校验时允许 HTTP URL
439
+ - `security.url_allowlist.allow_private_hosts` 允许私有/本地 IP 地址
440
+ - `security.response_headers.enabled` 可启用可配置响应头过滤(关闭时使用默认白名单)
441
+ - `security.csp` 配置 Content-Security-Policy
442
+ - `billing.circuit_breaker` 计费异常时 fail-closed
443
+ - `server.trusted_proxies` 启用可信代理解析 X-Forwarded-For
444
+ - `turnstile.required` 在 release 模式强制启用 Turnstile
445
+
446
+ **网关防御纵深建议(重点)**
447
+
448
+ - `gateway.upstream_response_read_max_bytes`:限制非流式上游响应读取大小(默认 `8MB`),用于防止异常响应导致内存放大。
449
+ - `gateway.proxy_probe_response_read_max_bytes`:限制代理探测响应读取大小(默认 `1MB`)。
450
+ - `gateway.gemini_debug_response_headers`:默认 `false`,仅在排障时短时开启,避免高频请求日志开销。
451
+ - `/auth/register`、`/auth/login`、`/auth/login/2fa`、`/auth/send-verify-code` 已提供服务端兜底限流(Redis 故障时 fail-close)。
452
+ - 推荐将 WAF/CDN 作为第一层防护,服务端限流与响应读取上限作为第二层兜底;两层同时保留,避免旁路流量与误配置风险。
453
+
454
+ **⚠️ 安全警告:HTTP URL 配置**
455
+
456
+ 当 `security.url_allowlist.enabled=false` 时,系统默认执行最小 URL 校验,**拒绝 HTTP URL**,仅允许 HTTPS。要允许 HTTP URL(例如用于开发或内网测试),必须显式设置:
457
+
458
+ ```yaml
459
+ security:
460
+ url_allowlist:
461
+ enabled: false # 禁用白名单检查
462
+ allow_insecure_http: true # 允许 HTTP URL(⚠️ 不安全)
463
+ ```
464
+
465
+ **或通过环境变量:**
466
+
467
+ ```bash
468
+ SECURITY_URL_ALLOWLIST_ENABLED=false
469
+ SECURITY_URL_ALLOWLIST_ALLOW_INSECURE_HTTP=true
470
+ ```
471
+
472
+ **允许 HTTP 的风险:**
473
+ - API 密钥和数据以**明文传输**(可被截获)
474
+ - 易受**中间人攻击 (MITM)**
475
+ - **不适合生产环境**
476
+
477
+ **适用场景:**
478
+ - ✅ 开发/测试环境的本地服务器(http://localhost)
479
+ - ✅ 内网可信端点
480
+ - ✅ 获取 HTTPS 前测试账号连通性
481
+ - ❌ 生产环境(仅使用 HTTPS)
482
+
483
+ **未设置此项时的错误示例:**
484
+ ```
485
+ Invalid base URL: invalid url scheme: http
486
+ ```
487
+
488
+ 如关闭 URL 校验或响应头过��,请加强网络层防护:
489
+ - 出站访问白名单限制上游域名/IP
490
+ - 阻断私网/回环/链路本地地址
491
+ - 强制仅允许 TLS 出站
492
+ - 在反向代理层移除敏感响应头
493
+
494
+ ```bash
495
+ # 6. 运行应用
496
+ ./sub2api
497
+ ```
498
+
499
+ #### HTTP/2 (h2c) 与 HTTP/1.1 回退
500
+
501
+ 后端明文端口默认支持 h2c,并保留 HTTP/1.1 回退用于 WebSocket 与旧客户端。浏览器通常不支持 h2c,性能收益主要在反向代理或内网链路。
502
+
503
+ **反向代理示例(Caddy):**
504
+
505
+ ```caddyfile
506
+ transport http {
507
+ versions h2c h1
508
+ }
509
+ ```
510
+
511
+ **验证:**
512
+
513
+ ```bash
514
+ # h2c prior knowledge
515
+ curl --http2-prior-knowledge -I http://localhost:8080/health
516
+ # HTTP/1.1 回退
517
+ curl --http1.1 -I http://localhost:8080/health
518
+ # WebSocket 回退验证(需管理员 token)
519
+ websocat -H="Sec-WebSocket-Protocol: sub2api-admin, jwt.<ADMIN_TOKEN>" ws://localhost:8080/api/v1/admin/ops/ws/qps
520
+ ```
521
+
522
+ #### 开发模式
523
+
524
+ ```bash
525
+ # 后端(支持热重载)
526
+ cd backend
527
+ go run ./cmd/server
528
+
529
+ # 前端(支持热重载)
530
+ cd frontend
531
+ pnpm run dev
532
+ ```
533
+
534
+ #### 代码生成
535
+
536
+ 修改 `backend/ent/schema` 后,需要重新生成 Ent + Wire:
537
+
538
+ ```bash
539
+ cd backend
540
+ go generate ./ent
541
+ go generate ./cmd/server
542
+ ```
543
+
544
+ ---
545
+
546
+ ## 简易模式
547
+
548
+ 简易模式适合个人开发者或内部团队快速使用,不依赖完整 SaaS 功能。
549
+
550
+ - 启用方式:设置环境变量 `RUN_MODE=simple`
551
+ - 功能差异:隐藏 SaaS 相关功能,跳过计费流程
552
+ - 安全注意事项:生产环境需同时设置 `SIMPLE_MODE_CONFIRM=true` 才允许启动
553
+
554
+ ---
555
+
556
+ ## Antigravity 使用说明
557
+
558
+ Sub2API 支持 [Antigravity](https://antigravity.so/) 账户,授权后可通过专用端点访问 Claude 和 Gemini 模型。
559
+
560
+ ### 专用端点
561
+
562
+ | 端点 | 模型 |
563
+ |------|------|
564
+ | `/antigravity/v1/messages` | Claude 模型 |
565
+ | `/antigravity/v1beta/` | Gemini 模型 |
566
+
567
+ ### Claude Code 配置示例
568
+
569
+ ```bash
570
+ export ANTHROPIC_BASE_URL="http://localhost:8080/antigravity"
571
+ export ANTHROPIC_AUTH_TOKEN="sk-xxx"
572
+ ```
573
+
574
+ ### 混合调度模式
575
+
576
+ Antigravity 账户支持可选的**混合调度**功能。开启后,通用端点 `/v1/messages` 和 `/v1beta/` 也会调度该账户。
577
+
578
+ > **⚠️ 注意**:Anthropic Claude 和 Antigravity Claude **不能在同一上下文中混合使用**,请通过分组功能做好隔离。
579
+
580
+
581
+ ### 已知问题
582
+ 在 Claude Code 中,无法自动退出Plan Mode。(正常使用原生Claude Api时,Plan 完成后,Claude Code会弹出弹出选项让用户同意或拒绝Plan。)
583
+ 解决办法:shift + Tab,手动退出Plan mode,然后输入内容 告诉 Claude Code 同意或拒绝 Plan
584
+ ---
585
+
586
+ ## 项目结构
587
+
588
+ ```
589
+ sub2api/
590
+ ├── backend/ # Go 后端服务
591
+ │ ├── cmd/server/ # 应用入口
592
+ │ ├── internal/ # 内部模块
593
+ │ │ ├── config/ # 配置管理
594
+ │ │ ├── model/ # 数据模型
595
+ │ │ ├── service/ # 业务逻辑
596
+ │ │ ├── handler/ # HTTP 处理器
597
+ │ │ └── gateway/ # API 网关核心
598
+ │ └── resources/ # 静态资源
599
+
600
+ ├── frontend/ # Vue 3 前端
601
+ │ └── src/
602
+ │ ├── api/ # API 调用
603
+ │ ├── stores/ # 状态管理
604
+ │ ├── views/ # 页面组件
605
+ │ └── components/ # 通用组件
606
+
607
+ └── deploy/ # 部署文件
608
+ ├── docker-compose.yml # Docker Compose 配置
609
+ ├── .env.example # Docker Compose 环境变量
610
+ ├── config.example.yaml # 二进制部署完整配置文件
611
+ └── install.sh # 一键安装脚本
612
+ ```
613
+
614
+ ## 免责声明
615
+
616
+ > **使用本项目前请仔细阅读:**
617
+ >
618
+ > :rotating_light: **服务条款风险**: 使用本项目可能违反 Anthropic 的服务条款。请在使用前仔细阅读 Anthropic 的用户协议,使用本项目的一切风险由用户自行承担。
619
+ >
620
+ > :book: **免责声明**: 本项目仅供技术学习和研究使用,作者不对因使用本项目导致的账户封禁、服务中断或其他损失承担任何责任。
621
+
622
+ ---
623
+
624
+ ## Star History
625
+
626
+ <a href="https://star-history.com/#Wei-Shaw/sub2api&Date">
627
+ <picture>
628
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Wei-Shaw/sub2api&type=Date&theme=dark" />
629
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Wei-Shaw/sub2api&type=Date" />
630
+ <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=Wei-Shaw/sub2api&type=Date" />
631
+ </picture>
632
+ </a>
633
+
634
+ ---
635
+
636
+ ## 许可证
637
+
638
+ MIT License
639
+
640
+ ---
641
+
642
+ <div align="center">
643
+
644
+ **如果觉得有用,请给个 Star 支持一下!**
645
+
646
+ </div>
assets/partners/logos/pincc-logo.png ADDED

Git LFS Details

  • SHA256: 3a3752a166d3f7df4facafbe422bf4ad95738f18d1e9608d138239d75939494b
  • Pointer size: 131 Bytes
  • Size of remote file: 175 kB
backend/.dockerignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .cache/
2
+ .DS_Store
backend/.golangci.yml ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: "2"
2
+
3
+ linters:
4
+ default: none
5
+ enable:
6
+ - depguard
7
+ - errcheck
8
+ - gosec
9
+ - govet
10
+ - ineffassign
11
+ - staticcheck
12
+ - unused
13
+
14
+ settings:
15
+ depguard:
16
+ rules:
17
+ # Enforce: service must not depend on repository.
18
+ service-no-repository:
19
+ list-mode: original
20
+ files:
21
+ - "**/internal/service/**"
22
+ - "!**/internal/service/ops_aggregation_service.go"
23
+ - "!**/internal/service/ops_alert_evaluator_service.go"
24
+ - "!**/internal/service/ops_cleanup_service.go"
25
+ - "!**/internal/service/ops_metrics_collector.go"
26
+ - "!**/internal/service/ops_scheduled_report_service.go"
27
+ - "!**/internal/service/wire.go"
28
+ deny:
29
+ - pkg: github.com/Wei-Shaw/sub2api/internal/repository
30
+ desc: "service must not import repository"
31
+ - pkg: gorm.io/gorm
32
+ desc: "service must not import gorm"
33
+ - pkg: github.com/redis/go-redis/v9
34
+ desc: "service must not import redis"
35
+ handler-no-repository:
36
+ list-mode: original
37
+ files:
38
+ - "**/internal/handler/**"
39
+ deny:
40
+ - pkg: github.com/Wei-Shaw/sub2api/internal/repository
41
+ desc: "handler must not import repository"
42
+ - pkg: gorm.io/gorm
43
+ desc: "handler must not import gorm"
44
+ - pkg: github.com/redis/go-redis/v9
45
+ desc: "handler must not import redis"
46
+ gosec:
47
+ excludes:
48
+ - G101
49
+ - G103
50
+ - G104
51
+ - G109
52
+ - G115
53
+ - G201
54
+ - G202
55
+ - G301
56
+ - G302
57
+ - G304
58
+ - G306
59
+ - G404
60
+ severity: high
61
+ confidence: high
62
+ errcheck:
63
+ # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
64
+ # Such cases aren't reported by default.
65
+ # Default: false
66
+ check-type-assertions: true
67
+ # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
68
+ # Such cases aren't reported by default.
69
+ # Default: false
70
+ check-blank: false
71
+ # To disable the errcheck built-in exclude list.
72
+ # See `-excludeonly` option in https://github.com/kisielk/errcheck#excluding-functions for details.
73
+ # Default: false
74
+ disable-default-exclusions: true
75
+ # List of functions to exclude from checking, where each entry is a single function to exclude.
76
+ # See https://github.com/kisielk/errcheck#excluding-functions for details.
77
+ exclude-functions:
78
+ - io/ioutil.ReadFile
79
+ - io.Copy(*bytes.Buffer)
80
+ - io.Copy(os.Stdout)
81
+ - fmt.Println
82
+ - fmt.Print
83
+ - fmt.Printf
84
+ - fmt.Fprint
85
+ - fmt.Fprintf
86
+ - fmt.Fprintln
87
+ # Display function signature instead of selector.
88
+ # Default: false
89
+ verbose: true
90
+ ineffassign:
91
+ # Check escaping variables of type error, may cause false positives.
92
+ # Default: false
93
+ check-escaping-errors: true
94
+ staticcheck:
95
+ # https://staticcheck.dev/docs/configuration/options/#dot_import_whitelist
96
+ dot-import-whitelist:
97
+ - fmt
98
+ # https://staticcheck.dev/docs/configuration/options/#initialisms
99
+ initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS" ]
100
+ # https://staticcheck.dev/docs/configuration/options/#http_status_code_whitelist
101
+ http-status-code-whitelist: [ "200", "400", "404", "500" ]
102
+ # "all" enables every SA/ST/S/QF check; only list the ones to disable.
103
+ checks:
104
+ - all
105
+ - -ST1000 # Package comment format
106
+ - -ST1003 # Poorly chosen identifier (ApiKey vs APIKey)
107
+ - -ST1020 # Comment on exported method format
108
+ - -ST1021 # Comment on exported type format
109
+ - -ST1022 # Comment on exported variable format
110
+ unused:
111
+ # Default: true
112
+ field-writes-are-uses: true
113
+ # Default: false
114
+ post-statements-are-reads: true
115
+ # Default: true
116
+ exported-fields-are-used: true
117
+ # Default: true
118
+ parameters-are-used: true
119
+ # Default: true
120
+ local-variables-are-used: false
121
+ # Default: true — must be true, ent generates 130K+ lines of code
122
+ generated-is-used: true
123
+
124
+ formatters:
125
+ enable:
126
+ - gofmt
127
+ settings:
128
+ gofmt:
129
+ # Simplify code: gofmt with `-s` option.
130
+ # Default: true
131
+ simplify: false
132
+ # Apply the rewrite rules to the source before reformatting.
133
+ # https://pkg.go.dev/cmd/gofmt
134
+ # Default: []
135
+ rewrite-rules:
136
+ - pattern: 'interface{}'
137
+ replacement: 'any'
138
+ - pattern: 'a[b:len(a)]'
139
+ replacement: 'a[b:]'
backend/Dockerfile ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM golang:1.25.7-alpine
2
+
3
+ WORKDIR /app
4
+
5
+ # 安装必要的工具
6
+ RUN apk add --no-cache git
7
+
8
+ # 复制go.mod和go.sum
9
+ COPY go.mod go.sum ./
10
+
11
+ # 下载依赖
12
+ RUN go mod download
13
+
14
+ # 复制源代码
15
+ COPY . .
16
+
17
+ # 构建应用
18
+ RUN go build -o main ./cmd/server/
19
+
20
+ # 暴露端口
21
+ EXPOSE 8080
22
+
23
+ # 运行应用
24
+ CMD ["./main"]
backend/Makefile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .PHONY: build generate test test-unit test-integration test-e2e
2
+
3
+ VERSION ?= $(shell tr -d '\r\n' < ./cmd/server/VERSION)
4
+ LDFLAGS ?= -s -w -X main.Version=$(VERSION)
5
+
6
+ build:
7
+ CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -trimpath -o bin/server ./cmd/server
8
+
9
+ generate:
10
+ go generate ./ent
11
+ go generate ./cmd/server
12
+
13
+ test:
14
+ go test ./...
15
+ golangci-lint run ./...
16
+
17
+ test-unit:
18
+ go test -tags=unit ./...
19
+
20
+ test-integration:
21
+ go test -tags=integration ./...
22
+
23
+ test-e2e:
24
+ ./scripts/e2e-test.sh
25
+
26
+ test-e2e-local:
27
+ go test -tags=e2e -v -timeout=300s ./internal/integration/...
backend/cmd/jwtgen/main.go ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "flag"
6
+ "fmt"
7
+ "log"
8
+ "time"
9
+
10
+ _ "github.com/Wei-Shaw/sub2api/ent/runtime"
11
+ "github.com/Wei-Shaw/sub2api/internal/config"
12
+ "github.com/Wei-Shaw/sub2api/internal/repository"
13
+ "github.com/Wei-Shaw/sub2api/internal/service"
14
+ )
15
+
16
+ func main() {
17
+ email := flag.String("email", "", "Admin email to issue a JWT for (defaults to first active admin)")
18
+ flag.Parse()
19
+
20
+ cfg, err := config.LoadForBootstrap()
21
+ if err != nil {
22
+ log.Fatalf("failed to load config: %v", err)
23
+ }
24
+
25
+ client, sqlDB, err := repository.InitEnt(cfg)
26
+ if err != nil {
27
+ log.Fatalf("failed to init db: %v", err)
28
+ }
29
+ defer func() {
30
+ if err := client.Close(); err != nil {
31
+ log.Printf("failed to close db: %v", err)
32
+ }
33
+ }()
34
+
35
+ userRepo := repository.NewUserRepository(client, sqlDB)
36
+ authService := service.NewAuthService(client, userRepo, nil, nil, cfg, nil, nil, nil, nil, nil, nil)
37
+
38
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
39
+ defer cancel()
40
+
41
+ var user *service.User
42
+ if *email != "" {
43
+ user, err = userRepo.GetByEmail(ctx, *email)
44
+ } else {
45
+ user, err = userRepo.GetFirstAdmin(ctx)
46
+ }
47
+ if err != nil {
48
+ log.Fatalf("failed to resolve admin user: %v", err)
49
+ }
50
+
51
+ token, err := authService.GenerateToken(user)
52
+ if err != nil {
53
+ log.Fatalf("failed to generate token: %v", err)
54
+ }
55
+
56
+ fmt.Printf("ADMIN_EMAIL=%s\nADMIN_USER_ID=%d\nJWT=%s\n", user.Email, user.ID, token)
57
+ }
backend/cmd/server/VERSION ADDED
@@ -0,0 +1 @@
 
 
1
+ 0.1.104
backend/cmd/server/main.go ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package main
2
+
3
+ //go:generate go run github.com/google/wire/cmd/wire
4
+
5
+ import (
6
+ "context"
7
+ _ "embed"
8
+ "errors"
9
+ "flag"
10
+ "log"
11
+ "net/http"
12
+ "os"
13
+ "os/signal"
14
+ "strings"
15
+ "syscall"
16
+ "time"
17
+
18
+ _ "github.com/Wei-Shaw/sub2api/ent/runtime"
19
+ "github.com/Wei-Shaw/sub2api/internal/config"
20
+ "github.com/Wei-Shaw/sub2api/internal/handler"
21
+ "github.com/Wei-Shaw/sub2api/internal/pkg/logger"
22
+ "github.com/Wei-Shaw/sub2api/internal/server/middleware"
23
+ "github.com/Wei-Shaw/sub2api/internal/setup"
24
+ "github.com/Wei-Shaw/sub2api/internal/web"
25
+
26
+ "github.com/gin-gonic/gin"
27
+ "golang.org/x/net/http2"
28
+ "golang.org/x/net/http2/h2c"
29
+ )
30
+
31
+ //go:embed VERSION
32
+ var embeddedVersion string
33
+
34
+ // Build-time variables (can be set by ldflags)
35
+ var (
36
+ Version = ""
37
+ Commit = "unknown"
38
+ Date = "unknown"
39
+ BuildType = "source" // "source" for manual builds, "release" for CI builds (set by ldflags)
40
+ )
41
+
42
+ func init() {
43
+ // 如果 Version 已通过 ldflags 注入(例如 -X main.Version=...),则不要覆盖。
44
+ if strings.TrimSpace(Version) != "" {
45
+ return
46
+ }
47
+
48
+ // 默认从 embedded VERSION 文件读取版本号(编译期打包进二进制)。
49
+ Version = strings.TrimSpace(embeddedVersion)
50
+ if Version == "" {
51
+ Version = "0.0.0-dev"
52
+ }
53
+ }
54
+
55
+ // initLogger configures the default slog handler based on gin.Mode().
56
+ // In non-release mode, Debug level logs are enabled.
57
+ func main() {
58
+ logger.InitBootstrap()
59
+ defer logger.Sync()
60
+
61
+ // Parse command line flags
62
+ setupMode := flag.Bool("setup", false, "Run setup wizard in CLI mode")
63
+ showVersion := flag.Bool("version", false, "Show version information")
64
+ flag.Parse()
65
+
66
+ if *showVersion {
67
+ log.Printf("Sub2API %s (commit: %s, built: %s)\n", Version, Commit, Date)
68
+ return
69
+ }
70
+
71
+ // CLI setup mode
72
+ if *setupMode {
73
+ if err := setup.RunCLI(); err != nil {
74
+ log.Fatalf("Setup failed: %v", err)
75
+ }
76
+ return
77
+ }
78
+
79
+ // Check if setup is needed
80
+ if setup.NeedsSetup() {
81
+ // Check if auto-setup is enabled (for Docker deployment)
82
+ if setup.AutoSetupEnabled() {
83
+ log.Println("Auto setup mode enabled...")
84
+ if err := setup.AutoSetupFromEnv(); err != nil {
85
+ log.Fatalf("Auto setup failed: %v", err)
86
+ }
87
+ // Continue to main server after auto-setup
88
+ } else {
89
+ log.Println("First run detected, starting setup wizard...")
90
+ runSetupServer()
91
+ return
92
+ }
93
+ }
94
+
95
+ // Normal server mode
96
+ runMainServer()
97
+ }
98
+
99
+ func runSetupServer() {
100
+ r := gin.New()
101
+ r.Use(middleware.Recovery())
102
+ r.Use(middleware.CORS(config.CORSConfig{}))
103
+ r.Use(middleware.SecurityHeaders(config.CSPConfig{Enabled: true, Policy: config.DefaultCSPPolicy}, nil))
104
+
105
+ // Register setup routes
106
+ setup.RegisterRoutes(r)
107
+
108
+ // Serve embedded frontend if available
109
+ if web.HasEmbeddedFrontend() {
110
+ r.Use(web.ServeEmbeddedFrontend())
111
+ }
112
+
113
+ // Get server address from config.yaml or environment variables (SERVER_HOST, SERVER_PORT)
114
+ // This allows users to run setup on a different address if needed
115
+ addr := config.GetServerAddress()
116
+ log.Printf("Setup wizard available at http://%s", addr)
117
+ log.Println("Complete the setup wizard to configure Sub2API")
118
+
119
+ server := &http.Server{
120
+ Addr: addr,
121
+ Handler: h2c.NewHandler(r, &http2.Server{}),
122
+ ReadHeaderTimeout: 30 * time.Second,
123
+ IdleTimeout: 120 * time.Second,
124
+ }
125
+
126
+ if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
127
+ log.Fatalf("Failed to start setup server: %v", err)
128
+ }
129
+ }
130
+
131
+ func runMainServer() {
132
+ cfg, err := config.LoadForBootstrap()
133
+ if err != nil {
134
+ log.Fatalf("Failed to load config: %v", err)
135
+ }
136
+ if err := logger.Init(logger.OptionsFromConfig(cfg.Log)); err != nil {
137
+ log.Fatalf("Failed to initialize logger: %v", err)
138
+ }
139
+ if cfg.RunMode == config.RunModeSimple {
140
+ log.Println("⚠️ WARNING: Running in SIMPLE mode - billing and quota checks are DISABLED")
141
+ }
142
+
143
+ buildInfo := handler.BuildInfo{
144
+ Version: Version,
145
+ BuildType: BuildType,
146
+ }
147
+
148
+ app, err := initializeApplication(buildInfo)
149
+ if err != nil {
150
+ log.Fatalf("Failed to initialize application: %v", err)
151
+ }
152
+ defer app.Cleanup()
153
+
154
+ // 启动服务器
155
+ go func() {
156
+ if err := app.Server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
157
+ log.Fatalf("Failed to start server: %v", err)
158
+ }
159
+ }()
160
+
161
+ log.Printf("Server started on %s", app.Server.Addr)
162
+
163
+ // 等待中断信号
164
+ quit := make(chan os.Signal, 1)
165
+ signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
166
+ <-quit
167
+
168
+ log.Println("Shutting down server...")
169
+
170
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
171
+ defer cancel()
172
+
173
+ if err := app.Server.Shutdown(ctx); err != nil {
174
+ log.Fatalf("Server forced to shutdown: %v", err)
175
+ }
176
+
177
+ log.Println("Server exited")
178
+ }
backend/cmd/server/wire.go ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //go:build wireinject
2
+ // +build wireinject
3
+
4
+ package main
5
+
6
+ import (
7
+ "context"
8
+ "log"
9
+ "net/http"
10
+ "sync"
11
+ "time"
12
+
13
+ "github.com/Wei-Shaw/sub2api/ent"
14
+ "github.com/Wei-Shaw/sub2api/internal/config"
15
+ "github.com/Wei-Shaw/sub2api/internal/handler"
16
+ "github.com/Wei-Shaw/sub2api/internal/repository"
17
+ "github.com/Wei-Shaw/sub2api/internal/server"
18
+ "github.com/Wei-Shaw/sub2api/internal/server/middleware"
19
+ "github.com/Wei-Shaw/sub2api/internal/service"
20
+
21
+ "github.com/google/wire"
22
+ "github.com/redis/go-redis/v9"
23
+ )
24
+
25
+ type Application struct {
26
+ Server *http.Server
27
+ Cleanup func()
28
+ }
29
+
30
+ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
31
+ wire.Build(
32
+ // Infrastructure layer ProviderSets
33
+ config.ProviderSet,
34
+
35
+ // Business layer ProviderSets
36
+ repository.ProviderSet,
37
+ service.ProviderSet,
38
+ middleware.ProviderSet,
39
+ handler.ProviderSet,
40
+
41
+ // Server layer ProviderSet
42
+ server.ProviderSet,
43
+
44
+ // Privacy client factory for OpenAI training opt-out
45
+ providePrivacyClientFactory,
46
+
47
+ // BuildInfo provider
48
+ provideServiceBuildInfo,
49
+
50
+ // Cleanup function provider
51
+ provideCleanup,
52
+
53
+ // Application struct
54
+ wire.Struct(new(Application), "Server", "Cleanup"),
55
+ )
56
+ return nil, nil
57
+ }
58
+
59
+ func providePrivacyClientFactory() service.PrivacyClientFactory {
60
+ return repository.CreatePrivacyReqClient
61
+ }
62
+
63
+ func provideServiceBuildInfo(buildInfo handler.BuildInfo) service.BuildInfo {
64
+ return service.BuildInfo{
65
+ Version: buildInfo.Version,
66
+ BuildType: buildInfo.BuildType,
67
+ }
68
+ }
69
+
70
+ func provideCleanup(
71
+ entClient *ent.Client,
72
+ rdb *redis.Client,
73
+ opsMetricsCollector *service.OpsMetricsCollector,
74
+ opsAggregation *service.OpsAggregationService,
75
+ opsAlertEvaluator *service.OpsAlertEvaluatorService,
76
+ opsCleanup *service.OpsCleanupService,
77
+ opsScheduledReport *service.OpsScheduledReportService,
78
+ opsSystemLogSink *service.OpsSystemLogSink,
79
+ soraMediaCleanup *service.SoraMediaCleanupService,
80
+ schedulerSnapshot *service.SchedulerSnapshotService,
81
+ tokenRefresh *service.TokenRefreshService,
82
+ accountExpiry *service.AccountExpiryService,
83
+ subscriptionExpiry *service.SubscriptionExpiryService,
84
+ usageCleanup *service.UsageCleanupService,
85
+ idempotencyCleanup *service.IdempotencyCleanupService,
86
+ pricing *service.PricingService,
87
+ emailQueue *service.EmailQueueService,
88
+ billingCache *service.BillingCacheService,
89
+ usageRecordWorkerPool *service.UsageRecordWorkerPool,
90
+ subscriptionService *service.SubscriptionService,
91
+ oauth *service.OAuthService,
92
+ openaiOAuth *service.OpenAIOAuthService,
93
+ geminiOAuth *service.GeminiOAuthService,
94
+ antigravityOAuth *service.AntigravityOAuthService,
95
+ openAIGateway *service.OpenAIGatewayService,
96
+ scheduledTestRunner *service.ScheduledTestRunnerService,
97
+ backupSvc *service.BackupService,
98
+ ) func() {
99
+ return func() {
100
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
101
+ defer cancel()
102
+
103
+ type cleanupStep struct {
104
+ name string
105
+ fn func() error
106
+ }
107
+
108
+ // 应用层清理步骤可并行执行,基础设施资源(Redis/Ent)最后按顺序关闭。
109
+ parallelSteps := []cleanupStep{
110
+ {"OpsScheduledReportService", func() error {
111
+ if opsScheduledReport != nil {
112
+ opsScheduledReport.Stop()
113
+ }
114
+ return nil
115
+ }},
116
+ {"OpsCleanupService", func() error {
117
+ if opsCleanup != nil {
118
+ opsCleanup.Stop()
119
+ }
120
+ return nil
121
+ }},
122
+ {"OpsSystemLogSink", func() error {
123
+ if opsSystemLogSink != nil {
124
+ opsSystemLogSink.Stop()
125
+ }
126
+ return nil
127
+ }},
128
+ {"SoraMediaCleanupService", func() error {
129
+ if soraMediaCleanup != nil {
130
+ soraMediaCleanup.Stop()
131
+ }
132
+ return nil
133
+ }},
134
+ {"OpsAlertEvaluatorService", func() error {
135
+ if opsAlertEvaluator != nil {
136
+ opsAlertEvaluator.Stop()
137
+ }
138
+ return nil
139
+ }},
140
+ {"OpsAggregationService", func() error {
141
+ if opsAggregation != nil {
142
+ opsAggregation.Stop()
143
+ }
144
+ return nil
145
+ }},
146
+ {"OpsMetricsCollector", func() error {
147
+ if opsMetricsCollector != nil {
148
+ opsMetricsCollector.Stop()
149
+ }
150
+ return nil
151
+ }},
152
+ {"SchedulerSnapshotService", func() error {
153
+ if schedulerSnapshot != nil {
154
+ schedulerSnapshot.Stop()
155
+ }
156
+ return nil
157
+ }},
158
+ {"UsageCleanupService", func() error {
159
+ if usageCleanup != nil {
160
+ usageCleanup.Stop()
161
+ }
162
+ return nil
163
+ }},
164
+ {"IdempotencyCleanupService", func() error {
165
+ if idempotencyCleanup != nil {
166
+ idempotencyCleanup.Stop()
167
+ }
168
+ return nil
169
+ }},
170
+ {"TokenRefreshService", func() error {
171
+ tokenRefresh.Stop()
172
+ return nil
173
+ }},
174
+ {"AccountExpiryService", func() error {
175
+ accountExpiry.Stop()
176
+ return nil
177
+ }},
178
+ {"SubscriptionExpiryService", func() error {
179
+ subscriptionExpiry.Stop()
180
+ return nil
181
+ }},
182
+ {"SubscriptionService", func() error {
183
+ if subscriptionService != nil {
184
+ subscriptionService.Stop()
185
+ }
186
+ return nil
187
+ }},
188
+ {"PricingService", func() error {
189
+ pricing.Stop()
190
+ return nil
191
+ }},
192
+ {"EmailQueueService", func() error {
193
+ emailQueue.Stop()
194
+ return nil
195
+ }},
196
+ {"BillingCacheService", func() error {
197
+ billingCache.Stop()
198
+ return nil
199
+ }},
200
+ {"UsageRecordWorkerPool", func() error {
201
+ if usageRecordWorkerPool != nil {
202
+ usageRecordWorkerPool.Stop()
203
+ }
204
+ return nil
205
+ }},
206
+ {"OAuthService", func() error {
207
+ oauth.Stop()
208
+ return nil
209
+ }},
210
+ {"OpenAIOAuthService", func() error {
211
+ openaiOAuth.Stop()
212
+ return nil
213
+ }},
214
+ {"GeminiOAuthService", func() error {
215
+ geminiOAuth.Stop()
216
+ return nil
217
+ }},
218
+ {"AntigravityOAuthService", func() error {
219
+ antigravityOAuth.Stop()
220
+ return nil
221
+ }},
222
+ {"OpenAIWSPool", func() error {
223
+ if openAIGateway != nil {
224
+ openAIGateway.CloseOpenAIWSPool()
225
+ }
226
+ return nil
227
+ }},
228
+ {"ScheduledTestRunnerService", func() error {
229
+ if scheduledTestRunner != nil {
230
+ scheduledTestRunner.Stop()
231
+ }
232
+ return nil
233
+ }},
234
+ {"BackupService", func() error {
235
+ if backupSvc != nil {
236
+ backupSvc.Stop()
237
+ }
238
+ return nil
239
+ }},
240
+ }
241
+
242
+ infraSteps := []cleanupStep{
243
+ {"Redis", func() error {
244
+ if rdb == nil {
245
+ return nil
246
+ }
247
+ return rdb.Close()
248
+ }},
249
+ {"Ent", func() error {
250
+ if entClient == nil {
251
+ return nil
252
+ }
253
+ return entClient.Close()
254
+ }},
255
+ }
256
+
257
+ runParallel := func(steps []cleanupStep) {
258
+ var wg sync.WaitGroup
259
+ for i := range steps {
260
+ step := steps[i]
261
+ wg.Add(1)
262
+ go func() {
263
+ defer wg.Done()
264
+ if err := step.fn(); err != nil {
265
+ log.Printf("[Cleanup] %s failed: %v", step.name, err)
266
+ return
267
+ }
268
+ log.Printf("[Cleanup] %s succeeded", step.name)
269
+ }()
270
+ }
271
+ wg.Wait()
272
+ }
273
+
274
+ runSequential := func(steps []cleanupStep) {
275
+ for i := range steps {
276
+ step := steps[i]
277
+ if err := step.fn(); err != nil {
278
+ log.Printf("[Cleanup] %s failed: %v", step.name, err)
279
+ continue
280
+ }
281
+ log.Printf("[Cleanup] %s succeeded", step.name)
282
+ }
283
+ }
284
+
285
+ runParallel(parallelSteps)
286
+ runSequential(infraSteps)
287
+
288
+ // Check if context timed out
289
+ select {
290
+ case <-ctx.Done():
291
+ log.Printf("[Cleanup] Warning: cleanup timed out after 10 seconds")
292
+ default:
293
+ log.Printf("[Cleanup] All cleanup steps completed")
294
+ }
295
+ }
296
+ }
backend/cmd/server/wire_gen.go ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by Wire. DO NOT EDIT.
2
+
3
+ //go:generate go run -mod=mod github.com/google/wire/cmd/wire
4
+ //go:build !wireinject
5
+ // +build !wireinject
6
+
7
+ package main
8
+
9
+ import (
10
+ "context"
11
+ "github.com/Wei-Shaw/sub2api/ent"
12
+ "github.com/Wei-Shaw/sub2api/internal/config"
13
+ "github.com/Wei-Shaw/sub2api/internal/handler"
14
+ "github.com/Wei-Shaw/sub2api/internal/handler/admin"
15
+ "github.com/Wei-Shaw/sub2api/internal/repository"
16
+ "github.com/Wei-Shaw/sub2api/internal/server"
17
+ "github.com/Wei-Shaw/sub2api/internal/server/middleware"
18
+ "github.com/Wei-Shaw/sub2api/internal/service"
19
+ "github.com/redis/go-redis/v9"
20
+ "log"
21
+ "net/http"
22
+ "sync"
23
+ "time"
24
+ )
25
+
26
+ import (
27
+ _ "embed"
28
+ _ "github.com/Wei-Shaw/sub2api/ent/runtime"
29
+ )
30
+
31
+ // Injectors from wire.go:
32
+
33
+ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
34
+ configConfig, err := config.ProvideConfig()
35
+ if err != nil {
36
+ return nil, err
37
+ }
38
+ client, err := repository.ProvideEnt(configConfig)
39
+ if err != nil {
40
+ return nil, err
41
+ }
42
+ db, err := repository.ProvideSQLDB(client)
43
+ if err != nil {
44
+ return nil, err
45
+ }
46
+ userRepository := repository.NewUserRepository(client, db)
47
+ redeemCodeRepository := repository.NewRedeemCodeRepository(client)
48
+ redisClient := repository.ProvideRedis(configConfig)
49
+ refreshTokenCache := repository.NewRefreshTokenCache(redisClient)
50
+ settingRepository := repository.NewSettingRepository(client)
51
+ groupRepository := repository.NewGroupRepository(client, db)
52
+ settingService := service.ProvideSettingService(settingRepository, groupRepository, configConfig)
53
+ emailCache := repository.NewEmailCache(redisClient)
54
+ emailService := service.NewEmailService(settingRepository, emailCache)
55
+ turnstileVerifier := repository.NewTurnstileVerifier()
56
+ turnstileService := service.NewTurnstileService(settingService, turnstileVerifier)
57
+ emailQueueService := service.ProvideEmailQueueService(emailService)
58
+ promoCodeRepository := repository.NewPromoCodeRepository(client)
59
+ billingCache := repository.NewBillingCache(redisClient)
60
+ userSubscriptionRepository := repository.NewUserSubscriptionRepository(client)
61
+ apiKeyRepository := repository.NewAPIKeyRepository(client, db)
62
+ billingCacheService := service.NewBillingCacheService(billingCache, userRepository, userSubscriptionRepository, apiKeyRepository, configConfig)
63
+ userGroupRateRepository := repository.NewUserGroupRateRepository(db)
64
+ apiKeyCache := repository.NewAPIKeyCache(redisClient)
65
+ apiKeyService := service.NewAPIKeyService(apiKeyRepository, userRepository, groupRepository, userSubscriptionRepository, userGroupRateRepository, apiKeyCache, configConfig)
66
+ apiKeyService.SetRateLimitCacheInvalidator(billingCache)
67
+ apiKeyAuthCacheInvalidator := service.ProvideAPIKeyAuthCacheInvalidator(apiKeyService)
68
+ promoService := service.NewPromoService(promoCodeRepository, userRepository, billingCacheService, client, apiKeyAuthCacheInvalidator)
69
+ subscriptionService := service.NewSubscriptionService(groupRepository, userSubscriptionRepository, billingCacheService, client, configConfig)
70
+ authService := service.NewAuthService(client, userRepository, redeemCodeRepository, refreshTokenCache, configConfig, settingService, emailService, turnstileService, emailQueueService, promoService, subscriptionService)
71
+ userService := service.NewUserService(userRepository, apiKeyAuthCacheInvalidator, billingCache)
72
+ redeemCache := repository.NewRedeemCache(redisClient)
73
+ redeemService := service.NewRedeemService(redeemCodeRepository, userRepository, subscriptionService, redeemCache, billingCacheService, client, apiKeyAuthCacheInvalidator)
74
+ secretEncryptor, err := repository.NewAESEncryptor(configConfig)
75
+ if err != nil {
76
+ return nil, err
77
+ }
78
+ totpCache := repository.NewTotpCache(redisClient)
79
+ totpService := service.NewTotpService(userRepository, secretEncryptor, totpCache, settingService, emailService, emailQueueService)
80
+ authHandler := handler.NewAuthHandler(configConfig, authService, userService, settingService, promoService, redeemService, totpService)
81
+ userHandler := handler.NewUserHandler(userService)
82
+ apiKeyHandler := handler.NewAPIKeyHandler(apiKeyService)
83
+ usageLogRepository := repository.NewUsageLogRepository(client, db)
84
+ usageBillingRepository := repository.NewUsageBillingRepository(client, db)
85
+ usageService := service.NewUsageService(usageLogRepository, userRepository, client, apiKeyAuthCacheInvalidator)
86
+ usageHandler := handler.NewUsageHandler(usageService, apiKeyService)
87
+ redeemHandler := handler.NewRedeemHandler(redeemService)
88
+ subscriptionHandler := handler.NewSubscriptionHandler(subscriptionService)
89
+ announcementRepository := repository.NewAnnouncementRepository(client)
90
+ announcementReadRepository := repository.NewAnnouncementReadRepository(client)
91
+ announcementService := service.NewAnnouncementService(announcementRepository, announcementReadRepository, userRepository, userSubscriptionRepository)
92
+ announcementHandler := handler.NewAnnouncementHandler(announcementService)
93
+ dashboardAggregationRepository := repository.NewDashboardAggregationRepository(db)
94
+ dashboardStatsCache := repository.NewDashboardCache(redisClient, configConfig)
95
+ dashboardService := service.NewDashboardService(usageLogRepository, dashboardAggregationRepository, dashboardStatsCache, configConfig)
96
+ timingWheelService, err := service.ProvideTimingWheelService()
97
+ if err != nil {
98
+ return nil, err
99
+ }
100
+ dashboardAggregationService := service.ProvideDashboardAggregationService(dashboardAggregationRepository, timingWheelService, configConfig)
101
+ dashboardHandler := admin.NewDashboardHandler(dashboardService, dashboardAggregationService)
102
+ schedulerCache := repository.NewSchedulerCache(redisClient)
103
+ accountRepository := repository.NewAccountRepository(client, db, schedulerCache)
104
+ soraAccountRepository := repository.NewSoraAccountRepository(db)
105
+ proxyRepository := repository.NewProxyRepository(client, db)
106
+ proxyExitInfoProber := repository.NewProxyExitInfoProber(configConfig)
107
+ proxyLatencyCache := repository.NewProxyLatencyCache(redisClient)
108
+ privacyClientFactory := providePrivacyClientFactory()
109
+ adminService := service.NewAdminService(userRepository, groupRepository, accountRepository, soraAccountRepository, proxyRepository, apiKeyRepository, redeemCodeRepository, userGroupRateRepository, billingCacheService, proxyExitInfoProber, proxyLatencyCache, apiKeyAuthCacheInvalidator, client, settingService, subscriptionService, userSubscriptionRepository, privacyClientFactory)
110
+ concurrencyCache := repository.ProvideConcurrencyCache(redisClient, configConfig)
111
+ concurrencyService := service.ProvideConcurrencyService(concurrencyCache, accountRepository, configConfig)
112
+ adminUserHandler := admin.NewUserHandler(adminService, concurrencyService)
113
+ claudeOAuthClient := repository.NewClaudeOAuthClient()
114
+ oAuthService := service.NewOAuthService(proxyRepository, claudeOAuthClient)
115
+ openAIOAuthClient := repository.NewOpenAIOAuthClient()
116
+ openAIOAuthService := service.NewOpenAIOAuthService(proxyRepository, openAIOAuthClient)
117
+ geminiOAuthClient := repository.NewGeminiOAuthClient(configConfig)
118
+ geminiCliCodeAssistClient := repository.NewGeminiCliCodeAssistClient()
119
+ driveClient := repository.NewGeminiDriveClient()
120
+ geminiOAuthService := service.NewGeminiOAuthService(proxyRepository, geminiOAuthClient, geminiCliCodeAssistClient, driveClient, configConfig)
121
+ antigravityOAuthService := service.NewAntigravityOAuthService(proxyRepository)
122
+ geminiQuotaService := service.NewGeminiQuotaService(configConfig, settingRepository)
123
+ tempUnschedCache := repository.NewTempUnschedCache(redisClient)
124
+ timeoutCounterCache := repository.NewTimeoutCounterCache(redisClient)
125
+ geminiTokenCache := repository.NewGeminiTokenCache(redisClient)
126
+ oauthRefreshAPI := service.NewOAuthRefreshAPI(accountRepository, geminiTokenCache)
127
+ compositeTokenCacheInvalidator := service.NewCompositeTokenCacheInvalidator(geminiTokenCache)
128
+ rateLimitService := service.ProvideRateLimitService(accountRepository, usageLogRepository, configConfig, geminiQuotaService, tempUnschedCache, timeoutCounterCache, settingService, compositeTokenCacheInvalidator)
129
+ httpUpstream := repository.NewHTTPUpstream(configConfig)
130
+ claudeUsageFetcher := repository.NewClaudeUsageFetcher(httpUpstream)
131
+ antigravityQuotaFetcher := service.NewAntigravityQuotaFetcher(proxyRepository)
132
+ usageCache := service.NewUsageCache()
133
+ identityCache := repository.NewIdentityCache(redisClient)
134
+ accountUsageService := service.NewAccountUsageService(accountRepository, usageLogRepository, claudeUsageFetcher, geminiQuotaService, antigravityQuotaFetcher, usageCache, identityCache)
135
+ geminiTokenProvider := service.ProvideGeminiTokenProvider(accountRepository, geminiTokenCache, geminiOAuthService, oauthRefreshAPI)
136
+ gatewayCache := repository.NewGatewayCache(redisClient)
137
+ schedulerOutboxRepository := repository.NewSchedulerOutboxRepository(db)
138
+ schedulerSnapshotService := service.ProvideSchedulerSnapshotService(schedulerCache, schedulerOutboxRepository, accountRepository, groupRepository, configConfig)
139
+ antigravityTokenProvider := service.ProvideAntigravityTokenProvider(accountRepository, geminiTokenCache, antigravityOAuthService, oauthRefreshAPI, tempUnschedCache)
140
+ antigravityGatewayService := service.NewAntigravityGatewayService(accountRepository, gatewayCache, schedulerSnapshotService, antigravityTokenProvider, rateLimitService, httpUpstream, settingService)
141
+ accountTestService := service.NewAccountTestService(accountRepository, geminiTokenProvider, antigravityGatewayService, httpUpstream, configConfig)
142
+ crsSyncService := service.NewCRSSyncService(accountRepository, proxyRepository, oAuthService, openAIOAuthService, geminiOAuthService, configConfig)
143
+ sessionLimitCache := repository.ProvideSessionLimitCache(redisClient, configConfig)
144
+ rpmCache := repository.NewRPMCache(redisClient)
145
+ groupCapacityService := service.NewGroupCapacityService(accountRepository, groupRepository, concurrencyService, sessionLimitCache, rpmCache)
146
+ groupHandler := admin.NewGroupHandler(adminService, dashboardService, groupCapacityService)
147
+ accountHandler := admin.NewAccountHandler(adminService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, rateLimitService, accountUsageService, accountTestService, concurrencyService, crsSyncService, sessionLimitCache, rpmCache, compositeTokenCacheInvalidator)
148
+ adminAnnouncementHandler := admin.NewAnnouncementHandler(announcementService)
149
+ dataManagementService := service.NewDataManagementService()
150
+ dataManagementHandler := admin.NewDataManagementHandler(dataManagementService)
151
+ backupObjectStoreFactory := repository.NewS3BackupStoreFactory()
152
+ dbDumper := repository.NewPgDumper(configConfig)
153
+ backupService := service.ProvideBackupService(settingRepository, configConfig, secretEncryptor, backupObjectStoreFactory, dbDumper)
154
+ backupHandler := admin.NewBackupHandler(backupService, userService)
155
+ oAuthHandler := admin.NewOAuthHandler(oAuthService)
156
+ openAIOAuthHandler := admin.NewOpenAIOAuthHandler(openAIOAuthService, adminService)
157
+ geminiOAuthHandler := admin.NewGeminiOAuthHandler(geminiOAuthService)
158
+ antigravityOAuthHandler := admin.NewAntigravityOAuthHandler(antigravityOAuthService)
159
+ proxyHandler := admin.NewProxyHandler(adminService)
160
+ adminRedeemHandler := admin.NewRedeemHandler(adminService, redeemService)
161
+ promoHandler := admin.NewPromoHandler(promoService)
162
+ opsRepository := repository.NewOpsRepository(db)
163
+ pricingRemoteClient := repository.ProvidePricingRemoteClient(configConfig)
164
+ pricingService, err := service.ProvidePricingService(configConfig, pricingRemoteClient)
165
+ if err != nil {
166
+ return nil, err
167
+ }
168
+ billingService := service.NewBillingService(configConfig, pricingService)
169
+ identityService := service.NewIdentityService(identityCache)
170
+ deferredService := service.ProvideDeferredService(accountRepository, timingWheelService)
171
+ claudeTokenProvider := service.ProvideClaudeTokenProvider(accountRepository, geminiTokenCache, oAuthService, oauthRefreshAPI)
172
+ digestSessionStore := service.NewDigestSessionStore()
173
+ gatewayService := service.NewGatewayService(accountRepository, groupRepository, usageLogRepository, usageBillingRepository, userRepository, userSubscriptionRepository, userGroupRateRepository, gatewayCache, configConfig, schedulerSnapshotService, concurrencyService, billingService, rateLimitService, billingCacheService, identityService, httpUpstream, deferredService, claudeTokenProvider, sessionLimitCache, rpmCache, digestSessionStore, settingService)
174
+ openAITokenProvider := service.ProvideOpenAITokenProvider(accountRepository, geminiTokenCache, openAIOAuthService, oauthRefreshAPI)
175
+ openAIGatewayService := service.NewOpenAIGatewayService(accountRepository, usageLogRepository, usageBillingRepository, userRepository, userSubscriptionRepository, userGroupRateRepository, gatewayCache, configConfig, schedulerSnapshotService, concurrencyService, billingService, rateLimitService, billingCacheService, httpUpstream, deferredService, openAITokenProvider)
176
+ geminiMessagesCompatService := service.NewGeminiMessagesCompatService(accountRepository, groupRepository, gatewayCache, schedulerSnapshotService, geminiTokenProvider, rateLimitService, httpUpstream, antigravityGatewayService, configConfig)
177
+ opsSystemLogSink := service.ProvideOpsSystemLogSink(opsRepository)
178
+ opsService := service.NewOpsService(opsRepository, settingRepository, configConfig, accountRepository, userRepository, concurrencyService, gatewayService, openAIGatewayService, geminiMessagesCompatService, antigravityGatewayService, opsSystemLogSink)
179
+ soraS3Storage := service.NewSoraS3Storage(settingService)
180
+ settingService.SetOnS3UpdateCallback(soraS3Storage.RefreshClient)
181
+ soraGenerationRepository := repository.NewSoraGenerationRepository(db)
182
+ soraQuotaService := service.NewSoraQuotaService(userRepository, groupRepository, settingService)
183
+ soraGenerationService := service.NewSoraGenerationService(soraGenerationRepository, soraS3Storage, soraQuotaService)
184
+ settingHandler := admin.NewSettingHandler(settingService, emailService, turnstileService, opsService, soraS3Storage)
185
+ opsHandler := admin.NewOpsHandler(opsService)
186
+ updateCache := repository.NewUpdateCache(redisClient)
187
+ gitHubReleaseClient := repository.ProvideGitHubReleaseClient(configConfig)
188
+ serviceBuildInfo := provideServiceBuildInfo(buildInfo)
189
+ updateService := service.ProvideUpdateService(updateCache, gitHubReleaseClient, serviceBuildInfo)
190
+ idempotencyRepository := repository.NewIdempotencyRepository(client, db)
191
+ systemOperationLockService := service.ProvideSystemOperationLockService(idempotencyRepository, configConfig)
192
+ systemHandler := handler.ProvideSystemHandler(updateService, systemOperationLockService)
193
+ adminSubscriptionHandler := admin.NewSubscriptionHandler(subscriptionService)
194
+ usageCleanupRepository := repository.NewUsageCleanupRepository(client, db)
195
+ usageCleanupService := service.ProvideUsageCleanupService(usageCleanupRepository, timingWheelService, dashboardAggregationService, configConfig)
196
+ adminUsageHandler := admin.NewUsageHandler(usageService, apiKeyService, adminService, usageCleanupService)
197
+ userAttributeDefinitionRepository := repository.NewUserAttributeDefinitionRepository(client)
198
+ userAttributeValueRepository := repository.NewUserAttributeValueRepository(client)
199
+ userAttributeService := service.NewUserAttributeService(userAttributeDefinitionRepository, userAttributeValueRepository)
200
+ userAttributeHandler := admin.NewUserAttributeHandler(userAttributeService)
201
+ errorPassthroughRepository := repository.NewErrorPassthroughRepository(client)
202
+ errorPassthroughCache := repository.NewErrorPassthroughCache(redisClient)
203
+ errorPassthroughService := service.NewErrorPassthroughService(errorPassthroughRepository, errorPassthroughCache)
204
+ errorPassthroughHandler := admin.NewErrorPassthroughHandler(errorPassthroughService)
205
+ adminAPIKeyHandler := admin.NewAdminAPIKeyHandler(adminService)
206
+ scheduledTestPlanRepository := repository.NewScheduledTestPlanRepository(db)
207
+ scheduledTestResultRepository := repository.NewScheduledTestResultRepository(db)
208
+ scheduledTestService := service.ProvideScheduledTestService(scheduledTestPlanRepository, scheduledTestResultRepository)
209
+ scheduledTestHandler := admin.NewScheduledTestHandler(scheduledTestService)
210
+ adminHandlers := handler.ProvideAdminHandlers(dashboardHandler, adminUserHandler, groupHandler, accountHandler, adminAnnouncementHandler, dataManagementHandler, backupHandler, oAuthHandler, openAIOAuthHandler, geminiOAuthHandler, antigravityOAuthHandler, proxyHandler, adminRedeemHandler, promoHandler, settingHandler, opsHandler, systemHandler, adminSubscriptionHandler, adminUsageHandler, userAttributeHandler, errorPassthroughHandler, adminAPIKeyHandler, scheduledTestHandler)
211
+ usageRecordWorkerPool := service.NewUsageRecordWorkerPool(configConfig)
212
+ userMsgQueueCache := repository.NewUserMsgQueueCache(redisClient)
213
+ userMessageQueueService := service.ProvideUserMessageQueueService(userMsgQueueCache, rpmCache, configConfig)
214
+ gatewayHandler := handler.NewGatewayHandler(gatewayService, geminiMessagesCompatService, antigravityGatewayService, userService, concurrencyService, billingCacheService, usageService, apiKeyService, usageRecordWorkerPool, errorPassthroughService, userMessageQueueService, configConfig, settingService)
215
+ openAIGatewayHandler := handler.NewOpenAIGatewayHandler(openAIGatewayService, concurrencyService, billingCacheService, apiKeyService, usageRecordWorkerPool, errorPassthroughService, configConfig)
216
+ soraSDKClient := service.ProvideSoraSDKClient(configConfig, httpUpstream, openAITokenProvider, accountRepository, soraAccountRepository)
217
+ soraMediaStorage := service.ProvideSoraMediaStorage(configConfig)
218
+ soraGatewayService := service.NewSoraGatewayService(soraSDKClient, rateLimitService, httpUpstream, configConfig)
219
+ soraClientHandler := handler.NewSoraClientHandler(soraGenerationService, soraQuotaService, soraS3Storage, soraGatewayService, gatewayService, soraMediaStorage, apiKeyService)
220
+ soraGatewayHandler := handler.NewSoraGatewayHandler(gatewayService, soraGatewayService, concurrencyService, billingCacheService, usageRecordWorkerPool, configConfig)
221
+ handlerSettingHandler := handler.ProvideSettingHandler(settingService, buildInfo)
222
+ totpHandler := handler.NewTotpHandler(totpService)
223
+ idempotencyCoordinator := service.ProvideIdempotencyCoordinator(idempotencyRepository, configConfig)
224
+ idempotencyCleanupService := service.ProvideIdempotencyCleanupService(idempotencyRepository, configConfig)
225
+ handlers := handler.ProvideHandlers(authHandler, userHandler, apiKeyHandler, usageHandler, redeemHandler, subscriptionHandler, announcementHandler, adminHandlers, gatewayHandler, openAIGatewayHandler, soraGatewayHandler, soraClientHandler, handlerSettingHandler, totpHandler, idempotencyCoordinator, idempotencyCleanupService)
226
+ jwtAuthMiddleware := middleware.NewJWTAuthMiddleware(authService, userService)
227
+ adminAuthMiddleware := middleware.NewAdminAuthMiddleware(authService, userService, settingService)
228
+ apiKeyAuthMiddleware := middleware.NewAPIKeyAuthMiddleware(apiKeyService, subscriptionService, configConfig)
229
+ engine := server.ProvideRouter(configConfig, handlers, jwtAuthMiddleware, adminAuthMiddleware, apiKeyAuthMiddleware, apiKeyService, subscriptionService, opsService, settingService, redisClient)
230
+ httpServer := server.ProvideHTTPServer(configConfig, engine)
231
+ opsMetricsCollector := service.ProvideOpsMetricsCollector(opsRepository, settingRepository, accountRepository, concurrencyService, db, redisClient, configConfig)
232
+ opsAggregationService := service.ProvideOpsAggregationService(opsRepository, settingRepository, db, redisClient, configConfig)
233
+ opsAlertEvaluatorService := service.ProvideOpsAlertEvaluatorService(opsService, opsRepository, emailService, redisClient, configConfig)
234
+ opsCleanupService := service.ProvideOpsCleanupService(opsRepository, db, redisClient, configConfig)
235
+ opsScheduledReportService := service.ProvideOpsScheduledReportService(opsService, userService, emailService, redisClient, configConfig)
236
+ soraMediaCleanupService := service.ProvideSoraMediaCleanupService(soraMediaStorage, configConfig)
237
+ tokenRefreshService := service.ProvideTokenRefreshService(accountRepository, soraAccountRepository, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, compositeTokenCacheInvalidator, schedulerCache, configConfig, tempUnschedCache, privacyClientFactory, proxyRepository, oauthRefreshAPI)
238
+ accountExpiryService := service.ProvideAccountExpiryService(accountRepository)
239
+ subscriptionExpiryService := service.ProvideSubscriptionExpiryService(userSubscriptionRepository)
240
+ scheduledTestRunnerService := service.ProvideScheduledTestRunnerService(scheduledTestPlanRepository, scheduledTestService, accountTestService, rateLimitService, configConfig)
241
+ v := provideCleanup(client, redisClient, opsMetricsCollector, opsAggregationService, opsAlertEvaluatorService, opsCleanupService, opsScheduledReportService, opsSystemLogSink, soraMediaCleanupService, schedulerSnapshotService, tokenRefreshService, accountExpiryService, subscriptionExpiryService, usageCleanupService, idempotencyCleanupService, pricingService, emailQueueService, billingCacheService, usageRecordWorkerPool, subscriptionService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, openAIGatewayService, scheduledTestRunnerService, backupService)
242
+ application := &Application{
243
+ Server: httpServer,
244
+ Cleanup: v,
245
+ }
246
+ return application, nil
247
+ }
248
+
249
+ // wire.go:
250
+
251
+ type Application struct {
252
+ Server *http.Server
253
+ Cleanup func()
254
+ }
255
+
256
+ func providePrivacyClientFactory() service.PrivacyClientFactory {
257
+ return repository.CreatePrivacyReqClient
258
+ }
259
+
260
+ func provideServiceBuildInfo(buildInfo handler.BuildInfo) service.BuildInfo {
261
+ return service.BuildInfo{
262
+ Version: buildInfo.Version,
263
+ BuildType: buildInfo.BuildType,
264
+ }
265
+ }
266
+
267
+ func provideCleanup(
268
+ entClient *ent.Client,
269
+ rdb *redis.Client,
270
+ opsMetricsCollector *service.OpsMetricsCollector,
271
+ opsAggregation *service.OpsAggregationService,
272
+ opsAlertEvaluator *service.OpsAlertEvaluatorService,
273
+ opsCleanup *service.OpsCleanupService,
274
+ opsScheduledReport *service.OpsScheduledReportService,
275
+ opsSystemLogSink *service.OpsSystemLogSink,
276
+ soraMediaCleanup *service.SoraMediaCleanupService,
277
+ schedulerSnapshot *service.SchedulerSnapshotService,
278
+ tokenRefresh *service.TokenRefreshService,
279
+ accountExpiry *service.AccountExpiryService,
280
+ subscriptionExpiry *service.SubscriptionExpiryService,
281
+ usageCleanup *service.UsageCleanupService,
282
+ idempotencyCleanup *service.IdempotencyCleanupService,
283
+ pricing *service.PricingService,
284
+ emailQueue *service.EmailQueueService,
285
+ billingCache *service.BillingCacheService,
286
+ usageRecordWorkerPool *service.UsageRecordWorkerPool,
287
+ subscriptionService *service.SubscriptionService,
288
+ oauth *service.OAuthService,
289
+ openaiOAuth *service.OpenAIOAuthService,
290
+ geminiOAuth *service.GeminiOAuthService,
291
+ antigravityOAuth *service.AntigravityOAuthService,
292
+ openAIGateway *service.OpenAIGatewayService,
293
+ scheduledTestRunner *service.ScheduledTestRunnerService,
294
+ backupSvc *service.BackupService,
295
+ ) func() {
296
+ return func() {
297
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
298
+ defer cancel()
299
+
300
+ type cleanupStep struct {
301
+ name string
302
+ fn func() error
303
+ }
304
+
305
+ parallelSteps := []cleanupStep{
306
+ {"OpsScheduledReportService", func() error {
307
+ if opsScheduledReport != nil {
308
+ opsScheduledReport.Stop()
309
+ }
310
+ return nil
311
+ }},
312
+ {"OpsCleanupService", func() error {
313
+ if opsCleanup != nil {
314
+ opsCleanup.Stop()
315
+ }
316
+ return nil
317
+ }},
318
+ {"OpsSystemLogSink", func() error {
319
+ if opsSystemLogSink != nil {
320
+ opsSystemLogSink.Stop()
321
+ }
322
+ return nil
323
+ }},
324
+ {"SoraMediaCleanupService", func() error {
325
+ if soraMediaCleanup != nil {
326
+ soraMediaCleanup.Stop()
327
+ }
328
+ return nil
329
+ }},
330
+ {"OpsAlertEvaluatorService", func() error {
331
+ if opsAlertEvaluator != nil {
332
+ opsAlertEvaluator.Stop()
333
+ }
334
+ return nil
335
+ }},
336
+ {"OpsAggregationService", func() error {
337
+ if opsAggregation != nil {
338
+ opsAggregation.Stop()
339
+ }
340
+ return nil
341
+ }},
342
+ {"OpsMetricsCollector", func() error {
343
+ if opsMetricsCollector != nil {
344
+ opsMetricsCollector.Stop()
345
+ }
346
+ return nil
347
+ }},
348
+ {"SchedulerSnapshotService", func() error {
349
+ if schedulerSnapshot != nil {
350
+ schedulerSnapshot.Stop()
351
+ }
352
+ return nil
353
+ }},
354
+ {"UsageCleanupService", func() error {
355
+ if usageCleanup != nil {
356
+ usageCleanup.Stop()
357
+ }
358
+ return nil
359
+ }},
360
+ {"IdempotencyCleanupService", func() error {
361
+ if idempotencyCleanup != nil {
362
+ idempotencyCleanup.Stop()
363
+ }
364
+ return nil
365
+ }},
366
+ {"TokenRefreshService", func() error {
367
+ tokenRefresh.Stop()
368
+ return nil
369
+ }},
370
+ {"AccountExpiryService", func() error {
371
+ accountExpiry.Stop()
372
+ return nil
373
+ }},
374
+ {"SubscriptionExpiryService", func() error {
375
+ subscriptionExpiry.Stop()
376
+ return nil
377
+ }},
378
+ {"SubscriptionService", func() error {
379
+ if subscriptionService != nil {
380
+ subscriptionService.Stop()
381
+ }
382
+ return nil
383
+ }},
384
+ {"PricingService", func() error {
385
+ pricing.Stop()
386
+ return nil
387
+ }},
388
+ {"EmailQueueService", func() error {
389
+ emailQueue.Stop()
390
+ return nil
391
+ }},
392
+ {"BillingCacheService", func() error {
393
+ billingCache.Stop()
394
+ return nil
395
+ }},
396
+ {"UsageRecordWorkerPool", func() error {
397
+ if usageRecordWorkerPool != nil {
398
+ usageRecordWorkerPool.Stop()
399
+ }
400
+ return nil
401
+ }},
402
+ {"OAuthService", func() error {
403
+ oauth.Stop()
404
+ return nil
405
+ }},
406
+ {"OpenAIOAuthService", func() error {
407
+ openaiOAuth.Stop()
408
+ return nil
409
+ }},
410
+ {"GeminiOAuthService", func() error {
411
+ geminiOAuth.Stop()
412
+ return nil
413
+ }},
414
+ {"AntigravityOAuthService", func() error {
415
+ antigravityOAuth.Stop()
416
+ return nil
417
+ }},
418
+ {"OpenAIWSPool", func() error {
419
+ if openAIGateway != nil {
420
+ openAIGateway.CloseOpenAIWSPool()
421
+ }
422
+ return nil
423
+ }},
424
+ {"ScheduledTestRunnerService", func() error {
425
+ if scheduledTestRunner != nil {
426
+ scheduledTestRunner.Stop()
427
+ }
428
+ return nil
429
+ }},
430
+ {"BackupService", func() error {
431
+ if backupSvc != nil {
432
+ backupSvc.Stop()
433
+ }
434
+ return nil
435
+ }},
436
+ }
437
+
438
+ infraSteps := []cleanupStep{
439
+ {"Redis", func() error {
440
+ if rdb == nil {
441
+ return nil
442
+ }
443
+ return rdb.Close()
444
+ }},
445
+ {"Ent", func() error {
446
+ if entClient == nil {
447
+ return nil
448
+ }
449
+ return entClient.Close()
450
+ }},
451
+ }
452
+
453
+ runParallel := func(steps []cleanupStep) {
454
+ var wg sync.WaitGroup
455
+ for i := range steps {
456
+ step := steps[i]
457
+ wg.Add(1)
458
+ go func() {
459
+ defer wg.Done()
460
+ if err := step.fn(); err != nil {
461
+ log.Printf("[Cleanup] %s failed: %v", step.name, err)
462
+ return
463
+ }
464
+ log.Printf("[Cleanup] %s succeeded", step.name)
465
+ }()
466
+ }
467
+ wg.Wait()
468
+ }
469
+
470
+ runSequential := func(steps []cleanupStep) {
471
+ for i := range steps {
472
+ step := steps[i]
473
+ if err := step.fn(); err != nil {
474
+ log.Printf("[Cleanup] %s failed: %v", step.name, err)
475
+ continue
476
+ }
477
+ log.Printf("[Cleanup] %s succeeded", step.name)
478
+ }
479
+ }
480
+
481
+ runParallel(parallelSteps)
482
+ runSequential(infraSteps)
483
+
484
+ select {
485
+ case <-ctx.Done():
486
+ log.Printf("[Cleanup] Warning: cleanup timed out after 10 seconds")
487
+ default:
488
+ log.Printf("[Cleanup] All cleanup steps completed")
489
+ }
490
+ }
491
+ }
backend/cmd/server/wire_gen_test.go ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package main
2
+
3
+ import (
4
+ "testing"
5
+ "time"
6
+
7
+ "github.com/Wei-Shaw/sub2api/internal/config"
8
+ "github.com/Wei-Shaw/sub2api/internal/handler"
9
+ "github.com/Wei-Shaw/sub2api/internal/service"
10
+ "github.com/stretchr/testify/require"
11
+ )
12
+
13
+ func TestProvideServiceBuildInfo(t *testing.T) {
14
+ in := handler.BuildInfo{
15
+ Version: "v-test",
16
+ BuildType: "release",
17
+ }
18
+ out := provideServiceBuildInfo(in)
19
+ require.Equal(t, in.Version, out.Version)
20
+ require.Equal(t, in.BuildType, out.BuildType)
21
+ }
22
+
23
+ func TestProvideCleanup_WithMinimalDependencies_NoPanic(t *testing.T) {
24
+ cfg := &config.Config{}
25
+
26
+ oauthSvc := service.NewOAuthService(nil, nil)
27
+ openAIOAuthSvc := service.NewOpenAIOAuthService(nil, nil)
28
+ geminiOAuthSvc := service.NewGeminiOAuthService(nil, nil, nil, nil, cfg)
29
+ antigravityOAuthSvc := service.NewAntigravityOAuthService(nil)
30
+
31
+ tokenRefreshSvc := service.NewTokenRefreshService(
32
+ nil,
33
+ oauthSvc,
34
+ openAIOAuthSvc,
35
+ geminiOAuthSvc,
36
+ antigravityOAuthSvc,
37
+ nil,
38
+ nil,
39
+ cfg,
40
+ nil,
41
+ )
42
+ accountExpirySvc := service.NewAccountExpiryService(nil, time.Second)
43
+ subscriptionExpirySvc := service.NewSubscriptionExpiryService(nil, time.Second)
44
+ pricingSvc := service.NewPricingService(cfg, nil)
45
+ emailQueueSvc := service.NewEmailQueueService(nil, 1)
46
+ billingCacheSvc := service.NewBillingCacheService(nil, nil, nil, nil, cfg)
47
+ idempotencyCleanupSvc := service.NewIdempotencyCleanupService(nil, cfg)
48
+ schedulerSnapshotSvc := service.NewSchedulerSnapshotService(nil, nil, nil, nil, cfg)
49
+ opsSystemLogSinkSvc := service.NewOpsSystemLogSink(nil)
50
+
51
+ cleanup := provideCleanup(
52
+ nil, // entClient
53
+ nil, // redis
54
+ &service.OpsMetricsCollector{},
55
+ &service.OpsAggregationService{},
56
+ &service.OpsAlertEvaluatorService{},
57
+ &service.OpsCleanupService{},
58
+ &service.OpsScheduledReportService{},
59
+ opsSystemLogSinkSvc,
60
+ &service.SoraMediaCleanupService{},
61
+ schedulerSnapshotSvc,
62
+ tokenRefreshSvc,
63
+ accountExpirySvc,
64
+ subscriptionExpirySvc,
65
+ &service.UsageCleanupService{},
66
+ idempotencyCleanupSvc,
67
+ pricingSvc,
68
+ emailQueueSvc,
69
+ billingCacheSvc,
70
+ &service.UsageRecordWorkerPool{},
71
+ &service.SubscriptionService{},
72
+ oauthSvc,
73
+ openAIOAuthSvc,
74
+ geminiOAuthSvc,
75
+ antigravityOAuthSvc,
76
+ nil, // openAIGateway
77
+ nil, // scheduledTestRunner
78
+ nil, // backupSvc
79
+ )
80
+
81
+ require.NotPanics(t, func() {
82
+ cleanup()
83
+ })
84
+ }
backend/ent/account.go ADDED
@@ -0,0 +1,536 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "encoding/json"
7
+ "fmt"
8
+ "strings"
9
+ "time"
10
+
11
+ "entgo.io/ent"
12
+ "entgo.io/ent/dialect/sql"
13
+ "github.com/Wei-Shaw/sub2api/ent/account"
14
+ "github.com/Wei-Shaw/sub2api/ent/proxy"
15
+ )
16
+
17
+ // Account is the model entity for the Account schema.
18
+ type Account struct {
19
+ config `json:"-"`
20
+ // ID of the ent.
21
+ ID int64 `json:"id,omitempty"`
22
+ // CreatedAt holds the value of the "created_at" field.
23
+ CreatedAt time.Time `json:"created_at,omitempty"`
24
+ // UpdatedAt holds the value of the "updated_at" field.
25
+ UpdatedAt time.Time `json:"updated_at,omitempty"`
26
+ // DeletedAt holds the value of the "deleted_at" field.
27
+ DeletedAt *time.Time `json:"deleted_at,omitempty"`
28
+ // Name holds the value of the "name" field.
29
+ Name string `json:"name,omitempty"`
30
+ // Notes holds the value of the "notes" field.
31
+ Notes *string `json:"notes,omitempty"`
32
+ // Platform holds the value of the "platform" field.
33
+ Platform string `json:"platform,omitempty"`
34
+ // Type holds the value of the "type" field.
35
+ Type string `json:"type,omitempty"`
36
+ // Credentials holds the value of the "credentials" field.
37
+ Credentials map[string]interface{} `json:"credentials,omitempty"`
38
+ // Extra holds the value of the "extra" field.
39
+ Extra map[string]interface{} `json:"extra,omitempty"`
40
+ // ProxyID holds the value of the "proxy_id" field.
41
+ ProxyID *int64 `json:"proxy_id,omitempty"`
42
+ // Concurrency holds the value of the "concurrency" field.
43
+ Concurrency int `json:"concurrency,omitempty"`
44
+ // LoadFactor holds the value of the "load_factor" field.
45
+ LoadFactor *int `json:"load_factor,omitempty"`
46
+ // Priority holds the value of the "priority" field.
47
+ Priority int `json:"priority,omitempty"`
48
+ // RateMultiplier holds the value of the "rate_multiplier" field.
49
+ RateMultiplier float64 `json:"rate_multiplier,omitempty"`
50
+ // Status holds the value of the "status" field.
51
+ Status string `json:"status,omitempty"`
52
+ // ErrorMessage holds the value of the "error_message" field.
53
+ ErrorMessage *string `json:"error_message,omitempty"`
54
+ // LastUsedAt holds the value of the "last_used_at" field.
55
+ LastUsedAt *time.Time `json:"last_used_at,omitempty"`
56
+ // Account expiration time (NULL means no expiration).
57
+ ExpiresAt *time.Time `json:"expires_at,omitempty"`
58
+ // Auto pause scheduling when account expires.
59
+ AutoPauseOnExpired bool `json:"auto_pause_on_expired,omitempty"`
60
+ // Schedulable holds the value of the "schedulable" field.
61
+ Schedulable bool `json:"schedulable,omitempty"`
62
+ // RateLimitedAt holds the value of the "rate_limited_at" field.
63
+ RateLimitedAt *time.Time `json:"rate_limited_at,omitempty"`
64
+ // RateLimitResetAt holds the value of the "rate_limit_reset_at" field.
65
+ RateLimitResetAt *time.Time `json:"rate_limit_reset_at,omitempty"`
66
+ // OverloadUntil holds the value of the "overload_until" field.
67
+ OverloadUntil *time.Time `json:"overload_until,omitempty"`
68
+ // TempUnschedulableUntil holds the value of the "temp_unschedulable_until" field.
69
+ TempUnschedulableUntil *time.Time `json:"temp_unschedulable_until,omitempty"`
70
+ // TempUnschedulableReason holds the value of the "temp_unschedulable_reason" field.
71
+ TempUnschedulableReason *string `json:"temp_unschedulable_reason,omitempty"`
72
+ // SessionWindowStart holds the value of the "session_window_start" field.
73
+ SessionWindowStart *time.Time `json:"session_window_start,omitempty"`
74
+ // SessionWindowEnd holds the value of the "session_window_end" field.
75
+ SessionWindowEnd *time.Time `json:"session_window_end,omitempty"`
76
+ // SessionWindowStatus holds the value of the "session_window_status" field.
77
+ SessionWindowStatus *string `json:"session_window_status,omitempty"`
78
+ // Edges holds the relations/edges for other nodes in the graph.
79
+ // The values are being populated by the AccountQuery when eager-loading is set.
80
+ Edges AccountEdges `json:"edges"`
81
+ selectValues sql.SelectValues
82
+ }
83
+
84
+ // AccountEdges holds the relations/edges for other nodes in the graph.
85
+ type AccountEdges struct {
86
+ // Groups holds the value of the groups edge.
87
+ Groups []*Group `json:"groups,omitempty"`
88
+ // Proxy holds the value of the proxy edge.
89
+ Proxy *Proxy `json:"proxy,omitempty"`
90
+ // UsageLogs holds the value of the usage_logs edge.
91
+ UsageLogs []*UsageLog `json:"usage_logs,omitempty"`
92
+ // AccountGroups holds the value of the account_groups edge.
93
+ AccountGroups []*AccountGroup `json:"account_groups,omitempty"`
94
+ // loadedTypes holds the information for reporting if a
95
+ // type was loaded (or requested) in eager-loading or not.
96
+ loadedTypes [4]bool
97
+ }
98
+
99
+ // GroupsOrErr returns the Groups value or an error if the edge
100
+ // was not loaded in eager-loading.
101
+ func (e AccountEdges) GroupsOrErr() ([]*Group, error) {
102
+ if e.loadedTypes[0] {
103
+ return e.Groups, nil
104
+ }
105
+ return nil, &NotLoadedError{edge: "groups"}
106
+ }
107
+
108
+ // ProxyOrErr returns the Proxy value or an error if the edge
109
+ // was not loaded in eager-loading, or loaded but was not found.
110
+ func (e AccountEdges) ProxyOrErr() (*Proxy, error) {
111
+ if e.Proxy != nil {
112
+ return e.Proxy, nil
113
+ } else if e.loadedTypes[1] {
114
+ return nil, &NotFoundError{label: proxy.Label}
115
+ }
116
+ return nil, &NotLoadedError{edge: "proxy"}
117
+ }
118
+
119
+ // UsageLogsOrErr returns the UsageLogs value or an error if the edge
120
+ // was not loaded in eager-loading.
121
+ func (e AccountEdges) UsageLogsOrErr() ([]*UsageLog, error) {
122
+ if e.loadedTypes[2] {
123
+ return e.UsageLogs, nil
124
+ }
125
+ return nil, &NotLoadedError{edge: "usage_logs"}
126
+ }
127
+
128
+ // AccountGroupsOrErr returns the AccountGroups value or an error if the edge
129
+ // was not loaded in eager-loading.
130
+ func (e AccountEdges) AccountGroupsOrErr() ([]*AccountGroup, error) {
131
+ if e.loadedTypes[3] {
132
+ return e.AccountGroups, nil
133
+ }
134
+ return nil, &NotLoadedError{edge: "account_groups"}
135
+ }
136
+
137
+ // scanValues returns the types for scanning values from sql.Rows.
138
+ func (*Account) scanValues(columns []string) ([]any, error) {
139
+ values := make([]any, len(columns))
140
+ for i := range columns {
141
+ switch columns[i] {
142
+ case account.FieldCredentials, account.FieldExtra:
143
+ values[i] = new([]byte)
144
+ case account.FieldAutoPauseOnExpired, account.FieldSchedulable:
145
+ values[i] = new(sql.NullBool)
146
+ case account.FieldRateMultiplier:
147
+ values[i] = new(sql.NullFloat64)
148
+ case account.FieldID, account.FieldProxyID, account.FieldConcurrency, account.FieldLoadFactor, account.FieldPriority:
149
+ values[i] = new(sql.NullInt64)
150
+ case account.FieldName, account.FieldNotes, account.FieldPlatform, account.FieldType, account.FieldStatus, account.FieldErrorMessage, account.FieldTempUnschedulableReason, account.FieldSessionWindowStatus:
151
+ values[i] = new(sql.NullString)
152
+ case account.FieldCreatedAt, account.FieldUpdatedAt, account.FieldDeletedAt, account.FieldLastUsedAt, account.FieldExpiresAt, account.FieldRateLimitedAt, account.FieldRateLimitResetAt, account.FieldOverloadUntil, account.FieldTempUnschedulableUntil, account.FieldSessionWindowStart, account.FieldSessionWindowEnd:
153
+ values[i] = new(sql.NullTime)
154
+ default:
155
+ values[i] = new(sql.UnknownType)
156
+ }
157
+ }
158
+ return values, nil
159
+ }
160
+
161
+ // assignValues assigns the values that were returned from sql.Rows (after scanning)
162
+ // to the Account fields.
163
+ func (_m *Account) assignValues(columns []string, values []any) error {
164
+ if m, n := len(values), len(columns); m < n {
165
+ return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
166
+ }
167
+ for i := range columns {
168
+ switch columns[i] {
169
+ case account.FieldID:
170
+ value, ok := values[i].(*sql.NullInt64)
171
+ if !ok {
172
+ return fmt.Errorf("unexpected type %T for field id", value)
173
+ }
174
+ _m.ID = int64(value.Int64)
175
+ case account.FieldCreatedAt:
176
+ if value, ok := values[i].(*sql.NullTime); !ok {
177
+ return fmt.Errorf("unexpected type %T for field created_at", values[i])
178
+ } else if value.Valid {
179
+ _m.CreatedAt = value.Time
180
+ }
181
+ case account.FieldUpdatedAt:
182
+ if value, ok := values[i].(*sql.NullTime); !ok {
183
+ return fmt.Errorf("unexpected type %T for field updated_at", values[i])
184
+ } else if value.Valid {
185
+ _m.UpdatedAt = value.Time
186
+ }
187
+ case account.FieldDeletedAt:
188
+ if value, ok := values[i].(*sql.NullTime); !ok {
189
+ return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
190
+ } else if value.Valid {
191
+ _m.DeletedAt = new(time.Time)
192
+ *_m.DeletedAt = value.Time
193
+ }
194
+ case account.FieldName:
195
+ if value, ok := values[i].(*sql.NullString); !ok {
196
+ return fmt.Errorf("unexpected type %T for field name", values[i])
197
+ } else if value.Valid {
198
+ _m.Name = value.String
199
+ }
200
+ case account.FieldNotes:
201
+ if value, ok := values[i].(*sql.NullString); !ok {
202
+ return fmt.Errorf("unexpected type %T for field notes", values[i])
203
+ } else if value.Valid {
204
+ _m.Notes = new(string)
205
+ *_m.Notes = value.String
206
+ }
207
+ case account.FieldPlatform:
208
+ if value, ok := values[i].(*sql.NullString); !ok {
209
+ return fmt.Errorf("unexpected type %T for field platform", values[i])
210
+ } else if value.Valid {
211
+ _m.Platform = value.String
212
+ }
213
+ case account.FieldType:
214
+ if value, ok := values[i].(*sql.NullString); !ok {
215
+ return fmt.Errorf("unexpected type %T for field type", values[i])
216
+ } else if value.Valid {
217
+ _m.Type = value.String
218
+ }
219
+ case account.FieldCredentials:
220
+ if value, ok := values[i].(*[]byte); !ok {
221
+ return fmt.Errorf("unexpected type %T for field credentials", values[i])
222
+ } else if value != nil && len(*value) > 0 {
223
+ if err := json.Unmarshal(*value, &_m.Credentials); err != nil {
224
+ return fmt.Errorf("unmarshal field credentials: %w", err)
225
+ }
226
+ }
227
+ case account.FieldExtra:
228
+ if value, ok := values[i].(*[]byte); !ok {
229
+ return fmt.Errorf("unexpected type %T for field extra", values[i])
230
+ } else if value != nil && len(*value) > 0 {
231
+ if err := json.Unmarshal(*value, &_m.Extra); err != nil {
232
+ return fmt.Errorf("unmarshal field extra: %w", err)
233
+ }
234
+ }
235
+ case account.FieldProxyID:
236
+ if value, ok := values[i].(*sql.NullInt64); !ok {
237
+ return fmt.Errorf("unexpected type %T for field proxy_id", values[i])
238
+ } else if value.Valid {
239
+ _m.ProxyID = new(int64)
240
+ *_m.ProxyID = value.Int64
241
+ }
242
+ case account.FieldConcurrency:
243
+ if value, ok := values[i].(*sql.NullInt64); !ok {
244
+ return fmt.Errorf("unexpected type %T for field concurrency", values[i])
245
+ } else if value.Valid {
246
+ _m.Concurrency = int(value.Int64)
247
+ }
248
+ case account.FieldLoadFactor:
249
+ if value, ok := values[i].(*sql.NullInt64); !ok {
250
+ return fmt.Errorf("unexpected type %T for field load_factor", values[i])
251
+ } else if value.Valid {
252
+ _m.LoadFactor = new(int)
253
+ *_m.LoadFactor = int(value.Int64)
254
+ }
255
+ case account.FieldPriority:
256
+ if value, ok := values[i].(*sql.NullInt64); !ok {
257
+ return fmt.Errorf("unexpected type %T for field priority", values[i])
258
+ } else if value.Valid {
259
+ _m.Priority = int(value.Int64)
260
+ }
261
+ case account.FieldRateMultiplier:
262
+ if value, ok := values[i].(*sql.NullFloat64); !ok {
263
+ return fmt.Errorf("unexpected type %T for field rate_multiplier", values[i])
264
+ } else if value.Valid {
265
+ _m.RateMultiplier = value.Float64
266
+ }
267
+ case account.FieldStatus:
268
+ if value, ok := values[i].(*sql.NullString); !ok {
269
+ return fmt.Errorf("unexpected type %T for field status", values[i])
270
+ } else if value.Valid {
271
+ _m.Status = value.String
272
+ }
273
+ case account.FieldErrorMessage:
274
+ if value, ok := values[i].(*sql.NullString); !ok {
275
+ return fmt.Errorf("unexpected type %T for field error_message", values[i])
276
+ } else if value.Valid {
277
+ _m.ErrorMessage = new(string)
278
+ *_m.ErrorMessage = value.String
279
+ }
280
+ case account.FieldLastUsedAt:
281
+ if value, ok := values[i].(*sql.NullTime); !ok {
282
+ return fmt.Errorf("unexpected type %T for field last_used_at", values[i])
283
+ } else if value.Valid {
284
+ _m.LastUsedAt = new(time.Time)
285
+ *_m.LastUsedAt = value.Time
286
+ }
287
+ case account.FieldExpiresAt:
288
+ if value, ok := values[i].(*sql.NullTime); !ok {
289
+ return fmt.Errorf("unexpected type %T for field expires_at", values[i])
290
+ } else if value.Valid {
291
+ _m.ExpiresAt = new(time.Time)
292
+ *_m.ExpiresAt = value.Time
293
+ }
294
+ case account.FieldAutoPauseOnExpired:
295
+ if value, ok := values[i].(*sql.NullBool); !ok {
296
+ return fmt.Errorf("unexpected type %T for field auto_pause_on_expired", values[i])
297
+ } else if value.Valid {
298
+ _m.AutoPauseOnExpired = value.Bool
299
+ }
300
+ case account.FieldSchedulable:
301
+ if value, ok := values[i].(*sql.NullBool); !ok {
302
+ return fmt.Errorf("unexpected type %T for field schedulable", values[i])
303
+ } else if value.Valid {
304
+ _m.Schedulable = value.Bool
305
+ }
306
+ case account.FieldRateLimitedAt:
307
+ if value, ok := values[i].(*sql.NullTime); !ok {
308
+ return fmt.Errorf("unexpected type %T for field rate_limited_at", values[i])
309
+ } else if value.Valid {
310
+ _m.RateLimitedAt = new(time.Time)
311
+ *_m.RateLimitedAt = value.Time
312
+ }
313
+ case account.FieldRateLimitResetAt:
314
+ if value, ok := values[i].(*sql.NullTime); !ok {
315
+ return fmt.Errorf("unexpected type %T for field rate_limit_reset_at", values[i])
316
+ } else if value.Valid {
317
+ _m.RateLimitResetAt = new(time.Time)
318
+ *_m.RateLimitResetAt = value.Time
319
+ }
320
+ case account.FieldOverloadUntil:
321
+ if value, ok := values[i].(*sql.NullTime); !ok {
322
+ return fmt.Errorf("unexpected type %T for field overload_until", values[i])
323
+ } else if value.Valid {
324
+ _m.OverloadUntil = new(time.Time)
325
+ *_m.OverloadUntil = value.Time
326
+ }
327
+ case account.FieldTempUnschedulableUntil:
328
+ if value, ok := values[i].(*sql.NullTime); !ok {
329
+ return fmt.Errorf("unexpected type %T for field temp_unschedulable_until", values[i])
330
+ } else if value.Valid {
331
+ _m.TempUnschedulableUntil = new(time.Time)
332
+ *_m.TempUnschedulableUntil = value.Time
333
+ }
334
+ case account.FieldTempUnschedulableReason:
335
+ if value, ok := values[i].(*sql.NullString); !ok {
336
+ return fmt.Errorf("unexpected type %T for field temp_unschedulable_reason", values[i])
337
+ } else if value.Valid {
338
+ _m.TempUnschedulableReason = new(string)
339
+ *_m.TempUnschedulableReason = value.String
340
+ }
341
+ case account.FieldSessionWindowStart:
342
+ if value, ok := values[i].(*sql.NullTime); !ok {
343
+ return fmt.Errorf("unexpected type %T for field session_window_start", values[i])
344
+ } else if value.Valid {
345
+ _m.SessionWindowStart = new(time.Time)
346
+ *_m.SessionWindowStart = value.Time
347
+ }
348
+ case account.FieldSessionWindowEnd:
349
+ if value, ok := values[i].(*sql.NullTime); !ok {
350
+ return fmt.Errorf("unexpected type %T for field session_window_end", values[i])
351
+ } else if value.Valid {
352
+ _m.SessionWindowEnd = new(time.Time)
353
+ *_m.SessionWindowEnd = value.Time
354
+ }
355
+ case account.FieldSessionWindowStatus:
356
+ if value, ok := values[i].(*sql.NullString); !ok {
357
+ return fmt.Errorf("unexpected type %T for field session_window_status", values[i])
358
+ } else if value.Valid {
359
+ _m.SessionWindowStatus = new(string)
360
+ *_m.SessionWindowStatus = value.String
361
+ }
362
+ default:
363
+ _m.selectValues.Set(columns[i], values[i])
364
+ }
365
+ }
366
+ return nil
367
+ }
368
+
369
+ // Value returns the ent.Value that was dynamically selected and assigned to the Account.
370
+ // This includes values selected through modifiers, order, etc.
371
+ func (_m *Account) Value(name string) (ent.Value, error) {
372
+ return _m.selectValues.Get(name)
373
+ }
374
+
375
+ // QueryGroups queries the "groups" edge of the Account entity.
376
+ func (_m *Account) QueryGroups() *GroupQuery {
377
+ return NewAccountClient(_m.config).QueryGroups(_m)
378
+ }
379
+
380
+ // QueryProxy queries the "proxy" edge of the Account entity.
381
+ func (_m *Account) QueryProxy() *ProxyQuery {
382
+ return NewAccountClient(_m.config).QueryProxy(_m)
383
+ }
384
+
385
+ // QueryUsageLogs queries the "usage_logs" edge of the Account entity.
386
+ func (_m *Account) QueryUsageLogs() *UsageLogQuery {
387
+ return NewAccountClient(_m.config).QueryUsageLogs(_m)
388
+ }
389
+
390
+ // QueryAccountGroups queries the "account_groups" edge of the Account entity.
391
+ func (_m *Account) QueryAccountGroups() *AccountGroupQuery {
392
+ return NewAccountClient(_m.config).QueryAccountGroups(_m)
393
+ }
394
+
395
+ // Update returns a builder for updating this Account.
396
+ // Note that you need to call Account.Unwrap() before calling this method if this Account
397
+ // was returned from a transaction, and the transaction was committed or rolled back.
398
+ func (_m *Account) Update() *AccountUpdateOne {
399
+ return NewAccountClient(_m.config).UpdateOne(_m)
400
+ }
401
+
402
+ // Unwrap unwraps the Account entity that was returned from a transaction after it was closed,
403
+ // so that all future queries will be executed through the driver which created the transaction.
404
+ func (_m *Account) Unwrap() *Account {
405
+ _tx, ok := _m.config.driver.(*txDriver)
406
+ if !ok {
407
+ panic("ent: Account is not a transactional entity")
408
+ }
409
+ _m.config.driver = _tx.drv
410
+ return _m
411
+ }
412
+
413
+ // String implements the fmt.Stringer.
414
+ func (_m *Account) String() string {
415
+ var builder strings.Builder
416
+ builder.WriteString("Account(")
417
+ builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
418
+ builder.WriteString("created_at=")
419
+ builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
420
+ builder.WriteString(", ")
421
+ builder.WriteString("updated_at=")
422
+ builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
423
+ builder.WriteString(", ")
424
+ if v := _m.DeletedAt; v != nil {
425
+ builder.WriteString("deleted_at=")
426
+ builder.WriteString(v.Format(time.ANSIC))
427
+ }
428
+ builder.WriteString(", ")
429
+ builder.WriteString("name=")
430
+ builder.WriteString(_m.Name)
431
+ builder.WriteString(", ")
432
+ if v := _m.Notes; v != nil {
433
+ builder.WriteString("notes=")
434
+ builder.WriteString(*v)
435
+ }
436
+ builder.WriteString(", ")
437
+ builder.WriteString("platform=")
438
+ builder.WriteString(_m.Platform)
439
+ builder.WriteString(", ")
440
+ builder.WriteString("type=")
441
+ builder.WriteString(_m.Type)
442
+ builder.WriteString(", ")
443
+ builder.WriteString("credentials=")
444
+ builder.WriteString(fmt.Sprintf("%v", _m.Credentials))
445
+ builder.WriteString(", ")
446
+ builder.WriteString("extra=")
447
+ builder.WriteString(fmt.Sprintf("%v", _m.Extra))
448
+ builder.WriteString(", ")
449
+ if v := _m.ProxyID; v != nil {
450
+ builder.WriteString("proxy_id=")
451
+ builder.WriteString(fmt.Sprintf("%v", *v))
452
+ }
453
+ builder.WriteString(", ")
454
+ builder.WriteString("concurrency=")
455
+ builder.WriteString(fmt.Sprintf("%v", _m.Concurrency))
456
+ builder.WriteString(", ")
457
+ if v := _m.LoadFactor; v != nil {
458
+ builder.WriteString("load_factor=")
459
+ builder.WriteString(fmt.Sprintf("%v", *v))
460
+ }
461
+ builder.WriteString(", ")
462
+ builder.WriteString("priority=")
463
+ builder.WriteString(fmt.Sprintf("%v", _m.Priority))
464
+ builder.WriteString(", ")
465
+ builder.WriteString("rate_multiplier=")
466
+ builder.WriteString(fmt.Sprintf("%v", _m.RateMultiplier))
467
+ builder.WriteString(", ")
468
+ builder.WriteString("status=")
469
+ builder.WriteString(_m.Status)
470
+ builder.WriteString(", ")
471
+ if v := _m.ErrorMessage; v != nil {
472
+ builder.WriteString("error_message=")
473
+ builder.WriteString(*v)
474
+ }
475
+ builder.WriteString(", ")
476
+ if v := _m.LastUsedAt; v != nil {
477
+ builder.WriteString("last_used_at=")
478
+ builder.WriteString(v.Format(time.ANSIC))
479
+ }
480
+ builder.WriteString(", ")
481
+ if v := _m.ExpiresAt; v != nil {
482
+ builder.WriteString("expires_at=")
483
+ builder.WriteString(v.Format(time.ANSIC))
484
+ }
485
+ builder.WriteString(", ")
486
+ builder.WriteString("auto_pause_on_expired=")
487
+ builder.WriteString(fmt.Sprintf("%v", _m.AutoPauseOnExpired))
488
+ builder.WriteString(", ")
489
+ builder.WriteString("schedulable=")
490
+ builder.WriteString(fmt.Sprintf("%v", _m.Schedulable))
491
+ builder.WriteString(", ")
492
+ if v := _m.RateLimitedAt; v != nil {
493
+ builder.WriteString("rate_limited_at=")
494
+ builder.WriteString(v.Format(time.ANSIC))
495
+ }
496
+ builder.WriteString(", ")
497
+ if v := _m.RateLimitResetAt; v != nil {
498
+ builder.WriteString("rate_limit_reset_at=")
499
+ builder.WriteString(v.Format(time.ANSIC))
500
+ }
501
+ builder.WriteString(", ")
502
+ if v := _m.OverloadUntil; v != nil {
503
+ builder.WriteString("overload_until=")
504
+ builder.WriteString(v.Format(time.ANSIC))
505
+ }
506
+ builder.WriteString(", ")
507
+ if v := _m.TempUnschedulableUntil; v != nil {
508
+ builder.WriteString("temp_unschedulable_until=")
509
+ builder.WriteString(v.Format(time.ANSIC))
510
+ }
511
+ builder.WriteString(", ")
512
+ if v := _m.TempUnschedulableReason; v != nil {
513
+ builder.WriteString("temp_unschedulable_reason=")
514
+ builder.WriteString(*v)
515
+ }
516
+ builder.WriteString(", ")
517
+ if v := _m.SessionWindowStart; v != nil {
518
+ builder.WriteString("session_window_start=")
519
+ builder.WriteString(v.Format(time.ANSIC))
520
+ }
521
+ builder.WriteString(", ")
522
+ if v := _m.SessionWindowEnd; v != nil {
523
+ builder.WriteString("session_window_end=")
524
+ builder.WriteString(v.Format(time.ANSIC))
525
+ }
526
+ builder.WriteString(", ")
527
+ if v := _m.SessionWindowStatus; v != nil {
528
+ builder.WriteString("session_window_status=")
529
+ builder.WriteString(*v)
530
+ }
531
+ builder.WriteByte(')')
532
+ return builder.String()
533
+ }
534
+
535
+ // Accounts is a parsable slice of Account.
536
+ type Accounts []*Account
backend/ent/account/account.go ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package account
4
+
5
+ import (
6
+ "time"
7
+
8
+ "entgo.io/ent"
9
+ "entgo.io/ent/dialect/sql"
10
+ "entgo.io/ent/dialect/sql/sqlgraph"
11
+ )
12
+
13
+ const (
14
+ // Label holds the string label denoting the account type in the database.
15
+ Label = "account"
16
+ // FieldID holds the string denoting the id field in the database.
17
+ FieldID = "id"
18
+ // FieldCreatedAt holds the string denoting the created_at field in the database.
19
+ FieldCreatedAt = "created_at"
20
+ // FieldUpdatedAt holds the string denoting the updated_at field in the database.
21
+ FieldUpdatedAt = "updated_at"
22
+ // FieldDeletedAt holds the string denoting the deleted_at field in the database.
23
+ FieldDeletedAt = "deleted_at"
24
+ // FieldName holds the string denoting the name field in the database.
25
+ FieldName = "name"
26
+ // FieldNotes holds the string denoting the notes field in the database.
27
+ FieldNotes = "notes"
28
+ // FieldPlatform holds the string denoting the platform field in the database.
29
+ FieldPlatform = "platform"
30
+ // FieldType holds the string denoting the type field in the database.
31
+ FieldType = "type"
32
+ // FieldCredentials holds the string denoting the credentials field in the database.
33
+ FieldCredentials = "credentials"
34
+ // FieldExtra holds the string denoting the extra field in the database.
35
+ FieldExtra = "extra"
36
+ // FieldProxyID holds the string denoting the proxy_id field in the database.
37
+ FieldProxyID = "proxy_id"
38
+ // FieldConcurrency holds the string denoting the concurrency field in the database.
39
+ FieldConcurrency = "concurrency"
40
+ // FieldLoadFactor holds the string denoting the load_factor field in the database.
41
+ FieldLoadFactor = "load_factor"
42
+ // FieldPriority holds the string denoting the priority field in the database.
43
+ FieldPriority = "priority"
44
+ // FieldRateMultiplier holds the string denoting the rate_multiplier field in the database.
45
+ FieldRateMultiplier = "rate_multiplier"
46
+ // FieldStatus holds the string denoting the status field in the database.
47
+ FieldStatus = "status"
48
+ // FieldErrorMessage holds the string denoting the error_message field in the database.
49
+ FieldErrorMessage = "error_message"
50
+ // FieldLastUsedAt holds the string denoting the last_used_at field in the database.
51
+ FieldLastUsedAt = "last_used_at"
52
+ // FieldExpiresAt holds the string denoting the expires_at field in the database.
53
+ FieldExpiresAt = "expires_at"
54
+ // FieldAutoPauseOnExpired holds the string denoting the auto_pause_on_expired field in the database.
55
+ FieldAutoPauseOnExpired = "auto_pause_on_expired"
56
+ // FieldSchedulable holds the string denoting the schedulable field in the database.
57
+ FieldSchedulable = "schedulable"
58
+ // FieldRateLimitedAt holds the string denoting the rate_limited_at field in the database.
59
+ FieldRateLimitedAt = "rate_limited_at"
60
+ // FieldRateLimitResetAt holds the string denoting the rate_limit_reset_at field in the database.
61
+ FieldRateLimitResetAt = "rate_limit_reset_at"
62
+ // FieldOverloadUntil holds the string denoting the overload_until field in the database.
63
+ FieldOverloadUntil = "overload_until"
64
+ // FieldTempUnschedulableUntil holds the string denoting the temp_unschedulable_until field in the database.
65
+ FieldTempUnschedulableUntil = "temp_unschedulable_until"
66
+ // FieldTempUnschedulableReason holds the string denoting the temp_unschedulable_reason field in the database.
67
+ FieldTempUnschedulableReason = "temp_unschedulable_reason"
68
+ // FieldSessionWindowStart holds the string denoting the session_window_start field in the database.
69
+ FieldSessionWindowStart = "session_window_start"
70
+ // FieldSessionWindowEnd holds the string denoting the session_window_end field in the database.
71
+ FieldSessionWindowEnd = "session_window_end"
72
+ // FieldSessionWindowStatus holds the string denoting the session_window_status field in the database.
73
+ FieldSessionWindowStatus = "session_window_status"
74
+ // EdgeGroups holds the string denoting the groups edge name in mutations.
75
+ EdgeGroups = "groups"
76
+ // EdgeProxy holds the string denoting the proxy edge name in mutations.
77
+ EdgeProxy = "proxy"
78
+ // EdgeUsageLogs holds the string denoting the usage_logs edge name in mutations.
79
+ EdgeUsageLogs = "usage_logs"
80
+ // EdgeAccountGroups holds the string denoting the account_groups edge name in mutations.
81
+ EdgeAccountGroups = "account_groups"
82
+ // Table holds the table name of the account in the database.
83
+ Table = "accounts"
84
+ // GroupsTable is the table that holds the groups relation/edge. The primary key declared below.
85
+ GroupsTable = "account_groups"
86
+ // GroupsInverseTable is the table name for the Group entity.
87
+ // It exists in this package in order to avoid circular dependency with the "group" package.
88
+ GroupsInverseTable = "groups"
89
+ // ProxyTable is the table that holds the proxy relation/edge.
90
+ ProxyTable = "accounts"
91
+ // ProxyInverseTable is the table name for the Proxy entity.
92
+ // It exists in this package in order to avoid circular dependency with the "proxy" package.
93
+ ProxyInverseTable = "proxies"
94
+ // ProxyColumn is the table column denoting the proxy relation/edge.
95
+ ProxyColumn = "proxy_id"
96
+ // UsageLogsTable is the table that holds the usage_logs relation/edge.
97
+ UsageLogsTable = "usage_logs"
98
+ // UsageLogsInverseTable is the table name for the UsageLog entity.
99
+ // It exists in this package in order to avoid circular dependency with the "usagelog" package.
100
+ UsageLogsInverseTable = "usage_logs"
101
+ // UsageLogsColumn is the table column denoting the usage_logs relation/edge.
102
+ UsageLogsColumn = "account_id"
103
+ // AccountGroupsTable is the table that holds the account_groups relation/edge.
104
+ AccountGroupsTable = "account_groups"
105
+ // AccountGroupsInverseTable is the table name for the AccountGroup entity.
106
+ // It exists in this package in order to avoid circular dependency with the "accountgroup" package.
107
+ AccountGroupsInverseTable = "account_groups"
108
+ // AccountGroupsColumn is the table column denoting the account_groups relation/edge.
109
+ AccountGroupsColumn = "account_id"
110
+ )
111
+
112
+ // Columns holds all SQL columns for account fields.
113
+ var Columns = []string{
114
+ FieldID,
115
+ FieldCreatedAt,
116
+ FieldUpdatedAt,
117
+ FieldDeletedAt,
118
+ FieldName,
119
+ FieldNotes,
120
+ FieldPlatform,
121
+ FieldType,
122
+ FieldCredentials,
123
+ FieldExtra,
124
+ FieldProxyID,
125
+ FieldConcurrency,
126
+ FieldLoadFactor,
127
+ FieldPriority,
128
+ FieldRateMultiplier,
129
+ FieldStatus,
130
+ FieldErrorMessage,
131
+ FieldLastUsedAt,
132
+ FieldExpiresAt,
133
+ FieldAutoPauseOnExpired,
134
+ FieldSchedulable,
135
+ FieldRateLimitedAt,
136
+ FieldRateLimitResetAt,
137
+ FieldOverloadUntil,
138
+ FieldTempUnschedulableUntil,
139
+ FieldTempUnschedulableReason,
140
+ FieldSessionWindowStart,
141
+ FieldSessionWindowEnd,
142
+ FieldSessionWindowStatus,
143
+ }
144
+
145
+ var (
146
+ // GroupsPrimaryKey and GroupsColumn2 are the table columns denoting the
147
+ // primary key for the groups relation (M2M).
148
+ GroupsPrimaryKey = []string{"account_id", "group_id"}
149
+ )
150
+
151
+ // ValidColumn reports if the column name is valid (part of the table columns).
152
+ func ValidColumn(column string) bool {
153
+ for i := range Columns {
154
+ if column == Columns[i] {
155
+ return true
156
+ }
157
+ }
158
+ return false
159
+ }
160
+
161
+ // Note that the variables below are initialized by the runtime
162
+ // package on the initialization of the application. Therefore,
163
+ // it should be imported in the main as follows:
164
+ //
165
+ // import _ "github.com/Wei-Shaw/sub2api/ent/runtime"
166
+ var (
167
+ Hooks [1]ent.Hook
168
+ Interceptors [1]ent.Interceptor
169
+ // DefaultCreatedAt holds the default value on creation for the "created_at" field.
170
+ DefaultCreatedAt func() time.Time
171
+ // DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
172
+ DefaultUpdatedAt func() time.Time
173
+ // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
174
+ UpdateDefaultUpdatedAt func() time.Time
175
+ // NameValidator is a validator for the "name" field. It is called by the builders before save.
176
+ NameValidator func(string) error
177
+ // PlatformValidator is a validator for the "platform" field. It is called by the builders before save.
178
+ PlatformValidator func(string) error
179
+ // TypeValidator is a validator for the "type" field. It is called by the builders before save.
180
+ TypeValidator func(string) error
181
+ // DefaultCredentials holds the default value on creation for the "credentials" field.
182
+ DefaultCredentials func() map[string]interface{}
183
+ // DefaultExtra holds the default value on creation for the "extra" field.
184
+ DefaultExtra func() map[string]interface{}
185
+ // DefaultConcurrency holds the default value on creation for the "concurrency" field.
186
+ DefaultConcurrency int
187
+ // DefaultPriority holds the default value on creation for the "priority" field.
188
+ DefaultPriority int
189
+ // DefaultRateMultiplier holds the default value on creation for the "rate_multiplier" field.
190
+ DefaultRateMultiplier float64
191
+ // DefaultStatus holds the default value on creation for the "status" field.
192
+ DefaultStatus string
193
+ // StatusValidator is a validator for the "status" field. It is called by the builders before save.
194
+ StatusValidator func(string) error
195
+ // DefaultAutoPauseOnExpired holds the default value on creation for the "auto_pause_on_expired" field.
196
+ DefaultAutoPauseOnExpired bool
197
+ // DefaultSchedulable holds the default value on creation for the "schedulable" field.
198
+ DefaultSchedulable bool
199
+ // SessionWindowStatusValidator is a validator for the "session_window_status" field. It is called by the builders before save.
200
+ SessionWindowStatusValidator func(string) error
201
+ )
202
+
203
+ // OrderOption defines the ordering options for the Account queries.
204
+ type OrderOption func(*sql.Selector)
205
+
206
+ // ByID orders the results by the id field.
207
+ func ByID(opts ...sql.OrderTermOption) OrderOption {
208
+ return sql.OrderByField(FieldID, opts...).ToFunc()
209
+ }
210
+
211
+ // ByCreatedAt orders the results by the created_at field.
212
+ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
213
+ return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
214
+ }
215
+
216
+ // ByUpdatedAt orders the results by the updated_at field.
217
+ func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
218
+ return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
219
+ }
220
+
221
+ // ByDeletedAt orders the results by the deleted_at field.
222
+ func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
223
+ return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
224
+ }
225
+
226
+ // ByName orders the results by the name field.
227
+ func ByName(opts ...sql.OrderTermOption) OrderOption {
228
+ return sql.OrderByField(FieldName, opts...).ToFunc()
229
+ }
230
+
231
+ // ByNotes orders the results by the notes field.
232
+ func ByNotes(opts ...sql.OrderTermOption) OrderOption {
233
+ return sql.OrderByField(FieldNotes, opts...).ToFunc()
234
+ }
235
+
236
+ // ByPlatform orders the results by the platform field.
237
+ func ByPlatform(opts ...sql.OrderTermOption) OrderOption {
238
+ return sql.OrderByField(FieldPlatform, opts...).ToFunc()
239
+ }
240
+
241
+ // ByType orders the results by the type field.
242
+ func ByType(opts ...sql.OrderTermOption) OrderOption {
243
+ return sql.OrderByField(FieldType, opts...).ToFunc()
244
+ }
245
+
246
+ // ByProxyID orders the results by the proxy_id field.
247
+ func ByProxyID(opts ...sql.OrderTermOption) OrderOption {
248
+ return sql.OrderByField(FieldProxyID, opts...).ToFunc()
249
+ }
250
+
251
+ // ByConcurrency orders the results by the concurrency field.
252
+ func ByConcurrency(opts ...sql.OrderTermOption) OrderOption {
253
+ return sql.OrderByField(FieldConcurrency, opts...).ToFunc()
254
+ }
255
+
256
+ // ByLoadFactor orders the results by the load_factor field.
257
+ func ByLoadFactor(opts ...sql.OrderTermOption) OrderOption {
258
+ return sql.OrderByField(FieldLoadFactor, opts...).ToFunc()
259
+ }
260
+
261
+ // ByPriority orders the results by the priority field.
262
+ func ByPriority(opts ...sql.OrderTermOption) OrderOption {
263
+ return sql.OrderByField(FieldPriority, opts...).ToFunc()
264
+ }
265
+
266
+ // ByRateMultiplier orders the results by the rate_multiplier field.
267
+ func ByRateMultiplier(opts ...sql.OrderTermOption) OrderOption {
268
+ return sql.OrderByField(FieldRateMultiplier, opts...).ToFunc()
269
+ }
270
+
271
+ // ByStatus orders the results by the status field.
272
+ func ByStatus(opts ...sql.OrderTermOption) OrderOption {
273
+ return sql.OrderByField(FieldStatus, opts...).ToFunc()
274
+ }
275
+
276
+ // ByErrorMessage orders the results by the error_message field.
277
+ func ByErrorMessage(opts ...sql.OrderTermOption) OrderOption {
278
+ return sql.OrderByField(FieldErrorMessage, opts...).ToFunc()
279
+ }
280
+
281
+ // ByLastUsedAt orders the results by the last_used_at field.
282
+ func ByLastUsedAt(opts ...sql.OrderTermOption) OrderOption {
283
+ return sql.OrderByField(FieldLastUsedAt, opts...).ToFunc()
284
+ }
285
+
286
+ // ByExpiresAt orders the results by the expires_at field.
287
+ func ByExpiresAt(opts ...sql.OrderTermOption) OrderOption {
288
+ return sql.OrderByField(FieldExpiresAt, opts...).ToFunc()
289
+ }
290
+
291
+ // ByAutoPauseOnExpired orders the results by the auto_pause_on_expired field.
292
+ func ByAutoPauseOnExpired(opts ...sql.OrderTermOption) OrderOption {
293
+ return sql.OrderByField(FieldAutoPauseOnExpired, opts...).ToFunc()
294
+ }
295
+
296
+ // BySchedulable orders the results by the schedulable field.
297
+ func BySchedulable(opts ...sql.OrderTermOption) OrderOption {
298
+ return sql.OrderByField(FieldSchedulable, opts...).ToFunc()
299
+ }
300
+
301
+ // ByRateLimitedAt orders the results by the rate_limited_at field.
302
+ func ByRateLimitedAt(opts ...sql.OrderTermOption) OrderOption {
303
+ return sql.OrderByField(FieldRateLimitedAt, opts...).ToFunc()
304
+ }
305
+
306
+ // ByRateLimitResetAt orders the results by the rate_limit_reset_at field.
307
+ func ByRateLimitResetAt(opts ...sql.OrderTermOption) OrderOption {
308
+ return sql.OrderByField(FieldRateLimitResetAt, opts...).ToFunc()
309
+ }
310
+
311
+ // ByOverloadUntil orders the results by the overload_until field.
312
+ func ByOverloadUntil(opts ...sql.OrderTermOption) OrderOption {
313
+ return sql.OrderByField(FieldOverloadUntil, opts...).ToFunc()
314
+ }
315
+
316
+ // ByTempUnschedulableUntil orders the results by the temp_unschedulable_until field.
317
+ func ByTempUnschedulableUntil(opts ...sql.OrderTermOption) OrderOption {
318
+ return sql.OrderByField(FieldTempUnschedulableUntil, opts...).ToFunc()
319
+ }
320
+
321
+ // ByTempUnschedulableReason orders the results by the temp_unschedulable_reason field.
322
+ func ByTempUnschedulableReason(opts ...sql.OrderTermOption) OrderOption {
323
+ return sql.OrderByField(FieldTempUnschedulableReason, opts...).ToFunc()
324
+ }
325
+
326
+ // BySessionWindowStart orders the results by the session_window_start field.
327
+ func BySessionWindowStart(opts ...sql.OrderTermOption) OrderOption {
328
+ return sql.OrderByField(FieldSessionWindowStart, opts...).ToFunc()
329
+ }
330
+
331
+ // BySessionWindowEnd orders the results by the session_window_end field.
332
+ func BySessionWindowEnd(opts ...sql.OrderTermOption) OrderOption {
333
+ return sql.OrderByField(FieldSessionWindowEnd, opts...).ToFunc()
334
+ }
335
+
336
+ // BySessionWindowStatus orders the results by the session_window_status field.
337
+ func BySessionWindowStatus(opts ...sql.OrderTermOption) OrderOption {
338
+ return sql.OrderByField(FieldSessionWindowStatus, opts...).ToFunc()
339
+ }
340
+
341
+ // ByGroupsCount orders the results by groups count.
342
+ func ByGroupsCount(opts ...sql.OrderTermOption) OrderOption {
343
+ return func(s *sql.Selector) {
344
+ sqlgraph.OrderByNeighborsCount(s, newGroupsStep(), opts...)
345
+ }
346
+ }
347
+
348
+ // ByGroups orders the results by groups terms.
349
+ func ByGroups(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
350
+ return func(s *sql.Selector) {
351
+ sqlgraph.OrderByNeighborTerms(s, newGroupsStep(), append([]sql.OrderTerm{term}, terms...)...)
352
+ }
353
+ }
354
+
355
+ // ByProxyField orders the results by proxy field.
356
+ func ByProxyField(field string, opts ...sql.OrderTermOption) OrderOption {
357
+ return func(s *sql.Selector) {
358
+ sqlgraph.OrderByNeighborTerms(s, newProxyStep(), sql.OrderByField(field, opts...))
359
+ }
360
+ }
361
+
362
+ // ByUsageLogsCount orders the results by usage_logs count.
363
+ func ByUsageLogsCount(opts ...sql.OrderTermOption) OrderOption {
364
+ return func(s *sql.Selector) {
365
+ sqlgraph.OrderByNeighborsCount(s, newUsageLogsStep(), opts...)
366
+ }
367
+ }
368
+
369
+ // ByUsageLogs orders the results by usage_logs terms.
370
+ func ByUsageLogs(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
371
+ return func(s *sql.Selector) {
372
+ sqlgraph.OrderByNeighborTerms(s, newUsageLogsStep(), append([]sql.OrderTerm{term}, terms...)...)
373
+ }
374
+ }
375
+
376
+ // ByAccountGroupsCount orders the results by account_groups count.
377
+ func ByAccountGroupsCount(opts ...sql.OrderTermOption) OrderOption {
378
+ return func(s *sql.Selector) {
379
+ sqlgraph.OrderByNeighborsCount(s, newAccountGroupsStep(), opts...)
380
+ }
381
+ }
382
+
383
+ // ByAccountGroups orders the results by account_groups terms.
384
+ func ByAccountGroups(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
385
+ return func(s *sql.Selector) {
386
+ sqlgraph.OrderByNeighborTerms(s, newAccountGroupsStep(), append([]sql.OrderTerm{term}, terms...)...)
387
+ }
388
+ }
389
+ func newGroupsStep() *sqlgraph.Step {
390
+ return sqlgraph.NewStep(
391
+ sqlgraph.From(Table, FieldID),
392
+ sqlgraph.To(GroupsInverseTable, FieldID),
393
+ sqlgraph.Edge(sqlgraph.M2M, false, GroupsTable, GroupsPrimaryKey...),
394
+ )
395
+ }
396
+ func newProxyStep() *sqlgraph.Step {
397
+ return sqlgraph.NewStep(
398
+ sqlgraph.From(Table, FieldID),
399
+ sqlgraph.To(ProxyInverseTable, FieldID),
400
+ sqlgraph.Edge(sqlgraph.M2O, false, ProxyTable, ProxyColumn),
401
+ )
402
+ }
403
+ func newUsageLogsStep() *sqlgraph.Step {
404
+ return sqlgraph.NewStep(
405
+ sqlgraph.From(Table, FieldID),
406
+ sqlgraph.To(UsageLogsInverseTable, FieldID),
407
+ sqlgraph.Edge(sqlgraph.O2M, false, UsageLogsTable, UsageLogsColumn),
408
+ )
409
+ }
410
+ func newAccountGroupsStep() *sqlgraph.Step {
411
+ return sqlgraph.NewStep(
412
+ sqlgraph.From(Table, FieldID),
413
+ sqlgraph.To(AccountGroupsInverseTable, AccountGroupsColumn),
414
+ sqlgraph.Edge(sqlgraph.O2M, true, AccountGroupsTable, AccountGroupsColumn),
415
+ )
416
+ }
backend/ent/account/where.go ADDED
@@ -0,0 +1,1603 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package account
4
+
5
+ import (
6
+ "time"
7
+
8
+ "entgo.io/ent/dialect/sql"
9
+ "entgo.io/ent/dialect/sql/sqlgraph"
10
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
11
+ )
12
+
13
+ // ID filters vertices based on their ID field.
14
+ func ID(id int64) predicate.Account {
15
+ return predicate.Account(sql.FieldEQ(FieldID, id))
16
+ }
17
+
18
+ // IDEQ applies the EQ predicate on the ID field.
19
+ func IDEQ(id int64) predicate.Account {
20
+ return predicate.Account(sql.FieldEQ(FieldID, id))
21
+ }
22
+
23
+ // IDNEQ applies the NEQ predicate on the ID field.
24
+ func IDNEQ(id int64) predicate.Account {
25
+ return predicate.Account(sql.FieldNEQ(FieldID, id))
26
+ }
27
+
28
+ // IDIn applies the In predicate on the ID field.
29
+ func IDIn(ids ...int64) predicate.Account {
30
+ return predicate.Account(sql.FieldIn(FieldID, ids...))
31
+ }
32
+
33
+ // IDNotIn applies the NotIn predicate on the ID field.
34
+ func IDNotIn(ids ...int64) predicate.Account {
35
+ return predicate.Account(sql.FieldNotIn(FieldID, ids...))
36
+ }
37
+
38
+ // IDGT applies the GT predicate on the ID field.
39
+ func IDGT(id int64) predicate.Account {
40
+ return predicate.Account(sql.FieldGT(FieldID, id))
41
+ }
42
+
43
+ // IDGTE applies the GTE predicate on the ID field.
44
+ func IDGTE(id int64) predicate.Account {
45
+ return predicate.Account(sql.FieldGTE(FieldID, id))
46
+ }
47
+
48
+ // IDLT applies the LT predicate on the ID field.
49
+ func IDLT(id int64) predicate.Account {
50
+ return predicate.Account(sql.FieldLT(FieldID, id))
51
+ }
52
+
53
+ // IDLTE applies the LTE predicate on the ID field.
54
+ func IDLTE(id int64) predicate.Account {
55
+ return predicate.Account(sql.FieldLTE(FieldID, id))
56
+ }
57
+
58
+ // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
59
+ func CreatedAt(v time.Time) predicate.Account {
60
+ return predicate.Account(sql.FieldEQ(FieldCreatedAt, v))
61
+ }
62
+
63
+ // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
64
+ func UpdatedAt(v time.Time) predicate.Account {
65
+ return predicate.Account(sql.FieldEQ(FieldUpdatedAt, v))
66
+ }
67
+
68
+ // DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
69
+ func DeletedAt(v time.Time) predicate.Account {
70
+ return predicate.Account(sql.FieldEQ(FieldDeletedAt, v))
71
+ }
72
+
73
+ // Name applies equality check predicate on the "name" field. It's identical to NameEQ.
74
+ func Name(v string) predicate.Account {
75
+ return predicate.Account(sql.FieldEQ(FieldName, v))
76
+ }
77
+
78
+ // Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ.
79
+ func Notes(v string) predicate.Account {
80
+ return predicate.Account(sql.FieldEQ(FieldNotes, v))
81
+ }
82
+
83
+ // Platform applies equality check predicate on the "platform" field. It's identical to PlatformEQ.
84
+ func Platform(v string) predicate.Account {
85
+ return predicate.Account(sql.FieldEQ(FieldPlatform, v))
86
+ }
87
+
88
+ // Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
89
+ func Type(v string) predicate.Account {
90
+ return predicate.Account(sql.FieldEQ(FieldType, v))
91
+ }
92
+
93
+ // ProxyID applies equality check predicate on the "proxy_id" field. It's identical to ProxyIDEQ.
94
+ func ProxyID(v int64) predicate.Account {
95
+ return predicate.Account(sql.FieldEQ(FieldProxyID, v))
96
+ }
97
+
98
+ // Concurrency applies equality check predicate on the "concurrency" field. It's identical to ConcurrencyEQ.
99
+ func Concurrency(v int) predicate.Account {
100
+ return predicate.Account(sql.FieldEQ(FieldConcurrency, v))
101
+ }
102
+
103
+ // LoadFactor applies equality check predicate on the "load_factor" field. It's identical to LoadFactorEQ.
104
+ func LoadFactor(v int) predicate.Account {
105
+ return predicate.Account(sql.FieldEQ(FieldLoadFactor, v))
106
+ }
107
+
108
+ // Priority applies equality check predicate on the "priority" field. It's identical to PriorityEQ.
109
+ func Priority(v int) predicate.Account {
110
+ return predicate.Account(sql.FieldEQ(FieldPriority, v))
111
+ }
112
+
113
+ // RateMultiplier applies equality check predicate on the "rate_multiplier" field. It's identical to RateMultiplierEQ.
114
+ func RateMultiplier(v float64) predicate.Account {
115
+ return predicate.Account(sql.FieldEQ(FieldRateMultiplier, v))
116
+ }
117
+
118
+ // Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
119
+ func Status(v string) predicate.Account {
120
+ return predicate.Account(sql.FieldEQ(FieldStatus, v))
121
+ }
122
+
123
+ // ErrorMessage applies equality check predicate on the "error_message" field. It's identical to ErrorMessageEQ.
124
+ func ErrorMessage(v string) predicate.Account {
125
+ return predicate.Account(sql.FieldEQ(FieldErrorMessage, v))
126
+ }
127
+
128
+ // LastUsedAt applies equality check predicate on the "last_used_at" field. It's identical to LastUsedAtEQ.
129
+ func LastUsedAt(v time.Time) predicate.Account {
130
+ return predicate.Account(sql.FieldEQ(FieldLastUsedAt, v))
131
+ }
132
+
133
+ // ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ.
134
+ func ExpiresAt(v time.Time) predicate.Account {
135
+ return predicate.Account(sql.FieldEQ(FieldExpiresAt, v))
136
+ }
137
+
138
+ // AutoPauseOnExpired applies equality check predicate on the "auto_pause_on_expired" field. It's identical to AutoPauseOnExpiredEQ.
139
+ func AutoPauseOnExpired(v bool) predicate.Account {
140
+ return predicate.Account(sql.FieldEQ(FieldAutoPauseOnExpired, v))
141
+ }
142
+
143
+ // Schedulable applies equality check predicate on the "schedulable" field. It's identical to SchedulableEQ.
144
+ func Schedulable(v bool) predicate.Account {
145
+ return predicate.Account(sql.FieldEQ(FieldSchedulable, v))
146
+ }
147
+
148
+ // RateLimitedAt applies equality check predicate on the "rate_limited_at" field. It's identical to RateLimitedAtEQ.
149
+ func RateLimitedAt(v time.Time) predicate.Account {
150
+ return predicate.Account(sql.FieldEQ(FieldRateLimitedAt, v))
151
+ }
152
+
153
+ // RateLimitResetAt applies equality check predicate on the "rate_limit_reset_at" field. It's identical to RateLimitResetAtEQ.
154
+ func RateLimitResetAt(v time.Time) predicate.Account {
155
+ return predicate.Account(sql.FieldEQ(FieldRateLimitResetAt, v))
156
+ }
157
+
158
+ // OverloadUntil applies equality check predicate on the "overload_until" field. It's identical to OverloadUntilEQ.
159
+ func OverloadUntil(v time.Time) predicate.Account {
160
+ return predicate.Account(sql.FieldEQ(FieldOverloadUntil, v))
161
+ }
162
+
163
+ // TempUnschedulableUntil applies equality check predicate on the "temp_unschedulable_until" field. It's identical to TempUnschedulableUntilEQ.
164
+ func TempUnschedulableUntil(v time.Time) predicate.Account {
165
+ return predicate.Account(sql.FieldEQ(FieldTempUnschedulableUntil, v))
166
+ }
167
+
168
+ // TempUnschedulableReason applies equality check predicate on the "temp_unschedulable_reason" field. It's identical to TempUnschedulableReasonEQ.
169
+ func TempUnschedulableReason(v string) predicate.Account {
170
+ return predicate.Account(sql.FieldEQ(FieldTempUnschedulableReason, v))
171
+ }
172
+
173
+ // SessionWindowStart applies equality check predicate on the "session_window_start" field. It's identical to SessionWindowStartEQ.
174
+ func SessionWindowStart(v time.Time) predicate.Account {
175
+ return predicate.Account(sql.FieldEQ(FieldSessionWindowStart, v))
176
+ }
177
+
178
+ // SessionWindowEnd applies equality check predicate on the "session_window_end" field. It's identical to SessionWindowEndEQ.
179
+ func SessionWindowEnd(v time.Time) predicate.Account {
180
+ return predicate.Account(sql.FieldEQ(FieldSessionWindowEnd, v))
181
+ }
182
+
183
+ // SessionWindowStatus applies equality check predicate on the "session_window_status" field. It's identical to SessionWindowStatusEQ.
184
+ func SessionWindowStatus(v string) predicate.Account {
185
+ return predicate.Account(sql.FieldEQ(FieldSessionWindowStatus, v))
186
+ }
187
+
188
+ // CreatedAtEQ applies the EQ predicate on the "created_at" field.
189
+ func CreatedAtEQ(v time.Time) predicate.Account {
190
+ return predicate.Account(sql.FieldEQ(FieldCreatedAt, v))
191
+ }
192
+
193
+ // CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
194
+ func CreatedAtNEQ(v time.Time) predicate.Account {
195
+ return predicate.Account(sql.FieldNEQ(FieldCreatedAt, v))
196
+ }
197
+
198
+ // CreatedAtIn applies the In predicate on the "created_at" field.
199
+ func CreatedAtIn(vs ...time.Time) predicate.Account {
200
+ return predicate.Account(sql.FieldIn(FieldCreatedAt, vs...))
201
+ }
202
+
203
+ // CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
204
+ func CreatedAtNotIn(vs ...time.Time) predicate.Account {
205
+ return predicate.Account(sql.FieldNotIn(FieldCreatedAt, vs...))
206
+ }
207
+
208
+ // CreatedAtGT applies the GT predicate on the "created_at" field.
209
+ func CreatedAtGT(v time.Time) predicate.Account {
210
+ return predicate.Account(sql.FieldGT(FieldCreatedAt, v))
211
+ }
212
+
213
+ // CreatedAtGTE applies the GTE predicate on the "created_at" field.
214
+ func CreatedAtGTE(v time.Time) predicate.Account {
215
+ return predicate.Account(sql.FieldGTE(FieldCreatedAt, v))
216
+ }
217
+
218
+ // CreatedAtLT applies the LT predicate on the "created_at" field.
219
+ func CreatedAtLT(v time.Time) predicate.Account {
220
+ return predicate.Account(sql.FieldLT(FieldCreatedAt, v))
221
+ }
222
+
223
+ // CreatedAtLTE applies the LTE predicate on the "created_at" field.
224
+ func CreatedAtLTE(v time.Time) predicate.Account {
225
+ return predicate.Account(sql.FieldLTE(FieldCreatedAt, v))
226
+ }
227
+
228
+ // UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
229
+ func UpdatedAtEQ(v time.Time) predicate.Account {
230
+ return predicate.Account(sql.FieldEQ(FieldUpdatedAt, v))
231
+ }
232
+
233
+ // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
234
+ func UpdatedAtNEQ(v time.Time) predicate.Account {
235
+ return predicate.Account(sql.FieldNEQ(FieldUpdatedAt, v))
236
+ }
237
+
238
+ // UpdatedAtIn applies the In predicate on the "updated_at" field.
239
+ func UpdatedAtIn(vs ...time.Time) predicate.Account {
240
+ return predicate.Account(sql.FieldIn(FieldUpdatedAt, vs...))
241
+ }
242
+
243
+ // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
244
+ func UpdatedAtNotIn(vs ...time.Time) predicate.Account {
245
+ return predicate.Account(sql.FieldNotIn(FieldUpdatedAt, vs...))
246
+ }
247
+
248
+ // UpdatedAtGT applies the GT predicate on the "updated_at" field.
249
+ func UpdatedAtGT(v time.Time) predicate.Account {
250
+ return predicate.Account(sql.FieldGT(FieldUpdatedAt, v))
251
+ }
252
+
253
+ // UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
254
+ func UpdatedAtGTE(v time.Time) predicate.Account {
255
+ return predicate.Account(sql.FieldGTE(FieldUpdatedAt, v))
256
+ }
257
+
258
+ // UpdatedAtLT applies the LT predicate on the "updated_at" field.
259
+ func UpdatedAtLT(v time.Time) predicate.Account {
260
+ return predicate.Account(sql.FieldLT(FieldUpdatedAt, v))
261
+ }
262
+
263
+ // UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
264
+ func UpdatedAtLTE(v time.Time) predicate.Account {
265
+ return predicate.Account(sql.FieldLTE(FieldUpdatedAt, v))
266
+ }
267
+
268
+ // DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
269
+ func DeletedAtEQ(v time.Time) predicate.Account {
270
+ return predicate.Account(sql.FieldEQ(FieldDeletedAt, v))
271
+ }
272
+
273
+ // DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
274
+ func DeletedAtNEQ(v time.Time) predicate.Account {
275
+ return predicate.Account(sql.FieldNEQ(FieldDeletedAt, v))
276
+ }
277
+
278
+ // DeletedAtIn applies the In predicate on the "deleted_at" field.
279
+ func DeletedAtIn(vs ...time.Time) predicate.Account {
280
+ return predicate.Account(sql.FieldIn(FieldDeletedAt, vs...))
281
+ }
282
+
283
+ // DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
284
+ func DeletedAtNotIn(vs ...time.Time) predicate.Account {
285
+ return predicate.Account(sql.FieldNotIn(FieldDeletedAt, vs...))
286
+ }
287
+
288
+ // DeletedAtGT applies the GT predicate on the "deleted_at" field.
289
+ func DeletedAtGT(v time.Time) predicate.Account {
290
+ return predicate.Account(sql.FieldGT(FieldDeletedAt, v))
291
+ }
292
+
293
+ // DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
294
+ func DeletedAtGTE(v time.Time) predicate.Account {
295
+ return predicate.Account(sql.FieldGTE(FieldDeletedAt, v))
296
+ }
297
+
298
+ // DeletedAtLT applies the LT predicate on the "deleted_at" field.
299
+ func DeletedAtLT(v time.Time) predicate.Account {
300
+ return predicate.Account(sql.FieldLT(FieldDeletedAt, v))
301
+ }
302
+
303
+ // DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
304
+ func DeletedAtLTE(v time.Time) predicate.Account {
305
+ return predicate.Account(sql.FieldLTE(FieldDeletedAt, v))
306
+ }
307
+
308
+ // DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
309
+ func DeletedAtIsNil() predicate.Account {
310
+ return predicate.Account(sql.FieldIsNull(FieldDeletedAt))
311
+ }
312
+
313
+ // DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
314
+ func DeletedAtNotNil() predicate.Account {
315
+ return predicate.Account(sql.FieldNotNull(FieldDeletedAt))
316
+ }
317
+
318
+ // NameEQ applies the EQ predicate on the "name" field.
319
+ func NameEQ(v string) predicate.Account {
320
+ return predicate.Account(sql.FieldEQ(FieldName, v))
321
+ }
322
+
323
+ // NameNEQ applies the NEQ predicate on the "name" field.
324
+ func NameNEQ(v string) predicate.Account {
325
+ return predicate.Account(sql.FieldNEQ(FieldName, v))
326
+ }
327
+
328
+ // NameIn applies the In predicate on the "name" field.
329
+ func NameIn(vs ...string) predicate.Account {
330
+ return predicate.Account(sql.FieldIn(FieldName, vs...))
331
+ }
332
+
333
+ // NameNotIn applies the NotIn predicate on the "name" field.
334
+ func NameNotIn(vs ...string) predicate.Account {
335
+ return predicate.Account(sql.FieldNotIn(FieldName, vs...))
336
+ }
337
+
338
+ // NameGT applies the GT predicate on the "name" field.
339
+ func NameGT(v string) predicate.Account {
340
+ return predicate.Account(sql.FieldGT(FieldName, v))
341
+ }
342
+
343
+ // NameGTE applies the GTE predicate on the "name" field.
344
+ func NameGTE(v string) predicate.Account {
345
+ return predicate.Account(sql.FieldGTE(FieldName, v))
346
+ }
347
+
348
+ // NameLT applies the LT predicate on the "name" field.
349
+ func NameLT(v string) predicate.Account {
350
+ return predicate.Account(sql.FieldLT(FieldName, v))
351
+ }
352
+
353
+ // NameLTE applies the LTE predicate on the "name" field.
354
+ func NameLTE(v string) predicate.Account {
355
+ return predicate.Account(sql.FieldLTE(FieldName, v))
356
+ }
357
+
358
+ // NameContains applies the Contains predicate on the "name" field.
359
+ func NameContains(v string) predicate.Account {
360
+ return predicate.Account(sql.FieldContains(FieldName, v))
361
+ }
362
+
363
+ // NameHasPrefix applies the HasPrefix predicate on the "name" field.
364
+ func NameHasPrefix(v string) predicate.Account {
365
+ return predicate.Account(sql.FieldHasPrefix(FieldName, v))
366
+ }
367
+
368
+ // NameHasSuffix applies the HasSuffix predicate on the "name" field.
369
+ func NameHasSuffix(v string) predicate.Account {
370
+ return predicate.Account(sql.FieldHasSuffix(FieldName, v))
371
+ }
372
+
373
+ // NameEqualFold applies the EqualFold predicate on the "name" field.
374
+ func NameEqualFold(v string) predicate.Account {
375
+ return predicate.Account(sql.FieldEqualFold(FieldName, v))
376
+ }
377
+
378
+ // NameContainsFold applies the ContainsFold predicate on the "name" field.
379
+ func NameContainsFold(v string) predicate.Account {
380
+ return predicate.Account(sql.FieldContainsFold(FieldName, v))
381
+ }
382
+
383
+ // NotesEQ applies the EQ predicate on the "notes" field.
384
+ func NotesEQ(v string) predicate.Account {
385
+ return predicate.Account(sql.FieldEQ(FieldNotes, v))
386
+ }
387
+
388
+ // NotesNEQ applies the NEQ predicate on the "notes" field.
389
+ func NotesNEQ(v string) predicate.Account {
390
+ return predicate.Account(sql.FieldNEQ(FieldNotes, v))
391
+ }
392
+
393
+ // NotesIn applies the In predicate on the "notes" field.
394
+ func NotesIn(vs ...string) predicate.Account {
395
+ return predicate.Account(sql.FieldIn(FieldNotes, vs...))
396
+ }
397
+
398
+ // NotesNotIn applies the NotIn predicate on the "notes" field.
399
+ func NotesNotIn(vs ...string) predicate.Account {
400
+ return predicate.Account(sql.FieldNotIn(FieldNotes, vs...))
401
+ }
402
+
403
+ // NotesGT applies the GT predicate on the "notes" field.
404
+ func NotesGT(v string) predicate.Account {
405
+ return predicate.Account(sql.FieldGT(FieldNotes, v))
406
+ }
407
+
408
+ // NotesGTE applies the GTE predicate on the "notes" field.
409
+ func NotesGTE(v string) predicate.Account {
410
+ return predicate.Account(sql.FieldGTE(FieldNotes, v))
411
+ }
412
+
413
+ // NotesLT applies the LT predicate on the "notes" field.
414
+ func NotesLT(v string) predicate.Account {
415
+ return predicate.Account(sql.FieldLT(FieldNotes, v))
416
+ }
417
+
418
+ // NotesLTE applies the LTE predicate on the "notes" field.
419
+ func NotesLTE(v string) predicate.Account {
420
+ return predicate.Account(sql.FieldLTE(FieldNotes, v))
421
+ }
422
+
423
+ // NotesContains applies the Contains predicate on the "notes" field.
424
+ func NotesContains(v string) predicate.Account {
425
+ return predicate.Account(sql.FieldContains(FieldNotes, v))
426
+ }
427
+
428
+ // NotesHasPrefix applies the HasPrefix predicate on the "notes" field.
429
+ func NotesHasPrefix(v string) predicate.Account {
430
+ return predicate.Account(sql.FieldHasPrefix(FieldNotes, v))
431
+ }
432
+
433
+ // NotesHasSuffix applies the HasSuffix predicate on the "notes" field.
434
+ func NotesHasSuffix(v string) predicate.Account {
435
+ return predicate.Account(sql.FieldHasSuffix(FieldNotes, v))
436
+ }
437
+
438
+ // NotesIsNil applies the IsNil predicate on the "notes" field.
439
+ func NotesIsNil() predicate.Account {
440
+ return predicate.Account(sql.FieldIsNull(FieldNotes))
441
+ }
442
+
443
+ // NotesNotNil applies the NotNil predicate on the "notes" field.
444
+ func NotesNotNil() predicate.Account {
445
+ return predicate.Account(sql.FieldNotNull(FieldNotes))
446
+ }
447
+
448
+ // NotesEqualFold applies the EqualFold predicate on the "notes" field.
449
+ func NotesEqualFold(v string) predicate.Account {
450
+ return predicate.Account(sql.FieldEqualFold(FieldNotes, v))
451
+ }
452
+
453
+ // NotesContainsFold applies the ContainsFold predicate on the "notes" field.
454
+ func NotesContainsFold(v string) predicate.Account {
455
+ return predicate.Account(sql.FieldContainsFold(FieldNotes, v))
456
+ }
457
+
458
+ // PlatformEQ applies the EQ predicate on the "platform" field.
459
+ func PlatformEQ(v string) predicate.Account {
460
+ return predicate.Account(sql.FieldEQ(FieldPlatform, v))
461
+ }
462
+
463
+ // PlatformNEQ applies the NEQ predicate on the "platform" field.
464
+ func PlatformNEQ(v string) predicate.Account {
465
+ return predicate.Account(sql.FieldNEQ(FieldPlatform, v))
466
+ }
467
+
468
+ // PlatformIn applies the In predicate on the "platform" field.
469
+ func PlatformIn(vs ...string) predicate.Account {
470
+ return predicate.Account(sql.FieldIn(FieldPlatform, vs...))
471
+ }
472
+
473
+ // PlatformNotIn applies the NotIn predicate on the "platform" field.
474
+ func PlatformNotIn(vs ...string) predicate.Account {
475
+ return predicate.Account(sql.FieldNotIn(FieldPlatform, vs...))
476
+ }
477
+
478
+ // PlatformGT applies the GT predicate on the "platform" field.
479
+ func PlatformGT(v string) predicate.Account {
480
+ return predicate.Account(sql.FieldGT(FieldPlatform, v))
481
+ }
482
+
483
+ // PlatformGTE applies the GTE predicate on the "platform" field.
484
+ func PlatformGTE(v string) predicate.Account {
485
+ return predicate.Account(sql.FieldGTE(FieldPlatform, v))
486
+ }
487
+
488
+ // PlatformLT applies the LT predicate on the "platform" field.
489
+ func PlatformLT(v string) predicate.Account {
490
+ return predicate.Account(sql.FieldLT(FieldPlatform, v))
491
+ }
492
+
493
+ // PlatformLTE applies the LTE predicate on the "platform" field.
494
+ func PlatformLTE(v string) predicate.Account {
495
+ return predicate.Account(sql.FieldLTE(FieldPlatform, v))
496
+ }
497
+
498
+ // PlatformContains applies the Contains predicate on the "platform" field.
499
+ func PlatformContains(v string) predicate.Account {
500
+ return predicate.Account(sql.FieldContains(FieldPlatform, v))
501
+ }
502
+
503
+ // PlatformHasPrefix applies the HasPrefix predicate on the "platform" field.
504
+ func PlatformHasPrefix(v string) predicate.Account {
505
+ return predicate.Account(sql.FieldHasPrefix(FieldPlatform, v))
506
+ }
507
+
508
+ // PlatformHasSuffix applies the HasSuffix predicate on the "platform" field.
509
+ func PlatformHasSuffix(v string) predicate.Account {
510
+ return predicate.Account(sql.FieldHasSuffix(FieldPlatform, v))
511
+ }
512
+
513
+ // PlatformEqualFold applies the EqualFold predicate on the "platform" field.
514
+ func PlatformEqualFold(v string) predicate.Account {
515
+ return predicate.Account(sql.FieldEqualFold(FieldPlatform, v))
516
+ }
517
+
518
+ // PlatformContainsFold applies the ContainsFold predicate on the "platform" field.
519
+ func PlatformContainsFold(v string) predicate.Account {
520
+ return predicate.Account(sql.FieldContainsFold(FieldPlatform, v))
521
+ }
522
+
523
+ // TypeEQ applies the EQ predicate on the "type" field.
524
+ func TypeEQ(v string) predicate.Account {
525
+ return predicate.Account(sql.FieldEQ(FieldType, v))
526
+ }
527
+
528
+ // TypeNEQ applies the NEQ predicate on the "type" field.
529
+ func TypeNEQ(v string) predicate.Account {
530
+ return predicate.Account(sql.FieldNEQ(FieldType, v))
531
+ }
532
+
533
+ // TypeIn applies the In predicate on the "type" field.
534
+ func TypeIn(vs ...string) predicate.Account {
535
+ return predicate.Account(sql.FieldIn(FieldType, vs...))
536
+ }
537
+
538
+ // TypeNotIn applies the NotIn predicate on the "type" field.
539
+ func TypeNotIn(vs ...string) predicate.Account {
540
+ return predicate.Account(sql.FieldNotIn(FieldType, vs...))
541
+ }
542
+
543
+ // TypeGT applies the GT predicate on the "type" field.
544
+ func TypeGT(v string) predicate.Account {
545
+ return predicate.Account(sql.FieldGT(FieldType, v))
546
+ }
547
+
548
+ // TypeGTE applies the GTE predicate on the "type" field.
549
+ func TypeGTE(v string) predicate.Account {
550
+ return predicate.Account(sql.FieldGTE(FieldType, v))
551
+ }
552
+
553
+ // TypeLT applies the LT predicate on the "type" field.
554
+ func TypeLT(v string) predicate.Account {
555
+ return predicate.Account(sql.FieldLT(FieldType, v))
556
+ }
557
+
558
+ // TypeLTE applies the LTE predicate on the "type" field.
559
+ func TypeLTE(v string) predicate.Account {
560
+ return predicate.Account(sql.FieldLTE(FieldType, v))
561
+ }
562
+
563
+ // TypeContains applies the Contains predicate on the "type" field.
564
+ func TypeContains(v string) predicate.Account {
565
+ return predicate.Account(sql.FieldContains(FieldType, v))
566
+ }
567
+
568
+ // TypeHasPrefix applies the HasPrefix predicate on the "type" field.
569
+ func TypeHasPrefix(v string) predicate.Account {
570
+ return predicate.Account(sql.FieldHasPrefix(FieldType, v))
571
+ }
572
+
573
+ // TypeHasSuffix applies the HasSuffix predicate on the "type" field.
574
+ func TypeHasSuffix(v string) predicate.Account {
575
+ return predicate.Account(sql.FieldHasSuffix(FieldType, v))
576
+ }
577
+
578
+ // TypeEqualFold applies the EqualFold predicate on the "type" field.
579
+ func TypeEqualFold(v string) predicate.Account {
580
+ return predicate.Account(sql.FieldEqualFold(FieldType, v))
581
+ }
582
+
583
+ // TypeContainsFold applies the ContainsFold predicate on the "type" field.
584
+ func TypeContainsFold(v string) predicate.Account {
585
+ return predicate.Account(sql.FieldContainsFold(FieldType, v))
586
+ }
587
+
588
+ // ProxyIDEQ applies the EQ predicate on the "proxy_id" field.
589
+ func ProxyIDEQ(v int64) predicate.Account {
590
+ return predicate.Account(sql.FieldEQ(FieldProxyID, v))
591
+ }
592
+
593
+ // ProxyIDNEQ applies the NEQ predicate on the "proxy_id" field.
594
+ func ProxyIDNEQ(v int64) predicate.Account {
595
+ return predicate.Account(sql.FieldNEQ(FieldProxyID, v))
596
+ }
597
+
598
+ // ProxyIDIn applies the In predicate on the "proxy_id" field.
599
+ func ProxyIDIn(vs ...int64) predicate.Account {
600
+ return predicate.Account(sql.FieldIn(FieldProxyID, vs...))
601
+ }
602
+
603
+ // ProxyIDNotIn applies the NotIn predicate on the "proxy_id" field.
604
+ func ProxyIDNotIn(vs ...int64) predicate.Account {
605
+ return predicate.Account(sql.FieldNotIn(FieldProxyID, vs...))
606
+ }
607
+
608
+ // ProxyIDIsNil applies the IsNil predicate on the "proxy_id" field.
609
+ func ProxyIDIsNil() predicate.Account {
610
+ return predicate.Account(sql.FieldIsNull(FieldProxyID))
611
+ }
612
+
613
+ // ProxyIDNotNil applies the NotNil predicate on the "proxy_id" field.
614
+ func ProxyIDNotNil() predicate.Account {
615
+ return predicate.Account(sql.FieldNotNull(FieldProxyID))
616
+ }
617
+
618
+ // ConcurrencyEQ applies the EQ predicate on the "concurrency" field.
619
+ func ConcurrencyEQ(v int) predicate.Account {
620
+ return predicate.Account(sql.FieldEQ(FieldConcurrency, v))
621
+ }
622
+
623
+ // ConcurrencyNEQ applies the NEQ predicate on the "concurrency" field.
624
+ func ConcurrencyNEQ(v int) predicate.Account {
625
+ return predicate.Account(sql.FieldNEQ(FieldConcurrency, v))
626
+ }
627
+
628
+ // ConcurrencyIn applies the In predicate on the "concurrency" field.
629
+ func ConcurrencyIn(vs ...int) predicate.Account {
630
+ return predicate.Account(sql.FieldIn(FieldConcurrency, vs...))
631
+ }
632
+
633
+ // ConcurrencyNotIn applies the NotIn predicate on the "concurrency" field.
634
+ func ConcurrencyNotIn(vs ...int) predicate.Account {
635
+ return predicate.Account(sql.FieldNotIn(FieldConcurrency, vs...))
636
+ }
637
+
638
+ // ConcurrencyGT applies the GT predicate on the "concurrency" field.
639
+ func ConcurrencyGT(v int) predicate.Account {
640
+ return predicate.Account(sql.FieldGT(FieldConcurrency, v))
641
+ }
642
+
643
+ // ConcurrencyGTE applies the GTE predicate on the "concurrency" field.
644
+ func ConcurrencyGTE(v int) predicate.Account {
645
+ return predicate.Account(sql.FieldGTE(FieldConcurrency, v))
646
+ }
647
+
648
+ // ConcurrencyLT applies the LT predicate on the "concurrency" field.
649
+ func ConcurrencyLT(v int) predicate.Account {
650
+ return predicate.Account(sql.FieldLT(FieldConcurrency, v))
651
+ }
652
+
653
+ // ConcurrencyLTE applies the LTE predicate on the "concurrency" field.
654
+ func ConcurrencyLTE(v int) predicate.Account {
655
+ return predicate.Account(sql.FieldLTE(FieldConcurrency, v))
656
+ }
657
+
658
+ // LoadFactorEQ applies the EQ predicate on the "load_factor" field.
659
+ func LoadFactorEQ(v int) predicate.Account {
660
+ return predicate.Account(sql.FieldEQ(FieldLoadFactor, v))
661
+ }
662
+
663
+ // LoadFactorNEQ applies the NEQ predicate on the "load_factor" field.
664
+ func LoadFactorNEQ(v int) predicate.Account {
665
+ return predicate.Account(sql.FieldNEQ(FieldLoadFactor, v))
666
+ }
667
+
668
+ // LoadFactorIn applies the In predicate on the "load_factor" field.
669
+ func LoadFactorIn(vs ...int) predicate.Account {
670
+ return predicate.Account(sql.FieldIn(FieldLoadFactor, vs...))
671
+ }
672
+
673
+ // LoadFactorNotIn applies the NotIn predicate on the "load_factor" field.
674
+ func LoadFactorNotIn(vs ...int) predicate.Account {
675
+ return predicate.Account(sql.FieldNotIn(FieldLoadFactor, vs...))
676
+ }
677
+
678
+ // LoadFactorGT applies the GT predicate on the "load_factor" field.
679
+ func LoadFactorGT(v int) predicate.Account {
680
+ return predicate.Account(sql.FieldGT(FieldLoadFactor, v))
681
+ }
682
+
683
+ // LoadFactorGTE applies the GTE predicate on the "load_factor" field.
684
+ func LoadFactorGTE(v int) predicate.Account {
685
+ return predicate.Account(sql.FieldGTE(FieldLoadFactor, v))
686
+ }
687
+
688
+ // LoadFactorLT applies the LT predicate on the "load_factor" field.
689
+ func LoadFactorLT(v int) predicate.Account {
690
+ return predicate.Account(sql.FieldLT(FieldLoadFactor, v))
691
+ }
692
+
693
+ // LoadFactorLTE applies the LTE predicate on the "load_factor" field.
694
+ func LoadFactorLTE(v int) predicate.Account {
695
+ return predicate.Account(sql.FieldLTE(FieldLoadFactor, v))
696
+ }
697
+
698
+ // LoadFactorIsNil applies the IsNil predicate on the "load_factor" field.
699
+ func LoadFactorIsNil() predicate.Account {
700
+ return predicate.Account(sql.FieldIsNull(FieldLoadFactor))
701
+ }
702
+
703
+ // LoadFactorNotNil applies the NotNil predicate on the "load_factor" field.
704
+ func LoadFactorNotNil() predicate.Account {
705
+ return predicate.Account(sql.FieldNotNull(FieldLoadFactor))
706
+ }
707
+
708
+ // PriorityEQ applies the EQ predicate on the "priority" field.
709
+ func PriorityEQ(v int) predicate.Account {
710
+ return predicate.Account(sql.FieldEQ(FieldPriority, v))
711
+ }
712
+
713
+ // PriorityNEQ applies the NEQ predicate on the "priority" field.
714
+ func PriorityNEQ(v int) predicate.Account {
715
+ return predicate.Account(sql.FieldNEQ(FieldPriority, v))
716
+ }
717
+
718
+ // PriorityIn applies the In predicate on the "priority" field.
719
+ func PriorityIn(vs ...int) predicate.Account {
720
+ return predicate.Account(sql.FieldIn(FieldPriority, vs...))
721
+ }
722
+
723
+ // PriorityNotIn applies the NotIn predicate on the "priority" field.
724
+ func PriorityNotIn(vs ...int) predicate.Account {
725
+ return predicate.Account(sql.FieldNotIn(FieldPriority, vs...))
726
+ }
727
+
728
+ // PriorityGT applies the GT predicate on the "priority" field.
729
+ func PriorityGT(v int) predicate.Account {
730
+ return predicate.Account(sql.FieldGT(FieldPriority, v))
731
+ }
732
+
733
+ // PriorityGTE applies the GTE predicate on the "priority" field.
734
+ func PriorityGTE(v int) predicate.Account {
735
+ return predicate.Account(sql.FieldGTE(FieldPriority, v))
736
+ }
737
+
738
+ // PriorityLT applies the LT predicate on the "priority" field.
739
+ func PriorityLT(v int) predicate.Account {
740
+ return predicate.Account(sql.FieldLT(FieldPriority, v))
741
+ }
742
+
743
+ // PriorityLTE applies the LTE predicate on the "priority" field.
744
+ func PriorityLTE(v int) predicate.Account {
745
+ return predicate.Account(sql.FieldLTE(FieldPriority, v))
746
+ }
747
+
748
+ // RateMultiplierEQ applies the EQ predicate on the "rate_multiplier" field.
749
+ func RateMultiplierEQ(v float64) predicate.Account {
750
+ return predicate.Account(sql.FieldEQ(FieldRateMultiplier, v))
751
+ }
752
+
753
+ // RateMultiplierNEQ applies the NEQ predicate on the "rate_multiplier" field.
754
+ func RateMultiplierNEQ(v float64) predicate.Account {
755
+ return predicate.Account(sql.FieldNEQ(FieldRateMultiplier, v))
756
+ }
757
+
758
+ // RateMultiplierIn applies the In predicate on the "rate_multiplier" field.
759
+ func RateMultiplierIn(vs ...float64) predicate.Account {
760
+ return predicate.Account(sql.FieldIn(FieldRateMultiplier, vs...))
761
+ }
762
+
763
+ // RateMultiplierNotIn applies the NotIn predicate on the "rate_multiplier" field.
764
+ func RateMultiplierNotIn(vs ...float64) predicate.Account {
765
+ return predicate.Account(sql.FieldNotIn(FieldRateMultiplier, vs...))
766
+ }
767
+
768
+ // RateMultiplierGT applies the GT predicate on the "rate_multiplier" field.
769
+ func RateMultiplierGT(v float64) predicate.Account {
770
+ return predicate.Account(sql.FieldGT(FieldRateMultiplier, v))
771
+ }
772
+
773
+ // RateMultiplierGTE applies the GTE predicate on the "rate_multiplier" field.
774
+ func RateMultiplierGTE(v float64) predicate.Account {
775
+ return predicate.Account(sql.FieldGTE(FieldRateMultiplier, v))
776
+ }
777
+
778
+ // RateMultiplierLT applies the LT predicate on the "rate_multiplier" field.
779
+ func RateMultiplierLT(v float64) predicate.Account {
780
+ return predicate.Account(sql.FieldLT(FieldRateMultiplier, v))
781
+ }
782
+
783
+ // RateMultiplierLTE applies the LTE predicate on the "rate_multiplier" field.
784
+ func RateMultiplierLTE(v float64) predicate.Account {
785
+ return predicate.Account(sql.FieldLTE(FieldRateMultiplier, v))
786
+ }
787
+
788
+ // StatusEQ applies the EQ predicate on the "status" field.
789
+ func StatusEQ(v string) predicate.Account {
790
+ return predicate.Account(sql.FieldEQ(FieldStatus, v))
791
+ }
792
+
793
+ // StatusNEQ applies the NEQ predicate on the "status" field.
794
+ func StatusNEQ(v string) predicate.Account {
795
+ return predicate.Account(sql.FieldNEQ(FieldStatus, v))
796
+ }
797
+
798
+ // StatusIn applies the In predicate on the "status" field.
799
+ func StatusIn(vs ...string) predicate.Account {
800
+ return predicate.Account(sql.FieldIn(FieldStatus, vs...))
801
+ }
802
+
803
+ // StatusNotIn applies the NotIn predicate on the "status" field.
804
+ func StatusNotIn(vs ...string) predicate.Account {
805
+ return predicate.Account(sql.FieldNotIn(FieldStatus, vs...))
806
+ }
807
+
808
+ // StatusGT applies the GT predicate on the "status" field.
809
+ func StatusGT(v string) predicate.Account {
810
+ return predicate.Account(sql.FieldGT(FieldStatus, v))
811
+ }
812
+
813
+ // StatusGTE applies the GTE predicate on the "status" field.
814
+ func StatusGTE(v string) predicate.Account {
815
+ return predicate.Account(sql.FieldGTE(FieldStatus, v))
816
+ }
817
+
818
+ // StatusLT applies the LT predicate on the "status" field.
819
+ func StatusLT(v string) predicate.Account {
820
+ return predicate.Account(sql.FieldLT(FieldStatus, v))
821
+ }
822
+
823
+ // StatusLTE applies the LTE predicate on the "status" field.
824
+ func StatusLTE(v string) predicate.Account {
825
+ return predicate.Account(sql.FieldLTE(FieldStatus, v))
826
+ }
827
+
828
+ // StatusContains applies the Contains predicate on the "status" field.
829
+ func StatusContains(v string) predicate.Account {
830
+ return predicate.Account(sql.FieldContains(FieldStatus, v))
831
+ }
832
+
833
+ // StatusHasPrefix applies the HasPrefix predicate on the "status" field.
834
+ func StatusHasPrefix(v string) predicate.Account {
835
+ return predicate.Account(sql.FieldHasPrefix(FieldStatus, v))
836
+ }
837
+
838
+ // StatusHasSuffix applies the HasSuffix predicate on the "status" field.
839
+ func StatusHasSuffix(v string) predicate.Account {
840
+ return predicate.Account(sql.FieldHasSuffix(FieldStatus, v))
841
+ }
842
+
843
+ // StatusEqualFold applies the EqualFold predicate on the "status" field.
844
+ func StatusEqualFold(v string) predicate.Account {
845
+ return predicate.Account(sql.FieldEqualFold(FieldStatus, v))
846
+ }
847
+
848
+ // StatusContainsFold applies the ContainsFold predicate on the "status" field.
849
+ func StatusContainsFold(v string) predicate.Account {
850
+ return predicate.Account(sql.FieldContainsFold(FieldStatus, v))
851
+ }
852
+
853
+ // ErrorMessageEQ applies the EQ predicate on the "error_message" field.
854
+ func ErrorMessageEQ(v string) predicate.Account {
855
+ return predicate.Account(sql.FieldEQ(FieldErrorMessage, v))
856
+ }
857
+
858
+ // ErrorMessageNEQ applies the NEQ predicate on the "error_message" field.
859
+ func ErrorMessageNEQ(v string) predicate.Account {
860
+ return predicate.Account(sql.FieldNEQ(FieldErrorMessage, v))
861
+ }
862
+
863
+ // ErrorMessageIn applies the In predicate on the "error_message" field.
864
+ func ErrorMessageIn(vs ...string) predicate.Account {
865
+ return predicate.Account(sql.FieldIn(FieldErrorMessage, vs...))
866
+ }
867
+
868
+ // ErrorMessageNotIn applies the NotIn predicate on the "error_message" field.
869
+ func ErrorMessageNotIn(vs ...string) predicate.Account {
870
+ return predicate.Account(sql.FieldNotIn(FieldErrorMessage, vs...))
871
+ }
872
+
873
+ // ErrorMessageGT applies the GT predicate on the "error_message" field.
874
+ func ErrorMessageGT(v string) predicate.Account {
875
+ return predicate.Account(sql.FieldGT(FieldErrorMessage, v))
876
+ }
877
+
878
+ // ErrorMessageGTE applies the GTE predicate on the "error_message" field.
879
+ func ErrorMessageGTE(v string) predicate.Account {
880
+ return predicate.Account(sql.FieldGTE(FieldErrorMessage, v))
881
+ }
882
+
883
+ // ErrorMessageLT applies the LT predicate on the "error_message" field.
884
+ func ErrorMessageLT(v string) predicate.Account {
885
+ return predicate.Account(sql.FieldLT(FieldErrorMessage, v))
886
+ }
887
+
888
+ // ErrorMessageLTE applies the LTE predicate on the "error_message" field.
889
+ func ErrorMessageLTE(v string) predicate.Account {
890
+ return predicate.Account(sql.FieldLTE(FieldErrorMessage, v))
891
+ }
892
+
893
+ // ErrorMessageContains applies the Contains predicate on the "error_message" field.
894
+ func ErrorMessageContains(v string) predicate.Account {
895
+ return predicate.Account(sql.FieldContains(FieldErrorMessage, v))
896
+ }
897
+
898
+ // ErrorMessageHasPrefix applies the HasPrefix predicate on the "error_message" field.
899
+ func ErrorMessageHasPrefix(v string) predicate.Account {
900
+ return predicate.Account(sql.FieldHasPrefix(FieldErrorMessage, v))
901
+ }
902
+
903
+ // ErrorMessageHasSuffix applies the HasSuffix predicate on the "error_message" field.
904
+ func ErrorMessageHasSuffix(v string) predicate.Account {
905
+ return predicate.Account(sql.FieldHasSuffix(FieldErrorMessage, v))
906
+ }
907
+
908
+ // ErrorMessageIsNil applies the IsNil predicate on the "error_message" field.
909
+ func ErrorMessageIsNil() predicate.Account {
910
+ return predicate.Account(sql.FieldIsNull(FieldErrorMessage))
911
+ }
912
+
913
+ // ErrorMessageNotNil applies the NotNil predicate on the "error_message" field.
914
+ func ErrorMessageNotNil() predicate.Account {
915
+ return predicate.Account(sql.FieldNotNull(FieldErrorMessage))
916
+ }
917
+
918
+ // ErrorMessageEqualFold applies the EqualFold predicate on the "error_message" field.
919
+ func ErrorMessageEqualFold(v string) predicate.Account {
920
+ return predicate.Account(sql.FieldEqualFold(FieldErrorMessage, v))
921
+ }
922
+
923
+ // ErrorMessageContainsFold applies the ContainsFold predicate on the "error_message" field.
924
+ func ErrorMessageContainsFold(v string) predicate.Account {
925
+ return predicate.Account(sql.FieldContainsFold(FieldErrorMessage, v))
926
+ }
927
+
928
+ // LastUsedAtEQ applies the EQ predicate on the "last_used_at" field.
929
+ func LastUsedAtEQ(v time.Time) predicate.Account {
930
+ return predicate.Account(sql.FieldEQ(FieldLastUsedAt, v))
931
+ }
932
+
933
+ // LastUsedAtNEQ applies the NEQ predicate on the "last_used_at" field.
934
+ func LastUsedAtNEQ(v time.Time) predicate.Account {
935
+ return predicate.Account(sql.FieldNEQ(FieldLastUsedAt, v))
936
+ }
937
+
938
+ // LastUsedAtIn applies the In predicate on the "last_used_at" field.
939
+ func LastUsedAtIn(vs ...time.Time) predicate.Account {
940
+ return predicate.Account(sql.FieldIn(FieldLastUsedAt, vs...))
941
+ }
942
+
943
+ // LastUsedAtNotIn applies the NotIn predicate on the "last_used_at" field.
944
+ func LastUsedAtNotIn(vs ...time.Time) predicate.Account {
945
+ return predicate.Account(sql.FieldNotIn(FieldLastUsedAt, vs...))
946
+ }
947
+
948
+ // LastUsedAtGT applies the GT predicate on the "last_used_at" field.
949
+ func LastUsedAtGT(v time.Time) predicate.Account {
950
+ return predicate.Account(sql.FieldGT(FieldLastUsedAt, v))
951
+ }
952
+
953
+ // LastUsedAtGTE applies the GTE predicate on the "last_used_at" field.
954
+ func LastUsedAtGTE(v time.Time) predicate.Account {
955
+ return predicate.Account(sql.FieldGTE(FieldLastUsedAt, v))
956
+ }
957
+
958
+ // LastUsedAtLT applies the LT predicate on the "last_used_at" field.
959
+ func LastUsedAtLT(v time.Time) predicate.Account {
960
+ return predicate.Account(sql.FieldLT(FieldLastUsedAt, v))
961
+ }
962
+
963
+ // LastUsedAtLTE applies the LTE predicate on the "last_used_at" field.
964
+ func LastUsedAtLTE(v time.Time) predicate.Account {
965
+ return predicate.Account(sql.FieldLTE(FieldLastUsedAt, v))
966
+ }
967
+
968
+ // LastUsedAtIsNil applies the IsNil predicate on the "last_used_at" field.
969
+ func LastUsedAtIsNil() predicate.Account {
970
+ return predicate.Account(sql.FieldIsNull(FieldLastUsedAt))
971
+ }
972
+
973
+ // LastUsedAtNotNil applies the NotNil predicate on the "last_used_at" field.
974
+ func LastUsedAtNotNil() predicate.Account {
975
+ return predicate.Account(sql.FieldNotNull(FieldLastUsedAt))
976
+ }
977
+
978
+ // ExpiresAtEQ applies the EQ predicate on the "expires_at" field.
979
+ func ExpiresAtEQ(v time.Time) predicate.Account {
980
+ return predicate.Account(sql.FieldEQ(FieldExpiresAt, v))
981
+ }
982
+
983
+ // ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field.
984
+ func ExpiresAtNEQ(v time.Time) predicate.Account {
985
+ return predicate.Account(sql.FieldNEQ(FieldExpiresAt, v))
986
+ }
987
+
988
+ // ExpiresAtIn applies the In predicate on the "expires_at" field.
989
+ func ExpiresAtIn(vs ...time.Time) predicate.Account {
990
+ return predicate.Account(sql.FieldIn(FieldExpiresAt, vs...))
991
+ }
992
+
993
+ // ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field.
994
+ func ExpiresAtNotIn(vs ...time.Time) predicate.Account {
995
+ return predicate.Account(sql.FieldNotIn(FieldExpiresAt, vs...))
996
+ }
997
+
998
+ // ExpiresAtGT applies the GT predicate on the "expires_at" field.
999
+ func ExpiresAtGT(v time.Time) predicate.Account {
1000
+ return predicate.Account(sql.FieldGT(FieldExpiresAt, v))
1001
+ }
1002
+
1003
+ // ExpiresAtGTE applies the GTE predicate on the "expires_at" field.
1004
+ func ExpiresAtGTE(v time.Time) predicate.Account {
1005
+ return predicate.Account(sql.FieldGTE(FieldExpiresAt, v))
1006
+ }
1007
+
1008
+ // ExpiresAtLT applies the LT predicate on the "expires_at" field.
1009
+ func ExpiresAtLT(v time.Time) predicate.Account {
1010
+ return predicate.Account(sql.FieldLT(FieldExpiresAt, v))
1011
+ }
1012
+
1013
+ // ExpiresAtLTE applies the LTE predicate on the "expires_at" field.
1014
+ func ExpiresAtLTE(v time.Time) predicate.Account {
1015
+ return predicate.Account(sql.FieldLTE(FieldExpiresAt, v))
1016
+ }
1017
+
1018
+ // ExpiresAtIsNil applies the IsNil predicate on the "expires_at" field.
1019
+ func ExpiresAtIsNil() predicate.Account {
1020
+ return predicate.Account(sql.FieldIsNull(FieldExpiresAt))
1021
+ }
1022
+
1023
+ // ExpiresAtNotNil applies the NotNil predicate on the "expires_at" field.
1024
+ func ExpiresAtNotNil() predicate.Account {
1025
+ return predicate.Account(sql.FieldNotNull(FieldExpiresAt))
1026
+ }
1027
+
1028
+ // AutoPauseOnExpiredEQ applies the EQ predicate on the "auto_pause_on_expired" field.
1029
+ func AutoPauseOnExpiredEQ(v bool) predicate.Account {
1030
+ return predicate.Account(sql.FieldEQ(FieldAutoPauseOnExpired, v))
1031
+ }
1032
+
1033
+ // AutoPauseOnExpiredNEQ applies the NEQ predicate on the "auto_pause_on_expired" field.
1034
+ func AutoPauseOnExpiredNEQ(v bool) predicate.Account {
1035
+ return predicate.Account(sql.FieldNEQ(FieldAutoPauseOnExpired, v))
1036
+ }
1037
+
1038
+ // SchedulableEQ applies the EQ predicate on the "schedulable" field.
1039
+ func SchedulableEQ(v bool) predicate.Account {
1040
+ return predicate.Account(sql.FieldEQ(FieldSchedulable, v))
1041
+ }
1042
+
1043
+ // SchedulableNEQ applies the NEQ predicate on the "schedulable" field.
1044
+ func SchedulableNEQ(v bool) predicate.Account {
1045
+ return predicate.Account(sql.FieldNEQ(FieldSchedulable, v))
1046
+ }
1047
+
1048
+ // RateLimitedAtEQ applies the EQ predicate on the "rate_limited_at" field.
1049
+ func RateLimitedAtEQ(v time.Time) predicate.Account {
1050
+ return predicate.Account(sql.FieldEQ(FieldRateLimitedAt, v))
1051
+ }
1052
+
1053
+ // RateLimitedAtNEQ applies the NEQ predicate on the "rate_limited_at" field.
1054
+ func RateLimitedAtNEQ(v time.Time) predicate.Account {
1055
+ return predicate.Account(sql.FieldNEQ(FieldRateLimitedAt, v))
1056
+ }
1057
+
1058
+ // RateLimitedAtIn applies the In predicate on the "rate_limited_at" field.
1059
+ func RateLimitedAtIn(vs ...time.Time) predicate.Account {
1060
+ return predicate.Account(sql.FieldIn(FieldRateLimitedAt, vs...))
1061
+ }
1062
+
1063
+ // RateLimitedAtNotIn applies the NotIn predicate on the "rate_limited_at" field.
1064
+ func RateLimitedAtNotIn(vs ...time.Time) predicate.Account {
1065
+ return predicate.Account(sql.FieldNotIn(FieldRateLimitedAt, vs...))
1066
+ }
1067
+
1068
+ // RateLimitedAtGT applies the GT predicate on the "rate_limited_at" field.
1069
+ func RateLimitedAtGT(v time.Time) predicate.Account {
1070
+ return predicate.Account(sql.FieldGT(FieldRateLimitedAt, v))
1071
+ }
1072
+
1073
+ // RateLimitedAtGTE applies the GTE predicate on the "rate_limited_at" field.
1074
+ func RateLimitedAtGTE(v time.Time) predicate.Account {
1075
+ return predicate.Account(sql.FieldGTE(FieldRateLimitedAt, v))
1076
+ }
1077
+
1078
+ // RateLimitedAtLT applies the LT predicate on the "rate_limited_at" field.
1079
+ func RateLimitedAtLT(v time.Time) predicate.Account {
1080
+ return predicate.Account(sql.FieldLT(FieldRateLimitedAt, v))
1081
+ }
1082
+
1083
+ // RateLimitedAtLTE applies the LTE predicate on the "rate_limited_at" field.
1084
+ func RateLimitedAtLTE(v time.Time) predicate.Account {
1085
+ return predicate.Account(sql.FieldLTE(FieldRateLimitedAt, v))
1086
+ }
1087
+
1088
+ // RateLimitedAtIsNil applies the IsNil predicate on the "rate_limited_at" field.
1089
+ func RateLimitedAtIsNil() predicate.Account {
1090
+ return predicate.Account(sql.FieldIsNull(FieldRateLimitedAt))
1091
+ }
1092
+
1093
+ // RateLimitedAtNotNil applies the NotNil predicate on the "rate_limited_at" field.
1094
+ func RateLimitedAtNotNil() predicate.Account {
1095
+ return predicate.Account(sql.FieldNotNull(FieldRateLimitedAt))
1096
+ }
1097
+
1098
+ // RateLimitResetAtEQ applies the EQ predicate on the "rate_limit_reset_at" field.
1099
+ func RateLimitResetAtEQ(v time.Time) predicate.Account {
1100
+ return predicate.Account(sql.FieldEQ(FieldRateLimitResetAt, v))
1101
+ }
1102
+
1103
+ // RateLimitResetAtNEQ applies the NEQ predicate on the "rate_limit_reset_at" field.
1104
+ func RateLimitResetAtNEQ(v time.Time) predicate.Account {
1105
+ return predicate.Account(sql.FieldNEQ(FieldRateLimitResetAt, v))
1106
+ }
1107
+
1108
+ // RateLimitResetAtIn applies the In predicate on the "rate_limit_reset_at" field.
1109
+ func RateLimitResetAtIn(vs ...time.Time) predicate.Account {
1110
+ return predicate.Account(sql.FieldIn(FieldRateLimitResetAt, vs...))
1111
+ }
1112
+
1113
+ // RateLimitResetAtNotIn applies the NotIn predicate on the "rate_limit_reset_at" field.
1114
+ func RateLimitResetAtNotIn(vs ...time.Time) predicate.Account {
1115
+ return predicate.Account(sql.FieldNotIn(FieldRateLimitResetAt, vs...))
1116
+ }
1117
+
1118
+ // RateLimitResetAtGT applies the GT predicate on the "rate_limit_reset_at" field.
1119
+ func RateLimitResetAtGT(v time.Time) predicate.Account {
1120
+ return predicate.Account(sql.FieldGT(FieldRateLimitResetAt, v))
1121
+ }
1122
+
1123
+ // RateLimitResetAtGTE applies the GTE predicate on the "rate_limit_reset_at" field.
1124
+ func RateLimitResetAtGTE(v time.Time) predicate.Account {
1125
+ return predicate.Account(sql.FieldGTE(FieldRateLimitResetAt, v))
1126
+ }
1127
+
1128
+ // RateLimitResetAtLT applies the LT predicate on the "rate_limit_reset_at" field.
1129
+ func RateLimitResetAtLT(v time.Time) predicate.Account {
1130
+ return predicate.Account(sql.FieldLT(FieldRateLimitResetAt, v))
1131
+ }
1132
+
1133
+ // RateLimitResetAtLTE applies the LTE predicate on the "rate_limit_reset_at" field.
1134
+ func RateLimitResetAtLTE(v time.Time) predicate.Account {
1135
+ return predicate.Account(sql.FieldLTE(FieldRateLimitResetAt, v))
1136
+ }
1137
+
1138
+ // RateLimitResetAtIsNil applies the IsNil predicate on the "rate_limit_reset_at" field.
1139
+ func RateLimitResetAtIsNil() predicate.Account {
1140
+ return predicate.Account(sql.FieldIsNull(FieldRateLimitResetAt))
1141
+ }
1142
+
1143
+ // RateLimitResetAtNotNil applies the NotNil predicate on the "rate_limit_reset_at" field.
1144
+ func RateLimitResetAtNotNil() predicate.Account {
1145
+ return predicate.Account(sql.FieldNotNull(FieldRateLimitResetAt))
1146
+ }
1147
+
1148
+ // OverloadUntilEQ applies the EQ predicate on the "overload_until" field.
1149
+ func OverloadUntilEQ(v time.Time) predicate.Account {
1150
+ return predicate.Account(sql.FieldEQ(FieldOverloadUntil, v))
1151
+ }
1152
+
1153
+ // OverloadUntilNEQ applies the NEQ predicate on the "overload_until" field.
1154
+ func OverloadUntilNEQ(v time.Time) predicate.Account {
1155
+ return predicate.Account(sql.FieldNEQ(FieldOverloadUntil, v))
1156
+ }
1157
+
1158
+ // OverloadUntilIn applies the In predicate on the "overload_until" field.
1159
+ func OverloadUntilIn(vs ...time.Time) predicate.Account {
1160
+ return predicate.Account(sql.FieldIn(FieldOverloadUntil, vs...))
1161
+ }
1162
+
1163
+ // OverloadUntilNotIn applies the NotIn predicate on the "overload_until" field.
1164
+ func OverloadUntilNotIn(vs ...time.Time) predicate.Account {
1165
+ return predicate.Account(sql.FieldNotIn(FieldOverloadUntil, vs...))
1166
+ }
1167
+
1168
+ // OverloadUntilGT applies the GT predicate on the "overload_until" field.
1169
+ func OverloadUntilGT(v time.Time) predicate.Account {
1170
+ return predicate.Account(sql.FieldGT(FieldOverloadUntil, v))
1171
+ }
1172
+
1173
+ // OverloadUntilGTE applies the GTE predicate on the "overload_until" field.
1174
+ func OverloadUntilGTE(v time.Time) predicate.Account {
1175
+ return predicate.Account(sql.FieldGTE(FieldOverloadUntil, v))
1176
+ }
1177
+
1178
+ // OverloadUntilLT applies the LT predicate on the "overload_until" field.
1179
+ func OverloadUntilLT(v time.Time) predicate.Account {
1180
+ return predicate.Account(sql.FieldLT(FieldOverloadUntil, v))
1181
+ }
1182
+
1183
+ // OverloadUntilLTE applies the LTE predicate on the "overload_until" field.
1184
+ func OverloadUntilLTE(v time.Time) predicate.Account {
1185
+ return predicate.Account(sql.FieldLTE(FieldOverloadUntil, v))
1186
+ }
1187
+
1188
+ // OverloadUntilIsNil applies the IsNil predicate on the "overload_until" field.
1189
+ func OverloadUntilIsNil() predicate.Account {
1190
+ return predicate.Account(sql.FieldIsNull(FieldOverloadUntil))
1191
+ }
1192
+
1193
+ // OverloadUntilNotNil applies the NotNil predicate on the "overload_until" field.
1194
+ func OverloadUntilNotNil() predicate.Account {
1195
+ return predicate.Account(sql.FieldNotNull(FieldOverloadUntil))
1196
+ }
1197
+
1198
+ // TempUnschedulableUntilEQ applies the EQ predicate on the "temp_unschedulable_until" field.
1199
+ func TempUnschedulableUntilEQ(v time.Time) predicate.Account {
1200
+ return predicate.Account(sql.FieldEQ(FieldTempUnschedulableUntil, v))
1201
+ }
1202
+
1203
+ // TempUnschedulableUntilNEQ applies the NEQ predicate on the "temp_unschedulable_until" field.
1204
+ func TempUnschedulableUntilNEQ(v time.Time) predicate.Account {
1205
+ return predicate.Account(sql.FieldNEQ(FieldTempUnschedulableUntil, v))
1206
+ }
1207
+
1208
+ // TempUnschedulableUntilIn applies the In predicate on the "temp_unschedulable_until" field.
1209
+ func TempUnschedulableUntilIn(vs ...time.Time) predicate.Account {
1210
+ return predicate.Account(sql.FieldIn(FieldTempUnschedulableUntil, vs...))
1211
+ }
1212
+
1213
+ // TempUnschedulableUntilNotIn applies the NotIn predicate on the "temp_unschedulable_until" field.
1214
+ func TempUnschedulableUntilNotIn(vs ...time.Time) predicate.Account {
1215
+ return predicate.Account(sql.FieldNotIn(FieldTempUnschedulableUntil, vs...))
1216
+ }
1217
+
1218
+ // TempUnschedulableUntilGT applies the GT predicate on the "temp_unschedulable_until" field.
1219
+ func TempUnschedulableUntilGT(v time.Time) predicate.Account {
1220
+ return predicate.Account(sql.FieldGT(FieldTempUnschedulableUntil, v))
1221
+ }
1222
+
1223
+ // TempUnschedulableUntilGTE applies the GTE predicate on the "temp_unschedulable_until" field.
1224
+ func TempUnschedulableUntilGTE(v time.Time) predicate.Account {
1225
+ return predicate.Account(sql.FieldGTE(FieldTempUnschedulableUntil, v))
1226
+ }
1227
+
1228
+ // TempUnschedulableUntilLT applies the LT predicate on the "temp_unschedulable_until" field.
1229
+ func TempUnschedulableUntilLT(v time.Time) predicate.Account {
1230
+ return predicate.Account(sql.FieldLT(FieldTempUnschedulableUntil, v))
1231
+ }
1232
+
1233
+ // TempUnschedulableUntilLTE applies the LTE predicate on the "temp_unschedulable_until" field.
1234
+ func TempUnschedulableUntilLTE(v time.Time) predicate.Account {
1235
+ return predicate.Account(sql.FieldLTE(FieldTempUnschedulableUntil, v))
1236
+ }
1237
+
1238
+ // TempUnschedulableUntilIsNil applies the IsNil predicate on the "temp_unschedulable_until" field.
1239
+ func TempUnschedulableUntilIsNil() predicate.Account {
1240
+ return predicate.Account(sql.FieldIsNull(FieldTempUnschedulableUntil))
1241
+ }
1242
+
1243
+ // TempUnschedulableUntilNotNil applies the NotNil predicate on the "temp_unschedulable_until" field.
1244
+ func TempUnschedulableUntilNotNil() predicate.Account {
1245
+ return predicate.Account(sql.FieldNotNull(FieldTempUnschedulableUntil))
1246
+ }
1247
+
1248
+ // TempUnschedulableReasonEQ applies the EQ predicate on the "temp_unschedulable_reason" field.
1249
+ func TempUnschedulableReasonEQ(v string) predicate.Account {
1250
+ return predicate.Account(sql.FieldEQ(FieldTempUnschedulableReason, v))
1251
+ }
1252
+
1253
+ // TempUnschedulableReasonNEQ applies the NEQ predicate on the "temp_unschedulable_reason" field.
1254
+ func TempUnschedulableReasonNEQ(v string) predicate.Account {
1255
+ return predicate.Account(sql.FieldNEQ(FieldTempUnschedulableReason, v))
1256
+ }
1257
+
1258
+ // TempUnschedulableReasonIn applies the In predicate on the "temp_unschedulable_reason" field.
1259
+ func TempUnschedulableReasonIn(vs ...string) predicate.Account {
1260
+ return predicate.Account(sql.FieldIn(FieldTempUnschedulableReason, vs...))
1261
+ }
1262
+
1263
+ // TempUnschedulableReasonNotIn applies the NotIn predicate on the "temp_unschedulable_reason" field.
1264
+ func TempUnschedulableReasonNotIn(vs ...string) predicate.Account {
1265
+ return predicate.Account(sql.FieldNotIn(FieldTempUnschedulableReason, vs...))
1266
+ }
1267
+
1268
+ // TempUnschedulableReasonGT applies the GT predicate on the "temp_unschedulable_reason" field.
1269
+ func TempUnschedulableReasonGT(v string) predicate.Account {
1270
+ return predicate.Account(sql.FieldGT(FieldTempUnschedulableReason, v))
1271
+ }
1272
+
1273
+ // TempUnschedulableReasonGTE applies the GTE predicate on the "temp_unschedulable_reason" field.
1274
+ func TempUnschedulableReasonGTE(v string) predicate.Account {
1275
+ return predicate.Account(sql.FieldGTE(FieldTempUnschedulableReason, v))
1276
+ }
1277
+
1278
+ // TempUnschedulableReasonLT applies the LT predicate on the "temp_unschedulable_reason" field.
1279
+ func TempUnschedulableReasonLT(v string) predicate.Account {
1280
+ return predicate.Account(sql.FieldLT(FieldTempUnschedulableReason, v))
1281
+ }
1282
+
1283
+ // TempUnschedulableReasonLTE applies the LTE predicate on the "temp_unschedulable_reason" field.
1284
+ func TempUnschedulableReasonLTE(v string) predicate.Account {
1285
+ return predicate.Account(sql.FieldLTE(FieldTempUnschedulableReason, v))
1286
+ }
1287
+
1288
+ // TempUnschedulableReasonContains applies the Contains predicate on the "temp_unschedulable_reason" field.
1289
+ func TempUnschedulableReasonContains(v string) predicate.Account {
1290
+ return predicate.Account(sql.FieldContains(FieldTempUnschedulableReason, v))
1291
+ }
1292
+
1293
+ // TempUnschedulableReasonHasPrefix applies the HasPrefix predicate on the "temp_unschedulable_reason" field.
1294
+ func TempUnschedulableReasonHasPrefix(v string) predicate.Account {
1295
+ return predicate.Account(sql.FieldHasPrefix(FieldTempUnschedulableReason, v))
1296
+ }
1297
+
1298
+ // TempUnschedulableReasonHasSuffix applies the HasSuffix predicate on the "temp_unschedulable_reason" field.
1299
+ func TempUnschedulableReasonHasSuffix(v string) predicate.Account {
1300
+ return predicate.Account(sql.FieldHasSuffix(FieldTempUnschedulableReason, v))
1301
+ }
1302
+
1303
+ // TempUnschedulableReasonIsNil applies the IsNil predicate on the "temp_unschedulable_reason" field.
1304
+ func TempUnschedulableReasonIsNil() predicate.Account {
1305
+ return predicate.Account(sql.FieldIsNull(FieldTempUnschedulableReason))
1306
+ }
1307
+
1308
+ // TempUnschedulableReasonNotNil applies the NotNil predicate on the "temp_unschedulable_reason" field.
1309
+ func TempUnschedulableReasonNotNil() predicate.Account {
1310
+ return predicate.Account(sql.FieldNotNull(FieldTempUnschedulableReason))
1311
+ }
1312
+
1313
+ // TempUnschedulableReasonEqualFold applies the EqualFold predicate on the "temp_unschedulable_reason" field.
1314
+ func TempUnschedulableReasonEqualFold(v string) predicate.Account {
1315
+ return predicate.Account(sql.FieldEqualFold(FieldTempUnschedulableReason, v))
1316
+ }
1317
+
1318
+ // TempUnschedulableReasonContainsFold applies the ContainsFold predicate on the "temp_unschedulable_reason" field.
1319
+ func TempUnschedulableReasonContainsFold(v string) predicate.Account {
1320
+ return predicate.Account(sql.FieldContainsFold(FieldTempUnschedulableReason, v))
1321
+ }
1322
+
1323
+ // SessionWindowStartEQ applies the EQ predicate on the "session_window_start" field.
1324
+ func SessionWindowStartEQ(v time.Time) predicate.Account {
1325
+ return predicate.Account(sql.FieldEQ(FieldSessionWindowStart, v))
1326
+ }
1327
+
1328
+ // SessionWindowStartNEQ applies the NEQ predicate on the "session_window_start" field.
1329
+ func SessionWindowStartNEQ(v time.Time) predicate.Account {
1330
+ return predicate.Account(sql.FieldNEQ(FieldSessionWindowStart, v))
1331
+ }
1332
+
1333
+ // SessionWindowStartIn applies the In predicate on the "session_window_start" field.
1334
+ func SessionWindowStartIn(vs ...time.Time) predicate.Account {
1335
+ return predicate.Account(sql.FieldIn(FieldSessionWindowStart, vs...))
1336
+ }
1337
+
1338
+ // SessionWindowStartNotIn applies the NotIn predicate on the "session_window_start" field.
1339
+ func SessionWindowStartNotIn(vs ...time.Time) predicate.Account {
1340
+ return predicate.Account(sql.FieldNotIn(FieldSessionWindowStart, vs...))
1341
+ }
1342
+
1343
+ // SessionWindowStartGT applies the GT predicate on the "session_window_start" field.
1344
+ func SessionWindowStartGT(v time.Time) predicate.Account {
1345
+ return predicate.Account(sql.FieldGT(FieldSessionWindowStart, v))
1346
+ }
1347
+
1348
+ // SessionWindowStartGTE applies the GTE predicate on the "session_window_start" field.
1349
+ func SessionWindowStartGTE(v time.Time) predicate.Account {
1350
+ return predicate.Account(sql.FieldGTE(FieldSessionWindowStart, v))
1351
+ }
1352
+
1353
+ // SessionWindowStartLT applies the LT predicate on the "session_window_start" field.
1354
+ func SessionWindowStartLT(v time.Time) predicate.Account {
1355
+ return predicate.Account(sql.FieldLT(FieldSessionWindowStart, v))
1356
+ }
1357
+
1358
+ // SessionWindowStartLTE applies the LTE predicate on the "session_window_start" field.
1359
+ func SessionWindowStartLTE(v time.Time) predicate.Account {
1360
+ return predicate.Account(sql.FieldLTE(FieldSessionWindowStart, v))
1361
+ }
1362
+
1363
+ // SessionWindowStartIsNil applies the IsNil predicate on the "session_window_start" field.
1364
+ func SessionWindowStartIsNil() predicate.Account {
1365
+ return predicate.Account(sql.FieldIsNull(FieldSessionWindowStart))
1366
+ }
1367
+
1368
+ // SessionWindowStartNotNil applies the NotNil predicate on the "session_window_start" field.
1369
+ func SessionWindowStartNotNil() predicate.Account {
1370
+ return predicate.Account(sql.FieldNotNull(FieldSessionWindowStart))
1371
+ }
1372
+
1373
+ // SessionWindowEndEQ applies the EQ predicate on the "session_window_end" field.
1374
+ func SessionWindowEndEQ(v time.Time) predicate.Account {
1375
+ return predicate.Account(sql.FieldEQ(FieldSessionWindowEnd, v))
1376
+ }
1377
+
1378
+ // SessionWindowEndNEQ applies the NEQ predicate on the "session_window_end" field.
1379
+ func SessionWindowEndNEQ(v time.Time) predicate.Account {
1380
+ return predicate.Account(sql.FieldNEQ(FieldSessionWindowEnd, v))
1381
+ }
1382
+
1383
+ // SessionWindowEndIn applies the In predicate on the "session_window_end" field.
1384
+ func SessionWindowEndIn(vs ...time.Time) predicate.Account {
1385
+ return predicate.Account(sql.FieldIn(FieldSessionWindowEnd, vs...))
1386
+ }
1387
+
1388
+ // SessionWindowEndNotIn applies the NotIn predicate on the "session_window_end" field.
1389
+ func SessionWindowEndNotIn(vs ...time.Time) predicate.Account {
1390
+ return predicate.Account(sql.FieldNotIn(FieldSessionWindowEnd, vs...))
1391
+ }
1392
+
1393
+ // SessionWindowEndGT applies the GT predicate on the "session_window_end" field.
1394
+ func SessionWindowEndGT(v time.Time) predicate.Account {
1395
+ return predicate.Account(sql.FieldGT(FieldSessionWindowEnd, v))
1396
+ }
1397
+
1398
+ // SessionWindowEndGTE applies the GTE predicate on the "session_window_end" field.
1399
+ func SessionWindowEndGTE(v time.Time) predicate.Account {
1400
+ return predicate.Account(sql.FieldGTE(FieldSessionWindowEnd, v))
1401
+ }
1402
+
1403
+ // SessionWindowEndLT applies the LT predicate on the "session_window_end" field.
1404
+ func SessionWindowEndLT(v time.Time) predicate.Account {
1405
+ return predicate.Account(sql.FieldLT(FieldSessionWindowEnd, v))
1406
+ }
1407
+
1408
+ // SessionWindowEndLTE applies the LTE predicate on the "session_window_end" field.
1409
+ func SessionWindowEndLTE(v time.Time) predicate.Account {
1410
+ return predicate.Account(sql.FieldLTE(FieldSessionWindowEnd, v))
1411
+ }
1412
+
1413
+ // SessionWindowEndIsNil applies the IsNil predicate on the "session_window_end" field.
1414
+ func SessionWindowEndIsNil() predicate.Account {
1415
+ return predicate.Account(sql.FieldIsNull(FieldSessionWindowEnd))
1416
+ }
1417
+
1418
+ // SessionWindowEndNotNil applies the NotNil predicate on the "session_window_end" field.
1419
+ func SessionWindowEndNotNil() predicate.Account {
1420
+ return predicate.Account(sql.FieldNotNull(FieldSessionWindowEnd))
1421
+ }
1422
+
1423
+ // SessionWindowStatusEQ applies the EQ predicate on the "session_window_status" field.
1424
+ func SessionWindowStatusEQ(v string) predicate.Account {
1425
+ return predicate.Account(sql.FieldEQ(FieldSessionWindowStatus, v))
1426
+ }
1427
+
1428
+ // SessionWindowStatusNEQ applies the NEQ predicate on the "session_window_status" field.
1429
+ func SessionWindowStatusNEQ(v string) predicate.Account {
1430
+ return predicate.Account(sql.FieldNEQ(FieldSessionWindowStatus, v))
1431
+ }
1432
+
1433
+ // SessionWindowStatusIn applies the In predicate on the "session_window_status" field.
1434
+ func SessionWindowStatusIn(vs ...string) predicate.Account {
1435
+ return predicate.Account(sql.FieldIn(FieldSessionWindowStatus, vs...))
1436
+ }
1437
+
1438
+ // SessionWindowStatusNotIn applies the NotIn predicate on the "session_window_status" field.
1439
+ func SessionWindowStatusNotIn(vs ...string) predicate.Account {
1440
+ return predicate.Account(sql.FieldNotIn(FieldSessionWindowStatus, vs...))
1441
+ }
1442
+
1443
+ // SessionWindowStatusGT applies the GT predicate on the "session_window_status" field.
1444
+ func SessionWindowStatusGT(v string) predicate.Account {
1445
+ return predicate.Account(sql.FieldGT(FieldSessionWindowStatus, v))
1446
+ }
1447
+
1448
+ // SessionWindowStatusGTE applies the GTE predicate on the "session_window_status" field.
1449
+ func SessionWindowStatusGTE(v string) predicate.Account {
1450
+ return predicate.Account(sql.FieldGTE(FieldSessionWindowStatus, v))
1451
+ }
1452
+
1453
+ // SessionWindowStatusLT applies the LT predicate on the "session_window_status" field.
1454
+ func SessionWindowStatusLT(v string) predicate.Account {
1455
+ return predicate.Account(sql.FieldLT(FieldSessionWindowStatus, v))
1456
+ }
1457
+
1458
+ // SessionWindowStatusLTE applies the LTE predicate on the "session_window_status" field.
1459
+ func SessionWindowStatusLTE(v string) predicate.Account {
1460
+ return predicate.Account(sql.FieldLTE(FieldSessionWindowStatus, v))
1461
+ }
1462
+
1463
+ // SessionWindowStatusContains applies the Contains predicate on the "session_window_status" field.
1464
+ func SessionWindowStatusContains(v string) predicate.Account {
1465
+ return predicate.Account(sql.FieldContains(FieldSessionWindowStatus, v))
1466
+ }
1467
+
1468
+ // SessionWindowStatusHasPrefix applies the HasPrefix predicate on the "session_window_status" field.
1469
+ func SessionWindowStatusHasPrefix(v string) predicate.Account {
1470
+ return predicate.Account(sql.FieldHasPrefix(FieldSessionWindowStatus, v))
1471
+ }
1472
+
1473
+ // SessionWindowStatusHasSuffix applies the HasSuffix predicate on the "session_window_status" field.
1474
+ func SessionWindowStatusHasSuffix(v string) predicate.Account {
1475
+ return predicate.Account(sql.FieldHasSuffix(FieldSessionWindowStatus, v))
1476
+ }
1477
+
1478
+ // SessionWindowStatusIsNil applies the IsNil predicate on the "session_window_status" field.
1479
+ func SessionWindowStatusIsNil() predicate.Account {
1480
+ return predicate.Account(sql.FieldIsNull(FieldSessionWindowStatus))
1481
+ }
1482
+
1483
+ // SessionWindowStatusNotNil applies the NotNil predicate on the "session_window_status" field.
1484
+ func SessionWindowStatusNotNil() predicate.Account {
1485
+ return predicate.Account(sql.FieldNotNull(FieldSessionWindowStatus))
1486
+ }
1487
+
1488
+ // SessionWindowStatusEqualFold applies the EqualFold predicate on the "session_window_status" field.
1489
+ func SessionWindowStatusEqualFold(v string) predicate.Account {
1490
+ return predicate.Account(sql.FieldEqualFold(FieldSessionWindowStatus, v))
1491
+ }
1492
+
1493
+ // SessionWindowStatusContainsFold applies the ContainsFold predicate on the "session_window_status" field.
1494
+ func SessionWindowStatusContainsFold(v string) predicate.Account {
1495
+ return predicate.Account(sql.FieldContainsFold(FieldSessionWindowStatus, v))
1496
+ }
1497
+
1498
+ // HasGroups applies the HasEdge predicate on the "groups" edge.
1499
+ func HasGroups() predicate.Account {
1500
+ return predicate.Account(func(s *sql.Selector) {
1501
+ step := sqlgraph.NewStep(
1502
+ sqlgraph.From(Table, FieldID),
1503
+ sqlgraph.Edge(sqlgraph.M2M, false, GroupsTable, GroupsPrimaryKey...),
1504
+ )
1505
+ sqlgraph.HasNeighbors(s, step)
1506
+ })
1507
+ }
1508
+
1509
+ // HasGroupsWith applies the HasEdge predicate on the "groups" edge with a given conditions (other predicates).
1510
+ func HasGroupsWith(preds ...predicate.Group) predicate.Account {
1511
+ return predicate.Account(func(s *sql.Selector) {
1512
+ step := newGroupsStep()
1513
+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
1514
+ for _, p := range preds {
1515
+ p(s)
1516
+ }
1517
+ })
1518
+ })
1519
+ }
1520
+
1521
+ // HasProxy applies the HasEdge predicate on the "proxy" edge.
1522
+ func HasProxy() predicate.Account {
1523
+ return predicate.Account(func(s *sql.Selector) {
1524
+ step := sqlgraph.NewStep(
1525
+ sqlgraph.From(Table, FieldID),
1526
+ sqlgraph.Edge(sqlgraph.M2O, false, ProxyTable, ProxyColumn),
1527
+ )
1528
+ sqlgraph.HasNeighbors(s, step)
1529
+ })
1530
+ }
1531
+
1532
+ // HasProxyWith applies the HasEdge predicate on the "proxy" edge with a given conditions (other predicates).
1533
+ func HasProxyWith(preds ...predicate.Proxy) predicate.Account {
1534
+ return predicate.Account(func(s *sql.Selector) {
1535
+ step := newProxyStep()
1536
+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
1537
+ for _, p := range preds {
1538
+ p(s)
1539
+ }
1540
+ })
1541
+ })
1542
+ }
1543
+
1544
+ // HasUsageLogs applies the HasEdge predicate on the "usage_logs" edge.
1545
+ func HasUsageLogs() predicate.Account {
1546
+ return predicate.Account(func(s *sql.Selector) {
1547
+ step := sqlgraph.NewStep(
1548
+ sqlgraph.From(Table, FieldID),
1549
+ sqlgraph.Edge(sqlgraph.O2M, false, UsageLogsTable, UsageLogsColumn),
1550
+ )
1551
+ sqlgraph.HasNeighbors(s, step)
1552
+ })
1553
+ }
1554
+
1555
+ // HasUsageLogsWith applies the HasEdge predicate on the "usage_logs" edge with a given conditions (other predicates).
1556
+ func HasUsageLogsWith(preds ...predicate.UsageLog) predicate.Account {
1557
+ return predicate.Account(func(s *sql.Selector) {
1558
+ step := newUsageLogsStep()
1559
+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
1560
+ for _, p := range preds {
1561
+ p(s)
1562
+ }
1563
+ })
1564
+ })
1565
+ }
1566
+
1567
+ // HasAccountGroups applies the HasEdge predicate on the "account_groups" edge.
1568
+ func HasAccountGroups() predicate.Account {
1569
+ return predicate.Account(func(s *sql.Selector) {
1570
+ step := sqlgraph.NewStep(
1571
+ sqlgraph.From(Table, FieldID),
1572
+ sqlgraph.Edge(sqlgraph.O2M, true, AccountGroupsTable, AccountGroupsColumn),
1573
+ )
1574
+ sqlgraph.HasNeighbors(s, step)
1575
+ })
1576
+ }
1577
+
1578
+ // HasAccountGroupsWith applies the HasEdge predicate on the "account_groups" edge with a given conditions (other predicates).
1579
+ func HasAccountGroupsWith(preds ...predicate.AccountGroup) predicate.Account {
1580
+ return predicate.Account(func(s *sql.Selector) {
1581
+ step := newAccountGroupsStep()
1582
+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
1583
+ for _, p := range preds {
1584
+ p(s)
1585
+ }
1586
+ })
1587
+ })
1588
+ }
1589
+
1590
+ // And groups predicates with the AND operator between them.
1591
+ func And(predicates ...predicate.Account) predicate.Account {
1592
+ return predicate.Account(sql.AndPredicates(predicates...))
1593
+ }
1594
+
1595
+ // Or groups predicates with the OR operator between them.
1596
+ func Or(predicates ...predicate.Account) predicate.Account {
1597
+ return predicate.Account(sql.OrPredicates(predicates...))
1598
+ }
1599
+
1600
+ // Not applies the not operator on the given predicate.
1601
+ func Not(p predicate.Account) predicate.Account {
1602
+ return predicate.Account(sql.NotPredicates(p))
1603
+ }
backend/ent/account_create.go ADDED
@@ -0,0 +1,2550 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+ "errors"
8
+ "fmt"
9
+ "time"
10
+
11
+ "entgo.io/ent/dialect/sql"
12
+ "entgo.io/ent/dialect/sql/sqlgraph"
13
+ "entgo.io/ent/schema/field"
14
+ "github.com/Wei-Shaw/sub2api/ent/account"
15
+ "github.com/Wei-Shaw/sub2api/ent/group"
16
+ "github.com/Wei-Shaw/sub2api/ent/proxy"
17
+ "github.com/Wei-Shaw/sub2api/ent/usagelog"
18
+ )
19
+
20
+ // AccountCreate is the builder for creating a Account entity.
21
+ type AccountCreate struct {
22
+ config
23
+ mutation *AccountMutation
24
+ hooks []Hook
25
+ conflict []sql.ConflictOption
26
+ }
27
+
28
+ // SetCreatedAt sets the "created_at" field.
29
+ func (_c *AccountCreate) SetCreatedAt(v time.Time) *AccountCreate {
30
+ _c.mutation.SetCreatedAt(v)
31
+ return _c
32
+ }
33
+
34
+ // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
35
+ func (_c *AccountCreate) SetNillableCreatedAt(v *time.Time) *AccountCreate {
36
+ if v != nil {
37
+ _c.SetCreatedAt(*v)
38
+ }
39
+ return _c
40
+ }
41
+
42
+ // SetUpdatedAt sets the "updated_at" field.
43
+ func (_c *AccountCreate) SetUpdatedAt(v time.Time) *AccountCreate {
44
+ _c.mutation.SetUpdatedAt(v)
45
+ return _c
46
+ }
47
+
48
+ // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
49
+ func (_c *AccountCreate) SetNillableUpdatedAt(v *time.Time) *AccountCreate {
50
+ if v != nil {
51
+ _c.SetUpdatedAt(*v)
52
+ }
53
+ return _c
54
+ }
55
+
56
+ // SetDeletedAt sets the "deleted_at" field.
57
+ func (_c *AccountCreate) SetDeletedAt(v time.Time) *AccountCreate {
58
+ _c.mutation.SetDeletedAt(v)
59
+ return _c
60
+ }
61
+
62
+ // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
63
+ func (_c *AccountCreate) SetNillableDeletedAt(v *time.Time) *AccountCreate {
64
+ if v != nil {
65
+ _c.SetDeletedAt(*v)
66
+ }
67
+ return _c
68
+ }
69
+
70
+ // SetName sets the "name" field.
71
+ func (_c *AccountCreate) SetName(v string) *AccountCreate {
72
+ _c.mutation.SetName(v)
73
+ return _c
74
+ }
75
+
76
+ // SetNotes sets the "notes" field.
77
+ func (_c *AccountCreate) SetNotes(v string) *AccountCreate {
78
+ _c.mutation.SetNotes(v)
79
+ return _c
80
+ }
81
+
82
+ // SetNillableNotes sets the "notes" field if the given value is not nil.
83
+ func (_c *AccountCreate) SetNillableNotes(v *string) *AccountCreate {
84
+ if v != nil {
85
+ _c.SetNotes(*v)
86
+ }
87
+ return _c
88
+ }
89
+
90
+ // SetPlatform sets the "platform" field.
91
+ func (_c *AccountCreate) SetPlatform(v string) *AccountCreate {
92
+ _c.mutation.SetPlatform(v)
93
+ return _c
94
+ }
95
+
96
+ // SetType sets the "type" field.
97
+ func (_c *AccountCreate) SetType(v string) *AccountCreate {
98
+ _c.mutation.SetType(v)
99
+ return _c
100
+ }
101
+
102
+ // SetCredentials sets the "credentials" field.
103
+ func (_c *AccountCreate) SetCredentials(v map[string]interface{}) *AccountCreate {
104
+ _c.mutation.SetCredentials(v)
105
+ return _c
106
+ }
107
+
108
+ // SetExtra sets the "extra" field.
109
+ func (_c *AccountCreate) SetExtra(v map[string]interface{}) *AccountCreate {
110
+ _c.mutation.SetExtra(v)
111
+ return _c
112
+ }
113
+
114
+ // SetProxyID sets the "proxy_id" field.
115
+ func (_c *AccountCreate) SetProxyID(v int64) *AccountCreate {
116
+ _c.mutation.SetProxyID(v)
117
+ return _c
118
+ }
119
+
120
+ // SetNillableProxyID sets the "proxy_id" field if the given value is not nil.
121
+ func (_c *AccountCreate) SetNillableProxyID(v *int64) *AccountCreate {
122
+ if v != nil {
123
+ _c.SetProxyID(*v)
124
+ }
125
+ return _c
126
+ }
127
+
128
+ // SetConcurrency sets the "concurrency" field.
129
+ func (_c *AccountCreate) SetConcurrency(v int) *AccountCreate {
130
+ _c.mutation.SetConcurrency(v)
131
+ return _c
132
+ }
133
+
134
+ // SetNillableConcurrency sets the "concurrency" field if the given value is not nil.
135
+ func (_c *AccountCreate) SetNillableConcurrency(v *int) *AccountCreate {
136
+ if v != nil {
137
+ _c.SetConcurrency(*v)
138
+ }
139
+ return _c
140
+ }
141
+
142
+ // SetLoadFactor sets the "load_factor" field.
143
+ func (_c *AccountCreate) SetLoadFactor(v int) *AccountCreate {
144
+ _c.mutation.SetLoadFactor(v)
145
+ return _c
146
+ }
147
+
148
+ // SetNillableLoadFactor sets the "load_factor" field if the given value is not nil.
149
+ func (_c *AccountCreate) SetNillableLoadFactor(v *int) *AccountCreate {
150
+ if v != nil {
151
+ _c.SetLoadFactor(*v)
152
+ }
153
+ return _c
154
+ }
155
+
156
+ // SetPriority sets the "priority" field.
157
+ func (_c *AccountCreate) SetPriority(v int) *AccountCreate {
158
+ _c.mutation.SetPriority(v)
159
+ return _c
160
+ }
161
+
162
+ // SetNillablePriority sets the "priority" field if the given value is not nil.
163
+ func (_c *AccountCreate) SetNillablePriority(v *int) *AccountCreate {
164
+ if v != nil {
165
+ _c.SetPriority(*v)
166
+ }
167
+ return _c
168
+ }
169
+
170
+ // SetRateMultiplier sets the "rate_multiplier" field.
171
+ func (_c *AccountCreate) SetRateMultiplier(v float64) *AccountCreate {
172
+ _c.mutation.SetRateMultiplier(v)
173
+ return _c
174
+ }
175
+
176
+ // SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
177
+ func (_c *AccountCreate) SetNillableRateMultiplier(v *float64) *AccountCreate {
178
+ if v != nil {
179
+ _c.SetRateMultiplier(*v)
180
+ }
181
+ return _c
182
+ }
183
+
184
+ // SetStatus sets the "status" field.
185
+ func (_c *AccountCreate) SetStatus(v string) *AccountCreate {
186
+ _c.mutation.SetStatus(v)
187
+ return _c
188
+ }
189
+
190
+ // SetNillableStatus sets the "status" field if the given value is not nil.
191
+ func (_c *AccountCreate) SetNillableStatus(v *string) *AccountCreate {
192
+ if v != nil {
193
+ _c.SetStatus(*v)
194
+ }
195
+ return _c
196
+ }
197
+
198
+ // SetErrorMessage sets the "error_message" field.
199
+ func (_c *AccountCreate) SetErrorMessage(v string) *AccountCreate {
200
+ _c.mutation.SetErrorMessage(v)
201
+ return _c
202
+ }
203
+
204
+ // SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
205
+ func (_c *AccountCreate) SetNillableErrorMessage(v *string) *AccountCreate {
206
+ if v != nil {
207
+ _c.SetErrorMessage(*v)
208
+ }
209
+ return _c
210
+ }
211
+
212
+ // SetLastUsedAt sets the "last_used_at" field.
213
+ func (_c *AccountCreate) SetLastUsedAt(v time.Time) *AccountCreate {
214
+ _c.mutation.SetLastUsedAt(v)
215
+ return _c
216
+ }
217
+
218
+ // SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
219
+ func (_c *AccountCreate) SetNillableLastUsedAt(v *time.Time) *AccountCreate {
220
+ if v != nil {
221
+ _c.SetLastUsedAt(*v)
222
+ }
223
+ return _c
224
+ }
225
+
226
+ // SetExpiresAt sets the "expires_at" field.
227
+ func (_c *AccountCreate) SetExpiresAt(v time.Time) *AccountCreate {
228
+ _c.mutation.SetExpiresAt(v)
229
+ return _c
230
+ }
231
+
232
+ // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
233
+ func (_c *AccountCreate) SetNillableExpiresAt(v *time.Time) *AccountCreate {
234
+ if v != nil {
235
+ _c.SetExpiresAt(*v)
236
+ }
237
+ return _c
238
+ }
239
+
240
+ // SetAutoPauseOnExpired sets the "auto_pause_on_expired" field.
241
+ func (_c *AccountCreate) SetAutoPauseOnExpired(v bool) *AccountCreate {
242
+ _c.mutation.SetAutoPauseOnExpired(v)
243
+ return _c
244
+ }
245
+
246
+ // SetNillableAutoPauseOnExpired sets the "auto_pause_on_expired" field if the given value is not nil.
247
+ func (_c *AccountCreate) SetNillableAutoPauseOnExpired(v *bool) *AccountCreate {
248
+ if v != nil {
249
+ _c.SetAutoPauseOnExpired(*v)
250
+ }
251
+ return _c
252
+ }
253
+
254
+ // SetSchedulable sets the "schedulable" field.
255
+ func (_c *AccountCreate) SetSchedulable(v bool) *AccountCreate {
256
+ _c.mutation.SetSchedulable(v)
257
+ return _c
258
+ }
259
+
260
+ // SetNillableSchedulable sets the "schedulable" field if the given value is not nil.
261
+ func (_c *AccountCreate) SetNillableSchedulable(v *bool) *AccountCreate {
262
+ if v != nil {
263
+ _c.SetSchedulable(*v)
264
+ }
265
+ return _c
266
+ }
267
+
268
+ // SetRateLimitedAt sets the "rate_limited_at" field.
269
+ func (_c *AccountCreate) SetRateLimitedAt(v time.Time) *AccountCreate {
270
+ _c.mutation.SetRateLimitedAt(v)
271
+ return _c
272
+ }
273
+
274
+ // SetNillableRateLimitedAt sets the "rate_limited_at" field if the given value is not nil.
275
+ func (_c *AccountCreate) SetNillableRateLimitedAt(v *time.Time) *AccountCreate {
276
+ if v != nil {
277
+ _c.SetRateLimitedAt(*v)
278
+ }
279
+ return _c
280
+ }
281
+
282
+ // SetRateLimitResetAt sets the "rate_limit_reset_at" field.
283
+ func (_c *AccountCreate) SetRateLimitResetAt(v time.Time) *AccountCreate {
284
+ _c.mutation.SetRateLimitResetAt(v)
285
+ return _c
286
+ }
287
+
288
+ // SetNillableRateLimitResetAt sets the "rate_limit_reset_at" field if the given value is not nil.
289
+ func (_c *AccountCreate) SetNillableRateLimitResetAt(v *time.Time) *AccountCreate {
290
+ if v != nil {
291
+ _c.SetRateLimitResetAt(*v)
292
+ }
293
+ return _c
294
+ }
295
+
296
+ // SetOverloadUntil sets the "overload_until" field.
297
+ func (_c *AccountCreate) SetOverloadUntil(v time.Time) *AccountCreate {
298
+ _c.mutation.SetOverloadUntil(v)
299
+ return _c
300
+ }
301
+
302
+ // SetNillableOverloadUntil sets the "overload_until" field if the given value is not nil.
303
+ func (_c *AccountCreate) SetNillableOverloadUntil(v *time.Time) *AccountCreate {
304
+ if v != nil {
305
+ _c.SetOverloadUntil(*v)
306
+ }
307
+ return _c
308
+ }
309
+
310
+ // SetTempUnschedulableUntil sets the "temp_unschedulable_until" field.
311
+ func (_c *AccountCreate) SetTempUnschedulableUntil(v time.Time) *AccountCreate {
312
+ _c.mutation.SetTempUnschedulableUntil(v)
313
+ return _c
314
+ }
315
+
316
+ // SetNillableTempUnschedulableUntil sets the "temp_unschedulable_until" field if the given value is not nil.
317
+ func (_c *AccountCreate) SetNillableTempUnschedulableUntil(v *time.Time) *AccountCreate {
318
+ if v != nil {
319
+ _c.SetTempUnschedulableUntil(*v)
320
+ }
321
+ return _c
322
+ }
323
+
324
+ // SetTempUnschedulableReason sets the "temp_unschedulable_reason" field.
325
+ func (_c *AccountCreate) SetTempUnschedulableReason(v string) *AccountCreate {
326
+ _c.mutation.SetTempUnschedulableReason(v)
327
+ return _c
328
+ }
329
+
330
+ // SetNillableTempUnschedulableReason sets the "temp_unschedulable_reason" field if the given value is not nil.
331
+ func (_c *AccountCreate) SetNillableTempUnschedulableReason(v *string) *AccountCreate {
332
+ if v != nil {
333
+ _c.SetTempUnschedulableReason(*v)
334
+ }
335
+ return _c
336
+ }
337
+
338
+ // SetSessionWindowStart sets the "session_window_start" field.
339
+ func (_c *AccountCreate) SetSessionWindowStart(v time.Time) *AccountCreate {
340
+ _c.mutation.SetSessionWindowStart(v)
341
+ return _c
342
+ }
343
+
344
+ // SetNillableSessionWindowStart sets the "session_window_start" field if the given value is not nil.
345
+ func (_c *AccountCreate) SetNillableSessionWindowStart(v *time.Time) *AccountCreate {
346
+ if v != nil {
347
+ _c.SetSessionWindowStart(*v)
348
+ }
349
+ return _c
350
+ }
351
+
352
+ // SetSessionWindowEnd sets the "session_window_end" field.
353
+ func (_c *AccountCreate) SetSessionWindowEnd(v time.Time) *AccountCreate {
354
+ _c.mutation.SetSessionWindowEnd(v)
355
+ return _c
356
+ }
357
+
358
+ // SetNillableSessionWindowEnd sets the "session_window_end" field if the given value is not nil.
359
+ func (_c *AccountCreate) SetNillableSessionWindowEnd(v *time.Time) *AccountCreate {
360
+ if v != nil {
361
+ _c.SetSessionWindowEnd(*v)
362
+ }
363
+ return _c
364
+ }
365
+
366
+ // SetSessionWindowStatus sets the "session_window_status" field.
367
+ func (_c *AccountCreate) SetSessionWindowStatus(v string) *AccountCreate {
368
+ _c.mutation.SetSessionWindowStatus(v)
369
+ return _c
370
+ }
371
+
372
+ // SetNillableSessionWindowStatus sets the "session_window_status" field if the given value is not nil.
373
+ func (_c *AccountCreate) SetNillableSessionWindowStatus(v *string) *AccountCreate {
374
+ if v != nil {
375
+ _c.SetSessionWindowStatus(*v)
376
+ }
377
+ return _c
378
+ }
379
+
380
+ // AddGroupIDs adds the "groups" edge to the Group entity by IDs.
381
+ func (_c *AccountCreate) AddGroupIDs(ids ...int64) *AccountCreate {
382
+ _c.mutation.AddGroupIDs(ids...)
383
+ return _c
384
+ }
385
+
386
+ // AddGroups adds the "groups" edges to the Group entity.
387
+ func (_c *AccountCreate) AddGroups(v ...*Group) *AccountCreate {
388
+ ids := make([]int64, len(v))
389
+ for i := range v {
390
+ ids[i] = v[i].ID
391
+ }
392
+ return _c.AddGroupIDs(ids...)
393
+ }
394
+
395
+ // SetProxy sets the "proxy" edge to the Proxy entity.
396
+ func (_c *AccountCreate) SetProxy(v *Proxy) *AccountCreate {
397
+ return _c.SetProxyID(v.ID)
398
+ }
399
+
400
+ // AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
401
+ func (_c *AccountCreate) AddUsageLogIDs(ids ...int64) *AccountCreate {
402
+ _c.mutation.AddUsageLogIDs(ids...)
403
+ return _c
404
+ }
405
+
406
+ // AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
407
+ func (_c *AccountCreate) AddUsageLogs(v ...*UsageLog) *AccountCreate {
408
+ ids := make([]int64, len(v))
409
+ for i := range v {
410
+ ids[i] = v[i].ID
411
+ }
412
+ return _c.AddUsageLogIDs(ids...)
413
+ }
414
+
415
+ // Mutation returns the AccountMutation object of the builder.
416
+ func (_c *AccountCreate) Mutation() *AccountMutation {
417
+ return _c.mutation
418
+ }
419
+
420
+ // Save creates the Account in the database.
421
+ func (_c *AccountCreate) Save(ctx context.Context) (*Account, error) {
422
+ if err := _c.defaults(); err != nil {
423
+ return nil, err
424
+ }
425
+ return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
426
+ }
427
+
428
+ // SaveX calls Save and panics if Save returns an error.
429
+ func (_c *AccountCreate) SaveX(ctx context.Context) *Account {
430
+ v, err := _c.Save(ctx)
431
+ if err != nil {
432
+ panic(err)
433
+ }
434
+ return v
435
+ }
436
+
437
+ // Exec executes the query.
438
+ func (_c *AccountCreate) Exec(ctx context.Context) error {
439
+ _, err := _c.Save(ctx)
440
+ return err
441
+ }
442
+
443
+ // ExecX is like Exec, but panics if an error occurs.
444
+ func (_c *AccountCreate) ExecX(ctx context.Context) {
445
+ if err := _c.Exec(ctx); err != nil {
446
+ panic(err)
447
+ }
448
+ }
449
+
450
+ // defaults sets the default values of the builder before save.
451
+ func (_c *AccountCreate) defaults() error {
452
+ if _, ok := _c.mutation.CreatedAt(); !ok {
453
+ if account.DefaultCreatedAt == nil {
454
+ return fmt.Errorf("ent: uninitialized account.DefaultCreatedAt (forgotten import ent/runtime?)")
455
+ }
456
+ v := account.DefaultCreatedAt()
457
+ _c.mutation.SetCreatedAt(v)
458
+ }
459
+ if _, ok := _c.mutation.UpdatedAt(); !ok {
460
+ if account.DefaultUpdatedAt == nil {
461
+ return fmt.Errorf("ent: uninitialized account.DefaultUpdatedAt (forgotten import ent/runtime?)")
462
+ }
463
+ v := account.DefaultUpdatedAt()
464
+ _c.mutation.SetUpdatedAt(v)
465
+ }
466
+ if _, ok := _c.mutation.Credentials(); !ok {
467
+ if account.DefaultCredentials == nil {
468
+ return fmt.Errorf("ent: uninitialized account.DefaultCredentials (forgotten import ent/runtime?)")
469
+ }
470
+ v := account.DefaultCredentials()
471
+ _c.mutation.SetCredentials(v)
472
+ }
473
+ if _, ok := _c.mutation.Extra(); !ok {
474
+ if account.DefaultExtra == nil {
475
+ return fmt.Errorf("ent: uninitialized account.DefaultExtra (forgotten import ent/runtime?)")
476
+ }
477
+ v := account.DefaultExtra()
478
+ _c.mutation.SetExtra(v)
479
+ }
480
+ if _, ok := _c.mutation.Concurrency(); !ok {
481
+ v := account.DefaultConcurrency
482
+ _c.mutation.SetConcurrency(v)
483
+ }
484
+ if _, ok := _c.mutation.Priority(); !ok {
485
+ v := account.DefaultPriority
486
+ _c.mutation.SetPriority(v)
487
+ }
488
+ if _, ok := _c.mutation.RateMultiplier(); !ok {
489
+ v := account.DefaultRateMultiplier
490
+ _c.mutation.SetRateMultiplier(v)
491
+ }
492
+ if _, ok := _c.mutation.Status(); !ok {
493
+ v := account.DefaultStatus
494
+ _c.mutation.SetStatus(v)
495
+ }
496
+ if _, ok := _c.mutation.AutoPauseOnExpired(); !ok {
497
+ v := account.DefaultAutoPauseOnExpired
498
+ _c.mutation.SetAutoPauseOnExpired(v)
499
+ }
500
+ if _, ok := _c.mutation.Schedulable(); !ok {
501
+ v := account.DefaultSchedulable
502
+ _c.mutation.SetSchedulable(v)
503
+ }
504
+ return nil
505
+ }
506
+
507
+ // check runs all checks and user-defined validators on the builder.
508
+ func (_c *AccountCreate) check() error {
509
+ if _, ok := _c.mutation.CreatedAt(); !ok {
510
+ return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Account.created_at"`)}
511
+ }
512
+ if _, ok := _c.mutation.UpdatedAt(); !ok {
513
+ return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Account.updated_at"`)}
514
+ }
515
+ if _, ok := _c.mutation.Name(); !ok {
516
+ return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Account.name"`)}
517
+ }
518
+ if v, ok := _c.mutation.Name(); ok {
519
+ if err := account.NameValidator(v); err != nil {
520
+ return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Account.name": %w`, err)}
521
+ }
522
+ }
523
+ if _, ok := _c.mutation.Platform(); !ok {
524
+ return &ValidationError{Name: "platform", err: errors.New(`ent: missing required field "Account.platform"`)}
525
+ }
526
+ if v, ok := _c.mutation.Platform(); ok {
527
+ if err := account.PlatformValidator(v); err != nil {
528
+ return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Account.platform": %w`, err)}
529
+ }
530
+ }
531
+ if _, ok := _c.mutation.GetType(); !ok {
532
+ return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Account.type"`)}
533
+ }
534
+ if v, ok := _c.mutation.GetType(); ok {
535
+ if err := account.TypeValidator(v); err != nil {
536
+ return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Account.type": %w`, err)}
537
+ }
538
+ }
539
+ if _, ok := _c.mutation.Credentials(); !ok {
540
+ return &ValidationError{Name: "credentials", err: errors.New(`ent: missing required field "Account.credentials"`)}
541
+ }
542
+ if _, ok := _c.mutation.Extra(); !ok {
543
+ return &ValidationError{Name: "extra", err: errors.New(`ent: missing required field "Account.extra"`)}
544
+ }
545
+ if _, ok := _c.mutation.Concurrency(); !ok {
546
+ return &ValidationError{Name: "concurrency", err: errors.New(`ent: missing required field "Account.concurrency"`)}
547
+ }
548
+ if _, ok := _c.mutation.Priority(); !ok {
549
+ return &ValidationError{Name: "priority", err: errors.New(`ent: missing required field "Account.priority"`)}
550
+ }
551
+ if _, ok := _c.mutation.RateMultiplier(); !ok {
552
+ return &ValidationError{Name: "rate_multiplier", err: errors.New(`ent: missing required field "Account.rate_multiplier"`)}
553
+ }
554
+ if _, ok := _c.mutation.Status(); !ok {
555
+ return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Account.status"`)}
556
+ }
557
+ if v, ok := _c.mutation.Status(); ok {
558
+ if err := account.StatusValidator(v); err != nil {
559
+ return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Account.status": %w`, err)}
560
+ }
561
+ }
562
+ if _, ok := _c.mutation.AutoPauseOnExpired(); !ok {
563
+ return &ValidationError{Name: "auto_pause_on_expired", err: errors.New(`ent: missing required field "Account.auto_pause_on_expired"`)}
564
+ }
565
+ if _, ok := _c.mutation.Schedulable(); !ok {
566
+ return &ValidationError{Name: "schedulable", err: errors.New(`ent: missing required field "Account.schedulable"`)}
567
+ }
568
+ if v, ok := _c.mutation.SessionWindowStatus(); ok {
569
+ if err := account.SessionWindowStatusValidator(v); err != nil {
570
+ return &ValidationError{Name: "session_window_status", err: fmt.Errorf(`ent: validator failed for field "Account.session_window_status": %w`, err)}
571
+ }
572
+ }
573
+ return nil
574
+ }
575
+
576
+ func (_c *AccountCreate) sqlSave(ctx context.Context) (*Account, error) {
577
+ if err := _c.check(); err != nil {
578
+ return nil, err
579
+ }
580
+ _node, _spec := _c.createSpec()
581
+ if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
582
+ if sqlgraph.IsConstraintError(err) {
583
+ err = &ConstraintError{msg: err.Error(), wrap: err}
584
+ }
585
+ return nil, err
586
+ }
587
+ id := _spec.ID.Value.(int64)
588
+ _node.ID = int64(id)
589
+ _c.mutation.id = &_node.ID
590
+ _c.mutation.done = true
591
+ return _node, nil
592
+ }
593
+
594
+ func (_c *AccountCreate) createSpec() (*Account, *sqlgraph.CreateSpec) {
595
+ var (
596
+ _node = &Account{config: _c.config}
597
+ _spec = sqlgraph.NewCreateSpec(account.Table, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64))
598
+ )
599
+ _spec.OnConflict = _c.conflict
600
+ if value, ok := _c.mutation.CreatedAt(); ok {
601
+ _spec.SetField(account.FieldCreatedAt, field.TypeTime, value)
602
+ _node.CreatedAt = value
603
+ }
604
+ if value, ok := _c.mutation.UpdatedAt(); ok {
605
+ _spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
606
+ _node.UpdatedAt = value
607
+ }
608
+ if value, ok := _c.mutation.DeletedAt(); ok {
609
+ _spec.SetField(account.FieldDeletedAt, field.TypeTime, value)
610
+ _node.DeletedAt = &value
611
+ }
612
+ if value, ok := _c.mutation.Name(); ok {
613
+ _spec.SetField(account.FieldName, field.TypeString, value)
614
+ _node.Name = value
615
+ }
616
+ if value, ok := _c.mutation.Notes(); ok {
617
+ _spec.SetField(account.FieldNotes, field.TypeString, value)
618
+ _node.Notes = &value
619
+ }
620
+ if value, ok := _c.mutation.Platform(); ok {
621
+ _spec.SetField(account.FieldPlatform, field.TypeString, value)
622
+ _node.Platform = value
623
+ }
624
+ if value, ok := _c.mutation.GetType(); ok {
625
+ _spec.SetField(account.FieldType, field.TypeString, value)
626
+ _node.Type = value
627
+ }
628
+ if value, ok := _c.mutation.Credentials(); ok {
629
+ _spec.SetField(account.FieldCredentials, field.TypeJSON, value)
630
+ _node.Credentials = value
631
+ }
632
+ if value, ok := _c.mutation.Extra(); ok {
633
+ _spec.SetField(account.FieldExtra, field.TypeJSON, value)
634
+ _node.Extra = value
635
+ }
636
+ if value, ok := _c.mutation.Concurrency(); ok {
637
+ _spec.SetField(account.FieldConcurrency, field.TypeInt, value)
638
+ _node.Concurrency = value
639
+ }
640
+ if value, ok := _c.mutation.LoadFactor(); ok {
641
+ _spec.SetField(account.FieldLoadFactor, field.TypeInt, value)
642
+ _node.LoadFactor = &value
643
+ }
644
+ if value, ok := _c.mutation.Priority(); ok {
645
+ _spec.SetField(account.FieldPriority, field.TypeInt, value)
646
+ _node.Priority = value
647
+ }
648
+ if value, ok := _c.mutation.RateMultiplier(); ok {
649
+ _spec.SetField(account.FieldRateMultiplier, field.TypeFloat64, value)
650
+ _node.RateMultiplier = value
651
+ }
652
+ if value, ok := _c.mutation.Status(); ok {
653
+ _spec.SetField(account.FieldStatus, field.TypeString, value)
654
+ _node.Status = value
655
+ }
656
+ if value, ok := _c.mutation.ErrorMessage(); ok {
657
+ _spec.SetField(account.FieldErrorMessage, field.TypeString, value)
658
+ _node.ErrorMessage = &value
659
+ }
660
+ if value, ok := _c.mutation.LastUsedAt(); ok {
661
+ _spec.SetField(account.FieldLastUsedAt, field.TypeTime, value)
662
+ _node.LastUsedAt = &value
663
+ }
664
+ if value, ok := _c.mutation.ExpiresAt(); ok {
665
+ _spec.SetField(account.FieldExpiresAt, field.TypeTime, value)
666
+ _node.ExpiresAt = &value
667
+ }
668
+ if value, ok := _c.mutation.AutoPauseOnExpired(); ok {
669
+ _spec.SetField(account.FieldAutoPauseOnExpired, field.TypeBool, value)
670
+ _node.AutoPauseOnExpired = value
671
+ }
672
+ if value, ok := _c.mutation.Schedulable(); ok {
673
+ _spec.SetField(account.FieldSchedulable, field.TypeBool, value)
674
+ _node.Schedulable = value
675
+ }
676
+ if value, ok := _c.mutation.RateLimitedAt(); ok {
677
+ _spec.SetField(account.FieldRateLimitedAt, field.TypeTime, value)
678
+ _node.RateLimitedAt = &value
679
+ }
680
+ if value, ok := _c.mutation.RateLimitResetAt(); ok {
681
+ _spec.SetField(account.FieldRateLimitResetAt, field.TypeTime, value)
682
+ _node.RateLimitResetAt = &value
683
+ }
684
+ if value, ok := _c.mutation.OverloadUntil(); ok {
685
+ _spec.SetField(account.FieldOverloadUntil, field.TypeTime, value)
686
+ _node.OverloadUntil = &value
687
+ }
688
+ if value, ok := _c.mutation.TempUnschedulableUntil(); ok {
689
+ _spec.SetField(account.FieldTempUnschedulableUntil, field.TypeTime, value)
690
+ _node.TempUnschedulableUntil = &value
691
+ }
692
+ if value, ok := _c.mutation.TempUnschedulableReason(); ok {
693
+ _spec.SetField(account.FieldTempUnschedulableReason, field.TypeString, value)
694
+ _node.TempUnschedulableReason = &value
695
+ }
696
+ if value, ok := _c.mutation.SessionWindowStart(); ok {
697
+ _spec.SetField(account.FieldSessionWindowStart, field.TypeTime, value)
698
+ _node.SessionWindowStart = &value
699
+ }
700
+ if value, ok := _c.mutation.SessionWindowEnd(); ok {
701
+ _spec.SetField(account.FieldSessionWindowEnd, field.TypeTime, value)
702
+ _node.SessionWindowEnd = &value
703
+ }
704
+ if value, ok := _c.mutation.SessionWindowStatus(); ok {
705
+ _spec.SetField(account.FieldSessionWindowStatus, field.TypeString, value)
706
+ _node.SessionWindowStatus = &value
707
+ }
708
+ if nodes := _c.mutation.GroupsIDs(); len(nodes) > 0 {
709
+ edge := &sqlgraph.EdgeSpec{
710
+ Rel: sqlgraph.M2M,
711
+ Inverse: false,
712
+ Table: account.GroupsTable,
713
+ Columns: account.GroupsPrimaryKey,
714
+ Bidi: false,
715
+ Target: &sqlgraph.EdgeTarget{
716
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
717
+ },
718
+ }
719
+ for _, k := range nodes {
720
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
721
+ }
722
+ createE := &AccountGroupCreate{config: _c.config, mutation: newAccountGroupMutation(_c.config, OpCreate)}
723
+ createE.defaults()
724
+ _, specE := createE.createSpec()
725
+ edge.Target.Fields = specE.Fields
726
+ _spec.Edges = append(_spec.Edges, edge)
727
+ }
728
+ if nodes := _c.mutation.ProxyIDs(); len(nodes) > 0 {
729
+ edge := &sqlgraph.EdgeSpec{
730
+ Rel: sqlgraph.M2O,
731
+ Inverse: false,
732
+ Table: account.ProxyTable,
733
+ Columns: []string{account.ProxyColumn},
734
+ Bidi: false,
735
+ Target: &sqlgraph.EdgeTarget{
736
+ IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
737
+ },
738
+ }
739
+ for _, k := range nodes {
740
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
741
+ }
742
+ _node.ProxyID = &nodes[0]
743
+ _spec.Edges = append(_spec.Edges, edge)
744
+ }
745
+ if nodes := _c.mutation.UsageLogsIDs(); len(nodes) > 0 {
746
+ edge := &sqlgraph.EdgeSpec{
747
+ Rel: sqlgraph.O2M,
748
+ Inverse: false,
749
+ Table: account.UsageLogsTable,
750
+ Columns: []string{account.UsageLogsColumn},
751
+ Bidi: false,
752
+ Target: &sqlgraph.EdgeTarget{
753
+ IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
754
+ },
755
+ }
756
+ for _, k := range nodes {
757
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
758
+ }
759
+ _spec.Edges = append(_spec.Edges, edge)
760
+ }
761
+ return _node, _spec
762
+ }
763
+
764
+ // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
765
+ // of the `INSERT` statement. For example:
766
+ //
767
+ // client.Account.Create().
768
+ // SetCreatedAt(v).
769
+ // OnConflict(
770
+ // // Update the row with the new values
771
+ // // the was proposed for insertion.
772
+ // sql.ResolveWithNewValues(),
773
+ // ).
774
+ // // Override some of the fields with custom
775
+ // // update values.
776
+ // Update(func(u *ent.AccountUpsert) {
777
+ // SetCreatedAt(v+v).
778
+ // }).
779
+ // Exec(ctx)
780
+ func (_c *AccountCreate) OnConflict(opts ...sql.ConflictOption) *AccountUpsertOne {
781
+ _c.conflict = opts
782
+ return &AccountUpsertOne{
783
+ create: _c,
784
+ }
785
+ }
786
+
787
+ // OnConflictColumns calls `OnConflict` and configures the columns
788
+ // as conflict target. Using this option is equivalent to using:
789
+ //
790
+ // client.Account.Create().
791
+ // OnConflict(sql.ConflictColumns(columns...)).
792
+ // Exec(ctx)
793
+ func (_c *AccountCreate) OnConflictColumns(columns ...string) *AccountUpsertOne {
794
+ _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
795
+ return &AccountUpsertOne{
796
+ create: _c,
797
+ }
798
+ }
799
+
800
+ type (
801
+ // AccountUpsertOne is the builder for "upsert"-ing
802
+ // one Account node.
803
+ AccountUpsertOne struct {
804
+ create *AccountCreate
805
+ }
806
+
807
+ // AccountUpsert is the "OnConflict" setter.
808
+ AccountUpsert struct {
809
+ *sql.UpdateSet
810
+ }
811
+ )
812
+
813
+ // SetUpdatedAt sets the "updated_at" field.
814
+ func (u *AccountUpsert) SetUpdatedAt(v time.Time) *AccountUpsert {
815
+ u.Set(account.FieldUpdatedAt, v)
816
+ return u
817
+ }
818
+
819
+ // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
820
+ func (u *AccountUpsert) UpdateUpdatedAt() *AccountUpsert {
821
+ u.SetExcluded(account.FieldUpdatedAt)
822
+ return u
823
+ }
824
+
825
+ // SetDeletedAt sets the "deleted_at" field.
826
+ func (u *AccountUpsert) SetDeletedAt(v time.Time) *AccountUpsert {
827
+ u.Set(account.FieldDeletedAt, v)
828
+ return u
829
+ }
830
+
831
+ // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
832
+ func (u *AccountUpsert) UpdateDeletedAt() *AccountUpsert {
833
+ u.SetExcluded(account.FieldDeletedAt)
834
+ return u
835
+ }
836
+
837
+ // ClearDeletedAt clears the value of the "deleted_at" field.
838
+ func (u *AccountUpsert) ClearDeletedAt() *AccountUpsert {
839
+ u.SetNull(account.FieldDeletedAt)
840
+ return u
841
+ }
842
+
843
+ // SetName sets the "name" field.
844
+ func (u *AccountUpsert) SetName(v string) *AccountUpsert {
845
+ u.Set(account.FieldName, v)
846
+ return u
847
+ }
848
+
849
+ // UpdateName sets the "name" field to the value that was provided on create.
850
+ func (u *AccountUpsert) UpdateName() *AccountUpsert {
851
+ u.SetExcluded(account.FieldName)
852
+ return u
853
+ }
854
+
855
+ // SetNotes sets the "notes" field.
856
+ func (u *AccountUpsert) SetNotes(v string) *AccountUpsert {
857
+ u.Set(account.FieldNotes, v)
858
+ return u
859
+ }
860
+
861
+ // UpdateNotes sets the "notes" field to the value that was provided on create.
862
+ func (u *AccountUpsert) UpdateNotes() *AccountUpsert {
863
+ u.SetExcluded(account.FieldNotes)
864
+ return u
865
+ }
866
+
867
+ // ClearNotes clears the value of the "notes" field.
868
+ func (u *AccountUpsert) ClearNotes() *AccountUpsert {
869
+ u.SetNull(account.FieldNotes)
870
+ return u
871
+ }
872
+
873
+ // SetPlatform sets the "platform" field.
874
+ func (u *AccountUpsert) SetPlatform(v string) *AccountUpsert {
875
+ u.Set(account.FieldPlatform, v)
876
+ return u
877
+ }
878
+
879
+ // UpdatePlatform sets the "platform" field to the value that was provided on create.
880
+ func (u *AccountUpsert) UpdatePlatform() *AccountUpsert {
881
+ u.SetExcluded(account.FieldPlatform)
882
+ return u
883
+ }
884
+
885
+ // SetType sets the "type" field.
886
+ func (u *AccountUpsert) SetType(v string) *AccountUpsert {
887
+ u.Set(account.FieldType, v)
888
+ return u
889
+ }
890
+
891
+ // UpdateType sets the "type" field to the value that was provided on create.
892
+ func (u *AccountUpsert) UpdateType() *AccountUpsert {
893
+ u.SetExcluded(account.FieldType)
894
+ return u
895
+ }
896
+
897
+ // SetCredentials sets the "credentials" field.
898
+ func (u *AccountUpsert) SetCredentials(v map[string]interface{}) *AccountUpsert {
899
+ u.Set(account.FieldCredentials, v)
900
+ return u
901
+ }
902
+
903
+ // UpdateCredentials sets the "credentials" field to the value that was provided on create.
904
+ func (u *AccountUpsert) UpdateCredentials() *AccountUpsert {
905
+ u.SetExcluded(account.FieldCredentials)
906
+ return u
907
+ }
908
+
909
+ // SetExtra sets the "extra" field.
910
+ func (u *AccountUpsert) SetExtra(v map[string]interface{}) *AccountUpsert {
911
+ u.Set(account.FieldExtra, v)
912
+ return u
913
+ }
914
+
915
+ // UpdateExtra sets the "extra" field to the value that was provided on create.
916
+ func (u *AccountUpsert) UpdateExtra() *AccountUpsert {
917
+ u.SetExcluded(account.FieldExtra)
918
+ return u
919
+ }
920
+
921
+ // SetProxyID sets the "proxy_id" field.
922
+ func (u *AccountUpsert) SetProxyID(v int64) *AccountUpsert {
923
+ u.Set(account.FieldProxyID, v)
924
+ return u
925
+ }
926
+
927
+ // UpdateProxyID sets the "proxy_id" field to the value that was provided on create.
928
+ func (u *AccountUpsert) UpdateProxyID() *AccountUpsert {
929
+ u.SetExcluded(account.FieldProxyID)
930
+ return u
931
+ }
932
+
933
+ // ClearProxyID clears the value of the "proxy_id" field.
934
+ func (u *AccountUpsert) ClearProxyID() *AccountUpsert {
935
+ u.SetNull(account.FieldProxyID)
936
+ return u
937
+ }
938
+
939
+ // SetConcurrency sets the "concurrency" field.
940
+ func (u *AccountUpsert) SetConcurrency(v int) *AccountUpsert {
941
+ u.Set(account.FieldConcurrency, v)
942
+ return u
943
+ }
944
+
945
+ // UpdateConcurrency sets the "concurrency" field to the value that was provided on create.
946
+ func (u *AccountUpsert) UpdateConcurrency() *AccountUpsert {
947
+ u.SetExcluded(account.FieldConcurrency)
948
+ return u
949
+ }
950
+
951
+ // AddConcurrency adds v to the "concurrency" field.
952
+ func (u *AccountUpsert) AddConcurrency(v int) *AccountUpsert {
953
+ u.Add(account.FieldConcurrency, v)
954
+ return u
955
+ }
956
+
957
+ // SetLoadFactor sets the "load_factor" field.
958
+ func (u *AccountUpsert) SetLoadFactor(v int) *AccountUpsert {
959
+ u.Set(account.FieldLoadFactor, v)
960
+ return u
961
+ }
962
+
963
+ // UpdateLoadFactor sets the "load_factor" field to the value that was provided on create.
964
+ func (u *AccountUpsert) UpdateLoadFactor() *AccountUpsert {
965
+ u.SetExcluded(account.FieldLoadFactor)
966
+ return u
967
+ }
968
+
969
+ // AddLoadFactor adds v to the "load_factor" field.
970
+ func (u *AccountUpsert) AddLoadFactor(v int) *AccountUpsert {
971
+ u.Add(account.FieldLoadFactor, v)
972
+ return u
973
+ }
974
+
975
+ // ClearLoadFactor clears the value of the "load_factor" field.
976
+ func (u *AccountUpsert) ClearLoadFactor() *AccountUpsert {
977
+ u.SetNull(account.FieldLoadFactor)
978
+ return u
979
+ }
980
+
981
+ // SetPriority sets the "priority" field.
982
+ func (u *AccountUpsert) SetPriority(v int) *AccountUpsert {
983
+ u.Set(account.FieldPriority, v)
984
+ return u
985
+ }
986
+
987
+ // UpdatePriority sets the "priority" field to the value that was provided on create.
988
+ func (u *AccountUpsert) UpdatePriority() *AccountUpsert {
989
+ u.SetExcluded(account.FieldPriority)
990
+ return u
991
+ }
992
+
993
+ // AddPriority adds v to the "priority" field.
994
+ func (u *AccountUpsert) AddPriority(v int) *AccountUpsert {
995
+ u.Add(account.FieldPriority, v)
996
+ return u
997
+ }
998
+
999
+ // SetRateMultiplier sets the "rate_multiplier" field.
1000
+ func (u *AccountUpsert) SetRateMultiplier(v float64) *AccountUpsert {
1001
+ u.Set(account.FieldRateMultiplier, v)
1002
+ return u
1003
+ }
1004
+
1005
+ // UpdateRateMultiplier sets the "rate_multiplier" field to the value that was provided on create.
1006
+ func (u *AccountUpsert) UpdateRateMultiplier() *AccountUpsert {
1007
+ u.SetExcluded(account.FieldRateMultiplier)
1008
+ return u
1009
+ }
1010
+
1011
+ // AddRateMultiplier adds v to the "rate_multiplier" field.
1012
+ func (u *AccountUpsert) AddRateMultiplier(v float64) *AccountUpsert {
1013
+ u.Add(account.FieldRateMultiplier, v)
1014
+ return u
1015
+ }
1016
+
1017
+ // SetStatus sets the "status" field.
1018
+ func (u *AccountUpsert) SetStatus(v string) *AccountUpsert {
1019
+ u.Set(account.FieldStatus, v)
1020
+ return u
1021
+ }
1022
+
1023
+ // UpdateStatus sets the "status" field to the value that was provided on create.
1024
+ func (u *AccountUpsert) UpdateStatus() *AccountUpsert {
1025
+ u.SetExcluded(account.FieldStatus)
1026
+ return u
1027
+ }
1028
+
1029
+ // SetErrorMessage sets the "error_message" field.
1030
+ func (u *AccountUpsert) SetErrorMessage(v string) *AccountUpsert {
1031
+ u.Set(account.FieldErrorMessage, v)
1032
+ return u
1033
+ }
1034
+
1035
+ // UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
1036
+ func (u *AccountUpsert) UpdateErrorMessage() *AccountUpsert {
1037
+ u.SetExcluded(account.FieldErrorMessage)
1038
+ return u
1039
+ }
1040
+
1041
+ // ClearErrorMessage clears the value of the "error_message" field.
1042
+ func (u *AccountUpsert) ClearErrorMessage() *AccountUpsert {
1043
+ u.SetNull(account.FieldErrorMessage)
1044
+ return u
1045
+ }
1046
+
1047
+ // SetLastUsedAt sets the "last_used_at" field.
1048
+ func (u *AccountUpsert) SetLastUsedAt(v time.Time) *AccountUpsert {
1049
+ u.Set(account.FieldLastUsedAt, v)
1050
+ return u
1051
+ }
1052
+
1053
+ // UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
1054
+ func (u *AccountUpsert) UpdateLastUsedAt() *AccountUpsert {
1055
+ u.SetExcluded(account.FieldLastUsedAt)
1056
+ return u
1057
+ }
1058
+
1059
+ // ClearLastUsedAt clears the value of the "last_used_at" field.
1060
+ func (u *AccountUpsert) ClearLastUsedAt() *AccountUpsert {
1061
+ u.SetNull(account.FieldLastUsedAt)
1062
+ return u
1063
+ }
1064
+
1065
+ // SetExpiresAt sets the "expires_at" field.
1066
+ func (u *AccountUpsert) SetExpiresAt(v time.Time) *AccountUpsert {
1067
+ u.Set(account.FieldExpiresAt, v)
1068
+ return u
1069
+ }
1070
+
1071
+ // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
1072
+ func (u *AccountUpsert) UpdateExpiresAt() *AccountUpsert {
1073
+ u.SetExcluded(account.FieldExpiresAt)
1074
+ return u
1075
+ }
1076
+
1077
+ // ClearExpiresAt clears the value of the "expires_at" field.
1078
+ func (u *AccountUpsert) ClearExpiresAt() *AccountUpsert {
1079
+ u.SetNull(account.FieldExpiresAt)
1080
+ return u
1081
+ }
1082
+
1083
+ // SetAutoPauseOnExpired sets the "auto_pause_on_expired" field.
1084
+ func (u *AccountUpsert) SetAutoPauseOnExpired(v bool) *AccountUpsert {
1085
+ u.Set(account.FieldAutoPauseOnExpired, v)
1086
+ return u
1087
+ }
1088
+
1089
+ // UpdateAutoPauseOnExpired sets the "auto_pause_on_expired" field to the value that was provided on create.
1090
+ func (u *AccountUpsert) UpdateAutoPauseOnExpired() *AccountUpsert {
1091
+ u.SetExcluded(account.FieldAutoPauseOnExpired)
1092
+ return u
1093
+ }
1094
+
1095
+ // SetSchedulable sets the "schedulable" field.
1096
+ func (u *AccountUpsert) SetSchedulable(v bool) *AccountUpsert {
1097
+ u.Set(account.FieldSchedulable, v)
1098
+ return u
1099
+ }
1100
+
1101
+ // UpdateSchedulable sets the "schedulable" field to the value that was provided on create.
1102
+ func (u *AccountUpsert) UpdateSchedulable() *AccountUpsert {
1103
+ u.SetExcluded(account.FieldSchedulable)
1104
+ return u
1105
+ }
1106
+
1107
+ // SetRateLimitedAt sets the "rate_limited_at" field.
1108
+ func (u *AccountUpsert) SetRateLimitedAt(v time.Time) *AccountUpsert {
1109
+ u.Set(account.FieldRateLimitedAt, v)
1110
+ return u
1111
+ }
1112
+
1113
+ // UpdateRateLimitedAt sets the "rate_limited_at" field to the value that was provided on create.
1114
+ func (u *AccountUpsert) UpdateRateLimitedAt() *AccountUpsert {
1115
+ u.SetExcluded(account.FieldRateLimitedAt)
1116
+ return u
1117
+ }
1118
+
1119
+ // ClearRateLimitedAt clears the value of the "rate_limited_at" field.
1120
+ func (u *AccountUpsert) ClearRateLimitedAt() *AccountUpsert {
1121
+ u.SetNull(account.FieldRateLimitedAt)
1122
+ return u
1123
+ }
1124
+
1125
+ // SetRateLimitResetAt sets the "rate_limit_reset_at" field.
1126
+ func (u *AccountUpsert) SetRateLimitResetAt(v time.Time) *AccountUpsert {
1127
+ u.Set(account.FieldRateLimitResetAt, v)
1128
+ return u
1129
+ }
1130
+
1131
+ // UpdateRateLimitResetAt sets the "rate_limit_reset_at" field to the value that was provided on create.
1132
+ func (u *AccountUpsert) UpdateRateLimitResetAt() *AccountUpsert {
1133
+ u.SetExcluded(account.FieldRateLimitResetAt)
1134
+ return u
1135
+ }
1136
+
1137
+ // ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
1138
+ func (u *AccountUpsert) ClearRateLimitResetAt() *AccountUpsert {
1139
+ u.SetNull(account.FieldRateLimitResetAt)
1140
+ return u
1141
+ }
1142
+
1143
+ // SetOverloadUntil sets the "overload_until" field.
1144
+ func (u *AccountUpsert) SetOverloadUntil(v time.Time) *AccountUpsert {
1145
+ u.Set(account.FieldOverloadUntil, v)
1146
+ return u
1147
+ }
1148
+
1149
+ // UpdateOverloadUntil sets the "overload_until" field to the value that was provided on create.
1150
+ func (u *AccountUpsert) UpdateOverloadUntil() *AccountUpsert {
1151
+ u.SetExcluded(account.FieldOverloadUntil)
1152
+ return u
1153
+ }
1154
+
1155
+ // ClearOverloadUntil clears the value of the "overload_until" field.
1156
+ func (u *AccountUpsert) ClearOverloadUntil() *AccountUpsert {
1157
+ u.SetNull(account.FieldOverloadUntil)
1158
+ return u
1159
+ }
1160
+
1161
+ // SetTempUnschedulableUntil sets the "temp_unschedulable_until" field.
1162
+ func (u *AccountUpsert) SetTempUnschedulableUntil(v time.Time) *AccountUpsert {
1163
+ u.Set(account.FieldTempUnschedulableUntil, v)
1164
+ return u
1165
+ }
1166
+
1167
+ // UpdateTempUnschedulableUntil sets the "temp_unschedulable_until" field to the value that was provided on create.
1168
+ func (u *AccountUpsert) UpdateTempUnschedulableUntil() *AccountUpsert {
1169
+ u.SetExcluded(account.FieldTempUnschedulableUntil)
1170
+ return u
1171
+ }
1172
+
1173
+ // ClearTempUnschedulableUntil clears the value of the "temp_unschedulable_until" field.
1174
+ func (u *AccountUpsert) ClearTempUnschedulableUntil() *AccountUpsert {
1175
+ u.SetNull(account.FieldTempUnschedulableUntil)
1176
+ return u
1177
+ }
1178
+
1179
+ // SetTempUnschedulableReason sets the "temp_unschedulable_reason" field.
1180
+ func (u *AccountUpsert) SetTempUnschedulableReason(v string) *AccountUpsert {
1181
+ u.Set(account.FieldTempUnschedulableReason, v)
1182
+ return u
1183
+ }
1184
+
1185
+ // UpdateTempUnschedulableReason sets the "temp_unschedulable_reason" field to the value that was provided on create.
1186
+ func (u *AccountUpsert) UpdateTempUnschedulableReason() *AccountUpsert {
1187
+ u.SetExcluded(account.FieldTempUnschedulableReason)
1188
+ return u
1189
+ }
1190
+
1191
+ // ClearTempUnschedulableReason clears the value of the "temp_unschedulable_reason" field.
1192
+ func (u *AccountUpsert) ClearTempUnschedulableReason() *AccountUpsert {
1193
+ u.SetNull(account.FieldTempUnschedulableReason)
1194
+ return u
1195
+ }
1196
+
1197
+ // SetSessionWindowStart sets the "session_window_start" field.
1198
+ func (u *AccountUpsert) SetSessionWindowStart(v time.Time) *AccountUpsert {
1199
+ u.Set(account.FieldSessionWindowStart, v)
1200
+ return u
1201
+ }
1202
+
1203
+ // UpdateSessionWindowStart sets the "session_window_start" field to the value that was provided on create.
1204
+ func (u *AccountUpsert) UpdateSessionWindowStart() *AccountUpsert {
1205
+ u.SetExcluded(account.FieldSessionWindowStart)
1206
+ return u
1207
+ }
1208
+
1209
+ // ClearSessionWindowStart clears the value of the "session_window_start" field.
1210
+ func (u *AccountUpsert) ClearSessionWindowStart() *AccountUpsert {
1211
+ u.SetNull(account.FieldSessionWindowStart)
1212
+ return u
1213
+ }
1214
+
1215
+ // SetSessionWindowEnd sets the "session_window_end" field.
1216
+ func (u *AccountUpsert) SetSessionWindowEnd(v time.Time) *AccountUpsert {
1217
+ u.Set(account.FieldSessionWindowEnd, v)
1218
+ return u
1219
+ }
1220
+
1221
+ // UpdateSessionWindowEnd sets the "session_window_end" field to the value that was provided on create.
1222
+ func (u *AccountUpsert) UpdateSessionWindowEnd() *AccountUpsert {
1223
+ u.SetExcluded(account.FieldSessionWindowEnd)
1224
+ return u
1225
+ }
1226
+
1227
+ // ClearSessionWindowEnd clears the value of the "session_window_end" field.
1228
+ func (u *AccountUpsert) ClearSessionWindowEnd() *AccountUpsert {
1229
+ u.SetNull(account.FieldSessionWindowEnd)
1230
+ return u
1231
+ }
1232
+
1233
+ // SetSessionWindowStatus sets the "session_window_status" field.
1234
+ func (u *AccountUpsert) SetSessionWindowStatus(v string) *AccountUpsert {
1235
+ u.Set(account.FieldSessionWindowStatus, v)
1236
+ return u
1237
+ }
1238
+
1239
+ // UpdateSessionWindowStatus sets the "session_window_status" field to the value that was provided on create.
1240
+ func (u *AccountUpsert) UpdateSessionWindowStatus() *AccountUpsert {
1241
+ u.SetExcluded(account.FieldSessionWindowStatus)
1242
+ return u
1243
+ }
1244
+
1245
+ // ClearSessionWindowStatus clears the value of the "session_window_status" field.
1246
+ func (u *AccountUpsert) ClearSessionWindowStatus() *AccountUpsert {
1247
+ u.SetNull(account.FieldSessionWindowStatus)
1248
+ return u
1249
+ }
1250
+
1251
+ // UpdateNewValues updates the mutable fields using the new values that were set on create.
1252
+ // Using this option is equivalent to using:
1253
+ //
1254
+ // client.Account.Create().
1255
+ // OnConflict(
1256
+ // sql.ResolveWithNewValues(),
1257
+ // ).
1258
+ // Exec(ctx)
1259
+ func (u *AccountUpsertOne) UpdateNewValues() *AccountUpsertOne {
1260
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
1261
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
1262
+ if _, exists := u.create.mutation.CreatedAt(); exists {
1263
+ s.SetIgnore(account.FieldCreatedAt)
1264
+ }
1265
+ }))
1266
+ return u
1267
+ }
1268
+
1269
+ // Ignore sets each column to itself in case of conflict.
1270
+ // Using this option is equivalent to using:
1271
+ //
1272
+ // client.Account.Create().
1273
+ // OnConflict(sql.ResolveWithIgnore()).
1274
+ // Exec(ctx)
1275
+ func (u *AccountUpsertOne) Ignore() *AccountUpsertOne {
1276
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
1277
+ return u
1278
+ }
1279
+
1280
+ // DoNothing configures the conflict_action to `DO NOTHING`.
1281
+ // Supported only by SQLite and PostgreSQL.
1282
+ func (u *AccountUpsertOne) DoNothing() *AccountUpsertOne {
1283
+ u.create.conflict = append(u.create.conflict, sql.DoNothing())
1284
+ return u
1285
+ }
1286
+
1287
+ // Update allows overriding fields `UPDATE` values. See the AccountCreate.OnConflict
1288
+ // documentation for more info.
1289
+ func (u *AccountUpsertOne) Update(set func(*AccountUpsert)) *AccountUpsertOne {
1290
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
1291
+ set(&AccountUpsert{UpdateSet: update})
1292
+ }))
1293
+ return u
1294
+ }
1295
+
1296
+ // SetUpdatedAt sets the "updated_at" field.
1297
+ func (u *AccountUpsertOne) SetUpdatedAt(v time.Time) *AccountUpsertOne {
1298
+ return u.Update(func(s *AccountUpsert) {
1299
+ s.SetUpdatedAt(v)
1300
+ })
1301
+ }
1302
+
1303
+ // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
1304
+ func (u *AccountUpsertOne) UpdateUpdatedAt() *AccountUpsertOne {
1305
+ return u.Update(func(s *AccountUpsert) {
1306
+ s.UpdateUpdatedAt()
1307
+ })
1308
+ }
1309
+
1310
+ // SetDeletedAt sets the "deleted_at" field.
1311
+ func (u *AccountUpsertOne) SetDeletedAt(v time.Time) *AccountUpsertOne {
1312
+ return u.Update(func(s *AccountUpsert) {
1313
+ s.SetDeletedAt(v)
1314
+ })
1315
+ }
1316
+
1317
+ // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
1318
+ func (u *AccountUpsertOne) UpdateDeletedAt() *AccountUpsertOne {
1319
+ return u.Update(func(s *AccountUpsert) {
1320
+ s.UpdateDeletedAt()
1321
+ })
1322
+ }
1323
+
1324
+ // ClearDeletedAt clears the value of the "deleted_at" field.
1325
+ func (u *AccountUpsertOne) ClearDeletedAt() *AccountUpsertOne {
1326
+ return u.Update(func(s *AccountUpsert) {
1327
+ s.ClearDeletedAt()
1328
+ })
1329
+ }
1330
+
1331
+ // SetName sets the "name" field.
1332
+ func (u *AccountUpsertOne) SetName(v string) *AccountUpsertOne {
1333
+ return u.Update(func(s *AccountUpsert) {
1334
+ s.SetName(v)
1335
+ })
1336
+ }
1337
+
1338
+ // UpdateName sets the "name" field to the value that was provided on create.
1339
+ func (u *AccountUpsertOne) UpdateName() *AccountUpsertOne {
1340
+ return u.Update(func(s *AccountUpsert) {
1341
+ s.UpdateName()
1342
+ })
1343
+ }
1344
+
1345
+ // SetNotes sets the "notes" field.
1346
+ func (u *AccountUpsertOne) SetNotes(v string) *AccountUpsertOne {
1347
+ return u.Update(func(s *AccountUpsert) {
1348
+ s.SetNotes(v)
1349
+ })
1350
+ }
1351
+
1352
+ // UpdateNotes sets the "notes" field to the value that was provided on create.
1353
+ func (u *AccountUpsertOne) UpdateNotes() *AccountUpsertOne {
1354
+ return u.Update(func(s *AccountUpsert) {
1355
+ s.UpdateNotes()
1356
+ })
1357
+ }
1358
+
1359
+ // ClearNotes clears the value of the "notes" field.
1360
+ func (u *AccountUpsertOne) ClearNotes() *AccountUpsertOne {
1361
+ return u.Update(func(s *AccountUpsert) {
1362
+ s.ClearNotes()
1363
+ })
1364
+ }
1365
+
1366
+ // SetPlatform sets the "platform" field.
1367
+ func (u *AccountUpsertOne) SetPlatform(v string) *AccountUpsertOne {
1368
+ return u.Update(func(s *AccountUpsert) {
1369
+ s.SetPlatform(v)
1370
+ })
1371
+ }
1372
+
1373
+ // UpdatePlatform sets the "platform" field to the value that was provided on create.
1374
+ func (u *AccountUpsertOne) UpdatePlatform() *AccountUpsertOne {
1375
+ return u.Update(func(s *AccountUpsert) {
1376
+ s.UpdatePlatform()
1377
+ })
1378
+ }
1379
+
1380
+ // SetType sets the "type" field.
1381
+ func (u *AccountUpsertOne) SetType(v string) *AccountUpsertOne {
1382
+ return u.Update(func(s *AccountUpsert) {
1383
+ s.SetType(v)
1384
+ })
1385
+ }
1386
+
1387
+ // UpdateType sets the "type" field to the value that was provided on create.
1388
+ func (u *AccountUpsertOne) UpdateType() *AccountUpsertOne {
1389
+ return u.Update(func(s *AccountUpsert) {
1390
+ s.UpdateType()
1391
+ })
1392
+ }
1393
+
1394
+ // SetCredentials sets the "credentials" field.
1395
+ func (u *AccountUpsertOne) SetCredentials(v map[string]interface{}) *AccountUpsertOne {
1396
+ return u.Update(func(s *AccountUpsert) {
1397
+ s.SetCredentials(v)
1398
+ })
1399
+ }
1400
+
1401
+ // UpdateCredentials sets the "credentials" field to the value that was provided on create.
1402
+ func (u *AccountUpsertOne) UpdateCredentials() *AccountUpsertOne {
1403
+ return u.Update(func(s *AccountUpsert) {
1404
+ s.UpdateCredentials()
1405
+ })
1406
+ }
1407
+
1408
+ // SetExtra sets the "extra" field.
1409
+ func (u *AccountUpsertOne) SetExtra(v map[string]interface{}) *AccountUpsertOne {
1410
+ return u.Update(func(s *AccountUpsert) {
1411
+ s.SetExtra(v)
1412
+ })
1413
+ }
1414
+
1415
+ // UpdateExtra sets the "extra" field to the value that was provided on create.
1416
+ func (u *AccountUpsertOne) UpdateExtra() *AccountUpsertOne {
1417
+ return u.Update(func(s *AccountUpsert) {
1418
+ s.UpdateExtra()
1419
+ })
1420
+ }
1421
+
1422
+ // SetProxyID sets the "proxy_id" field.
1423
+ func (u *AccountUpsertOne) SetProxyID(v int64) *AccountUpsertOne {
1424
+ return u.Update(func(s *AccountUpsert) {
1425
+ s.SetProxyID(v)
1426
+ })
1427
+ }
1428
+
1429
+ // UpdateProxyID sets the "proxy_id" field to the value that was provided on create.
1430
+ func (u *AccountUpsertOne) UpdateProxyID() *AccountUpsertOne {
1431
+ return u.Update(func(s *AccountUpsert) {
1432
+ s.UpdateProxyID()
1433
+ })
1434
+ }
1435
+
1436
+ // ClearProxyID clears the value of the "proxy_id" field.
1437
+ func (u *AccountUpsertOne) ClearProxyID() *AccountUpsertOne {
1438
+ return u.Update(func(s *AccountUpsert) {
1439
+ s.ClearProxyID()
1440
+ })
1441
+ }
1442
+
1443
+ // SetConcurrency sets the "concurrency" field.
1444
+ func (u *AccountUpsertOne) SetConcurrency(v int) *AccountUpsertOne {
1445
+ return u.Update(func(s *AccountUpsert) {
1446
+ s.SetConcurrency(v)
1447
+ })
1448
+ }
1449
+
1450
+ // AddConcurrency adds v to the "concurrency" field.
1451
+ func (u *AccountUpsertOne) AddConcurrency(v int) *AccountUpsertOne {
1452
+ return u.Update(func(s *AccountUpsert) {
1453
+ s.AddConcurrency(v)
1454
+ })
1455
+ }
1456
+
1457
+ // UpdateConcurrency sets the "concurrency" field to the value that was provided on create.
1458
+ func (u *AccountUpsertOne) UpdateConcurrency() *AccountUpsertOne {
1459
+ return u.Update(func(s *AccountUpsert) {
1460
+ s.UpdateConcurrency()
1461
+ })
1462
+ }
1463
+
1464
+ // SetLoadFactor sets the "load_factor" field.
1465
+ func (u *AccountUpsertOne) SetLoadFactor(v int) *AccountUpsertOne {
1466
+ return u.Update(func(s *AccountUpsert) {
1467
+ s.SetLoadFactor(v)
1468
+ })
1469
+ }
1470
+
1471
+ // AddLoadFactor adds v to the "load_factor" field.
1472
+ func (u *AccountUpsertOne) AddLoadFactor(v int) *AccountUpsertOne {
1473
+ return u.Update(func(s *AccountUpsert) {
1474
+ s.AddLoadFactor(v)
1475
+ })
1476
+ }
1477
+
1478
+ // UpdateLoadFactor sets the "load_factor" field to the value that was provided on create.
1479
+ func (u *AccountUpsertOne) UpdateLoadFactor() *AccountUpsertOne {
1480
+ return u.Update(func(s *AccountUpsert) {
1481
+ s.UpdateLoadFactor()
1482
+ })
1483
+ }
1484
+
1485
+ // ClearLoadFactor clears the value of the "load_factor" field.
1486
+ func (u *AccountUpsertOne) ClearLoadFactor() *AccountUpsertOne {
1487
+ return u.Update(func(s *AccountUpsert) {
1488
+ s.ClearLoadFactor()
1489
+ })
1490
+ }
1491
+
1492
+ // SetPriority sets the "priority" field.
1493
+ func (u *AccountUpsertOne) SetPriority(v int) *AccountUpsertOne {
1494
+ return u.Update(func(s *AccountUpsert) {
1495
+ s.SetPriority(v)
1496
+ })
1497
+ }
1498
+
1499
+ // AddPriority adds v to the "priority" field.
1500
+ func (u *AccountUpsertOne) AddPriority(v int) *AccountUpsertOne {
1501
+ return u.Update(func(s *AccountUpsert) {
1502
+ s.AddPriority(v)
1503
+ })
1504
+ }
1505
+
1506
+ // UpdatePriority sets the "priority" field to the value that was provided on create.
1507
+ func (u *AccountUpsertOne) UpdatePriority() *AccountUpsertOne {
1508
+ return u.Update(func(s *AccountUpsert) {
1509
+ s.UpdatePriority()
1510
+ })
1511
+ }
1512
+
1513
+ // SetRateMultiplier sets the "rate_multiplier" field.
1514
+ func (u *AccountUpsertOne) SetRateMultiplier(v float64) *AccountUpsertOne {
1515
+ return u.Update(func(s *AccountUpsert) {
1516
+ s.SetRateMultiplier(v)
1517
+ })
1518
+ }
1519
+
1520
+ // AddRateMultiplier adds v to the "rate_multiplier" field.
1521
+ func (u *AccountUpsertOne) AddRateMultiplier(v float64) *AccountUpsertOne {
1522
+ return u.Update(func(s *AccountUpsert) {
1523
+ s.AddRateMultiplier(v)
1524
+ })
1525
+ }
1526
+
1527
+ // UpdateRateMultiplier sets the "rate_multiplier" field to the value that was provided on create.
1528
+ func (u *AccountUpsertOne) UpdateRateMultiplier() *AccountUpsertOne {
1529
+ return u.Update(func(s *AccountUpsert) {
1530
+ s.UpdateRateMultiplier()
1531
+ })
1532
+ }
1533
+
1534
+ // SetStatus sets the "status" field.
1535
+ func (u *AccountUpsertOne) SetStatus(v string) *AccountUpsertOne {
1536
+ return u.Update(func(s *AccountUpsert) {
1537
+ s.SetStatus(v)
1538
+ })
1539
+ }
1540
+
1541
+ // UpdateStatus sets the "status" field to the value that was provided on create.
1542
+ func (u *AccountUpsertOne) UpdateStatus() *AccountUpsertOne {
1543
+ return u.Update(func(s *AccountUpsert) {
1544
+ s.UpdateStatus()
1545
+ })
1546
+ }
1547
+
1548
+ // SetErrorMessage sets the "error_message" field.
1549
+ func (u *AccountUpsertOne) SetErrorMessage(v string) *AccountUpsertOne {
1550
+ return u.Update(func(s *AccountUpsert) {
1551
+ s.SetErrorMessage(v)
1552
+ })
1553
+ }
1554
+
1555
+ // UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
1556
+ func (u *AccountUpsertOne) UpdateErrorMessage() *AccountUpsertOne {
1557
+ return u.Update(func(s *AccountUpsert) {
1558
+ s.UpdateErrorMessage()
1559
+ })
1560
+ }
1561
+
1562
+ // ClearErrorMessage clears the value of the "error_message" field.
1563
+ func (u *AccountUpsertOne) ClearErrorMessage() *AccountUpsertOne {
1564
+ return u.Update(func(s *AccountUpsert) {
1565
+ s.ClearErrorMessage()
1566
+ })
1567
+ }
1568
+
1569
+ // SetLastUsedAt sets the "last_used_at" field.
1570
+ func (u *AccountUpsertOne) SetLastUsedAt(v time.Time) *AccountUpsertOne {
1571
+ return u.Update(func(s *AccountUpsert) {
1572
+ s.SetLastUsedAt(v)
1573
+ })
1574
+ }
1575
+
1576
+ // UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
1577
+ func (u *AccountUpsertOne) UpdateLastUsedAt() *AccountUpsertOne {
1578
+ return u.Update(func(s *AccountUpsert) {
1579
+ s.UpdateLastUsedAt()
1580
+ })
1581
+ }
1582
+
1583
+ // ClearLastUsedAt clears the value of the "last_used_at" field.
1584
+ func (u *AccountUpsertOne) ClearLastUsedAt() *AccountUpsertOne {
1585
+ return u.Update(func(s *AccountUpsert) {
1586
+ s.ClearLastUsedAt()
1587
+ })
1588
+ }
1589
+
1590
+ // SetExpiresAt sets the "expires_at" field.
1591
+ func (u *AccountUpsertOne) SetExpiresAt(v time.Time) *AccountUpsertOne {
1592
+ return u.Update(func(s *AccountUpsert) {
1593
+ s.SetExpiresAt(v)
1594
+ })
1595
+ }
1596
+
1597
+ // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
1598
+ func (u *AccountUpsertOne) UpdateExpiresAt() *AccountUpsertOne {
1599
+ return u.Update(func(s *AccountUpsert) {
1600
+ s.UpdateExpiresAt()
1601
+ })
1602
+ }
1603
+
1604
+ // ClearExpiresAt clears the value of the "expires_at" field.
1605
+ func (u *AccountUpsertOne) ClearExpiresAt() *AccountUpsertOne {
1606
+ return u.Update(func(s *AccountUpsert) {
1607
+ s.ClearExpiresAt()
1608
+ })
1609
+ }
1610
+
1611
+ // SetAutoPauseOnExpired sets the "auto_pause_on_expired" field.
1612
+ func (u *AccountUpsertOne) SetAutoPauseOnExpired(v bool) *AccountUpsertOne {
1613
+ return u.Update(func(s *AccountUpsert) {
1614
+ s.SetAutoPauseOnExpired(v)
1615
+ })
1616
+ }
1617
+
1618
+ // UpdateAutoPauseOnExpired sets the "auto_pause_on_expired" field to the value that was provided on create.
1619
+ func (u *AccountUpsertOne) UpdateAutoPauseOnExpired() *AccountUpsertOne {
1620
+ return u.Update(func(s *AccountUpsert) {
1621
+ s.UpdateAutoPauseOnExpired()
1622
+ })
1623
+ }
1624
+
1625
+ // SetSchedulable sets the "schedulable" field.
1626
+ func (u *AccountUpsertOne) SetSchedulable(v bool) *AccountUpsertOne {
1627
+ return u.Update(func(s *AccountUpsert) {
1628
+ s.SetSchedulable(v)
1629
+ })
1630
+ }
1631
+
1632
+ // UpdateSchedulable sets the "schedulable" field to the value that was provided on create.
1633
+ func (u *AccountUpsertOne) UpdateSchedulable() *AccountUpsertOne {
1634
+ return u.Update(func(s *AccountUpsert) {
1635
+ s.UpdateSchedulable()
1636
+ })
1637
+ }
1638
+
1639
+ // SetRateLimitedAt sets the "rate_limited_at" field.
1640
+ func (u *AccountUpsertOne) SetRateLimitedAt(v time.Time) *AccountUpsertOne {
1641
+ return u.Update(func(s *AccountUpsert) {
1642
+ s.SetRateLimitedAt(v)
1643
+ })
1644
+ }
1645
+
1646
+ // UpdateRateLimitedAt sets the "rate_limited_at" field to the value that was provided on create.
1647
+ func (u *AccountUpsertOne) UpdateRateLimitedAt() *AccountUpsertOne {
1648
+ return u.Update(func(s *AccountUpsert) {
1649
+ s.UpdateRateLimitedAt()
1650
+ })
1651
+ }
1652
+
1653
+ // ClearRateLimitedAt clears the value of the "rate_limited_at" field.
1654
+ func (u *AccountUpsertOne) ClearRateLimitedAt() *AccountUpsertOne {
1655
+ return u.Update(func(s *AccountUpsert) {
1656
+ s.ClearRateLimitedAt()
1657
+ })
1658
+ }
1659
+
1660
+ // SetRateLimitResetAt sets the "rate_limit_reset_at" field.
1661
+ func (u *AccountUpsertOne) SetRateLimitResetAt(v time.Time) *AccountUpsertOne {
1662
+ return u.Update(func(s *AccountUpsert) {
1663
+ s.SetRateLimitResetAt(v)
1664
+ })
1665
+ }
1666
+
1667
+ // UpdateRateLimitResetAt sets the "rate_limit_reset_at" field to the value that was provided on create.
1668
+ func (u *AccountUpsertOne) UpdateRateLimitResetAt() *AccountUpsertOne {
1669
+ return u.Update(func(s *AccountUpsert) {
1670
+ s.UpdateRateLimitResetAt()
1671
+ })
1672
+ }
1673
+
1674
+ // ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
1675
+ func (u *AccountUpsertOne) ClearRateLimitResetAt() *AccountUpsertOne {
1676
+ return u.Update(func(s *AccountUpsert) {
1677
+ s.ClearRateLimitResetAt()
1678
+ })
1679
+ }
1680
+
1681
+ // SetOverloadUntil sets the "overload_until" field.
1682
+ func (u *AccountUpsertOne) SetOverloadUntil(v time.Time) *AccountUpsertOne {
1683
+ return u.Update(func(s *AccountUpsert) {
1684
+ s.SetOverloadUntil(v)
1685
+ })
1686
+ }
1687
+
1688
+ // UpdateOverloadUntil sets the "overload_until" field to the value that was provided on create.
1689
+ func (u *AccountUpsertOne) UpdateOverloadUntil() *AccountUpsertOne {
1690
+ return u.Update(func(s *AccountUpsert) {
1691
+ s.UpdateOverloadUntil()
1692
+ })
1693
+ }
1694
+
1695
+ // ClearOverloadUntil clears the value of the "overload_until" field.
1696
+ func (u *AccountUpsertOne) ClearOverloadUntil() *AccountUpsertOne {
1697
+ return u.Update(func(s *AccountUpsert) {
1698
+ s.ClearOverloadUntil()
1699
+ })
1700
+ }
1701
+
1702
+ // SetTempUnschedulableUntil sets the "temp_unschedulable_until" field.
1703
+ func (u *AccountUpsertOne) SetTempUnschedulableUntil(v time.Time) *AccountUpsertOne {
1704
+ return u.Update(func(s *AccountUpsert) {
1705
+ s.SetTempUnschedulableUntil(v)
1706
+ })
1707
+ }
1708
+
1709
+ // UpdateTempUnschedulableUntil sets the "temp_unschedulable_until" field to the value that was provided on create.
1710
+ func (u *AccountUpsertOne) UpdateTempUnschedulableUntil() *AccountUpsertOne {
1711
+ return u.Update(func(s *AccountUpsert) {
1712
+ s.UpdateTempUnschedulableUntil()
1713
+ })
1714
+ }
1715
+
1716
+ // ClearTempUnschedulableUntil clears the value of the "temp_unschedulable_until" field.
1717
+ func (u *AccountUpsertOne) ClearTempUnschedulableUntil() *AccountUpsertOne {
1718
+ return u.Update(func(s *AccountUpsert) {
1719
+ s.ClearTempUnschedulableUntil()
1720
+ })
1721
+ }
1722
+
1723
+ // SetTempUnschedulableReason sets the "temp_unschedulable_reason" field.
1724
+ func (u *AccountUpsertOne) SetTempUnschedulableReason(v string) *AccountUpsertOne {
1725
+ return u.Update(func(s *AccountUpsert) {
1726
+ s.SetTempUnschedulableReason(v)
1727
+ })
1728
+ }
1729
+
1730
+ // UpdateTempUnschedulableReason sets the "temp_unschedulable_reason" field to the value that was provided on create.
1731
+ func (u *AccountUpsertOne) UpdateTempUnschedulableReason() *AccountUpsertOne {
1732
+ return u.Update(func(s *AccountUpsert) {
1733
+ s.UpdateTempUnschedulableReason()
1734
+ })
1735
+ }
1736
+
1737
+ // ClearTempUnschedulableReason clears the value of the "temp_unschedulable_reason" field.
1738
+ func (u *AccountUpsertOne) ClearTempUnschedulableReason() *AccountUpsertOne {
1739
+ return u.Update(func(s *AccountUpsert) {
1740
+ s.ClearTempUnschedulableReason()
1741
+ })
1742
+ }
1743
+
1744
+ // SetSessionWindowStart sets the "session_window_start" field.
1745
+ func (u *AccountUpsertOne) SetSessionWindowStart(v time.Time) *AccountUpsertOne {
1746
+ return u.Update(func(s *AccountUpsert) {
1747
+ s.SetSessionWindowStart(v)
1748
+ })
1749
+ }
1750
+
1751
+ // UpdateSessionWindowStart sets the "session_window_start" field to the value that was provided on create.
1752
+ func (u *AccountUpsertOne) UpdateSessionWindowStart() *AccountUpsertOne {
1753
+ return u.Update(func(s *AccountUpsert) {
1754
+ s.UpdateSessionWindowStart()
1755
+ })
1756
+ }
1757
+
1758
+ // ClearSessionWindowStart clears the value of the "session_window_start" field.
1759
+ func (u *AccountUpsertOne) ClearSessionWindowStart() *AccountUpsertOne {
1760
+ return u.Update(func(s *AccountUpsert) {
1761
+ s.ClearSessionWindowStart()
1762
+ })
1763
+ }
1764
+
1765
+ // SetSessionWindowEnd sets the "session_window_end" field.
1766
+ func (u *AccountUpsertOne) SetSessionWindowEnd(v time.Time) *AccountUpsertOne {
1767
+ return u.Update(func(s *AccountUpsert) {
1768
+ s.SetSessionWindowEnd(v)
1769
+ })
1770
+ }
1771
+
1772
+ // UpdateSessionWindowEnd sets the "session_window_end" field to the value that was provided on create.
1773
+ func (u *AccountUpsertOne) UpdateSessionWindowEnd() *AccountUpsertOne {
1774
+ return u.Update(func(s *AccountUpsert) {
1775
+ s.UpdateSessionWindowEnd()
1776
+ })
1777
+ }
1778
+
1779
+ // ClearSessionWindowEnd clears the value of the "session_window_end" field.
1780
+ func (u *AccountUpsertOne) ClearSessionWindowEnd() *AccountUpsertOne {
1781
+ return u.Update(func(s *AccountUpsert) {
1782
+ s.ClearSessionWindowEnd()
1783
+ })
1784
+ }
1785
+
1786
+ // SetSessionWindowStatus sets the "session_window_status" field.
1787
+ func (u *AccountUpsertOne) SetSessionWindowStatus(v string) *AccountUpsertOne {
1788
+ return u.Update(func(s *AccountUpsert) {
1789
+ s.SetSessionWindowStatus(v)
1790
+ })
1791
+ }
1792
+
1793
+ // UpdateSessionWindowStatus sets the "session_window_status" field to the value that was provided on create.
1794
+ func (u *AccountUpsertOne) UpdateSessionWindowStatus() *AccountUpsertOne {
1795
+ return u.Update(func(s *AccountUpsert) {
1796
+ s.UpdateSessionWindowStatus()
1797
+ })
1798
+ }
1799
+
1800
+ // ClearSessionWindowStatus clears the value of the "session_window_status" field.
1801
+ func (u *AccountUpsertOne) ClearSessionWindowStatus() *AccountUpsertOne {
1802
+ return u.Update(func(s *AccountUpsert) {
1803
+ s.ClearSessionWindowStatus()
1804
+ })
1805
+ }
1806
+
1807
+ // Exec executes the query.
1808
+ func (u *AccountUpsertOne) Exec(ctx context.Context) error {
1809
+ if len(u.create.conflict) == 0 {
1810
+ return errors.New("ent: missing options for AccountCreate.OnConflict")
1811
+ }
1812
+ return u.create.Exec(ctx)
1813
+ }
1814
+
1815
+ // ExecX is like Exec, but panics if an error occurs.
1816
+ func (u *AccountUpsertOne) ExecX(ctx context.Context) {
1817
+ if err := u.create.Exec(ctx); err != nil {
1818
+ panic(err)
1819
+ }
1820
+ }
1821
+
1822
+ // Exec executes the UPSERT query and returns the inserted/updated ID.
1823
+ func (u *AccountUpsertOne) ID(ctx context.Context) (id int64, err error) {
1824
+ node, err := u.create.Save(ctx)
1825
+ if err != nil {
1826
+ return id, err
1827
+ }
1828
+ return node.ID, nil
1829
+ }
1830
+
1831
+ // IDX is like ID, but panics if an error occurs.
1832
+ func (u *AccountUpsertOne) IDX(ctx context.Context) int64 {
1833
+ id, err := u.ID(ctx)
1834
+ if err != nil {
1835
+ panic(err)
1836
+ }
1837
+ return id
1838
+ }
1839
+
1840
+ // AccountCreateBulk is the builder for creating many Account entities in bulk.
1841
+ type AccountCreateBulk struct {
1842
+ config
1843
+ err error
1844
+ builders []*AccountCreate
1845
+ conflict []sql.ConflictOption
1846
+ }
1847
+
1848
+ // Save creates the Account entities in the database.
1849
+ func (_c *AccountCreateBulk) Save(ctx context.Context) ([]*Account, error) {
1850
+ if _c.err != nil {
1851
+ return nil, _c.err
1852
+ }
1853
+ specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
1854
+ nodes := make([]*Account, len(_c.builders))
1855
+ mutators := make([]Mutator, len(_c.builders))
1856
+ for i := range _c.builders {
1857
+ func(i int, root context.Context) {
1858
+ builder := _c.builders[i]
1859
+ builder.defaults()
1860
+ var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
1861
+ mutation, ok := m.(*AccountMutation)
1862
+ if !ok {
1863
+ return nil, fmt.Errorf("unexpected mutation type %T", m)
1864
+ }
1865
+ if err := builder.check(); err != nil {
1866
+ return nil, err
1867
+ }
1868
+ builder.mutation = mutation
1869
+ var err error
1870
+ nodes[i], specs[i] = builder.createSpec()
1871
+ if i < len(mutators)-1 {
1872
+ _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
1873
+ } else {
1874
+ spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
1875
+ spec.OnConflict = _c.conflict
1876
+ // Invoke the actual operation on the latest mutation in the chain.
1877
+ if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
1878
+ if sqlgraph.IsConstraintError(err) {
1879
+ err = &ConstraintError{msg: err.Error(), wrap: err}
1880
+ }
1881
+ }
1882
+ }
1883
+ if err != nil {
1884
+ return nil, err
1885
+ }
1886
+ mutation.id = &nodes[i].ID
1887
+ if specs[i].ID.Value != nil {
1888
+ id := specs[i].ID.Value.(int64)
1889
+ nodes[i].ID = int64(id)
1890
+ }
1891
+ mutation.done = true
1892
+ return nodes[i], nil
1893
+ })
1894
+ for i := len(builder.hooks) - 1; i >= 0; i-- {
1895
+ mut = builder.hooks[i](mut)
1896
+ }
1897
+ mutators[i] = mut
1898
+ }(i, ctx)
1899
+ }
1900
+ if len(mutators) > 0 {
1901
+ if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
1902
+ return nil, err
1903
+ }
1904
+ }
1905
+ return nodes, nil
1906
+ }
1907
+
1908
+ // SaveX is like Save, but panics if an error occurs.
1909
+ func (_c *AccountCreateBulk) SaveX(ctx context.Context) []*Account {
1910
+ v, err := _c.Save(ctx)
1911
+ if err != nil {
1912
+ panic(err)
1913
+ }
1914
+ return v
1915
+ }
1916
+
1917
+ // Exec executes the query.
1918
+ func (_c *AccountCreateBulk) Exec(ctx context.Context) error {
1919
+ _, err := _c.Save(ctx)
1920
+ return err
1921
+ }
1922
+
1923
+ // ExecX is like Exec, but panics if an error occurs.
1924
+ func (_c *AccountCreateBulk) ExecX(ctx context.Context) {
1925
+ if err := _c.Exec(ctx); err != nil {
1926
+ panic(err)
1927
+ }
1928
+ }
1929
+
1930
+ // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
1931
+ // of the `INSERT` statement. For example:
1932
+ //
1933
+ // client.Account.CreateBulk(builders...).
1934
+ // OnConflict(
1935
+ // // Update the row with the new values
1936
+ // // the was proposed for insertion.
1937
+ // sql.ResolveWithNewValues(),
1938
+ // ).
1939
+ // // Override some of the fields with custom
1940
+ // // update values.
1941
+ // Update(func(u *ent.AccountUpsert) {
1942
+ // SetCreatedAt(v+v).
1943
+ // }).
1944
+ // Exec(ctx)
1945
+ func (_c *AccountCreateBulk) OnConflict(opts ...sql.ConflictOption) *AccountUpsertBulk {
1946
+ _c.conflict = opts
1947
+ return &AccountUpsertBulk{
1948
+ create: _c,
1949
+ }
1950
+ }
1951
+
1952
+ // OnConflictColumns calls `OnConflict` and configures the columns
1953
+ // as conflict target. Using this option is equivalent to using:
1954
+ //
1955
+ // client.Account.Create().
1956
+ // OnConflict(sql.ConflictColumns(columns...)).
1957
+ // Exec(ctx)
1958
+ func (_c *AccountCreateBulk) OnConflictColumns(columns ...string) *AccountUpsertBulk {
1959
+ _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
1960
+ return &AccountUpsertBulk{
1961
+ create: _c,
1962
+ }
1963
+ }
1964
+
1965
+ // AccountUpsertBulk is the builder for "upsert"-ing
1966
+ // a bulk of Account nodes.
1967
+ type AccountUpsertBulk struct {
1968
+ create *AccountCreateBulk
1969
+ }
1970
+
1971
+ // UpdateNewValues updates the mutable fields using the new values that
1972
+ // were set on create. Using this option is equivalent to using:
1973
+ //
1974
+ // client.Account.Create().
1975
+ // OnConflict(
1976
+ // sql.ResolveWithNewValues(),
1977
+ // ).
1978
+ // Exec(ctx)
1979
+ func (u *AccountUpsertBulk) UpdateNewValues() *AccountUpsertBulk {
1980
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
1981
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
1982
+ for _, b := range u.create.builders {
1983
+ if _, exists := b.mutation.CreatedAt(); exists {
1984
+ s.SetIgnore(account.FieldCreatedAt)
1985
+ }
1986
+ }
1987
+ }))
1988
+ return u
1989
+ }
1990
+
1991
+ // Ignore sets each column to itself in case of conflict.
1992
+ // Using this option is equivalent to using:
1993
+ //
1994
+ // client.Account.Create().
1995
+ // OnConflict(sql.ResolveWithIgnore()).
1996
+ // Exec(ctx)
1997
+ func (u *AccountUpsertBulk) Ignore() *AccountUpsertBulk {
1998
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
1999
+ return u
2000
+ }
2001
+
2002
+ // DoNothing configures the conflict_action to `DO NOTHING`.
2003
+ // Supported only by SQLite and PostgreSQL.
2004
+ func (u *AccountUpsertBulk) DoNothing() *AccountUpsertBulk {
2005
+ u.create.conflict = append(u.create.conflict, sql.DoNothing())
2006
+ return u
2007
+ }
2008
+
2009
+ // Update allows overriding fields `UPDATE` values. See the AccountCreateBulk.OnConflict
2010
+ // documentation for more info.
2011
+ func (u *AccountUpsertBulk) Update(set func(*AccountUpsert)) *AccountUpsertBulk {
2012
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
2013
+ set(&AccountUpsert{UpdateSet: update})
2014
+ }))
2015
+ return u
2016
+ }
2017
+
2018
+ // SetUpdatedAt sets the "updated_at" field.
2019
+ func (u *AccountUpsertBulk) SetUpdatedAt(v time.Time) *AccountUpsertBulk {
2020
+ return u.Update(func(s *AccountUpsert) {
2021
+ s.SetUpdatedAt(v)
2022
+ })
2023
+ }
2024
+
2025
+ // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
2026
+ func (u *AccountUpsertBulk) UpdateUpdatedAt() *AccountUpsertBulk {
2027
+ return u.Update(func(s *AccountUpsert) {
2028
+ s.UpdateUpdatedAt()
2029
+ })
2030
+ }
2031
+
2032
+ // SetDeletedAt sets the "deleted_at" field.
2033
+ func (u *AccountUpsertBulk) SetDeletedAt(v time.Time) *AccountUpsertBulk {
2034
+ return u.Update(func(s *AccountUpsert) {
2035
+ s.SetDeletedAt(v)
2036
+ })
2037
+ }
2038
+
2039
+ // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
2040
+ func (u *AccountUpsertBulk) UpdateDeletedAt() *AccountUpsertBulk {
2041
+ return u.Update(func(s *AccountUpsert) {
2042
+ s.UpdateDeletedAt()
2043
+ })
2044
+ }
2045
+
2046
+ // ClearDeletedAt clears the value of the "deleted_at" field.
2047
+ func (u *AccountUpsertBulk) ClearDeletedAt() *AccountUpsertBulk {
2048
+ return u.Update(func(s *AccountUpsert) {
2049
+ s.ClearDeletedAt()
2050
+ })
2051
+ }
2052
+
2053
+ // SetName sets the "name" field.
2054
+ func (u *AccountUpsertBulk) SetName(v string) *AccountUpsertBulk {
2055
+ return u.Update(func(s *AccountUpsert) {
2056
+ s.SetName(v)
2057
+ })
2058
+ }
2059
+
2060
+ // UpdateName sets the "name" field to the value that was provided on create.
2061
+ func (u *AccountUpsertBulk) UpdateName() *AccountUpsertBulk {
2062
+ return u.Update(func(s *AccountUpsert) {
2063
+ s.UpdateName()
2064
+ })
2065
+ }
2066
+
2067
+ // SetNotes sets the "notes" field.
2068
+ func (u *AccountUpsertBulk) SetNotes(v string) *AccountUpsertBulk {
2069
+ return u.Update(func(s *AccountUpsert) {
2070
+ s.SetNotes(v)
2071
+ })
2072
+ }
2073
+
2074
+ // UpdateNotes sets the "notes" field to the value that was provided on create.
2075
+ func (u *AccountUpsertBulk) UpdateNotes() *AccountUpsertBulk {
2076
+ return u.Update(func(s *AccountUpsert) {
2077
+ s.UpdateNotes()
2078
+ })
2079
+ }
2080
+
2081
+ // ClearNotes clears the value of the "notes" field.
2082
+ func (u *AccountUpsertBulk) ClearNotes() *AccountUpsertBulk {
2083
+ return u.Update(func(s *AccountUpsert) {
2084
+ s.ClearNotes()
2085
+ })
2086
+ }
2087
+
2088
+ // SetPlatform sets the "platform" field.
2089
+ func (u *AccountUpsertBulk) SetPlatform(v string) *AccountUpsertBulk {
2090
+ return u.Update(func(s *AccountUpsert) {
2091
+ s.SetPlatform(v)
2092
+ })
2093
+ }
2094
+
2095
+ // UpdatePlatform sets the "platform" field to the value that was provided on create.
2096
+ func (u *AccountUpsertBulk) UpdatePlatform() *AccountUpsertBulk {
2097
+ return u.Update(func(s *AccountUpsert) {
2098
+ s.UpdatePlatform()
2099
+ })
2100
+ }
2101
+
2102
+ // SetType sets the "type" field.
2103
+ func (u *AccountUpsertBulk) SetType(v string) *AccountUpsertBulk {
2104
+ return u.Update(func(s *AccountUpsert) {
2105
+ s.SetType(v)
2106
+ })
2107
+ }
2108
+
2109
+ // UpdateType sets the "type" field to the value that was provided on create.
2110
+ func (u *AccountUpsertBulk) UpdateType() *AccountUpsertBulk {
2111
+ return u.Update(func(s *AccountUpsert) {
2112
+ s.UpdateType()
2113
+ })
2114
+ }
2115
+
2116
+ // SetCredentials sets the "credentials" field.
2117
+ func (u *AccountUpsertBulk) SetCredentials(v map[string]interface{}) *AccountUpsertBulk {
2118
+ return u.Update(func(s *AccountUpsert) {
2119
+ s.SetCredentials(v)
2120
+ })
2121
+ }
2122
+
2123
+ // UpdateCredentials sets the "credentials" field to the value that was provided on create.
2124
+ func (u *AccountUpsertBulk) UpdateCredentials() *AccountUpsertBulk {
2125
+ return u.Update(func(s *AccountUpsert) {
2126
+ s.UpdateCredentials()
2127
+ })
2128
+ }
2129
+
2130
+ // SetExtra sets the "extra" field.
2131
+ func (u *AccountUpsertBulk) SetExtra(v map[string]interface{}) *AccountUpsertBulk {
2132
+ return u.Update(func(s *AccountUpsert) {
2133
+ s.SetExtra(v)
2134
+ })
2135
+ }
2136
+
2137
+ // UpdateExtra sets the "extra" field to the value that was provided on create.
2138
+ func (u *AccountUpsertBulk) UpdateExtra() *AccountUpsertBulk {
2139
+ return u.Update(func(s *AccountUpsert) {
2140
+ s.UpdateExtra()
2141
+ })
2142
+ }
2143
+
2144
+ // SetProxyID sets the "proxy_id" field.
2145
+ func (u *AccountUpsertBulk) SetProxyID(v int64) *AccountUpsertBulk {
2146
+ return u.Update(func(s *AccountUpsert) {
2147
+ s.SetProxyID(v)
2148
+ })
2149
+ }
2150
+
2151
+ // UpdateProxyID sets the "proxy_id" field to the value that was provided on create.
2152
+ func (u *AccountUpsertBulk) UpdateProxyID() *AccountUpsertBulk {
2153
+ return u.Update(func(s *AccountUpsert) {
2154
+ s.UpdateProxyID()
2155
+ })
2156
+ }
2157
+
2158
+ // ClearProxyID clears the value of the "proxy_id" field.
2159
+ func (u *AccountUpsertBulk) ClearProxyID() *AccountUpsertBulk {
2160
+ return u.Update(func(s *AccountUpsert) {
2161
+ s.ClearProxyID()
2162
+ })
2163
+ }
2164
+
2165
+ // SetConcurrency sets the "concurrency" field.
2166
+ func (u *AccountUpsertBulk) SetConcurrency(v int) *AccountUpsertBulk {
2167
+ return u.Update(func(s *AccountUpsert) {
2168
+ s.SetConcurrency(v)
2169
+ })
2170
+ }
2171
+
2172
+ // AddConcurrency adds v to the "concurrency" field.
2173
+ func (u *AccountUpsertBulk) AddConcurrency(v int) *AccountUpsertBulk {
2174
+ return u.Update(func(s *AccountUpsert) {
2175
+ s.AddConcurrency(v)
2176
+ })
2177
+ }
2178
+
2179
+ // UpdateConcurrency sets the "concurrency" field to the value that was provided on create.
2180
+ func (u *AccountUpsertBulk) UpdateConcurrency() *AccountUpsertBulk {
2181
+ return u.Update(func(s *AccountUpsert) {
2182
+ s.UpdateConcurrency()
2183
+ })
2184
+ }
2185
+
2186
+ // SetLoadFactor sets the "load_factor" field.
2187
+ func (u *AccountUpsertBulk) SetLoadFactor(v int) *AccountUpsertBulk {
2188
+ return u.Update(func(s *AccountUpsert) {
2189
+ s.SetLoadFactor(v)
2190
+ })
2191
+ }
2192
+
2193
+ // AddLoadFactor adds v to the "load_factor" field.
2194
+ func (u *AccountUpsertBulk) AddLoadFactor(v int) *AccountUpsertBulk {
2195
+ return u.Update(func(s *AccountUpsert) {
2196
+ s.AddLoadFactor(v)
2197
+ })
2198
+ }
2199
+
2200
+ // UpdateLoadFactor sets the "load_factor" field to the value that was provided on create.
2201
+ func (u *AccountUpsertBulk) UpdateLoadFactor() *AccountUpsertBulk {
2202
+ return u.Update(func(s *AccountUpsert) {
2203
+ s.UpdateLoadFactor()
2204
+ })
2205
+ }
2206
+
2207
+ // ClearLoadFactor clears the value of the "load_factor" field.
2208
+ func (u *AccountUpsertBulk) ClearLoadFactor() *AccountUpsertBulk {
2209
+ return u.Update(func(s *AccountUpsert) {
2210
+ s.ClearLoadFactor()
2211
+ })
2212
+ }
2213
+
2214
+ // SetPriority sets the "priority" field.
2215
+ func (u *AccountUpsertBulk) SetPriority(v int) *AccountUpsertBulk {
2216
+ return u.Update(func(s *AccountUpsert) {
2217
+ s.SetPriority(v)
2218
+ })
2219
+ }
2220
+
2221
+ // AddPriority adds v to the "priority" field.
2222
+ func (u *AccountUpsertBulk) AddPriority(v int) *AccountUpsertBulk {
2223
+ return u.Update(func(s *AccountUpsert) {
2224
+ s.AddPriority(v)
2225
+ })
2226
+ }
2227
+
2228
+ // UpdatePriority sets the "priority" field to the value that was provided on create.
2229
+ func (u *AccountUpsertBulk) UpdatePriority() *AccountUpsertBulk {
2230
+ return u.Update(func(s *AccountUpsert) {
2231
+ s.UpdatePriority()
2232
+ })
2233
+ }
2234
+
2235
+ // SetRateMultiplier sets the "rate_multiplier" field.
2236
+ func (u *AccountUpsertBulk) SetRateMultiplier(v float64) *AccountUpsertBulk {
2237
+ return u.Update(func(s *AccountUpsert) {
2238
+ s.SetRateMultiplier(v)
2239
+ })
2240
+ }
2241
+
2242
+ // AddRateMultiplier adds v to the "rate_multiplier" field.
2243
+ func (u *AccountUpsertBulk) AddRateMultiplier(v float64) *AccountUpsertBulk {
2244
+ return u.Update(func(s *AccountUpsert) {
2245
+ s.AddRateMultiplier(v)
2246
+ })
2247
+ }
2248
+
2249
+ // UpdateRateMultiplier sets the "rate_multiplier" field to the value that was provided on create.
2250
+ func (u *AccountUpsertBulk) UpdateRateMultiplier() *AccountUpsertBulk {
2251
+ return u.Update(func(s *AccountUpsert) {
2252
+ s.UpdateRateMultiplier()
2253
+ })
2254
+ }
2255
+
2256
+ // SetStatus sets the "status" field.
2257
+ func (u *AccountUpsertBulk) SetStatus(v string) *AccountUpsertBulk {
2258
+ return u.Update(func(s *AccountUpsert) {
2259
+ s.SetStatus(v)
2260
+ })
2261
+ }
2262
+
2263
+ // UpdateStatus sets the "status" field to the value that was provided on create.
2264
+ func (u *AccountUpsertBulk) UpdateStatus() *AccountUpsertBulk {
2265
+ return u.Update(func(s *AccountUpsert) {
2266
+ s.UpdateStatus()
2267
+ })
2268
+ }
2269
+
2270
+ // SetErrorMessage sets the "error_message" field.
2271
+ func (u *AccountUpsertBulk) SetErrorMessage(v string) *AccountUpsertBulk {
2272
+ return u.Update(func(s *AccountUpsert) {
2273
+ s.SetErrorMessage(v)
2274
+ })
2275
+ }
2276
+
2277
+ // UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
2278
+ func (u *AccountUpsertBulk) UpdateErrorMessage() *AccountUpsertBulk {
2279
+ return u.Update(func(s *AccountUpsert) {
2280
+ s.UpdateErrorMessage()
2281
+ })
2282
+ }
2283
+
2284
+ // ClearErrorMessage clears the value of the "error_message" field.
2285
+ func (u *AccountUpsertBulk) ClearErrorMessage() *AccountUpsertBulk {
2286
+ return u.Update(func(s *AccountUpsert) {
2287
+ s.ClearErrorMessage()
2288
+ })
2289
+ }
2290
+
2291
+ // SetLastUsedAt sets the "last_used_at" field.
2292
+ func (u *AccountUpsertBulk) SetLastUsedAt(v time.Time) *AccountUpsertBulk {
2293
+ return u.Update(func(s *AccountUpsert) {
2294
+ s.SetLastUsedAt(v)
2295
+ })
2296
+ }
2297
+
2298
+ // UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
2299
+ func (u *AccountUpsertBulk) UpdateLastUsedAt() *AccountUpsertBulk {
2300
+ return u.Update(func(s *AccountUpsert) {
2301
+ s.UpdateLastUsedAt()
2302
+ })
2303
+ }
2304
+
2305
+ // ClearLastUsedAt clears the value of the "last_used_at" field.
2306
+ func (u *AccountUpsertBulk) ClearLastUsedAt() *AccountUpsertBulk {
2307
+ return u.Update(func(s *AccountUpsert) {
2308
+ s.ClearLastUsedAt()
2309
+ })
2310
+ }
2311
+
2312
+ // SetExpiresAt sets the "expires_at" field.
2313
+ func (u *AccountUpsertBulk) SetExpiresAt(v time.Time) *AccountUpsertBulk {
2314
+ return u.Update(func(s *AccountUpsert) {
2315
+ s.SetExpiresAt(v)
2316
+ })
2317
+ }
2318
+
2319
+ // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
2320
+ func (u *AccountUpsertBulk) UpdateExpiresAt() *AccountUpsertBulk {
2321
+ return u.Update(func(s *AccountUpsert) {
2322
+ s.UpdateExpiresAt()
2323
+ })
2324
+ }
2325
+
2326
+ // ClearExpiresAt clears the value of the "expires_at" field.
2327
+ func (u *AccountUpsertBulk) ClearExpiresAt() *AccountUpsertBulk {
2328
+ return u.Update(func(s *AccountUpsert) {
2329
+ s.ClearExpiresAt()
2330
+ })
2331
+ }
2332
+
2333
+ // SetAutoPauseOnExpired sets the "auto_pause_on_expired" field.
2334
+ func (u *AccountUpsertBulk) SetAutoPauseOnExpired(v bool) *AccountUpsertBulk {
2335
+ return u.Update(func(s *AccountUpsert) {
2336
+ s.SetAutoPauseOnExpired(v)
2337
+ })
2338
+ }
2339
+
2340
+ // UpdateAutoPauseOnExpired sets the "auto_pause_on_expired" field to the value that was provided on create.
2341
+ func (u *AccountUpsertBulk) UpdateAutoPauseOnExpired() *AccountUpsertBulk {
2342
+ return u.Update(func(s *AccountUpsert) {
2343
+ s.UpdateAutoPauseOnExpired()
2344
+ })
2345
+ }
2346
+
2347
+ // SetSchedulable sets the "schedulable" field.
2348
+ func (u *AccountUpsertBulk) SetSchedulable(v bool) *AccountUpsertBulk {
2349
+ return u.Update(func(s *AccountUpsert) {
2350
+ s.SetSchedulable(v)
2351
+ })
2352
+ }
2353
+
2354
+ // UpdateSchedulable sets the "schedulable" field to the value that was provided on create.
2355
+ func (u *AccountUpsertBulk) UpdateSchedulable() *AccountUpsertBulk {
2356
+ return u.Update(func(s *AccountUpsert) {
2357
+ s.UpdateSchedulable()
2358
+ })
2359
+ }
2360
+
2361
+ // SetRateLimitedAt sets the "rate_limited_at" field.
2362
+ func (u *AccountUpsertBulk) SetRateLimitedAt(v time.Time) *AccountUpsertBulk {
2363
+ return u.Update(func(s *AccountUpsert) {
2364
+ s.SetRateLimitedAt(v)
2365
+ })
2366
+ }
2367
+
2368
+ // UpdateRateLimitedAt sets the "rate_limited_at" field to the value that was provided on create.
2369
+ func (u *AccountUpsertBulk) UpdateRateLimitedAt() *AccountUpsertBulk {
2370
+ return u.Update(func(s *AccountUpsert) {
2371
+ s.UpdateRateLimitedAt()
2372
+ })
2373
+ }
2374
+
2375
+ // ClearRateLimitedAt clears the value of the "rate_limited_at" field.
2376
+ func (u *AccountUpsertBulk) ClearRateLimitedAt() *AccountUpsertBulk {
2377
+ return u.Update(func(s *AccountUpsert) {
2378
+ s.ClearRateLimitedAt()
2379
+ })
2380
+ }
2381
+
2382
+ // SetRateLimitResetAt sets the "rate_limit_reset_at" field.
2383
+ func (u *AccountUpsertBulk) SetRateLimitResetAt(v time.Time) *AccountUpsertBulk {
2384
+ return u.Update(func(s *AccountUpsert) {
2385
+ s.SetRateLimitResetAt(v)
2386
+ })
2387
+ }
2388
+
2389
+ // UpdateRateLimitResetAt sets the "rate_limit_reset_at" field to the value that was provided on create.
2390
+ func (u *AccountUpsertBulk) UpdateRateLimitResetAt() *AccountUpsertBulk {
2391
+ return u.Update(func(s *AccountUpsert) {
2392
+ s.UpdateRateLimitResetAt()
2393
+ })
2394
+ }
2395
+
2396
+ // ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
2397
+ func (u *AccountUpsertBulk) ClearRateLimitResetAt() *AccountUpsertBulk {
2398
+ return u.Update(func(s *AccountUpsert) {
2399
+ s.ClearRateLimitResetAt()
2400
+ })
2401
+ }
2402
+
2403
+ // SetOverloadUntil sets the "overload_until" field.
2404
+ func (u *AccountUpsertBulk) SetOverloadUntil(v time.Time) *AccountUpsertBulk {
2405
+ return u.Update(func(s *AccountUpsert) {
2406
+ s.SetOverloadUntil(v)
2407
+ })
2408
+ }
2409
+
2410
+ // UpdateOverloadUntil sets the "overload_until" field to the value that was provided on create.
2411
+ func (u *AccountUpsertBulk) UpdateOverloadUntil() *AccountUpsertBulk {
2412
+ return u.Update(func(s *AccountUpsert) {
2413
+ s.UpdateOverloadUntil()
2414
+ })
2415
+ }
2416
+
2417
+ // ClearOverloadUntil clears the value of the "overload_until" field.
2418
+ func (u *AccountUpsertBulk) ClearOverloadUntil() *AccountUpsertBulk {
2419
+ return u.Update(func(s *AccountUpsert) {
2420
+ s.ClearOverloadUntil()
2421
+ })
2422
+ }
2423
+
2424
+ // SetTempUnschedulableUntil sets the "temp_unschedulable_until" field.
2425
+ func (u *AccountUpsertBulk) SetTempUnschedulableUntil(v time.Time) *AccountUpsertBulk {
2426
+ return u.Update(func(s *AccountUpsert) {
2427
+ s.SetTempUnschedulableUntil(v)
2428
+ })
2429
+ }
2430
+
2431
+ // UpdateTempUnschedulableUntil sets the "temp_unschedulable_until" field to the value that was provided on create.
2432
+ func (u *AccountUpsertBulk) UpdateTempUnschedulableUntil() *AccountUpsertBulk {
2433
+ return u.Update(func(s *AccountUpsert) {
2434
+ s.UpdateTempUnschedulableUntil()
2435
+ })
2436
+ }
2437
+
2438
+ // ClearTempUnschedulableUntil clears the value of the "temp_unschedulable_until" field.
2439
+ func (u *AccountUpsertBulk) ClearTempUnschedulableUntil() *AccountUpsertBulk {
2440
+ return u.Update(func(s *AccountUpsert) {
2441
+ s.ClearTempUnschedulableUntil()
2442
+ })
2443
+ }
2444
+
2445
+ // SetTempUnschedulableReason sets the "temp_unschedulable_reason" field.
2446
+ func (u *AccountUpsertBulk) SetTempUnschedulableReason(v string) *AccountUpsertBulk {
2447
+ return u.Update(func(s *AccountUpsert) {
2448
+ s.SetTempUnschedulableReason(v)
2449
+ })
2450
+ }
2451
+
2452
+ // UpdateTempUnschedulableReason sets the "temp_unschedulable_reason" field to the value that was provided on create.
2453
+ func (u *AccountUpsertBulk) UpdateTempUnschedulableReason() *AccountUpsertBulk {
2454
+ return u.Update(func(s *AccountUpsert) {
2455
+ s.UpdateTempUnschedulableReason()
2456
+ })
2457
+ }
2458
+
2459
+ // ClearTempUnschedulableReason clears the value of the "temp_unschedulable_reason" field.
2460
+ func (u *AccountUpsertBulk) ClearTempUnschedulableReason() *AccountUpsertBulk {
2461
+ return u.Update(func(s *AccountUpsert) {
2462
+ s.ClearTempUnschedulableReason()
2463
+ })
2464
+ }
2465
+
2466
+ // SetSessionWindowStart sets the "session_window_start" field.
2467
+ func (u *AccountUpsertBulk) SetSessionWindowStart(v time.Time) *AccountUpsertBulk {
2468
+ return u.Update(func(s *AccountUpsert) {
2469
+ s.SetSessionWindowStart(v)
2470
+ })
2471
+ }
2472
+
2473
+ // UpdateSessionWindowStart sets the "session_window_start" field to the value that was provided on create.
2474
+ func (u *AccountUpsertBulk) UpdateSessionWindowStart() *AccountUpsertBulk {
2475
+ return u.Update(func(s *AccountUpsert) {
2476
+ s.UpdateSessionWindowStart()
2477
+ })
2478
+ }
2479
+
2480
+ // ClearSessionWindowStart clears the value of the "session_window_start" field.
2481
+ func (u *AccountUpsertBulk) ClearSessionWindowStart() *AccountUpsertBulk {
2482
+ return u.Update(func(s *AccountUpsert) {
2483
+ s.ClearSessionWindowStart()
2484
+ })
2485
+ }
2486
+
2487
+ // SetSessionWindowEnd sets the "session_window_end" field.
2488
+ func (u *AccountUpsertBulk) SetSessionWindowEnd(v time.Time) *AccountUpsertBulk {
2489
+ return u.Update(func(s *AccountUpsert) {
2490
+ s.SetSessionWindowEnd(v)
2491
+ })
2492
+ }
2493
+
2494
+ // UpdateSessionWindowEnd sets the "session_window_end" field to the value that was provided on create.
2495
+ func (u *AccountUpsertBulk) UpdateSessionWindowEnd() *AccountUpsertBulk {
2496
+ return u.Update(func(s *AccountUpsert) {
2497
+ s.UpdateSessionWindowEnd()
2498
+ })
2499
+ }
2500
+
2501
+ // ClearSessionWindowEnd clears the value of the "session_window_end" field.
2502
+ func (u *AccountUpsertBulk) ClearSessionWindowEnd() *AccountUpsertBulk {
2503
+ return u.Update(func(s *AccountUpsert) {
2504
+ s.ClearSessionWindowEnd()
2505
+ })
2506
+ }
2507
+
2508
+ // SetSessionWindowStatus sets the "session_window_status" field.
2509
+ func (u *AccountUpsertBulk) SetSessionWindowStatus(v string) *AccountUpsertBulk {
2510
+ return u.Update(func(s *AccountUpsert) {
2511
+ s.SetSessionWindowStatus(v)
2512
+ })
2513
+ }
2514
+
2515
+ // UpdateSessionWindowStatus sets the "session_window_status" field to the value that was provided on create.
2516
+ func (u *AccountUpsertBulk) UpdateSessionWindowStatus() *AccountUpsertBulk {
2517
+ return u.Update(func(s *AccountUpsert) {
2518
+ s.UpdateSessionWindowStatus()
2519
+ })
2520
+ }
2521
+
2522
+ // ClearSessionWindowStatus clears the value of the "session_window_status" field.
2523
+ func (u *AccountUpsertBulk) ClearSessionWindowStatus() *AccountUpsertBulk {
2524
+ return u.Update(func(s *AccountUpsert) {
2525
+ s.ClearSessionWindowStatus()
2526
+ })
2527
+ }
2528
+
2529
+ // Exec executes the query.
2530
+ func (u *AccountUpsertBulk) Exec(ctx context.Context) error {
2531
+ if u.create.err != nil {
2532
+ return u.create.err
2533
+ }
2534
+ for i, b := range u.create.builders {
2535
+ if len(b.conflict) != 0 {
2536
+ return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AccountCreateBulk instead", i)
2537
+ }
2538
+ }
2539
+ if len(u.create.conflict) == 0 {
2540
+ return errors.New("ent: missing options for AccountCreateBulk.OnConflict")
2541
+ }
2542
+ return u.create.Exec(ctx)
2543
+ }
2544
+
2545
+ // ExecX is like Exec, but panics if an error occurs.
2546
+ func (u *AccountUpsertBulk) ExecX(ctx context.Context) {
2547
+ if err := u.create.Exec(ctx); err != nil {
2548
+ panic(err)
2549
+ }
2550
+ }
backend/ent/account_delete.go ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+
8
+ "entgo.io/ent/dialect/sql"
9
+ "entgo.io/ent/dialect/sql/sqlgraph"
10
+ "entgo.io/ent/schema/field"
11
+ "github.com/Wei-Shaw/sub2api/ent/account"
12
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
13
+ )
14
+
15
+ // AccountDelete is the builder for deleting a Account entity.
16
+ type AccountDelete struct {
17
+ config
18
+ hooks []Hook
19
+ mutation *AccountMutation
20
+ }
21
+
22
+ // Where appends a list predicates to the AccountDelete builder.
23
+ func (_d *AccountDelete) Where(ps ...predicate.Account) *AccountDelete {
24
+ _d.mutation.Where(ps...)
25
+ return _d
26
+ }
27
+
28
+ // Exec executes the deletion query and returns how many vertices were deleted.
29
+ func (_d *AccountDelete) Exec(ctx context.Context) (int, error) {
30
+ return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
31
+ }
32
+
33
+ // ExecX is like Exec, but panics if an error occurs.
34
+ func (_d *AccountDelete) ExecX(ctx context.Context) int {
35
+ n, err := _d.Exec(ctx)
36
+ if err != nil {
37
+ panic(err)
38
+ }
39
+ return n
40
+ }
41
+
42
+ func (_d *AccountDelete) sqlExec(ctx context.Context) (int, error) {
43
+ _spec := sqlgraph.NewDeleteSpec(account.Table, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64))
44
+ if ps := _d.mutation.predicates; len(ps) > 0 {
45
+ _spec.Predicate = func(selector *sql.Selector) {
46
+ for i := range ps {
47
+ ps[i](selector)
48
+ }
49
+ }
50
+ }
51
+ affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
52
+ if err != nil && sqlgraph.IsConstraintError(err) {
53
+ err = &ConstraintError{msg: err.Error(), wrap: err}
54
+ }
55
+ _d.mutation.done = true
56
+ return affected, err
57
+ }
58
+
59
+ // AccountDeleteOne is the builder for deleting a single Account entity.
60
+ type AccountDeleteOne struct {
61
+ _d *AccountDelete
62
+ }
63
+
64
+ // Where appends a list predicates to the AccountDelete builder.
65
+ func (_d *AccountDeleteOne) Where(ps ...predicate.Account) *AccountDeleteOne {
66
+ _d._d.mutation.Where(ps...)
67
+ return _d
68
+ }
69
+
70
+ // Exec executes the deletion query.
71
+ func (_d *AccountDeleteOne) Exec(ctx context.Context) error {
72
+ n, err := _d._d.Exec(ctx)
73
+ switch {
74
+ case err != nil:
75
+ return err
76
+ case n == 0:
77
+ return &NotFoundError{account.Label}
78
+ default:
79
+ return nil
80
+ }
81
+ }
82
+
83
+ // ExecX is like Exec, but panics if an error occurs.
84
+ func (_d *AccountDeleteOne) ExecX(ctx context.Context) {
85
+ if err := _d.Exec(ctx); err != nil {
86
+ panic(err)
87
+ }
88
+ }
backend/ent/account_query.go ADDED
@@ -0,0 +1,900 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+ "database/sql/driver"
8
+ "fmt"
9
+ "math"
10
+
11
+ "entgo.io/ent"
12
+ "entgo.io/ent/dialect"
13
+ "entgo.io/ent/dialect/sql"
14
+ "entgo.io/ent/dialect/sql/sqlgraph"
15
+ "entgo.io/ent/schema/field"
16
+ "github.com/Wei-Shaw/sub2api/ent/account"
17
+ "github.com/Wei-Shaw/sub2api/ent/accountgroup"
18
+ "github.com/Wei-Shaw/sub2api/ent/group"
19
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
20
+ "github.com/Wei-Shaw/sub2api/ent/proxy"
21
+ "github.com/Wei-Shaw/sub2api/ent/usagelog"
22
+ )
23
+
24
+ // AccountQuery is the builder for querying Account entities.
25
+ type AccountQuery struct {
26
+ config
27
+ ctx *QueryContext
28
+ order []account.OrderOption
29
+ inters []Interceptor
30
+ predicates []predicate.Account
31
+ withGroups *GroupQuery
32
+ withProxy *ProxyQuery
33
+ withUsageLogs *UsageLogQuery
34
+ withAccountGroups *AccountGroupQuery
35
+ modifiers []func(*sql.Selector)
36
+ // intermediate query (i.e. traversal path).
37
+ sql *sql.Selector
38
+ path func(context.Context) (*sql.Selector, error)
39
+ }
40
+
41
+ // Where adds a new predicate for the AccountQuery builder.
42
+ func (_q *AccountQuery) Where(ps ...predicate.Account) *AccountQuery {
43
+ _q.predicates = append(_q.predicates, ps...)
44
+ return _q
45
+ }
46
+
47
+ // Limit the number of records to be returned by this query.
48
+ func (_q *AccountQuery) Limit(limit int) *AccountQuery {
49
+ _q.ctx.Limit = &limit
50
+ return _q
51
+ }
52
+
53
+ // Offset to start from.
54
+ func (_q *AccountQuery) Offset(offset int) *AccountQuery {
55
+ _q.ctx.Offset = &offset
56
+ return _q
57
+ }
58
+
59
+ // Unique configures the query builder to filter duplicate records on query.
60
+ // By default, unique is set to true, and can be disabled using this method.
61
+ func (_q *AccountQuery) Unique(unique bool) *AccountQuery {
62
+ _q.ctx.Unique = &unique
63
+ return _q
64
+ }
65
+
66
+ // Order specifies how the records should be ordered.
67
+ func (_q *AccountQuery) Order(o ...account.OrderOption) *AccountQuery {
68
+ _q.order = append(_q.order, o...)
69
+ return _q
70
+ }
71
+
72
+ // QueryGroups chains the current query on the "groups" edge.
73
+ func (_q *AccountQuery) QueryGroups() *GroupQuery {
74
+ query := (&GroupClient{config: _q.config}).Query()
75
+ query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
76
+ if err := _q.prepareQuery(ctx); err != nil {
77
+ return nil, err
78
+ }
79
+ selector := _q.sqlQuery(ctx)
80
+ if err := selector.Err(); err != nil {
81
+ return nil, err
82
+ }
83
+ step := sqlgraph.NewStep(
84
+ sqlgraph.From(account.Table, account.FieldID, selector),
85
+ sqlgraph.To(group.Table, group.FieldID),
86
+ sqlgraph.Edge(sqlgraph.M2M, false, account.GroupsTable, account.GroupsPrimaryKey...),
87
+ )
88
+ fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
89
+ return fromU, nil
90
+ }
91
+ return query
92
+ }
93
+
94
+ // QueryProxy chains the current query on the "proxy" edge.
95
+ func (_q *AccountQuery) QueryProxy() *ProxyQuery {
96
+ query := (&ProxyClient{config: _q.config}).Query()
97
+ query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
98
+ if err := _q.prepareQuery(ctx); err != nil {
99
+ return nil, err
100
+ }
101
+ selector := _q.sqlQuery(ctx)
102
+ if err := selector.Err(); err != nil {
103
+ return nil, err
104
+ }
105
+ step := sqlgraph.NewStep(
106
+ sqlgraph.From(account.Table, account.FieldID, selector),
107
+ sqlgraph.To(proxy.Table, proxy.FieldID),
108
+ sqlgraph.Edge(sqlgraph.M2O, false, account.ProxyTable, account.ProxyColumn),
109
+ )
110
+ fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
111
+ return fromU, nil
112
+ }
113
+ return query
114
+ }
115
+
116
+ // QueryUsageLogs chains the current query on the "usage_logs" edge.
117
+ func (_q *AccountQuery) QueryUsageLogs() *UsageLogQuery {
118
+ query := (&UsageLogClient{config: _q.config}).Query()
119
+ query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
120
+ if err := _q.prepareQuery(ctx); err != nil {
121
+ return nil, err
122
+ }
123
+ selector := _q.sqlQuery(ctx)
124
+ if err := selector.Err(); err != nil {
125
+ return nil, err
126
+ }
127
+ step := sqlgraph.NewStep(
128
+ sqlgraph.From(account.Table, account.FieldID, selector),
129
+ sqlgraph.To(usagelog.Table, usagelog.FieldID),
130
+ sqlgraph.Edge(sqlgraph.O2M, false, account.UsageLogsTable, account.UsageLogsColumn),
131
+ )
132
+ fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
133
+ return fromU, nil
134
+ }
135
+ return query
136
+ }
137
+
138
+ // QueryAccountGroups chains the current query on the "account_groups" edge.
139
+ func (_q *AccountQuery) QueryAccountGroups() *AccountGroupQuery {
140
+ query := (&AccountGroupClient{config: _q.config}).Query()
141
+ query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
142
+ if err := _q.prepareQuery(ctx); err != nil {
143
+ return nil, err
144
+ }
145
+ selector := _q.sqlQuery(ctx)
146
+ if err := selector.Err(); err != nil {
147
+ return nil, err
148
+ }
149
+ step := sqlgraph.NewStep(
150
+ sqlgraph.From(account.Table, account.FieldID, selector),
151
+ sqlgraph.To(accountgroup.Table, accountgroup.AccountColumn),
152
+ sqlgraph.Edge(sqlgraph.O2M, true, account.AccountGroupsTable, account.AccountGroupsColumn),
153
+ )
154
+ fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
155
+ return fromU, nil
156
+ }
157
+ return query
158
+ }
159
+
160
+ // First returns the first Account entity from the query.
161
+ // Returns a *NotFoundError when no Account was found.
162
+ func (_q *AccountQuery) First(ctx context.Context) (*Account, error) {
163
+ nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
164
+ if err != nil {
165
+ return nil, err
166
+ }
167
+ if len(nodes) == 0 {
168
+ return nil, &NotFoundError{account.Label}
169
+ }
170
+ return nodes[0], nil
171
+ }
172
+
173
+ // FirstX is like First, but panics if an error occurs.
174
+ func (_q *AccountQuery) FirstX(ctx context.Context) *Account {
175
+ node, err := _q.First(ctx)
176
+ if err != nil && !IsNotFound(err) {
177
+ panic(err)
178
+ }
179
+ return node
180
+ }
181
+
182
+ // FirstID returns the first Account ID from the query.
183
+ // Returns a *NotFoundError when no Account ID was found.
184
+ func (_q *AccountQuery) FirstID(ctx context.Context) (id int64, err error) {
185
+ var ids []int64
186
+ if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
187
+ return
188
+ }
189
+ if len(ids) == 0 {
190
+ err = &NotFoundError{account.Label}
191
+ return
192
+ }
193
+ return ids[0], nil
194
+ }
195
+
196
+ // FirstIDX is like FirstID, but panics if an error occurs.
197
+ func (_q *AccountQuery) FirstIDX(ctx context.Context) int64 {
198
+ id, err := _q.FirstID(ctx)
199
+ if err != nil && !IsNotFound(err) {
200
+ panic(err)
201
+ }
202
+ return id
203
+ }
204
+
205
+ // Only returns a single Account entity found by the query, ensuring it only returns one.
206
+ // Returns a *NotSingularError when more than one Account entity is found.
207
+ // Returns a *NotFoundError when no Account entities are found.
208
+ func (_q *AccountQuery) Only(ctx context.Context) (*Account, error) {
209
+ nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
210
+ if err != nil {
211
+ return nil, err
212
+ }
213
+ switch len(nodes) {
214
+ case 1:
215
+ return nodes[0], nil
216
+ case 0:
217
+ return nil, &NotFoundError{account.Label}
218
+ default:
219
+ return nil, &NotSingularError{account.Label}
220
+ }
221
+ }
222
+
223
+ // OnlyX is like Only, but panics if an error occurs.
224
+ func (_q *AccountQuery) OnlyX(ctx context.Context) *Account {
225
+ node, err := _q.Only(ctx)
226
+ if err != nil {
227
+ panic(err)
228
+ }
229
+ return node
230
+ }
231
+
232
+ // OnlyID is like Only, but returns the only Account ID in the query.
233
+ // Returns a *NotSingularError when more than one Account ID is found.
234
+ // Returns a *NotFoundError when no entities are found.
235
+ func (_q *AccountQuery) OnlyID(ctx context.Context) (id int64, err error) {
236
+ var ids []int64
237
+ if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
238
+ return
239
+ }
240
+ switch len(ids) {
241
+ case 1:
242
+ id = ids[0]
243
+ case 0:
244
+ err = &NotFoundError{account.Label}
245
+ default:
246
+ err = &NotSingularError{account.Label}
247
+ }
248
+ return
249
+ }
250
+
251
+ // OnlyIDX is like OnlyID, but panics if an error occurs.
252
+ func (_q *AccountQuery) OnlyIDX(ctx context.Context) int64 {
253
+ id, err := _q.OnlyID(ctx)
254
+ if err != nil {
255
+ panic(err)
256
+ }
257
+ return id
258
+ }
259
+
260
+ // All executes the query and returns a list of Accounts.
261
+ func (_q *AccountQuery) All(ctx context.Context) ([]*Account, error) {
262
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
263
+ if err := _q.prepareQuery(ctx); err != nil {
264
+ return nil, err
265
+ }
266
+ qr := querierAll[[]*Account, *AccountQuery]()
267
+ return withInterceptors[[]*Account](ctx, _q, qr, _q.inters)
268
+ }
269
+
270
+ // AllX is like All, but panics if an error occurs.
271
+ func (_q *AccountQuery) AllX(ctx context.Context) []*Account {
272
+ nodes, err := _q.All(ctx)
273
+ if err != nil {
274
+ panic(err)
275
+ }
276
+ return nodes
277
+ }
278
+
279
+ // IDs executes the query and returns a list of Account IDs.
280
+ func (_q *AccountQuery) IDs(ctx context.Context) (ids []int64, err error) {
281
+ if _q.ctx.Unique == nil && _q.path != nil {
282
+ _q.Unique(true)
283
+ }
284
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
285
+ if err = _q.Select(account.FieldID).Scan(ctx, &ids); err != nil {
286
+ return nil, err
287
+ }
288
+ return ids, nil
289
+ }
290
+
291
+ // IDsX is like IDs, but panics if an error occurs.
292
+ func (_q *AccountQuery) IDsX(ctx context.Context) []int64 {
293
+ ids, err := _q.IDs(ctx)
294
+ if err != nil {
295
+ panic(err)
296
+ }
297
+ return ids
298
+ }
299
+
300
+ // Count returns the count of the given query.
301
+ func (_q *AccountQuery) Count(ctx context.Context) (int, error) {
302
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
303
+ if err := _q.prepareQuery(ctx); err != nil {
304
+ return 0, err
305
+ }
306
+ return withInterceptors[int](ctx, _q, querierCount[*AccountQuery](), _q.inters)
307
+ }
308
+
309
+ // CountX is like Count, but panics if an error occurs.
310
+ func (_q *AccountQuery) CountX(ctx context.Context) int {
311
+ count, err := _q.Count(ctx)
312
+ if err != nil {
313
+ panic(err)
314
+ }
315
+ return count
316
+ }
317
+
318
+ // Exist returns true if the query has elements in the graph.
319
+ func (_q *AccountQuery) Exist(ctx context.Context) (bool, error) {
320
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
321
+ switch _, err := _q.FirstID(ctx); {
322
+ case IsNotFound(err):
323
+ return false, nil
324
+ case err != nil:
325
+ return false, fmt.Errorf("ent: check existence: %w", err)
326
+ default:
327
+ return true, nil
328
+ }
329
+ }
330
+
331
+ // ExistX is like Exist, but panics if an error occurs.
332
+ func (_q *AccountQuery) ExistX(ctx context.Context) bool {
333
+ exist, err := _q.Exist(ctx)
334
+ if err != nil {
335
+ panic(err)
336
+ }
337
+ return exist
338
+ }
339
+
340
+ // Clone returns a duplicate of the AccountQuery builder, including all associated steps. It can be
341
+ // used to prepare common query builders and use them differently after the clone is made.
342
+ func (_q *AccountQuery) Clone() *AccountQuery {
343
+ if _q == nil {
344
+ return nil
345
+ }
346
+ return &AccountQuery{
347
+ config: _q.config,
348
+ ctx: _q.ctx.Clone(),
349
+ order: append([]account.OrderOption{}, _q.order...),
350
+ inters: append([]Interceptor{}, _q.inters...),
351
+ predicates: append([]predicate.Account{}, _q.predicates...),
352
+ withGroups: _q.withGroups.Clone(),
353
+ withProxy: _q.withProxy.Clone(),
354
+ withUsageLogs: _q.withUsageLogs.Clone(),
355
+ withAccountGroups: _q.withAccountGroups.Clone(),
356
+ // clone intermediate query.
357
+ sql: _q.sql.Clone(),
358
+ path: _q.path,
359
+ }
360
+ }
361
+
362
+ // WithGroups tells the query-builder to eager-load the nodes that are connected to
363
+ // the "groups" edge. The optional arguments are used to configure the query builder of the edge.
364
+ func (_q *AccountQuery) WithGroups(opts ...func(*GroupQuery)) *AccountQuery {
365
+ query := (&GroupClient{config: _q.config}).Query()
366
+ for _, opt := range opts {
367
+ opt(query)
368
+ }
369
+ _q.withGroups = query
370
+ return _q
371
+ }
372
+
373
+ // WithProxy tells the query-builder to eager-load the nodes that are connected to
374
+ // the "proxy" edge. The optional arguments are used to configure the query builder of the edge.
375
+ func (_q *AccountQuery) WithProxy(opts ...func(*ProxyQuery)) *AccountQuery {
376
+ query := (&ProxyClient{config: _q.config}).Query()
377
+ for _, opt := range opts {
378
+ opt(query)
379
+ }
380
+ _q.withProxy = query
381
+ return _q
382
+ }
383
+
384
+ // WithUsageLogs tells the query-builder to eager-load the nodes that are connected to
385
+ // the "usage_logs" edge. The optional arguments are used to configure the query builder of the edge.
386
+ func (_q *AccountQuery) WithUsageLogs(opts ...func(*UsageLogQuery)) *AccountQuery {
387
+ query := (&UsageLogClient{config: _q.config}).Query()
388
+ for _, opt := range opts {
389
+ opt(query)
390
+ }
391
+ _q.withUsageLogs = query
392
+ return _q
393
+ }
394
+
395
+ // WithAccountGroups tells the query-builder to eager-load the nodes that are connected to
396
+ // the "account_groups" edge. The optional arguments are used to configure the query builder of the edge.
397
+ func (_q *AccountQuery) WithAccountGroups(opts ...func(*AccountGroupQuery)) *AccountQuery {
398
+ query := (&AccountGroupClient{config: _q.config}).Query()
399
+ for _, opt := range opts {
400
+ opt(query)
401
+ }
402
+ _q.withAccountGroups = query
403
+ return _q
404
+ }
405
+
406
+ // GroupBy is used to group vertices by one or more fields/columns.
407
+ // It is often used with aggregate functions, like: count, max, mean, min, sum.
408
+ //
409
+ // Example:
410
+ //
411
+ // var v []struct {
412
+ // CreatedAt time.Time `json:"created_at,omitempty"`
413
+ // Count int `json:"count,omitempty"`
414
+ // }
415
+ //
416
+ // client.Account.Query().
417
+ // GroupBy(account.FieldCreatedAt).
418
+ // Aggregate(ent.Count()).
419
+ // Scan(ctx, &v)
420
+ func (_q *AccountQuery) GroupBy(field string, fields ...string) *AccountGroupBy {
421
+ _q.ctx.Fields = append([]string{field}, fields...)
422
+ grbuild := &AccountGroupBy{build: _q}
423
+ grbuild.flds = &_q.ctx.Fields
424
+ grbuild.label = account.Label
425
+ grbuild.scan = grbuild.Scan
426
+ return grbuild
427
+ }
428
+
429
+ // Select allows the selection one or more fields/columns for the given query,
430
+ // instead of selecting all fields in the entity.
431
+ //
432
+ // Example:
433
+ //
434
+ // var v []struct {
435
+ // CreatedAt time.Time `json:"created_at,omitempty"`
436
+ // }
437
+ //
438
+ // client.Account.Query().
439
+ // Select(account.FieldCreatedAt).
440
+ // Scan(ctx, &v)
441
+ func (_q *AccountQuery) Select(fields ...string) *AccountSelect {
442
+ _q.ctx.Fields = append(_q.ctx.Fields, fields...)
443
+ sbuild := &AccountSelect{AccountQuery: _q}
444
+ sbuild.label = account.Label
445
+ sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
446
+ return sbuild
447
+ }
448
+
449
+ // Aggregate returns a AccountSelect configured with the given aggregations.
450
+ func (_q *AccountQuery) Aggregate(fns ...AggregateFunc) *AccountSelect {
451
+ return _q.Select().Aggregate(fns...)
452
+ }
453
+
454
+ func (_q *AccountQuery) prepareQuery(ctx context.Context) error {
455
+ for _, inter := range _q.inters {
456
+ if inter == nil {
457
+ return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
458
+ }
459
+ if trv, ok := inter.(Traverser); ok {
460
+ if err := trv.Traverse(ctx, _q); err != nil {
461
+ return err
462
+ }
463
+ }
464
+ }
465
+ for _, f := range _q.ctx.Fields {
466
+ if !account.ValidColumn(f) {
467
+ return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
468
+ }
469
+ }
470
+ if _q.path != nil {
471
+ prev, err := _q.path(ctx)
472
+ if err != nil {
473
+ return err
474
+ }
475
+ _q.sql = prev
476
+ }
477
+ return nil
478
+ }
479
+
480
+ func (_q *AccountQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Account, error) {
481
+ var (
482
+ nodes = []*Account{}
483
+ _spec = _q.querySpec()
484
+ loadedTypes = [4]bool{
485
+ _q.withGroups != nil,
486
+ _q.withProxy != nil,
487
+ _q.withUsageLogs != nil,
488
+ _q.withAccountGroups != nil,
489
+ }
490
+ )
491
+ _spec.ScanValues = func(columns []string) ([]any, error) {
492
+ return (*Account).scanValues(nil, columns)
493
+ }
494
+ _spec.Assign = func(columns []string, values []any) error {
495
+ node := &Account{config: _q.config}
496
+ nodes = append(nodes, node)
497
+ node.Edges.loadedTypes = loadedTypes
498
+ return node.assignValues(columns, values)
499
+ }
500
+ if len(_q.modifiers) > 0 {
501
+ _spec.Modifiers = _q.modifiers
502
+ }
503
+ for i := range hooks {
504
+ hooks[i](ctx, _spec)
505
+ }
506
+ if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
507
+ return nil, err
508
+ }
509
+ if len(nodes) == 0 {
510
+ return nodes, nil
511
+ }
512
+ if query := _q.withGroups; query != nil {
513
+ if err := _q.loadGroups(ctx, query, nodes,
514
+ func(n *Account) { n.Edges.Groups = []*Group{} },
515
+ func(n *Account, e *Group) { n.Edges.Groups = append(n.Edges.Groups, e) }); err != nil {
516
+ return nil, err
517
+ }
518
+ }
519
+ if query := _q.withProxy; query != nil {
520
+ if err := _q.loadProxy(ctx, query, nodes, nil,
521
+ func(n *Account, e *Proxy) { n.Edges.Proxy = e }); err != nil {
522
+ return nil, err
523
+ }
524
+ }
525
+ if query := _q.withUsageLogs; query != nil {
526
+ if err := _q.loadUsageLogs(ctx, query, nodes,
527
+ func(n *Account) { n.Edges.UsageLogs = []*UsageLog{} },
528
+ func(n *Account, e *UsageLog) { n.Edges.UsageLogs = append(n.Edges.UsageLogs, e) }); err != nil {
529
+ return nil, err
530
+ }
531
+ }
532
+ if query := _q.withAccountGroups; query != nil {
533
+ if err := _q.loadAccountGroups(ctx, query, nodes,
534
+ func(n *Account) { n.Edges.AccountGroups = []*AccountGroup{} },
535
+ func(n *Account, e *AccountGroup) { n.Edges.AccountGroups = append(n.Edges.AccountGroups, e) }); err != nil {
536
+ return nil, err
537
+ }
538
+ }
539
+ return nodes, nil
540
+ }
541
+
542
+ func (_q *AccountQuery) loadGroups(ctx context.Context, query *GroupQuery, nodes []*Account, init func(*Account), assign func(*Account, *Group)) error {
543
+ edgeIDs := make([]driver.Value, len(nodes))
544
+ byID := make(map[int64]*Account)
545
+ nids := make(map[int64]map[*Account]struct{})
546
+ for i, node := range nodes {
547
+ edgeIDs[i] = node.ID
548
+ byID[node.ID] = node
549
+ if init != nil {
550
+ init(node)
551
+ }
552
+ }
553
+ query.Where(func(s *sql.Selector) {
554
+ joinT := sql.Table(account.GroupsTable)
555
+ s.Join(joinT).On(s.C(group.FieldID), joinT.C(account.GroupsPrimaryKey[1]))
556
+ s.Where(sql.InValues(joinT.C(account.GroupsPrimaryKey[0]), edgeIDs...))
557
+ columns := s.SelectedColumns()
558
+ s.Select(joinT.C(account.GroupsPrimaryKey[0]))
559
+ s.AppendSelect(columns...)
560
+ s.SetDistinct(false)
561
+ })
562
+ if err := query.prepareQuery(ctx); err != nil {
563
+ return err
564
+ }
565
+ qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
566
+ return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
567
+ assign := spec.Assign
568
+ values := spec.ScanValues
569
+ spec.ScanValues = func(columns []string) ([]any, error) {
570
+ values, err := values(columns[1:])
571
+ if err != nil {
572
+ return nil, err
573
+ }
574
+ return append([]any{new(sql.NullInt64)}, values...), nil
575
+ }
576
+ spec.Assign = func(columns []string, values []any) error {
577
+ outValue := values[0].(*sql.NullInt64).Int64
578
+ inValue := values[1].(*sql.NullInt64).Int64
579
+ if nids[inValue] == nil {
580
+ nids[inValue] = map[*Account]struct{}{byID[outValue]: {}}
581
+ return assign(columns[1:], values[1:])
582
+ }
583
+ nids[inValue][byID[outValue]] = struct{}{}
584
+ return nil
585
+ }
586
+ })
587
+ })
588
+ neighbors, err := withInterceptors[[]*Group](ctx, query, qr, query.inters)
589
+ if err != nil {
590
+ return err
591
+ }
592
+ for _, n := range neighbors {
593
+ nodes, ok := nids[n.ID]
594
+ if !ok {
595
+ return fmt.Errorf(`unexpected "groups" node returned %v`, n.ID)
596
+ }
597
+ for kn := range nodes {
598
+ assign(kn, n)
599
+ }
600
+ }
601
+ return nil
602
+ }
603
+ func (_q *AccountQuery) loadProxy(ctx context.Context, query *ProxyQuery, nodes []*Account, init func(*Account), assign func(*Account, *Proxy)) error {
604
+ ids := make([]int64, 0, len(nodes))
605
+ nodeids := make(map[int64][]*Account)
606
+ for i := range nodes {
607
+ if nodes[i].ProxyID == nil {
608
+ continue
609
+ }
610
+ fk := *nodes[i].ProxyID
611
+ if _, ok := nodeids[fk]; !ok {
612
+ ids = append(ids, fk)
613
+ }
614
+ nodeids[fk] = append(nodeids[fk], nodes[i])
615
+ }
616
+ if len(ids) == 0 {
617
+ return nil
618
+ }
619
+ query.Where(proxy.IDIn(ids...))
620
+ neighbors, err := query.All(ctx)
621
+ if err != nil {
622
+ return err
623
+ }
624
+ for _, n := range neighbors {
625
+ nodes, ok := nodeids[n.ID]
626
+ if !ok {
627
+ return fmt.Errorf(`unexpected foreign-key "proxy_id" returned %v`, n.ID)
628
+ }
629
+ for i := range nodes {
630
+ assign(nodes[i], n)
631
+ }
632
+ }
633
+ return nil
634
+ }
635
+ func (_q *AccountQuery) loadUsageLogs(ctx context.Context, query *UsageLogQuery, nodes []*Account, init func(*Account), assign func(*Account, *UsageLog)) error {
636
+ fks := make([]driver.Value, 0, len(nodes))
637
+ nodeids := make(map[int64]*Account)
638
+ for i := range nodes {
639
+ fks = append(fks, nodes[i].ID)
640
+ nodeids[nodes[i].ID] = nodes[i]
641
+ if init != nil {
642
+ init(nodes[i])
643
+ }
644
+ }
645
+ if len(query.ctx.Fields) > 0 {
646
+ query.ctx.AppendFieldOnce(usagelog.FieldAccountID)
647
+ }
648
+ query.Where(predicate.UsageLog(func(s *sql.Selector) {
649
+ s.Where(sql.InValues(s.C(account.UsageLogsColumn), fks...))
650
+ }))
651
+ neighbors, err := query.All(ctx)
652
+ if err != nil {
653
+ return err
654
+ }
655
+ for _, n := range neighbors {
656
+ fk := n.AccountID
657
+ node, ok := nodeids[fk]
658
+ if !ok {
659
+ return fmt.Errorf(`unexpected referenced foreign-key "account_id" returned %v for node %v`, fk, n.ID)
660
+ }
661
+ assign(node, n)
662
+ }
663
+ return nil
664
+ }
665
+ func (_q *AccountQuery) loadAccountGroups(ctx context.Context, query *AccountGroupQuery, nodes []*Account, init func(*Account), assign func(*Account, *AccountGroup)) error {
666
+ fks := make([]driver.Value, 0, len(nodes))
667
+ nodeids := make(map[int64]*Account)
668
+ for i := range nodes {
669
+ fks = append(fks, nodes[i].ID)
670
+ nodeids[nodes[i].ID] = nodes[i]
671
+ if init != nil {
672
+ init(nodes[i])
673
+ }
674
+ }
675
+ if len(query.ctx.Fields) > 0 {
676
+ query.ctx.AppendFieldOnce(accountgroup.FieldAccountID)
677
+ }
678
+ query.Where(predicate.AccountGroup(func(s *sql.Selector) {
679
+ s.Where(sql.InValues(s.C(account.AccountGroupsColumn), fks...))
680
+ }))
681
+ neighbors, err := query.All(ctx)
682
+ if err != nil {
683
+ return err
684
+ }
685
+ for _, n := range neighbors {
686
+ fk := n.AccountID
687
+ node, ok := nodeids[fk]
688
+ if !ok {
689
+ return fmt.Errorf(`unexpected referenced foreign-key "account_id" returned %v for node %v`, fk, n)
690
+ }
691
+ assign(node, n)
692
+ }
693
+ return nil
694
+ }
695
+
696
+ func (_q *AccountQuery) sqlCount(ctx context.Context) (int, error) {
697
+ _spec := _q.querySpec()
698
+ if len(_q.modifiers) > 0 {
699
+ _spec.Modifiers = _q.modifiers
700
+ }
701
+ _spec.Node.Columns = _q.ctx.Fields
702
+ if len(_q.ctx.Fields) > 0 {
703
+ _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
704
+ }
705
+ return sqlgraph.CountNodes(ctx, _q.driver, _spec)
706
+ }
707
+
708
+ func (_q *AccountQuery) querySpec() *sqlgraph.QuerySpec {
709
+ _spec := sqlgraph.NewQuerySpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64))
710
+ _spec.From = _q.sql
711
+ if unique := _q.ctx.Unique; unique != nil {
712
+ _spec.Unique = *unique
713
+ } else if _q.path != nil {
714
+ _spec.Unique = true
715
+ }
716
+ if fields := _q.ctx.Fields; len(fields) > 0 {
717
+ _spec.Node.Columns = make([]string, 0, len(fields))
718
+ _spec.Node.Columns = append(_spec.Node.Columns, account.FieldID)
719
+ for i := range fields {
720
+ if fields[i] != account.FieldID {
721
+ _spec.Node.Columns = append(_spec.Node.Columns, fields[i])
722
+ }
723
+ }
724
+ if _q.withProxy != nil {
725
+ _spec.Node.AddColumnOnce(account.FieldProxyID)
726
+ }
727
+ }
728
+ if ps := _q.predicates; len(ps) > 0 {
729
+ _spec.Predicate = func(selector *sql.Selector) {
730
+ for i := range ps {
731
+ ps[i](selector)
732
+ }
733
+ }
734
+ }
735
+ if limit := _q.ctx.Limit; limit != nil {
736
+ _spec.Limit = *limit
737
+ }
738
+ if offset := _q.ctx.Offset; offset != nil {
739
+ _spec.Offset = *offset
740
+ }
741
+ if ps := _q.order; len(ps) > 0 {
742
+ _spec.Order = func(selector *sql.Selector) {
743
+ for i := range ps {
744
+ ps[i](selector)
745
+ }
746
+ }
747
+ }
748
+ return _spec
749
+ }
750
+
751
+ func (_q *AccountQuery) sqlQuery(ctx context.Context) *sql.Selector {
752
+ builder := sql.Dialect(_q.driver.Dialect())
753
+ t1 := builder.Table(account.Table)
754
+ columns := _q.ctx.Fields
755
+ if len(columns) == 0 {
756
+ columns = account.Columns
757
+ }
758
+ selector := builder.Select(t1.Columns(columns...)...).From(t1)
759
+ if _q.sql != nil {
760
+ selector = _q.sql
761
+ selector.Select(selector.Columns(columns...)...)
762
+ }
763
+ if _q.ctx.Unique != nil && *_q.ctx.Unique {
764
+ selector.Distinct()
765
+ }
766
+ for _, m := range _q.modifiers {
767
+ m(selector)
768
+ }
769
+ for _, p := range _q.predicates {
770
+ p(selector)
771
+ }
772
+ for _, p := range _q.order {
773
+ p(selector)
774
+ }
775
+ if offset := _q.ctx.Offset; offset != nil {
776
+ // limit is mandatory for offset clause. We start
777
+ // with default value, and override it below if needed.
778
+ selector.Offset(*offset).Limit(math.MaxInt32)
779
+ }
780
+ if limit := _q.ctx.Limit; limit != nil {
781
+ selector.Limit(*limit)
782
+ }
783
+ return selector
784
+ }
785
+
786
+ // ForUpdate locks the selected rows against concurrent updates, and prevent them from being
787
+ // updated, deleted or "selected ... for update" by other sessions, until the transaction is
788
+ // either committed or rolled-back.
789
+ func (_q *AccountQuery) ForUpdate(opts ...sql.LockOption) *AccountQuery {
790
+ if _q.driver.Dialect() == dialect.Postgres {
791
+ _q.Unique(false)
792
+ }
793
+ _q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
794
+ s.ForUpdate(opts...)
795
+ })
796
+ return _q
797
+ }
798
+
799
+ // ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
800
+ // on any rows that are read. Other sessions can read the rows, but cannot modify them
801
+ // until your transaction commits.
802
+ func (_q *AccountQuery) ForShare(opts ...sql.LockOption) *AccountQuery {
803
+ if _q.driver.Dialect() == dialect.Postgres {
804
+ _q.Unique(false)
805
+ }
806
+ _q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
807
+ s.ForShare(opts...)
808
+ })
809
+ return _q
810
+ }
811
+
812
+ // AccountGroupBy is the group-by builder for Account entities.
813
+ type AccountGroupBy struct {
814
+ selector
815
+ build *AccountQuery
816
+ }
817
+
818
+ // Aggregate adds the given aggregation functions to the group-by query.
819
+ func (_g *AccountGroupBy) Aggregate(fns ...AggregateFunc) *AccountGroupBy {
820
+ _g.fns = append(_g.fns, fns...)
821
+ return _g
822
+ }
823
+
824
+ // Scan applies the selector query and scans the result into the given value.
825
+ func (_g *AccountGroupBy) Scan(ctx context.Context, v any) error {
826
+ ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
827
+ if err := _g.build.prepareQuery(ctx); err != nil {
828
+ return err
829
+ }
830
+ return scanWithInterceptors[*AccountQuery, *AccountGroupBy](ctx, _g.build, _g, _g.build.inters, v)
831
+ }
832
+
833
+ func (_g *AccountGroupBy) sqlScan(ctx context.Context, root *AccountQuery, v any) error {
834
+ selector := root.sqlQuery(ctx).Select()
835
+ aggregation := make([]string, 0, len(_g.fns))
836
+ for _, fn := range _g.fns {
837
+ aggregation = append(aggregation, fn(selector))
838
+ }
839
+ if len(selector.SelectedColumns()) == 0 {
840
+ columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
841
+ for _, f := range *_g.flds {
842
+ columns = append(columns, selector.C(f))
843
+ }
844
+ columns = append(columns, aggregation...)
845
+ selector.Select(columns...)
846
+ }
847
+ selector.GroupBy(selector.Columns(*_g.flds...)...)
848
+ if err := selector.Err(); err != nil {
849
+ return err
850
+ }
851
+ rows := &sql.Rows{}
852
+ query, args := selector.Query()
853
+ if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
854
+ return err
855
+ }
856
+ defer rows.Close()
857
+ return sql.ScanSlice(rows, v)
858
+ }
859
+
860
+ // AccountSelect is the builder for selecting fields of Account entities.
861
+ type AccountSelect struct {
862
+ *AccountQuery
863
+ selector
864
+ }
865
+
866
+ // Aggregate adds the given aggregation functions to the selector query.
867
+ func (_s *AccountSelect) Aggregate(fns ...AggregateFunc) *AccountSelect {
868
+ _s.fns = append(_s.fns, fns...)
869
+ return _s
870
+ }
871
+
872
+ // Scan applies the selector query and scans the result into the given value.
873
+ func (_s *AccountSelect) Scan(ctx context.Context, v any) error {
874
+ ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
875
+ if err := _s.prepareQuery(ctx); err != nil {
876
+ return err
877
+ }
878
+ return scanWithInterceptors[*AccountQuery, *AccountSelect](ctx, _s.AccountQuery, _s, _s.inters, v)
879
+ }
880
+
881
+ func (_s *AccountSelect) sqlScan(ctx context.Context, root *AccountQuery, v any) error {
882
+ selector := root.sqlQuery(ctx)
883
+ aggregation := make([]string, 0, len(_s.fns))
884
+ for _, fn := range _s.fns {
885
+ aggregation = append(aggregation, fn(selector))
886
+ }
887
+ switch n := len(*_s.selector.flds); {
888
+ case n == 0 && len(aggregation) > 0:
889
+ selector.Select(aggregation...)
890
+ case n != 0 && len(aggregation) > 0:
891
+ selector.AppendSelect(aggregation...)
892
+ }
893
+ rows := &sql.Rows{}
894
+ query, args := selector.Query()
895
+ if err := _s.driver.Query(ctx, query, args, rows); err != nil {
896
+ return err
897
+ }
898
+ defer rows.Close()
899
+ return sql.ScanSlice(rows, v)
900
+ }
backend/ent/account_update.go ADDED
@@ -0,0 +1,1911 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+ "errors"
8
+ "fmt"
9
+ "time"
10
+
11
+ "entgo.io/ent/dialect/sql"
12
+ "entgo.io/ent/dialect/sql/sqlgraph"
13
+ "entgo.io/ent/schema/field"
14
+ "github.com/Wei-Shaw/sub2api/ent/account"
15
+ "github.com/Wei-Shaw/sub2api/ent/group"
16
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
17
+ "github.com/Wei-Shaw/sub2api/ent/proxy"
18
+ "github.com/Wei-Shaw/sub2api/ent/usagelog"
19
+ )
20
+
21
+ // AccountUpdate is the builder for updating Account entities.
22
+ type AccountUpdate struct {
23
+ config
24
+ hooks []Hook
25
+ mutation *AccountMutation
26
+ }
27
+
28
+ // Where appends a list predicates to the AccountUpdate builder.
29
+ func (_u *AccountUpdate) Where(ps ...predicate.Account) *AccountUpdate {
30
+ _u.mutation.Where(ps...)
31
+ return _u
32
+ }
33
+
34
+ // SetUpdatedAt sets the "updated_at" field.
35
+ func (_u *AccountUpdate) SetUpdatedAt(v time.Time) *AccountUpdate {
36
+ _u.mutation.SetUpdatedAt(v)
37
+ return _u
38
+ }
39
+
40
+ // SetDeletedAt sets the "deleted_at" field.
41
+ func (_u *AccountUpdate) SetDeletedAt(v time.Time) *AccountUpdate {
42
+ _u.mutation.SetDeletedAt(v)
43
+ return _u
44
+ }
45
+
46
+ // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
47
+ func (_u *AccountUpdate) SetNillableDeletedAt(v *time.Time) *AccountUpdate {
48
+ if v != nil {
49
+ _u.SetDeletedAt(*v)
50
+ }
51
+ return _u
52
+ }
53
+
54
+ // ClearDeletedAt clears the value of the "deleted_at" field.
55
+ func (_u *AccountUpdate) ClearDeletedAt() *AccountUpdate {
56
+ _u.mutation.ClearDeletedAt()
57
+ return _u
58
+ }
59
+
60
+ // SetName sets the "name" field.
61
+ func (_u *AccountUpdate) SetName(v string) *AccountUpdate {
62
+ _u.mutation.SetName(v)
63
+ return _u
64
+ }
65
+
66
+ // SetNillableName sets the "name" field if the given value is not nil.
67
+ func (_u *AccountUpdate) SetNillableName(v *string) *AccountUpdate {
68
+ if v != nil {
69
+ _u.SetName(*v)
70
+ }
71
+ return _u
72
+ }
73
+
74
+ // SetNotes sets the "notes" field.
75
+ func (_u *AccountUpdate) SetNotes(v string) *AccountUpdate {
76
+ _u.mutation.SetNotes(v)
77
+ return _u
78
+ }
79
+
80
+ // SetNillableNotes sets the "notes" field if the given value is not nil.
81
+ func (_u *AccountUpdate) SetNillableNotes(v *string) *AccountUpdate {
82
+ if v != nil {
83
+ _u.SetNotes(*v)
84
+ }
85
+ return _u
86
+ }
87
+
88
+ // ClearNotes clears the value of the "notes" field.
89
+ func (_u *AccountUpdate) ClearNotes() *AccountUpdate {
90
+ _u.mutation.ClearNotes()
91
+ return _u
92
+ }
93
+
94
+ // SetPlatform sets the "platform" field.
95
+ func (_u *AccountUpdate) SetPlatform(v string) *AccountUpdate {
96
+ _u.mutation.SetPlatform(v)
97
+ return _u
98
+ }
99
+
100
+ // SetNillablePlatform sets the "platform" field if the given value is not nil.
101
+ func (_u *AccountUpdate) SetNillablePlatform(v *string) *AccountUpdate {
102
+ if v != nil {
103
+ _u.SetPlatform(*v)
104
+ }
105
+ return _u
106
+ }
107
+
108
+ // SetType sets the "type" field.
109
+ func (_u *AccountUpdate) SetType(v string) *AccountUpdate {
110
+ _u.mutation.SetType(v)
111
+ return _u
112
+ }
113
+
114
+ // SetNillableType sets the "type" field if the given value is not nil.
115
+ func (_u *AccountUpdate) SetNillableType(v *string) *AccountUpdate {
116
+ if v != nil {
117
+ _u.SetType(*v)
118
+ }
119
+ return _u
120
+ }
121
+
122
+ // SetCredentials sets the "credentials" field.
123
+ func (_u *AccountUpdate) SetCredentials(v map[string]interface{}) *AccountUpdate {
124
+ _u.mutation.SetCredentials(v)
125
+ return _u
126
+ }
127
+
128
+ // SetExtra sets the "extra" field.
129
+ func (_u *AccountUpdate) SetExtra(v map[string]interface{}) *AccountUpdate {
130
+ _u.mutation.SetExtra(v)
131
+ return _u
132
+ }
133
+
134
+ // SetProxyID sets the "proxy_id" field.
135
+ func (_u *AccountUpdate) SetProxyID(v int64) *AccountUpdate {
136
+ _u.mutation.SetProxyID(v)
137
+ return _u
138
+ }
139
+
140
+ // SetNillableProxyID sets the "proxy_id" field if the given value is not nil.
141
+ func (_u *AccountUpdate) SetNillableProxyID(v *int64) *AccountUpdate {
142
+ if v != nil {
143
+ _u.SetProxyID(*v)
144
+ }
145
+ return _u
146
+ }
147
+
148
+ // ClearProxyID clears the value of the "proxy_id" field.
149
+ func (_u *AccountUpdate) ClearProxyID() *AccountUpdate {
150
+ _u.mutation.ClearProxyID()
151
+ return _u
152
+ }
153
+
154
+ // SetConcurrency sets the "concurrency" field.
155
+ func (_u *AccountUpdate) SetConcurrency(v int) *AccountUpdate {
156
+ _u.mutation.ResetConcurrency()
157
+ _u.mutation.SetConcurrency(v)
158
+ return _u
159
+ }
160
+
161
+ // SetNillableConcurrency sets the "concurrency" field if the given value is not nil.
162
+ func (_u *AccountUpdate) SetNillableConcurrency(v *int) *AccountUpdate {
163
+ if v != nil {
164
+ _u.SetConcurrency(*v)
165
+ }
166
+ return _u
167
+ }
168
+
169
+ // AddConcurrency adds value to the "concurrency" field.
170
+ func (_u *AccountUpdate) AddConcurrency(v int) *AccountUpdate {
171
+ _u.mutation.AddConcurrency(v)
172
+ return _u
173
+ }
174
+
175
+ // SetLoadFactor sets the "load_factor" field.
176
+ func (_u *AccountUpdate) SetLoadFactor(v int) *AccountUpdate {
177
+ _u.mutation.ResetLoadFactor()
178
+ _u.mutation.SetLoadFactor(v)
179
+ return _u
180
+ }
181
+
182
+ // SetNillableLoadFactor sets the "load_factor" field if the given value is not nil.
183
+ func (_u *AccountUpdate) SetNillableLoadFactor(v *int) *AccountUpdate {
184
+ if v != nil {
185
+ _u.SetLoadFactor(*v)
186
+ }
187
+ return _u
188
+ }
189
+
190
+ // AddLoadFactor adds value to the "load_factor" field.
191
+ func (_u *AccountUpdate) AddLoadFactor(v int) *AccountUpdate {
192
+ _u.mutation.AddLoadFactor(v)
193
+ return _u
194
+ }
195
+
196
+ // ClearLoadFactor clears the value of the "load_factor" field.
197
+ func (_u *AccountUpdate) ClearLoadFactor() *AccountUpdate {
198
+ _u.mutation.ClearLoadFactor()
199
+ return _u
200
+ }
201
+
202
+ // SetPriority sets the "priority" field.
203
+ func (_u *AccountUpdate) SetPriority(v int) *AccountUpdate {
204
+ _u.mutation.ResetPriority()
205
+ _u.mutation.SetPriority(v)
206
+ return _u
207
+ }
208
+
209
+ // SetNillablePriority sets the "priority" field if the given value is not nil.
210
+ func (_u *AccountUpdate) SetNillablePriority(v *int) *AccountUpdate {
211
+ if v != nil {
212
+ _u.SetPriority(*v)
213
+ }
214
+ return _u
215
+ }
216
+
217
+ // AddPriority adds value to the "priority" field.
218
+ func (_u *AccountUpdate) AddPriority(v int) *AccountUpdate {
219
+ _u.mutation.AddPriority(v)
220
+ return _u
221
+ }
222
+
223
+ // SetRateMultiplier sets the "rate_multiplier" field.
224
+ func (_u *AccountUpdate) SetRateMultiplier(v float64) *AccountUpdate {
225
+ _u.mutation.ResetRateMultiplier()
226
+ _u.mutation.SetRateMultiplier(v)
227
+ return _u
228
+ }
229
+
230
+ // SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
231
+ func (_u *AccountUpdate) SetNillableRateMultiplier(v *float64) *AccountUpdate {
232
+ if v != nil {
233
+ _u.SetRateMultiplier(*v)
234
+ }
235
+ return _u
236
+ }
237
+
238
+ // AddRateMultiplier adds value to the "rate_multiplier" field.
239
+ func (_u *AccountUpdate) AddRateMultiplier(v float64) *AccountUpdate {
240
+ _u.mutation.AddRateMultiplier(v)
241
+ return _u
242
+ }
243
+
244
+ // SetStatus sets the "status" field.
245
+ func (_u *AccountUpdate) SetStatus(v string) *AccountUpdate {
246
+ _u.mutation.SetStatus(v)
247
+ return _u
248
+ }
249
+
250
+ // SetNillableStatus sets the "status" field if the given value is not nil.
251
+ func (_u *AccountUpdate) SetNillableStatus(v *string) *AccountUpdate {
252
+ if v != nil {
253
+ _u.SetStatus(*v)
254
+ }
255
+ return _u
256
+ }
257
+
258
+ // SetErrorMessage sets the "error_message" field.
259
+ func (_u *AccountUpdate) SetErrorMessage(v string) *AccountUpdate {
260
+ _u.mutation.SetErrorMessage(v)
261
+ return _u
262
+ }
263
+
264
+ // SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
265
+ func (_u *AccountUpdate) SetNillableErrorMessage(v *string) *AccountUpdate {
266
+ if v != nil {
267
+ _u.SetErrorMessage(*v)
268
+ }
269
+ return _u
270
+ }
271
+
272
+ // ClearErrorMessage clears the value of the "error_message" field.
273
+ func (_u *AccountUpdate) ClearErrorMessage() *AccountUpdate {
274
+ _u.mutation.ClearErrorMessage()
275
+ return _u
276
+ }
277
+
278
+ // SetLastUsedAt sets the "last_used_at" field.
279
+ func (_u *AccountUpdate) SetLastUsedAt(v time.Time) *AccountUpdate {
280
+ _u.mutation.SetLastUsedAt(v)
281
+ return _u
282
+ }
283
+
284
+ // SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
285
+ func (_u *AccountUpdate) SetNillableLastUsedAt(v *time.Time) *AccountUpdate {
286
+ if v != nil {
287
+ _u.SetLastUsedAt(*v)
288
+ }
289
+ return _u
290
+ }
291
+
292
+ // ClearLastUsedAt clears the value of the "last_used_at" field.
293
+ func (_u *AccountUpdate) ClearLastUsedAt() *AccountUpdate {
294
+ _u.mutation.ClearLastUsedAt()
295
+ return _u
296
+ }
297
+
298
+ // SetExpiresAt sets the "expires_at" field.
299
+ func (_u *AccountUpdate) SetExpiresAt(v time.Time) *AccountUpdate {
300
+ _u.mutation.SetExpiresAt(v)
301
+ return _u
302
+ }
303
+
304
+ // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
305
+ func (_u *AccountUpdate) SetNillableExpiresAt(v *time.Time) *AccountUpdate {
306
+ if v != nil {
307
+ _u.SetExpiresAt(*v)
308
+ }
309
+ return _u
310
+ }
311
+
312
+ // ClearExpiresAt clears the value of the "expires_at" field.
313
+ func (_u *AccountUpdate) ClearExpiresAt() *AccountUpdate {
314
+ _u.mutation.ClearExpiresAt()
315
+ return _u
316
+ }
317
+
318
+ // SetAutoPauseOnExpired sets the "auto_pause_on_expired" field.
319
+ func (_u *AccountUpdate) SetAutoPauseOnExpired(v bool) *AccountUpdate {
320
+ _u.mutation.SetAutoPauseOnExpired(v)
321
+ return _u
322
+ }
323
+
324
+ // SetNillableAutoPauseOnExpired sets the "auto_pause_on_expired" field if the given value is not nil.
325
+ func (_u *AccountUpdate) SetNillableAutoPauseOnExpired(v *bool) *AccountUpdate {
326
+ if v != nil {
327
+ _u.SetAutoPauseOnExpired(*v)
328
+ }
329
+ return _u
330
+ }
331
+
332
+ // SetSchedulable sets the "schedulable" field.
333
+ func (_u *AccountUpdate) SetSchedulable(v bool) *AccountUpdate {
334
+ _u.mutation.SetSchedulable(v)
335
+ return _u
336
+ }
337
+
338
+ // SetNillableSchedulable sets the "schedulable" field if the given value is not nil.
339
+ func (_u *AccountUpdate) SetNillableSchedulable(v *bool) *AccountUpdate {
340
+ if v != nil {
341
+ _u.SetSchedulable(*v)
342
+ }
343
+ return _u
344
+ }
345
+
346
+ // SetRateLimitedAt sets the "rate_limited_at" field.
347
+ func (_u *AccountUpdate) SetRateLimitedAt(v time.Time) *AccountUpdate {
348
+ _u.mutation.SetRateLimitedAt(v)
349
+ return _u
350
+ }
351
+
352
+ // SetNillableRateLimitedAt sets the "rate_limited_at" field if the given value is not nil.
353
+ func (_u *AccountUpdate) SetNillableRateLimitedAt(v *time.Time) *AccountUpdate {
354
+ if v != nil {
355
+ _u.SetRateLimitedAt(*v)
356
+ }
357
+ return _u
358
+ }
359
+
360
+ // ClearRateLimitedAt clears the value of the "rate_limited_at" field.
361
+ func (_u *AccountUpdate) ClearRateLimitedAt() *AccountUpdate {
362
+ _u.mutation.ClearRateLimitedAt()
363
+ return _u
364
+ }
365
+
366
+ // SetRateLimitResetAt sets the "rate_limit_reset_at" field.
367
+ func (_u *AccountUpdate) SetRateLimitResetAt(v time.Time) *AccountUpdate {
368
+ _u.mutation.SetRateLimitResetAt(v)
369
+ return _u
370
+ }
371
+
372
+ // SetNillableRateLimitResetAt sets the "rate_limit_reset_at" field if the given value is not nil.
373
+ func (_u *AccountUpdate) SetNillableRateLimitResetAt(v *time.Time) *AccountUpdate {
374
+ if v != nil {
375
+ _u.SetRateLimitResetAt(*v)
376
+ }
377
+ return _u
378
+ }
379
+
380
+ // ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
381
+ func (_u *AccountUpdate) ClearRateLimitResetAt() *AccountUpdate {
382
+ _u.mutation.ClearRateLimitResetAt()
383
+ return _u
384
+ }
385
+
386
+ // SetOverloadUntil sets the "overload_until" field.
387
+ func (_u *AccountUpdate) SetOverloadUntil(v time.Time) *AccountUpdate {
388
+ _u.mutation.SetOverloadUntil(v)
389
+ return _u
390
+ }
391
+
392
+ // SetNillableOverloadUntil sets the "overload_until" field if the given value is not nil.
393
+ func (_u *AccountUpdate) SetNillableOverloadUntil(v *time.Time) *AccountUpdate {
394
+ if v != nil {
395
+ _u.SetOverloadUntil(*v)
396
+ }
397
+ return _u
398
+ }
399
+
400
+ // ClearOverloadUntil clears the value of the "overload_until" field.
401
+ func (_u *AccountUpdate) ClearOverloadUntil() *AccountUpdate {
402
+ _u.mutation.ClearOverloadUntil()
403
+ return _u
404
+ }
405
+
406
+ // SetTempUnschedulableUntil sets the "temp_unschedulable_until" field.
407
+ func (_u *AccountUpdate) SetTempUnschedulableUntil(v time.Time) *AccountUpdate {
408
+ _u.mutation.SetTempUnschedulableUntil(v)
409
+ return _u
410
+ }
411
+
412
+ // SetNillableTempUnschedulableUntil sets the "temp_unschedulable_until" field if the given value is not nil.
413
+ func (_u *AccountUpdate) SetNillableTempUnschedulableUntil(v *time.Time) *AccountUpdate {
414
+ if v != nil {
415
+ _u.SetTempUnschedulableUntil(*v)
416
+ }
417
+ return _u
418
+ }
419
+
420
+ // ClearTempUnschedulableUntil clears the value of the "temp_unschedulable_until" field.
421
+ func (_u *AccountUpdate) ClearTempUnschedulableUntil() *AccountUpdate {
422
+ _u.mutation.ClearTempUnschedulableUntil()
423
+ return _u
424
+ }
425
+
426
+ // SetTempUnschedulableReason sets the "temp_unschedulable_reason" field.
427
+ func (_u *AccountUpdate) SetTempUnschedulableReason(v string) *AccountUpdate {
428
+ _u.mutation.SetTempUnschedulableReason(v)
429
+ return _u
430
+ }
431
+
432
+ // SetNillableTempUnschedulableReason sets the "temp_unschedulable_reason" field if the given value is not nil.
433
+ func (_u *AccountUpdate) SetNillableTempUnschedulableReason(v *string) *AccountUpdate {
434
+ if v != nil {
435
+ _u.SetTempUnschedulableReason(*v)
436
+ }
437
+ return _u
438
+ }
439
+
440
+ // ClearTempUnschedulableReason clears the value of the "temp_unschedulable_reason" field.
441
+ func (_u *AccountUpdate) ClearTempUnschedulableReason() *AccountUpdate {
442
+ _u.mutation.ClearTempUnschedulableReason()
443
+ return _u
444
+ }
445
+
446
+ // SetSessionWindowStart sets the "session_window_start" field.
447
+ func (_u *AccountUpdate) SetSessionWindowStart(v time.Time) *AccountUpdate {
448
+ _u.mutation.SetSessionWindowStart(v)
449
+ return _u
450
+ }
451
+
452
+ // SetNillableSessionWindowStart sets the "session_window_start" field if the given value is not nil.
453
+ func (_u *AccountUpdate) SetNillableSessionWindowStart(v *time.Time) *AccountUpdate {
454
+ if v != nil {
455
+ _u.SetSessionWindowStart(*v)
456
+ }
457
+ return _u
458
+ }
459
+
460
+ // ClearSessionWindowStart clears the value of the "session_window_start" field.
461
+ func (_u *AccountUpdate) ClearSessionWindowStart() *AccountUpdate {
462
+ _u.mutation.ClearSessionWindowStart()
463
+ return _u
464
+ }
465
+
466
+ // SetSessionWindowEnd sets the "session_window_end" field.
467
+ func (_u *AccountUpdate) SetSessionWindowEnd(v time.Time) *AccountUpdate {
468
+ _u.mutation.SetSessionWindowEnd(v)
469
+ return _u
470
+ }
471
+
472
+ // SetNillableSessionWindowEnd sets the "session_window_end" field if the given value is not nil.
473
+ func (_u *AccountUpdate) SetNillableSessionWindowEnd(v *time.Time) *AccountUpdate {
474
+ if v != nil {
475
+ _u.SetSessionWindowEnd(*v)
476
+ }
477
+ return _u
478
+ }
479
+
480
+ // ClearSessionWindowEnd clears the value of the "session_window_end" field.
481
+ func (_u *AccountUpdate) ClearSessionWindowEnd() *AccountUpdate {
482
+ _u.mutation.ClearSessionWindowEnd()
483
+ return _u
484
+ }
485
+
486
+ // SetSessionWindowStatus sets the "session_window_status" field.
487
+ func (_u *AccountUpdate) SetSessionWindowStatus(v string) *AccountUpdate {
488
+ _u.mutation.SetSessionWindowStatus(v)
489
+ return _u
490
+ }
491
+
492
+ // SetNillableSessionWindowStatus sets the "session_window_status" field if the given value is not nil.
493
+ func (_u *AccountUpdate) SetNillableSessionWindowStatus(v *string) *AccountUpdate {
494
+ if v != nil {
495
+ _u.SetSessionWindowStatus(*v)
496
+ }
497
+ return _u
498
+ }
499
+
500
+ // ClearSessionWindowStatus clears the value of the "session_window_status" field.
501
+ func (_u *AccountUpdate) ClearSessionWindowStatus() *AccountUpdate {
502
+ _u.mutation.ClearSessionWindowStatus()
503
+ return _u
504
+ }
505
+
506
+ // AddGroupIDs adds the "groups" edge to the Group entity by IDs.
507
+ func (_u *AccountUpdate) AddGroupIDs(ids ...int64) *AccountUpdate {
508
+ _u.mutation.AddGroupIDs(ids...)
509
+ return _u
510
+ }
511
+
512
+ // AddGroups adds the "groups" edges to the Group entity.
513
+ func (_u *AccountUpdate) AddGroups(v ...*Group) *AccountUpdate {
514
+ ids := make([]int64, len(v))
515
+ for i := range v {
516
+ ids[i] = v[i].ID
517
+ }
518
+ return _u.AddGroupIDs(ids...)
519
+ }
520
+
521
+ // SetProxy sets the "proxy" edge to the Proxy entity.
522
+ func (_u *AccountUpdate) SetProxy(v *Proxy) *AccountUpdate {
523
+ return _u.SetProxyID(v.ID)
524
+ }
525
+
526
+ // AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
527
+ func (_u *AccountUpdate) AddUsageLogIDs(ids ...int64) *AccountUpdate {
528
+ _u.mutation.AddUsageLogIDs(ids...)
529
+ return _u
530
+ }
531
+
532
+ // AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
533
+ func (_u *AccountUpdate) AddUsageLogs(v ...*UsageLog) *AccountUpdate {
534
+ ids := make([]int64, len(v))
535
+ for i := range v {
536
+ ids[i] = v[i].ID
537
+ }
538
+ return _u.AddUsageLogIDs(ids...)
539
+ }
540
+
541
+ // Mutation returns the AccountMutation object of the builder.
542
+ func (_u *AccountUpdate) Mutation() *AccountMutation {
543
+ return _u.mutation
544
+ }
545
+
546
+ // ClearGroups clears all "groups" edges to the Group entity.
547
+ func (_u *AccountUpdate) ClearGroups() *AccountUpdate {
548
+ _u.mutation.ClearGroups()
549
+ return _u
550
+ }
551
+
552
+ // RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
553
+ func (_u *AccountUpdate) RemoveGroupIDs(ids ...int64) *AccountUpdate {
554
+ _u.mutation.RemoveGroupIDs(ids...)
555
+ return _u
556
+ }
557
+
558
+ // RemoveGroups removes "groups" edges to Group entities.
559
+ func (_u *AccountUpdate) RemoveGroups(v ...*Group) *AccountUpdate {
560
+ ids := make([]int64, len(v))
561
+ for i := range v {
562
+ ids[i] = v[i].ID
563
+ }
564
+ return _u.RemoveGroupIDs(ids...)
565
+ }
566
+
567
+ // ClearProxy clears the "proxy" edge to the Proxy entity.
568
+ func (_u *AccountUpdate) ClearProxy() *AccountUpdate {
569
+ _u.mutation.ClearProxy()
570
+ return _u
571
+ }
572
+
573
+ // ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
574
+ func (_u *AccountUpdate) ClearUsageLogs() *AccountUpdate {
575
+ _u.mutation.ClearUsageLogs()
576
+ return _u
577
+ }
578
+
579
+ // RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
580
+ func (_u *AccountUpdate) RemoveUsageLogIDs(ids ...int64) *AccountUpdate {
581
+ _u.mutation.RemoveUsageLogIDs(ids...)
582
+ return _u
583
+ }
584
+
585
+ // RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
586
+ func (_u *AccountUpdate) RemoveUsageLogs(v ...*UsageLog) *AccountUpdate {
587
+ ids := make([]int64, len(v))
588
+ for i := range v {
589
+ ids[i] = v[i].ID
590
+ }
591
+ return _u.RemoveUsageLogIDs(ids...)
592
+ }
593
+
594
+ // Save executes the query and returns the number of nodes affected by the update operation.
595
+ func (_u *AccountUpdate) Save(ctx context.Context) (int, error) {
596
+ if err := _u.defaults(); err != nil {
597
+ return 0, err
598
+ }
599
+ return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
600
+ }
601
+
602
+ // SaveX is like Save, but panics if an error occurs.
603
+ func (_u *AccountUpdate) SaveX(ctx context.Context) int {
604
+ affected, err := _u.Save(ctx)
605
+ if err != nil {
606
+ panic(err)
607
+ }
608
+ return affected
609
+ }
610
+
611
+ // Exec executes the query.
612
+ func (_u *AccountUpdate) Exec(ctx context.Context) error {
613
+ _, err := _u.Save(ctx)
614
+ return err
615
+ }
616
+
617
+ // ExecX is like Exec, but panics if an error occurs.
618
+ func (_u *AccountUpdate) ExecX(ctx context.Context) {
619
+ if err := _u.Exec(ctx); err != nil {
620
+ panic(err)
621
+ }
622
+ }
623
+
624
+ // defaults sets the default values of the builder before save.
625
+ func (_u *AccountUpdate) defaults() error {
626
+ if _, ok := _u.mutation.UpdatedAt(); !ok {
627
+ if account.UpdateDefaultUpdatedAt == nil {
628
+ return fmt.Errorf("ent: uninitialized account.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
629
+ }
630
+ v := account.UpdateDefaultUpdatedAt()
631
+ _u.mutation.SetUpdatedAt(v)
632
+ }
633
+ return nil
634
+ }
635
+
636
+ // check runs all checks and user-defined validators on the builder.
637
+ func (_u *AccountUpdate) check() error {
638
+ if v, ok := _u.mutation.Name(); ok {
639
+ if err := account.NameValidator(v); err != nil {
640
+ return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Account.name": %w`, err)}
641
+ }
642
+ }
643
+ if v, ok := _u.mutation.Platform(); ok {
644
+ if err := account.PlatformValidator(v); err != nil {
645
+ return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Account.platform": %w`, err)}
646
+ }
647
+ }
648
+ if v, ok := _u.mutation.GetType(); ok {
649
+ if err := account.TypeValidator(v); err != nil {
650
+ return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Account.type": %w`, err)}
651
+ }
652
+ }
653
+ if v, ok := _u.mutation.Status(); ok {
654
+ if err := account.StatusValidator(v); err != nil {
655
+ return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Account.status": %w`, err)}
656
+ }
657
+ }
658
+ if v, ok := _u.mutation.SessionWindowStatus(); ok {
659
+ if err := account.SessionWindowStatusValidator(v); err != nil {
660
+ return &ValidationError{Name: "session_window_status", err: fmt.Errorf(`ent: validator failed for field "Account.session_window_status": %w`, err)}
661
+ }
662
+ }
663
+ return nil
664
+ }
665
+
666
+ func (_u *AccountUpdate) sqlSave(ctx context.Context) (_node int, err error) {
667
+ if err := _u.check(); err != nil {
668
+ return _node, err
669
+ }
670
+ _spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64))
671
+ if ps := _u.mutation.predicates; len(ps) > 0 {
672
+ _spec.Predicate = func(selector *sql.Selector) {
673
+ for i := range ps {
674
+ ps[i](selector)
675
+ }
676
+ }
677
+ }
678
+ if value, ok := _u.mutation.UpdatedAt(); ok {
679
+ _spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
680
+ }
681
+ if value, ok := _u.mutation.DeletedAt(); ok {
682
+ _spec.SetField(account.FieldDeletedAt, field.TypeTime, value)
683
+ }
684
+ if _u.mutation.DeletedAtCleared() {
685
+ _spec.ClearField(account.FieldDeletedAt, field.TypeTime)
686
+ }
687
+ if value, ok := _u.mutation.Name(); ok {
688
+ _spec.SetField(account.FieldName, field.TypeString, value)
689
+ }
690
+ if value, ok := _u.mutation.Notes(); ok {
691
+ _spec.SetField(account.FieldNotes, field.TypeString, value)
692
+ }
693
+ if _u.mutation.NotesCleared() {
694
+ _spec.ClearField(account.FieldNotes, field.TypeString)
695
+ }
696
+ if value, ok := _u.mutation.Platform(); ok {
697
+ _spec.SetField(account.FieldPlatform, field.TypeString, value)
698
+ }
699
+ if value, ok := _u.mutation.GetType(); ok {
700
+ _spec.SetField(account.FieldType, field.TypeString, value)
701
+ }
702
+ if value, ok := _u.mutation.Credentials(); ok {
703
+ _spec.SetField(account.FieldCredentials, field.TypeJSON, value)
704
+ }
705
+ if value, ok := _u.mutation.Extra(); ok {
706
+ _spec.SetField(account.FieldExtra, field.TypeJSON, value)
707
+ }
708
+ if value, ok := _u.mutation.Concurrency(); ok {
709
+ _spec.SetField(account.FieldConcurrency, field.TypeInt, value)
710
+ }
711
+ if value, ok := _u.mutation.AddedConcurrency(); ok {
712
+ _spec.AddField(account.FieldConcurrency, field.TypeInt, value)
713
+ }
714
+ if value, ok := _u.mutation.LoadFactor(); ok {
715
+ _spec.SetField(account.FieldLoadFactor, field.TypeInt, value)
716
+ }
717
+ if value, ok := _u.mutation.AddedLoadFactor(); ok {
718
+ _spec.AddField(account.FieldLoadFactor, field.TypeInt, value)
719
+ }
720
+ if _u.mutation.LoadFactorCleared() {
721
+ _spec.ClearField(account.FieldLoadFactor, field.TypeInt)
722
+ }
723
+ if value, ok := _u.mutation.Priority(); ok {
724
+ _spec.SetField(account.FieldPriority, field.TypeInt, value)
725
+ }
726
+ if value, ok := _u.mutation.AddedPriority(); ok {
727
+ _spec.AddField(account.FieldPriority, field.TypeInt, value)
728
+ }
729
+ if value, ok := _u.mutation.RateMultiplier(); ok {
730
+ _spec.SetField(account.FieldRateMultiplier, field.TypeFloat64, value)
731
+ }
732
+ if value, ok := _u.mutation.AddedRateMultiplier(); ok {
733
+ _spec.AddField(account.FieldRateMultiplier, field.TypeFloat64, value)
734
+ }
735
+ if value, ok := _u.mutation.Status(); ok {
736
+ _spec.SetField(account.FieldStatus, field.TypeString, value)
737
+ }
738
+ if value, ok := _u.mutation.ErrorMessage(); ok {
739
+ _spec.SetField(account.FieldErrorMessage, field.TypeString, value)
740
+ }
741
+ if _u.mutation.ErrorMessageCleared() {
742
+ _spec.ClearField(account.FieldErrorMessage, field.TypeString)
743
+ }
744
+ if value, ok := _u.mutation.LastUsedAt(); ok {
745
+ _spec.SetField(account.FieldLastUsedAt, field.TypeTime, value)
746
+ }
747
+ if _u.mutation.LastUsedAtCleared() {
748
+ _spec.ClearField(account.FieldLastUsedAt, field.TypeTime)
749
+ }
750
+ if value, ok := _u.mutation.ExpiresAt(); ok {
751
+ _spec.SetField(account.FieldExpiresAt, field.TypeTime, value)
752
+ }
753
+ if _u.mutation.ExpiresAtCleared() {
754
+ _spec.ClearField(account.FieldExpiresAt, field.TypeTime)
755
+ }
756
+ if value, ok := _u.mutation.AutoPauseOnExpired(); ok {
757
+ _spec.SetField(account.FieldAutoPauseOnExpired, field.TypeBool, value)
758
+ }
759
+ if value, ok := _u.mutation.Schedulable(); ok {
760
+ _spec.SetField(account.FieldSchedulable, field.TypeBool, value)
761
+ }
762
+ if value, ok := _u.mutation.RateLimitedAt(); ok {
763
+ _spec.SetField(account.FieldRateLimitedAt, field.TypeTime, value)
764
+ }
765
+ if _u.mutation.RateLimitedAtCleared() {
766
+ _spec.ClearField(account.FieldRateLimitedAt, field.TypeTime)
767
+ }
768
+ if value, ok := _u.mutation.RateLimitResetAt(); ok {
769
+ _spec.SetField(account.FieldRateLimitResetAt, field.TypeTime, value)
770
+ }
771
+ if _u.mutation.RateLimitResetAtCleared() {
772
+ _spec.ClearField(account.FieldRateLimitResetAt, field.TypeTime)
773
+ }
774
+ if value, ok := _u.mutation.OverloadUntil(); ok {
775
+ _spec.SetField(account.FieldOverloadUntil, field.TypeTime, value)
776
+ }
777
+ if _u.mutation.OverloadUntilCleared() {
778
+ _spec.ClearField(account.FieldOverloadUntil, field.TypeTime)
779
+ }
780
+ if value, ok := _u.mutation.TempUnschedulableUntil(); ok {
781
+ _spec.SetField(account.FieldTempUnschedulableUntil, field.TypeTime, value)
782
+ }
783
+ if _u.mutation.TempUnschedulableUntilCleared() {
784
+ _spec.ClearField(account.FieldTempUnschedulableUntil, field.TypeTime)
785
+ }
786
+ if value, ok := _u.mutation.TempUnschedulableReason(); ok {
787
+ _spec.SetField(account.FieldTempUnschedulableReason, field.TypeString, value)
788
+ }
789
+ if _u.mutation.TempUnschedulableReasonCleared() {
790
+ _spec.ClearField(account.FieldTempUnschedulableReason, field.TypeString)
791
+ }
792
+ if value, ok := _u.mutation.SessionWindowStart(); ok {
793
+ _spec.SetField(account.FieldSessionWindowStart, field.TypeTime, value)
794
+ }
795
+ if _u.mutation.SessionWindowStartCleared() {
796
+ _spec.ClearField(account.FieldSessionWindowStart, field.TypeTime)
797
+ }
798
+ if value, ok := _u.mutation.SessionWindowEnd(); ok {
799
+ _spec.SetField(account.FieldSessionWindowEnd, field.TypeTime, value)
800
+ }
801
+ if _u.mutation.SessionWindowEndCleared() {
802
+ _spec.ClearField(account.FieldSessionWindowEnd, field.TypeTime)
803
+ }
804
+ if value, ok := _u.mutation.SessionWindowStatus(); ok {
805
+ _spec.SetField(account.FieldSessionWindowStatus, field.TypeString, value)
806
+ }
807
+ if _u.mutation.SessionWindowStatusCleared() {
808
+ _spec.ClearField(account.FieldSessionWindowStatus, field.TypeString)
809
+ }
810
+ if _u.mutation.GroupsCleared() {
811
+ edge := &sqlgraph.EdgeSpec{
812
+ Rel: sqlgraph.M2M,
813
+ Inverse: false,
814
+ Table: account.GroupsTable,
815
+ Columns: account.GroupsPrimaryKey,
816
+ Bidi: false,
817
+ Target: &sqlgraph.EdgeTarget{
818
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
819
+ },
820
+ }
821
+ createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
822
+ createE.defaults()
823
+ _, specE := createE.createSpec()
824
+ edge.Target.Fields = specE.Fields
825
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
826
+ }
827
+ if nodes := _u.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !_u.mutation.GroupsCleared() {
828
+ edge := &sqlgraph.EdgeSpec{
829
+ Rel: sqlgraph.M2M,
830
+ Inverse: false,
831
+ Table: account.GroupsTable,
832
+ Columns: account.GroupsPrimaryKey,
833
+ Bidi: false,
834
+ Target: &sqlgraph.EdgeTarget{
835
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
836
+ },
837
+ }
838
+ for _, k := range nodes {
839
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
840
+ }
841
+ createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
842
+ createE.defaults()
843
+ _, specE := createE.createSpec()
844
+ edge.Target.Fields = specE.Fields
845
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
846
+ }
847
+ if nodes := _u.mutation.GroupsIDs(); len(nodes) > 0 {
848
+ edge := &sqlgraph.EdgeSpec{
849
+ Rel: sqlgraph.M2M,
850
+ Inverse: false,
851
+ Table: account.GroupsTable,
852
+ Columns: account.GroupsPrimaryKey,
853
+ Bidi: false,
854
+ Target: &sqlgraph.EdgeTarget{
855
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
856
+ },
857
+ }
858
+ for _, k := range nodes {
859
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
860
+ }
861
+ createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
862
+ createE.defaults()
863
+ _, specE := createE.createSpec()
864
+ edge.Target.Fields = specE.Fields
865
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
866
+ }
867
+ if _u.mutation.ProxyCleared() {
868
+ edge := &sqlgraph.EdgeSpec{
869
+ Rel: sqlgraph.M2O,
870
+ Inverse: false,
871
+ Table: account.ProxyTable,
872
+ Columns: []string{account.ProxyColumn},
873
+ Bidi: false,
874
+ Target: &sqlgraph.EdgeTarget{
875
+ IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
876
+ },
877
+ }
878
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
879
+ }
880
+ if nodes := _u.mutation.ProxyIDs(); len(nodes) > 0 {
881
+ edge := &sqlgraph.EdgeSpec{
882
+ Rel: sqlgraph.M2O,
883
+ Inverse: false,
884
+ Table: account.ProxyTable,
885
+ Columns: []string{account.ProxyColumn},
886
+ Bidi: false,
887
+ Target: &sqlgraph.EdgeTarget{
888
+ IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
889
+ },
890
+ }
891
+ for _, k := range nodes {
892
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
893
+ }
894
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
895
+ }
896
+ if _u.mutation.UsageLogsCleared() {
897
+ edge := &sqlgraph.EdgeSpec{
898
+ Rel: sqlgraph.O2M,
899
+ Inverse: false,
900
+ Table: account.UsageLogsTable,
901
+ Columns: []string{account.UsageLogsColumn},
902
+ Bidi: false,
903
+ Target: &sqlgraph.EdgeTarget{
904
+ IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
905
+ },
906
+ }
907
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
908
+ }
909
+ if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
910
+ edge := &sqlgraph.EdgeSpec{
911
+ Rel: sqlgraph.O2M,
912
+ Inverse: false,
913
+ Table: account.UsageLogsTable,
914
+ Columns: []string{account.UsageLogsColumn},
915
+ Bidi: false,
916
+ Target: &sqlgraph.EdgeTarget{
917
+ IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
918
+ },
919
+ }
920
+ for _, k := range nodes {
921
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
922
+ }
923
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
924
+ }
925
+ if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
926
+ edge := &sqlgraph.EdgeSpec{
927
+ Rel: sqlgraph.O2M,
928
+ Inverse: false,
929
+ Table: account.UsageLogsTable,
930
+ Columns: []string{account.UsageLogsColumn},
931
+ Bidi: false,
932
+ Target: &sqlgraph.EdgeTarget{
933
+ IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
934
+ },
935
+ }
936
+ for _, k := range nodes {
937
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
938
+ }
939
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
940
+ }
941
+ if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
942
+ if _, ok := err.(*sqlgraph.NotFoundError); ok {
943
+ err = &NotFoundError{account.Label}
944
+ } else if sqlgraph.IsConstraintError(err) {
945
+ err = &ConstraintError{msg: err.Error(), wrap: err}
946
+ }
947
+ return 0, err
948
+ }
949
+ _u.mutation.done = true
950
+ return _node, nil
951
+ }
952
+
953
+ // AccountUpdateOne is the builder for updating a single Account entity.
954
+ type AccountUpdateOne struct {
955
+ config
956
+ fields []string
957
+ hooks []Hook
958
+ mutation *AccountMutation
959
+ }
960
+
961
+ // SetUpdatedAt sets the "updated_at" field.
962
+ func (_u *AccountUpdateOne) SetUpdatedAt(v time.Time) *AccountUpdateOne {
963
+ _u.mutation.SetUpdatedAt(v)
964
+ return _u
965
+ }
966
+
967
+ // SetDeletedAt sets the "deleted_at" field.
968
+ func (_u *AccountUpdateOne) SetDeletedAt(v time.Time) *AccountUpdateOne {
969
+ _u.mutation.SetDeletedAt(v)
970
+ return _u
971
+ }
972
+
973
+ // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
974
+ func (_u *AccountUpdateOne) SetNillableDeletedAt(v *time.Time) *AccountUpdateOne {
975
+ if v != nil {
976
+ _u.SetDeletedAt(*v)
977
+ }
978
+ return _u
979
+ }
980
+
981
+ // ClearDeletedAt clears the value of the "deleted_at" field.
982
+ func (_u *AccountUpdateOne) ClearDeletedAt() *AccountUpdateOne {
983
+ _u.mutation.ClearDeletedAt()
984
+ return _u
985
+ }
986
+
987
+ // SetName sets the "name" field.
988
+ func (_u *AccountUpdateOne) SetName(v string) *AccountUpdateOne {
989
+ _u.mutation.SetName(v)
990
+ return _u
991
+ }
992
+
993
+ // SetNillableName sets the "name" field if the given value is not nil.
994
+ func (_u *AccountUpdateOne) SetNillableName(v *string) *AccountUpdateOne {
995
+ if v != nil {
996
+ _u.SetName(*v)
997
+ }
998
+ return _u
999
+ }
1000
+
1001
+ // SetNotes sets the "notes" field.
1002
+ func (_u *AccountUpdateOne) SetNotes(v string) *AccountUpdateOne {
1003
+ _u.mutation.SetNotes(v)
1004
+ return _u
1005
+ }
1006
+
1007
+ // SetNillableNotes sets the "notes" field if the given value is not nil.
1008
+ func (_u *AccountUpdateOne) SetNillableNotes(v *string) *AccountUpdateOne {
1009
+ if v != nil {
1010
+ _u.SetNotes(*v)
1011
+ }
1012
+ return _u
1013
+ }
1014
+
1015
+ // ClearNotes clears the value of the "notes" field.
1016
+ func (_u *AccountUpdateOne) ClearNotes() *AccountUpdateOne {
1017
+ _u.mutation.ClearNotes()
1018
+ return _u
1019
+ }
1020
+
1021
+ // SetPlatform sets the "platform" field.
1022
+ func (_u *AccountUpdateOne) SetPlatform(v string) *AccountUpdateOne {
1023
+ _u.mutation.SetPlatform(v)
1024
+ return _u
1025
+ }
1026
+
1027
+ // SetNillablePlatform sets the "platform" field if the given value is not nil.
1028
+ func (_u *AccountUpdateOne) SetNillablePlatform(v *string) *AccountUpdateOne {
1029
+ if v != nil {
1030
+ _u.SetPlatform(*v)
1031
+ }
1032
+ return _u
1033
+ }
1034
+
1035
+ // SetType sets the "type" field.
1036
+ func (_u *AccountUpdateOne) SetType(v string) *AccountUpdateOne {
1037
+ _u.mutation.SetType(v)
1038
+ return _u
1039
+ }
1040
+
1041
+ // SetNillableType sets the "type" field if the given value is not nil.
1042
+ func (_u *AccountUpdateOne) SetNillableType(v *string) *AccountUpdateOne {
1043
+ if v != nil {
1044
+ _u.SetType(*v)
1045
+ }
1046
+ return _u
1047
+ }
1048
+
1049
+ // SetCredentials sets the "credentials" field.
1050
+ func (_u *AccountUpdateOne) SetCredentials(v map[string]interface{}) *AccountUpdateOne {
1051
+ _u.mutation.SetCredentials(v)
1052
+ return _u
1053
+ }
1054
+
1055
+ // SetExtra sets the "extra" field.
1056
+ func (_u *AccountUpdateOne) SetExtra(v map[string]interface{}) *AccountUpdateOne {
1057
+ _u.mutation.SetExtra(v)
1058
+ return _u
1059
+ }
1060
+
1061
+ // SetProxyID sets the "proxy_id" field.
1062
+ func (_u *AccountUpdateOne) SetProxyID(v int64) *AccountUpdateOne {
1063
+ _u.mutation.SetProxyID(v)
1064
+ return _u
1065
+ }
1066
+
1067
+ // SetNillableProxyID sets the "proxy_id" field if the given value is not nil.
1068
+ func (_u *AccountUpdateOne) SetNillableProxyID(v *int64) *AccountUpdateOne {
1069
+ if v != nil {
1070
+ _u.SetProxyID(*v)
1071
+ }
1072
+ return _u
1073
+ }
1074
+
1075
+ // ClearProxyID clears the value of the "proxy_id" field.
1076
+ func (_u *AccountUpdateOne) ClearProxyID() *AccountUpdateOne {
1077
+ _u.mutation.ClearProxyID()
1078
+ return _u
1079
+ }
1080
+
1081
+ // SetConcurrency sets the "concurrency" field.
1082
+ func (_u *AccountUpdateOne) SetConcurrency(v int) *AccountUpdateOne {
1083
+ _u.mutation.ResetConcurrency()
1084
+ _u.mutation.SetConcurrency(v)
1085
+ return _u
1086
+ }
1087
+
1088
+ // SetNillableConcurrency sets the "concurrency" field if the given value is not nil.
1089
+ func (_u *AccountUpdateOne) SetNillableConcurrency(v *int) *AccountUpdateOne {
1090
+ if v != nil {
1091
+ _u.SetConcurrency(*v)
1092
+ }
1093
+ return _u
1094
+ }
1095
+
1096
+ // AddConcurrency adds value to the "concurrency" field.
1097
+ func (_u *AccountUpdateOne) AddConcurrency(v int) *AccountUpdateOne {
1098
+ _u.mutation.AddConcurrency(v)
1099
+ return _u
1100
+ }
1101
+
1102
+ // SetLoadFactor sets the "load_factor" field.
1103
+ func (_u *AccountUpdateOne) SetLoadFactor(v int) *AccountUpdateOne {
1104
+ _u.mutation.ResetLoadFactor()
1105
+ _u.mutation.SetLoadFactor(v)
1106
+ return _u
1107
+ }
1108
+
1109
+ // SetNillableLoadFactor sets the "load_factor" field if the given value is not nil.
1110
+ func (_u *AccountUpdateOne) SetNillableLoadFactor(v *int) *AccountUpdateOne {
1111
+ if v != nil {
1112
+ _u.SetLoadFactor(*v)
1113
+ }
1114
+ return _u
1115
+ }
1116
+
1117
+ // AddLoadFactor adds value to the "load_factor" field.
1118
+ func (_u *AccountUpdateOne) AddLoadFactor(v int) *AccountUpdateOne {
1119
+ _u.mutation.AddLoadFactor(v)
1120
+ return _u
1121
+ }
1122
+
1123
+ // ClearLoadFactor clears the value of the "load_factor" field.
1124
+ func (_u *AccountUpdateOne) ClearLoadFactor() *AccountUpdateOne {
1125
+ _u.mutation.ClearLoadFactor()
1126
+ return _u
1127
+ }
1128
+
1129
+ // SetPriority sets the "priority" field.
1130
+ func (_u *AccountUpdateOne) SetPriority(v int) *AccountUpdateOne {
1131
+ _u.mutation.ResetPriority()
1132
+ _u.mutation.SetPriority(v)
1133
+ return _u
1134
+ }
1135
+
1136
+ // SetNillablePriority sets the "priority" field if the given value is not nil.
1137
+ func (_u *AccountUpdateOne) SetNillablePriority(v *int) *AccountUpdateOne {
1138
+ if v != nil {
1139
+ _u.SetPriority(*v)
1140
+ }
1141
+ return _u
1142
+ }
1143
+
1144
+ // AddPriority adds value to the "priority" field.
1145
+ func (_u *AccountUpdateOne) AddPriority(v int) *AccountUpdateOne {
1146
+ _u.mutation.AddPriority(v)
1147
+ return _u
1148
+ }
1149
+
1150
+ // SetRateMultiplier sets the "rate_multiplier" field.
1151
+ func (_u *AccountUpdateOne) SetRateMultiplier(v float64) *AccountUpdateOne {
1152
+ _u.mutation.ResetRateMultiplier()
1153
+ _u.mutation.SetRateMultiplier(v)
1154
+ return _u
1155
+ }
1156
+
1157
+ // SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
1158
+ func (_u *AccountUpdateOne) SetNillableRateMultiplier(v *float64) *AccountUpdateOne {
1159
+ if v != nil {
1160
+ _u.SetRateMultiplier(*v)
1161
+ }
1162
+ return _u
1163
+ }
1164
+
1165
+ // AddRateMultiplier adds value to the "rate_multiplier" field.
1166
+ func (_u *AccountUpdateOne) AddRateMultiplier(v float64) *AccountUpdateOne {
1167
+ _u.mutation.AddRateMultiplier(v)
1168
+ return _u
1169
+ }
1170
+
1171
+ // SetStatus sets the "status" field.
1172
+ func (_u *AccountUpdateOne) SetStatus(v string) *AccountUpdateOne {
1173
+ _u.mutation.SetStatus(v)
1174
+ return _u
1175
+ }
1176
+
1177
+ // SetNillableStatus sets the "status" field if the given value is not nil.
1178
+ func (_u *AccountUpdateOne) SetNillableStatus(v *string) *AccountUpdateOne {
1179
+ if v != nil {
1180
+ _u.SetStatus(*v)
1181
+ }
1182
+ return _u
1183
+ }
1184
+
1185
+ // SetErrorMessage sets the "error_message" field.
1186
+ func (_u *AccountUpdateOne) SetErrorMessage(v string) *AccountUpdateOne {
1187
+ _u.mutation.SetErrorMessage(v)
1188
+ return _u
1189
+ }
1190
+
1191
+ // SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
1192
+ func (_u *AccountUpdateOne) SetNillableErrorMessage(v *string) *AccountUpdateOne {
1193
+ if v != nil {
1194
+ _u.SetErrorMessage(*v)
1195
+ }
1196
+ return _u
1197
+ }
1198
+
1199
+ // ClearErrorMessage clears the value of the "error_message" field.
1200
+ func (_u *AccountUpdateOne) ClearErrorMessage() *AccountUpdateOne {
1201
+ _u.mutation.ClearErrorMessage()
1202
+ return _u
1203
+ }
1204
+
1205
+ // SetLastUsedAt sets the "last_used_at" field.
1206
+ func (_u *AccountUpdateOne) SetLastUsedAt(v time.Time) *AccountUpdateOne {
1207
+ _u.mutation.SetLastUsedAt(v)
1208
+ return _u
1209
+ }
1210
+
1211
+ // SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
1212
+ func (_u *AccountUpdateOne) SetNillableLastUsedAt(v *time.Time) *AccountUpdateOne {
1213
+ if v != nil {
1214
+ _u.SetLastUsedAt(*v)
1215
+ }
1216
+ return _u
1217
+ }
1218
+
1219
+ // ClearLastUsedAt clears the value of the "last_used_at" field.
1220
+ func (_u *AccountUpdateOne) ClearLastUsedAt() *AccountUpdateOne {
1221
+ _u.mutation.ClearLastUsedAt()
1222
+ return _u
1223
+ }
1224
+
1225
+ // SetExpiresAt sets the "expires_at" field.
1226
+ func (_u *AccountUpdateOne) SetExpiresAt(v time.Time) *AccountUpdateOne {
1227
+ _u.mutation.SetExpiresAt(v)
1228
+ return _u
1229
+ }
1230
+
1231
+ // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
1232
+ func (_u *AccountUpdateOne) SetNillableExpiresAt(v *time.Time) *AccountUpdateOne {
1233
+ if v != nil {
1234
+ _u.SetExpiresAt(*v)
1235
+ }
1236
+ return _u
1237
+ }
1238
+
1239
+ // ClearExpiresAt clears the value of the "expires_at" field.
1240
+ func (_u *AccountUpdateOne) ClearExpiresAt() *AccountUpdateOne {
1241
+ _u.mutation.ClearExpiresAt()
1242
+ return _u
1243
+ }
1244
+
1245
+ // SetAutoPauseOnExpired sets the "auto_pause_on_expired" field.
1246
+ func (_u *AccountUpdateOne) SetAutoPauseOnExpired(v bool) *AccountUpdateOne {
1247
+ _u.mutation.SetAutoPauseOnExpired(v)
1248
+ return _u
1249
+ }
1250
+
1251
+ // SetNillableAutoPauseOnExpired sets the "auto_pause_on_expired" field if the given value is not nil.
1252
+ func (_u *AccountUpdateOne) SetNillableAutoPauseOnExpired(v *bool) *AccountUpdateOne {
1253
+ if v != nil {
1254
+ _u.SetAutoPauseOnExpired(*v)
1255
+ }
1256
+ return _u
1257
+ }
1258
+
1259
+ // SetSchedulable sets the "schedulable" field.
1260
+ func (_u *AccountUpdateOne) SetSchedulable(v bool) *AccountUpdateOne {
1261
+ _u.mutation.SetSchedulable(v)
1262
+ return _u
1263
+ }
1264
+
1265
+ // SetNillableSchedulable sets the "schedulable" field if the given value is not nil.
1266
+ func (_u *AccountUpdateOne) SetNillableSchedulable(v *bool) *AccountUpdateOne {
1267
+ if v != nil {
1268
+ _u.SetSchedulable(*v)
1269
+ }
1270
+ return _u
1271
+ }
1272
+
1273
+ // SetRateLimitedAt sets the "rate_limited_at" field.
1274
+ func (_u *AccountUpdateOne) SetRateLimitedAt(v time.Time) *AccountUpdateOne {
1275
+ _u.mutation.SetRateLimitedAt(v)
1276
+ return _u
1277
+ }
1278
+
1279
+ // SetNillableRateLimitedAt sets the "rate_limited_at" field if the given value is not nil.
1280
+ func (_u *AccountUpdateOne) SetNillableRateLimitedAt(v *time.Time) *AccountUpdateOne {
1281
+ if v != nil {
1282
+ _u.SetRateLimitedAt(*v)
1283
+ }
1284
+ return _u
1285
+ }
1286
+
1287
+ // ClearRateLimitedAt clears the value of the "rate_limited_at" field.
1288
+ func (_u *AccountUpdateOne) ClearRateLimitedAt() *AccountUpdateOne {
1289
+ _u.mutation.ClearRateLimitedAt()
1290
+ return _u
1291
+ }
1292
+
1293
+ // SetRateLimitResetAt sets the "rate_limit_reset_at" field.
1294
+ func (_u *AccountUpdateOne) SetRateLimitResetAt(v time.Time) *AccountUpdateOne {
1295
+ _u.mutation.SetRateLimitResetAt(v)
1296
+ return _u
1297
+ }
1298
+
1299
+ // SetNillableRateLimitResetAt sets the "rate_limit_reset_at" field if the given value is not nil.
1300
+ func (_u *AccountUpdateOne) SetNillableRateLimitResetAt(v *time.Time) *AccountUpdateOne {
1301
+ if v != nil {
1302
+ _u.SetRateLimitResetAt(*v)
1303
+ }
1304
+ return _u
1305
+ }
1306
+
1307
+ // ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
1308
+ func (_u *AccountUpdateOne) ClearRateLimitResetAt() *AccountUpdateOne {
1309
+ _u.mutation.ClearRateLimitResetAt()
1310
+ return _u
1311
+ }
1312
+
1313
+ // SetOverloadUntil sets the "overload_until" field.
1314
+ func (_u *AccountUpdateOne) SetOverloadUntil(v time.Time) *AccountUpdateOne {
1315
+ _u.mutation.SetOverloadUntil(v)
1316
+ return _u
1317
+ }
1318
+
1319
+ // SetNillableOverloadUntil sets the "overload_until" field if the given value is not nil.
1320
+ func (_u *AccountUpdateOne) SetNillableOverloadUntil(v *time.Time) *AccountUpdateOne {
1321
+ if v != nil {
1322
+ _u.SetOverloadUntil(*v)
1323
+ }
1324
+ return _u
1325
+ }
1326
+
1327
+ // ClearOverloadUntil clears the value of the "overload_until" field.
1328
+ func (_u *AccountUpdateOne) ClearOverloadUntil() *AccountUpdateOne {
1329
+ _u.mutation.ClearOverloadUntil()
1330
+ return _u
1331
+ }
1332
+
1333
+ // SetTempUnschedulableUntil sets the "temp_unschedulable_until" field.
1334
+ func (_u *AccountUpdateOne) SetTempUnschedulableUntil(v time.Time) *AccountUpdateOne {
1335
+ _u.mutation.SetTempUnschedulableUntil(v)
1336
+ return _u
1337
+ }
1338
+
1339
+ // SetNillableTempUnschedulableUntil sets the "temp_unschedulable_until" field if the given value is not nil.
1340
+ func (_u *AccountUpdateOne) SetNillableTempUnschedulableUntil(v *time.Time) *AccountUpdateOne {
1341
+ if v != nil {
1342
+ _u.SetTempUnschedulableUntil(*v)
1343
+ }
1344
+ return _u
1345
+ }
1346
+
1347
+ // ClearTempUnschedulableUntil clears the value of the "temp_unschedulable_until" field.
1348
+ func (_u *AccountUpdateOne) ClearTempUnschedulableUntil() *AccountUpdateOne {
1349
+ _u.mutation.ClearTempUnschedulableUntil()
1350
+ return _u
1351
+ }
1352
+
1353
+ // SetTempUnschedulableReason sets the "temp_unschedulable_reason" field.
1354
+ func (_u *AccountUpdateOne) SetTempUnschedulableReason(v string) *AccountUpdateOne {
1355
+ _u.mutation.SetTempUnschedulableReason(v)
1356
+ return _u
1357
+ }
1358
+
1359
+ // SetNillableTempUnschedulableReason sets the "temp_unschedulable_reason" field if the given value is not nil.
1360
+ func (_u *AccountUpdateOne) SetNillableTempUnschedulableReason(v *string) *AccountUpdateOne {
1361
+ if v != nil {
1362
+ _u.SetTempUnschedulableReason(*v)
1363
+ }
1364
+ return _u
1365
+ }
1366
+
1367
+ // ClearTempUnschedulableReason clears the value of the "temp_unschedulable_reason" field.
1368
+ func (_u *AccountUpdateOne) ClearTempUnschedulableReason() *AccountUpdateOne {
1369
+ _u.mutation.ClearTempUnschedulableReason()
1370
+ return _u
1371
+ }
1372
+
1373
+ // SetSessionWindowStart sets the "session_window_start" field.
1374
+ func (_u *AccountUpdateOne) SetSessionWindowStart(v time.Time) *AccountUpdateOne {
1375
+ _u.mutation.SetSessionWindowStart(v)
1376
+ return _u
1377
+ }
1378
+
1379
+ // SetNillableSessionWindowStart sets the "session_window_start" field if the given value is not nil.
1380
+ func (_u *AccountUpdateOne) SetNillableSessionWindowStart(v *time.Time) *AccountUpdateOne {
1381
+ if v != nil {
1382
+ _u.SetSessionWindowStart(*v)
1383
+ }
1384
+ return _u
1385
+ }
1386
+
1387
+ // ClearSessionWindowStart clears the value of the "session_window_start" field.
1388
+ func (_u *AccountUpdateOne) ClearSessionWindowStart() *AccountUpdateOne {
1389
+ _u.mutation.ClearSessionWindowStart()
1390
+ return _u
1391
+ }
1392
+
1393
+ // SetSessionWindowEnd sets the "session_window_end" field.
1394
+ func (_u *AccountUpdateOne) SetSessionWindowEnd(v time.Time) *AccountUpdateOne {
1395
+ _u.mutation.SetSessionWindowEnd(v)
1396
+ return _u
1397
+ }
1398
+
1399
+ // SetNillableSessionWindowEnd sets the "session_window_end" field if the given value is not nil.
1400
+ func (_u *AccountUpdateOne) SetNillableSessionWindowEnd(v *time.Time) *AccountUpdateOne {
1401
+ if v != nil {
1402
+ _u.SetSessionWindowEnd(*v)
1403
+ }
1404
+ return _u
1405
+ }
1406
+
1407
+ // ClearSessionWindowEnd clears the value of the "session_window_end" field.
1408
+ func (_u *AccountUpdateOne) ClearSessionWindowEnd() *AccountUpdateOne {
1409
+ _u.mutation.ClearSessionWindowEnd()
1410
+ return _u
1411
+ }
1412
+
1413
+ // SetSessionWindowStatus sets the "session_window_status" field.
1414
+ func (_u *AccountUpdateOne) SetSessionWindowStatus(v string) *AccountUpdateOne {
1415
+ _u.mutation.SetSessionWindowStatus(v)
1416
+ return _u
1417
+ }
1418
+
1419
+ // SetNillableSessionWindowStatus sets the "session_window_status" field if the given value is not nil.
1420
+ func (_u *AccountUpdateOne) SetNillableSessionWindowStatus(v *string) *AccountUpdateOne {
1421
+ if v != nil {
1422
+ _u.SetSessionWindowStatus(*v)
1423
+ }
1424
+ return _u
1425
+ }
1426
+
1427
+ // ClearSessionWindowStatus clears the value of the "session_window_status" field.
1428
+ func (_u *AccountUpdateOne) ClearSessionWindowStatus() *AccountUpdateOne {
1429
+ _u.mutation.ClearSessionWindowStatus()
1430
+ return _u
1431
+ }
1432
+
1433
+ // AddGroupIDs adds the "groups" edge to the Group entity by IDs.
1434
+ func (_u *AccountUpdateOne) AddGroupIDs(ids ...int64) *AccountUpdateOne {
1435
+ _u.mutation.AddGroupIDs(ids...)
1436
+ return _u
1437
+ }
1438
+
1439
+ // AddGroups adds the "groups" edges to the Group entity.
1440
+ func (_u *AccountUpdateOne) AddGroups(v ...*Group) *AccountUpdateOne {
1441
+ ids := make([]int64, len(v))
1442
+ for i := range v {
1443
+ ids[i] = v[i].ID
1444
+ }
1445
+ return _u.AddGroupIDs(ids...)
1446
+ }
1447
+
1448
+ // SetProxy sets the "proxy" edge to the Proxy entity.
1449
+ func (_u *AccountUpdateOne) SetProxy(v *Proxy) *AccountUpdateOne {
1450
+ return _u.SetProxyID(v.ID)
1451
+ }
1452
+
1453
+ // AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
1454
+ func (_u *AccountUpdateOne) AddUsageLogIDs(ids ...int64) *AccountUpdateOne {
1455
+ _u.mutation.AddUsageLogIDs(ids...)
1456
+ return _u
1457
+ }
1458
+
1459
+ // AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
1460
+ func (_u *AccountUpdateOne) AddUsageLogs(v ...*UsageLog) *AccountUpdateOne {
1461
+ ids := make([]int64, len(v))
1462
+ for i := range v {
1463
+ ids[i] = v[i].ID
1464
+ }
1465
+ return _u.AddUsageLogIDs(ids...)
1466
+ }
1467
+
1468
+ // Mutation returns the AccountMutation object of the builder.
1469
+ func (_u *AccountUpdateOne) Mutation() *AccountMutation {
1470
+ return _u.mutation
1471
+ }
1472
+
1473
+ // ClearGroups clears all "groups" edges to the Group entity.
1474
+ func (_u *AccountUpdateOne) ClearGroups() *AccountUpdateOne {
1475
+ _u.mutation.ClearGroups()
1476
+ return _u
1477
+ }
1478
+
1479
+ // RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
1480
+ func (_u *AccountUpdateOne) RemoveGroupIDs(ids ...int64) *AccountUpdateOne {
1481
+ _u.mutation.RemoveGroupIDs(ids...)
1482
+ return _u
1483
+ }
1484
+
1485
+ // RemoveGroups removes "groups" edges to Group entities.
1486
+ func (_u *AccountUpdateOne) RemoveGroups(v ...*Group) *AccountUpdateOne {
1487
+ ids := make([]int64, len(v))
1488
+ for i := range v {
1489
+ ids[i] = v[i].ID
1490
+ }
1491
+ return _u.RemoveGroupIDs(ids...)
1492
+ }
1493
+
1494
+ // ClearProxy clears the "proxy" edge to the Proxy entity.
1495
+ func (_u *AccountUpdateOne) ClearProxy() *AccountUpdateOne {
1496
+ _u.mutation.ClearProxy()
1497
+ return _u
1498
+ }
1499
+
1500
+ // ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
1501
+ func (_u *AccountUpdateOne) ClearUsageLogs() *AccountUpdateOne {
1502
+ _u.mutation.ClearUsageLogs()
1503
+ return _u
1504
+ }
1505
+
1506
+ // RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
1507
+ func (_u *AccountUpdateOne) RemoveUsageLogIDs(ids ...int64) *AccountUpdateOne {
1508
+ _u.mutation.RemoveUsageLogIDs(ids...)
1509
+ return _u
1510
+ }
1511
+
1512
+ // RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
1513
+ func (_u *AccountUpdateOne) RemoveUsageLogs(v ...*UsageLog) *AccountUpdateOne {
1514
+ ids := make([]int64, len(v))
1515
+ for i := range v {
1516
+ ids[i] = v[i].ID
1517
+ }
1518
+ return _u.RemoveUsageLogIDs(ids...)
1519
+ }
1520
+
1521
+ // Where appends a list predicates to the AccountUpdate builder.
1522
+ func (_u *AccountUpdateOne) Where(ps ...predicate.Account) *AccountUpdateOne {
1523
+ _u.mutation.Where(ps...)
1524
+ return _u
1525
+ }
1526
+
1527
+ // Select allows selecting one or more fields (columns) of the returned entity.
1528
+ // The default is selecting all fields defined in the entity schema.
1529
+ func (_u *AccountUpdateOne) Select(field string, fields ...string) *AccountUpdateOne {
1530
+ _u.fields = append([]string{field}, fields...)
1531
+ return _u
1532
+ }
1533
+
1534
+ // Save executes the query and returns the updated Account entity.
1535
+ func (_u *AccountUpdateOne) Save(ctx context.Context) (*Account, error) {
1536
+ if err := _u.defaults(); err != nil {
1537
+ return nil, err
1538
+ }
1539
+ return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
1540
+ }
1541
+
1542
+ // SaveX is like Save, but panics if an error occurs.
1543
+ func (_u *AccountUpdateOne) SaveX(ctx context.Context) *Account {
1544
+ node, err := _u.Save(ctx)
1545
+ if err != nil {
1546
+ panic(err)
1547
+ }
1548
+ return node
1549
+ }
1550
+
1551
+ // Exec executes the query on the entity.
1552
+ func (_u *AccountUpdateOne) Exec(ctx context.Context) error {
1553
+ _, err := _u.Save(ctx)
1554
+ return err
1555
+ }
1556
+
1557
+ // ExecX is like Exec, but panics if an error occurs.
1558
+ func (_u *AccountUpdateOne) ExecX(ctx context.Context) {
1559
+ if err := _u.Exec(ctx); err != nil {
1560
+ panic(err)
1561
+ }
1562
+ }
1563
+
1564
+ // defaults sets the default values of the builder before save.
1565
+ func (_u *AccountUpdateOne) defaults() error {
1566
+ if _, ok := _u.mutation.UpdatedAt(); !ok {
1567
+ if account.UpdateDefaultUpdatedAt == nil {
1568
+ return fmt.Errorf("ent: uninitialized account.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
1569
+ }
1570
+ v := account.UpdateDefaultUpdatedAt()
1571
+ _u.mutation.SetUpdatedAt(v)
1572
+ }
1573
+ return nil
1574
+ }
1575
+
1576
+ // check runs all checks and user-defined validators on the builder.
1577
+ func (_u *AccountUpdateOne) check() error {
1578
+ if v, ok := _u.mutation.Name(); ok {
1579
+ if err := account.NameValidator(v); err != nil {
1580
+ return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Account.name": %w`, err)}
1581
+ }
1582
+ }
1583
+ if v, ok := _u.mutation.Platform(); ok {
1584
+ if err := account.PlatformValidator(v); err != nil {
1585
+ return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Account.platform": %w`, err)}
1586
+ }
1587
+ }
1588
+ if v, ok := _u.mutation.GetType(); ok {
1589
+ if err := account.TypeValidator(v); err != nil {
1590
+ return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Account.type": %w`, err)}
1591
+ }
1592
+ }
1593
+ if v, ok := _u.mutation.Status(); ok {
1594
+ if err := account.StatusValidator(v); err != nil {
1595
+ return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Account.status": %w`, err)}
1596
+ }
1597
+ }
1598
+ if v, ok := _u.mutation.SessionWindowStatus(); ok {
1599
+ if err := account.SessionWindowStatusValidator(v); err != nil {
1600
+ return &ValidationError{Name: "session_window_status", err: fmt.Errorf(`ent: validator failed for field "Account.session_window_status": %w`, err)}
1601
+ }
1602
+ }
1603
+ return nil
1604
+ }
1605
+
1606
+ func (_u *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err error) {
1607
+ if err := _u.check(); err != nil {
1608
+ return _node, err
1609
+ }
1610
+ _spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64))
1611
+ id, ok := _u.mutation.ID()
1612
+ if !ok {
1613
+ return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Account.id" for update`)}
1614
+ }
1615
+ _spec.Node.ID.Value = id
1616
+ if fields := _u.fields; len(fields) > 0 {
1617
+ _spec.Node.Columns = make([]string, 0, len(fields))
1618
+ _spec.Node.Columns = append(_spec.Node.Columns, account.FieldID)
1619
+ for _, f := range fields {
1620
+ if !account.ValidColumn(f) {
1621
+ return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
1622
+ }
1623
+ if f != account.FieldID {
1624
+ _spec.Node.Columns = append(_spec.Node.Columns, f)
1625
+ }
1626
+ }
1627
+ }
1628
+ if ps := _u.mutation.predicates; len(ps) > 0 {
1629
+ _spec.Predicate = func(selector *sql.Selector) {
1630
+ for i := range ps {
1631
+ ps[i](selector)
1632
+ }
1633
+ }
1634
+ }
1635
+ if value, ok := _u.mutation.UpdatedAt(); ok {
1636
+ _spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
1637
+ }
1638
+ if value, ok := _u.mutation.DeletedAt(); ok {
1639
+ _spec.SetField(account.FieldDeletedAt, field.TypeTime, value)
1640
+ }
1641
+ if _u.mutation.DeletedAtCleared() {
1642
+ _spec.ClearField(account.FieldDeletedAt, field.TypeTime)
1643
+ }
1644
+ if value, ok := _u.mutation.Name(); ok {
1645
+ _spec.SetField(account.FieldName, field.TypeString, value)
1646
+ }
1647
+ if value, ok := _u.mutation.Notes(); ok {
1648
+ _spec.SetField(account.FieldNotes, field.TypeString, value)
1649
+ }
1650
+ if _u.mutation.NotesCleared() {
1651
+ _spec.ClearField(account.FieldNotes, field.TypeString)
1652
+ }
1653
+ if value, ok := _u.mutation.Platform(); ok {
1654
+ _spec.SetField(account.FieldPlatform, field.TypeString, value)
1655
+ }
1656
+ if value, ok := _u.mutation.GetType(); ok {
1657
+ _spec.SetField(account.FieldType, field.TypeString, value)
1658
+ }
1659
+ if value, ok := _u.mutation.Credentials(); ok {
1660
+ _spec.SetField(account.FieldCredentials, field.TypeJSON, value)
1661
+ }
1662
+ if value, ok := _u.mutation.Extra(); ok {
1663
+ _spec.SetField(account.FieldExtra, field.TypeJSON, value)
1664
+ }
1665
+ if value, ok := _u.mutation.Concurrency(); ok {
1666
+ _spec.SetField(account.FieldConcurrency, field.TypeInt, value)
1667
+ }
1668
+ if value, ok := _u.mutation.AddedConcurrency(); ok {
1669
+ _spec.AddField(account.FieldConcurrency, field.TypeInt, value)
1670
+ }
1671
+ if value, ok := _u.mutation.LoadFactor(); ok {
1672
+ _spec.SetField(account.FieldLoadFactor, field.TypeInt, value)
1673
+ }
1674
+ if value, ok := _u.mutation.AddedLoadFactor(); ok {
1675
+ _spec.AddField(account.FieldLoadFactor, field.TypeInt, value)
1676
+ }
1677
+ if _u.mutation.LoadFactorCleared() {
1678
+ _spec.ClearField(account.FieldLoadFactor, field.TypeInt)
1679
+ }
1680
+ if value, ok := _u.mutation.Priority(); ok {
1681
+ _spec.SetField(account.FieldPriority, field.TypeInt, value)
1682
+ }
1683
+ if value, ok := _u.mutation.AddedPriority(); ok {
1684
+ _spec.AddField(account.FieldPriority, field.TypeInt, value)
1685
+ }
1686
+ if value, ok := _u.mutation.RateMultiplier(); ok {
1687
+ _spec.SetField(account.FieldRateMultiplier, field.TypeFloat64, value)
1688
+ }
1689
+ if value, ok := _u.mutation.AddedRateMultiplier(); ok {
1690
+ _spec.AddField(account.FieldRateMultiplier, field.TypeFloat64, value)
1691
+ }
1692
+ if value, ok := _u.mutation.Status(); ok {
1693
+ _spec.SetField(account.FieldStatus, field.TypeString, value)
1694
+ }
1695
+ if value, ok := _u.mutation.ErrorMessage(); ok {
1696
+ _spec.SetField(account.FieldErrorMessage, field.TypeString, value)
1697
+ }
1698
+ if _u.mutation.ErrorMessageCleared() {
1699
+ _spec.ClearField(account.FieldErrorMessage, field.TypeString)
1700
+ }
1701
+ if value, ok := _u.mutation.LastUsedAt(); ok {
1702
+ _spec.SetField(account.FieldLastUsedAt, field.TypeTime, value)
1703
+ }
1704
+ if _u.mutation.LastUsedAtCleared() {
1705
+ _spec.ClearField(account.FieldLastUsedAt, field.TypeTime)
1706
+ }
1707
+ if value, ok := _u.mutation.ExpiresAt(); ok {
1708
+ _spec.SetField(account.FieldExpiresAt, field.TypeTime, value)
1709
+ }
1710
+ if _u.mutation.ExpiresAtCleared() {
1711
+ _spec.ClearField(account.FieldExpiresAt, field.TypeTime)
1712
+ }
1713
+ if value, ok := _u.mutation.AutoPauseOnExpired(); ok {
1714
+ _spec.SetField(account.FieldAutoPauseOnExpired, field.TypeBool, value)
1715
+ }
1716
+ if value, ok := _u.mutation.Schedulable(); ok {
1717
+ _spec.SetField(account.FieldSchedulable, field.TypeBool, value)
1718
+ }
1719
+ if value, ok := _u.mutation.RateLimitedAt(); ok {
1720
+ _spec.SetField(account.FieldRateLimitedAt, field.TypeTime, value)
1721
+ }
1722
+ if _u.mutation.RateLimitedAtCleared() {
1723
+ _spec.ClearField(account.FieldRateLimitedAt, field.TypeTime)
1724
+ }
1725
+ if value, ok := _u.mutation.RateLimitResetAt(); ok {
1726
+ _spec.SetField(account.FieldRateLimitResetAt, field.TypeTime, value)
1727
+ }
1728
+ if _u.mutation.RateLimitResetAtCleared() {
1729
+ _spec.ClearField(account.FieldRateLimitResetAt, field.TypeTime)
1730
+ }
1731
+ if value, ok := _u.mutation.OverloadUntil(); ok {
1732
+ _spec.SetField(account.FieldOverloadUntil, field.TypeTime, value)
1733
+ }
1734
+ if _u.mutation.OverloadUntilCleared() {
1735
+ _spec.ClearField(account.FieldOverloadUntil, field.TypeTime)
1736
+ }
1737
+ if value, ok := _u.mutation.TempUnschedulableUntil(); ok {
1738
+ _spec.SetField(account.FieldTempUnschedulableUntil, field.TypeTime, value)
1739
+ }
1740
+ if _u.mutation.TempUnschedulableUntilCleared() {
1741
+ _spec.ClearField(account.FieldTempUnschedulableUntil, field.TypeTime)
1742
+ }
1743
+ if value, ok := _u.mutation.TempUnschedulableReason(); ok {
1744
+ _spec.SetField(account.FieldTempUnschedulableReason, field.TypeString, value)
1745
+ }
1746
+ if _u.mutation.TempUnschedulableReasonCleared() {
1747
+ _spec.ClearField(account.FieldTempUnschedulableReason, field.TypeString)
1748
+ }
1749
+ if value, ok := _u.mutation.SessionWindowStart(); ok {
1750
+ _spec.SetField(account.FieldSessionWindowStart, field.TypeTime, value)
1751
+ }
1752
+ if _u.mutation.SessionWindowStartCleared() {
1753
+ _spec.ClearField(account.FieldSessionWindowStart, field.TypeTime)
1754
+ }
1755
+ if value, ok := _u.mutation.SessionWindowEnd(); ok {
1756
+ _spec.SetField(account.FieldSessionWindowEnd, field.TypeTime, value)
1757
+ }
1758
+ if _u.mutation.SessionWindowEndCleared() {
1759
+ _spec.ClearField(account.FieldSessionWindowEnd, field.TypeTime)
1760
+ }
1761
+ if value, ok := _u.mutation.SessionWindowStatus(); ok {
1762
+ _spec.SetField(account.FieldSessionWindowStatus, field.TypeString, value)
1763
+ }
1764
+ if _u.mutation.SessionWindowStatusCleared() {
1765
+ _spec.ClearField(account.FieldSessionWindowStatus, field.TypeString)
1766
+ }
1767
+ if _u.mutation.GroupsCleared() {
1768
+ edge := &sqlgraph.EdgeSpec{
1769
+ Rel: sqlgraph.M2M,
1770
+ Inverse: false,
1771
+ Table: account.GroupsTable,
1772
+ Columns: account.GroupsPrimaryKey,
1773
+ Bidi: false,
1774
+ Target: &sqlgraph.EdgeTarget{
1775
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
1776
+ },
1777
+ }
1778
+ createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
1779
+ createE.defaults()
1780
+ _, specE := createE.createSpec()
1781
+ edge.Target.Fields = specE.Fields
1782
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
1783
+ }
1784
+ if nodes := _u.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !_u.mutation.GroupsCleared() {
1785
+ edge := &sqlgraph.EdgeSpec{
1786
+ Rel: sqlgraph.M2M,
1787
+ Inverse: false,
1788
+ Table: account.GroupsTable,
1789
+ Columns: account.GroupsPrimaryKey,
1790
+ Bidi: false,
1791
+ Target: &sqlgraph.EdgeTarget{
1792
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
1793
+ },
1794
+ }
1795
+ for _, k := range nodes {
1796
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
1797
+ }
1798
+ createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
1799
+ createE.defaults()
1800
+ _, specE := createE.createSpec()
1801
+ edge.Target.Fields = specE.Fields
1802
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
1803
+ }
1804
+ if nodes := _u.mutation.GroupsIDs(); len(nodes) > 0 {
1805
+ edge := &sqlgraph.EdgeSpec{
1806
+ Rel: sqlgraph.M2M,
1807
+ Inverse: false,
1808
+ Table: account.GroupsTable,
1809
+ Columns: account.GroupsPrimaryKey,
1810
+ Bidi: false,
1811
+ Target: &sqlgraph.EdgeTarget{
1812
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
1813
+ },
1814
+ }
1815
+ for _, k := range nodes {
1816
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
1817
+ }
1818
+ createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
1819
+ createE.defaults()
1820
+ _, specE := createE.createSpec()
1821
+ edge.Target.Fields = specE.Fields
1822
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
1823
+ }
1824
+ if _u.mutation.ProxyCleared() {
1825
+ edge := &sqlgraph.EdgeSpec{
1826
+ Rel: sqlgraph.M2O,
1827
+ Inverse: false,
1828
+ Table: account.ProxyTable,
1829
+ Columns: []string{account.ProxyColumn},
1830
+ Bidi: false,
1831
+ Target: &sqlgraph.EdgeTarget{
1832
+ IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
1833
+ },
1834
+ }
1835
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
1836
+ }
1837
+ if nodes := _u.mutation.ProxyIDs(); len(nodes) > 0 {
1838
+ edge := &sqlgraph.EdgeSpec{
1839
+ Rel: sqlgraph.M2O,
1840
+ Inverse: false,
1841
+ Table: account.ProxyTable,
1842
+ Columns: []string{account.ProxyColumn},
1843
+ Bidi: false,
1844
+ Target: &sqlgraph.EdgeTarget{
1845
+ IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
1846
+ },
1847
+ }
1848
+ for _, k := range nodes {
1849
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
1850
+ }
1851
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
1852
+ }
1853
+ if _u.mutation.UsageLogsCleared() {
1854
+ edge := &sqlgraph.EdgeSpec{
1855
+ Rel: sqlgraph.O2M,
1856
+ Inverse: false,
1857
+ Table: account.UsageLogsTable,
1858
+ Columns: []string{account.UsageLogsColumn},
1859
+ Bidi: false,
1860
+ Target: &sqlgraph.EdgeTarget{
1861
+ IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
1862
+ },
1863
+ }
1864
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
1865
+ }
1866
+ if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
1867
+ edge := &sqlgraph.EdgeSpec{
1868
+ Rel: sqlgraph.O2M,
1869
+ Inverse: false,
1870
+ Table: account.UsageLogsTable,
1871
+ Columns: []string{account.UsageLogsColumn},
1872
+ Bidi: false,
1873
+ Target: &sqlgraph.EdgeTarget{
1874
+ IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
1875
+ },
1876
+ }
1877
+ for _, k := range nodes {
1878
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
1879
+ }
1880
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
1881
+ }
1882
+ if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
1883
+ edge := &sqlgraph.EdgeSpec{
1884
+ Rel: sqlgraph.O2M,
1885
+ Inverse: false,
1886
+ Table: account.UsageLogsTable,
1887
+ Columns: []string{account.UsageLogsColumn},
1888
+ Bidi: false,
1889
+ Target: &sqlgraph.EdgeTarget{
1890
+ IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
1891
+ },
1892
+ }
1893
+ for _, k := range nodes {
1894
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
1895
+ }
1896
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
1897
+ }
1898
+ _node = &Account{config: _u.config}
1899
+ _spec.Assign = _node.assignValues
1900
+ _spec.ScanValues = _node.scanValues
1901
+ if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
1902
+ if _, ok := err.(*sqlgraph.NotFoundError); ok {
1903
+ err = &NotFoundError{account.Label}
1904
+ } else if sqlgraph.IsConstraintError(err) {
1905
+ err = &ConstraintError{msg: err.Error(), wrap: err}
1906
+ }
1907
+ return nil, err
1908
+ }
1909
+ _u.mutation.done = true
1910
+ return _node, nil
1911
+ }
backend/ent/accountgroup.go ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "fmt"
7
+ "strings"
8
+ "time"
9
+
10
+ "entgo.io/ent"
11
+ "entgo.io/ent/dialect/sql"
12
+ "github.com/Wei-Shaw/sub2api/ent/account"
13
+ "github.com/Wei-Shaw/sub2api/ent/accountgroup"
14
+ "github.com/Wei-Shaw/sub2api/ent/group"
15
+ )
16
+
17
+ // AccountGroup is the model entity for the AccountGroup schema.
18
+ type AccountGroup struct {
19
+ config `json:"-"`
20
+ // AccountID holds the value of the "account_id" field.
21
+ AccountID int64 `json:"account_id,omitempty"`
22
+ // GroupID holds the value of the "group_id" field.
23
+ GroupID int64 `json:"group_id,omitempty"`
24
+ // Priority holds the value of the "priority" field.
25
+ Priority int `json:"priority,omitempty"`
26
+ // CreatedAt holds the value of the "created_at" field.
27
+ CreatedAt time.Time `json:"created_at,omitempty"`
28
+ // Edges holds the relations/edges for other nodes in the graph.
29
+ // The values are being populated by the AccountGroupQuery when eager-loading is set.
30
+ Edges AccountGroupEdges `json:"edges"`
31
+ selectValues sql.SelectValues
32
+ }
33
+
34
+ // AccountGroupEdges holds the relations/edges for other nodes in the graph.
35
+ type AccountGroupEdges struct {
36
+ // Account holds the value of the account edge.
37
+ Account *Account `json:"account,omitempty"`
38
+ // Group holds the value of the group edge.
39
+ Group *Group `json:"group,omitempty"`
40
+ // loadedTypes holds the information for reporting if a
41
+ // type was loaded (or requested) in eager-loading or not.
42
+ loadedTypes [2]bool
43
+ }
44
+
45
+ // AccountOrErr returns the Account value or an error if the edge
46
+ // was not loaded in eager-loading, or loaded but was not found.
47
+ func (e AccountGroupEdges) AccountOrErr() (*Account, error) {
48
+ if e.Account != nil {
49
+ return e.Account, nil
50
+ } else if e.loadedTypes[0] {
51
+ return nil, &NotFoundError{label: account.Label}
52
+ }
53
+ return nil, &NotLoadedError{edge: "account"}
54
+ }
55
+
56
+ // GroupOrErr returns the Group value or an error if the edge
57
+ // was not loaded in eager-loading, or loaded but was not found.
58
+ func (e AccountGroupEdges) GroupOrErr() (*Group, error) {
59
+ if e.Group != nil {
60
+ return e.Group, nil
61
+ } else if e.loadedTypes[1] {
62
+ return nil, &NotFoundError{label: group.Label}
63
+ }
64
+ return nil, &NotLoadedError{edge: "group"}
65
+ }
66
+
67
+ // scanValues returns the types for scanning values from sql.Rows.
68
+ func (*AccountGroup) scanValues(columns []string) ([]any, error) {
69
+ values := make([]any, len(columns))
70
+ for i := range columns {
71
+ switch columns[i] {
72
+ case accountgroup.FieldAccountID, accountgroup.FieldGroupID, accountgroup.FieldPriority:
73
+ values[i] = new(sql.NullInt64)
74
+ case accountgroup.FieldCreatedAt:
75
+ values[i] = new(sql.NullTime)
76
+ default:
77
+ values[i] = new(sql.UnknownType)
78
+ }
79
+ }
80
+ return values, nil
81
+ }
82
+
83
+ // assignValues assigns the values that were returned from sql.Rows (after scanning)
84
+ // to the AccountGroup fields.
85
+ func (_m *AccountGroup) assignValues(columns []string, values []any) error {
86
+ if m, n := len(values), len(columns); m < n {
87
+ return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
88
+ }
89
+ for i := range columns {
90
+ switch columns[i] {
91
+ case accountgroup.FieldAccountID:
92
+ if value, ok := values[i].(*sql.NullInt64); !ok {
93
+ return fmt.Errorf("unexpected type %T for field account_id", values[i])
94
+ } else if value.Valid {
95
+ _m.AccountID = value.Int64
96
+ }
97
+ case accountgroup.FieldGroupID:
98
+ if value, ok := values[i].(*sql.NullInt64); !ok {
99
+ return fmt.Errorf("unexpected type %T for field group_id", values[i])
100
+ } else if value.Valid {
101
+ _m.GroupID = value.Int64
102
+ }
103
+ case accountgroup.FieldPriority:
104
+ if value, ok := values[i].(*sql.NullInt64); !ok {
105
+ return fmt.Errorf("unexpected type %T for field priority", values[i])
106
+ } else if value.Valid {
107
+ _m.Priority = int(value.Int64)
108
+ }
109
+ case accountgroup.FieldCreatedAt:
110
+ if value, ok := values[i].(*sql.NullTime); !ok {
111
+ return fmt.Errorf("unexpected type %T for field created_at", values[i])
112
+ } else if value.Valid {
113
+ _m.CreatedAt = value.Time
114
+ }
115
+ default:
116
+ _m.selectValues.Set(columns[i], values[i])
117
+ }
118
+ }
119
+ return nil
120
+ }
121
+
122
+ // Value returns the ent.Value that was dynamically selected and assigned to the AccountGroup.
123
+ // This includes values selected through modifiers, order, etc.
124
+ func (_m *AccountGroup) Value(name string) (ent.Value, error) {
125
+ return _m.selectValues.Get(name)
126
+ }
127
+
128
+ // QueryAccount queries the "account" edge of the AccountGroup entity.
129
+ func (_m *AccountGroup) QueryAccount() *AccountQuery {
130
+ return NewAccountGroupClient(_m.config).QueryAccount(_m)
131
+ }
132
+
133
+ // QueryGroup queries the "group" edge of the AccountGroup entity.
134
+ func (_m *AccountGroup) QueryGroup() *GroupQuery {
135
+ return NewAccountGroupClient(_m.config).QueryGroup(_m)
136
+ }
137
+
138
+ // Update returns a builder for updating this AccountGroup.
139
+ // Note that you need to call AccountGroup.Unwrap() before calling this method if this AccountGroup
140
+ // was returned from a transaction, and the transaction was committed or rolled back.
141
+ func (_m *AccountGroup) Update() *AccountGroupUpdateOne {
142
+ return NewAccountGroupClient(_m.config).UpdateOne(_m)
143
+ }
144
+
145
+ // Unwrap unwraps the AccountGroup entity that was returned from a transaction after it was closed,
146
+ // so that all future queries will be executed through the driver which created the transaction.
147
+ func (_m *AccountGroup) Unwrap() *AccountGroup {
148
+ _tx, ok := _m.config.driver.(*txDriver)
149
+ if !ok {
150
+ panic("ent: AccountGroup is not a transactional entity")
151
+ }
152
+ _m.config.driver = _tx.drv
153
+ return _m
154
+ }
155
+
156
+ // String implements the fmt.Stringer.
157
+ func (_m *AccountGroup) String() string {
158
+ var builder strings.Builder
159
+ builder.WriteString("AccountGroup(")
160
+ builder.WriteString("account_id=")
161
+ builder.WriteString(fmt.Sprintf("%v", _m.AccountID))
162
+ builder.WriteString(", ")
163
+ builder.WriteString("group_id=")
164
+ builder.WriteString(fmt.Sprintf("%v", _m.GroupID))
165
+ builder.WriteString(", ")
166
+ builder.WriteString("priority=")
167
+ builder.WriteString(fmt.Sprintf("%v", _m.Priority))
168
+ builder.WriteString(", ")
169
+ builder.WriteString("created_at=")
170
+ builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
171
+ builder.WriteByte(')')
172
+ return builder.String()
173
+ }
174
+
175
+ // AccountGroups is a parsable slice of AccountGroup.
176
+ type AccountGroups []*AccountGroup
backend/ent/accountgroup/accountgroup.go ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package accountgroup
4
+
5
+ import (
6
+ "time"
7
+
8
+ "entgo.io/ent/dialect/sql"
9
+ "entgo.io/ent/dialect/sql/sqlgraph"
10
+ )
11
+
12
+ const (
13
+ // Label holds the string label denoting the accountgroup type in the database.
14
+ Label = "account_group"
15
+ // FieldAccountID holds the string denoting the account_id field in the database.
16
+ FieldAccountID = "account_id"
17
+ // FieldGroupID holds the string denoting the group_id field in the database.
18
+ FieldGroupID = "group_id"
19
+ // FieldPriority holds the string denoting the priority field in the database.
20
+ FieldPriority = "priority"
21
+ // FieldCreatedAt holds the string denoting the created_at field in the database.
22
+ FieldCreatedAt = "created_at"
23
+ // EdgeAccount holds the string denoting the account edge name in mutations.
24
+ EdgeAccount = "account"
25
+ // EdgeGroup holds the string denoting the group edge name in mutations.
26
+ EdgeGroup = "group"
27
+ // AccountFieldID holds the string denoting the ID field of the Account.
28
+ AccountFieldID = "id"
29
+ // GroupFieldID holds the string denoting the ID field of the Group.
30
+ GroupFieldID = "id"
31
+ // Table holds the table name of the accountgroup in the database.
32
+ Table = "account_groups"
33
+ // AccountTable is the table that holds the account relation/edge.
34
+ AccountTable = "account_groups"
35
+ // AccountInverseTable is the table name for the Account entity.
36
+ // It exists in this package in order to avoid circular dependency with the "account" package.
37
+ AccountInverseTable = "accounts"
38
+ // AccountColumn is the table column denoting the account relation/edge.
39
+ AccountColumn = "account_id"
40
+ // GroupTable is the table that holds the group relation/edge.
41
+ GroupTable = "account_groups"
42
+ // GroupInverseTable is the table name for the Group entity.
43
+ // It exists in this package in order to avoid circular dependency with the "group" package.
44
+ GroupInverseTable = "groups"
45
+ // GroupColumn is the table column denoting the group relation/edge.
46
+ GroupColumn = "group_id"
47
+ )
48
+
49
+ // Columns holds all SQL columns for accountgroup fields.
50
+ var Columns = []string{
51
+ FieldAccountID,
52
+ FieldGroupID,
53
+ FieldPriority,
54
+ FieldCreatedAt,
55
+ }
56
+
57
+ // ValidColumn reports if the column name is valid (part of the table columns).
58
+ func ValidColumn(column string) bool {
59
+ for i := range Columns {
60
+ if column == Columns[i] {
61
+ return true
62
+ }
63
+ }
64
+ return false
65
+ }
66
+
67
+ var (
68
+ // DefaultPriority holds the default value on creation for the "priority" field.
69
+ DefaultPriority int
70
+ // DefaultCreatedAt holds the default value on creation for the "created_at" field.
71
+ DefaultCreatedAt func() time.Time
72
+ )
73
+
74
+ // OrderOption defines the ordering options for the AccountGroup queries.
75
+ type OrderOption func(*sql.Selector)
76
+
77
+ // ByAccountID orders the results by the account_id field.
78
+ func ByAccountID(opts ...sql.OrderTermOption) OrderOption {
79
+ return sql.OrderByField(FieldAccountID, opts...).ToFunc()
80
+ }
81
+
82
+ // ByGroupID orders the results by the group_id field.
83
+ func ByGroupID(opts ...sql.OrderTermOption) OrderOption {
84
+ return sql.OrderByField(FieldGroupID, opts...).ToFunc()
85
+ }
86
+
87
+ // ByPriority orders the results by the priority field.
88
+ func ByPriority(opts ...sql.OrderTermOption) OrderOption {
89
+ return sql.OrderByField(FieldPriority, opts...).ToFunc()
90
+ }
91
+
92
+ // ByCreatedAt orders the results by the created_at field.
93
+ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
94
+ return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
95
+ }
96
+
97
+ // ByAccountField orders the results by account field.
98
+ func ByAccountField(field string, opts ...sql.OrderTermOption) OrderOption {
99
+ return func(s *sql.Selector) {
100
+ sqlgraph.OrderByNeighborTerms(s, newAccountStep(), sql.OrderByField(field, opts...))
101
+ }
102
+ }
103
+
104
+ // ByGroupField orders the results by group field.
105
+ func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption {
106
+ return func(s *sql.Selector) {
107
+ sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...))
108
+ }
109
+ }
110
+ func newAccountStep() *sqlgraph.Step {
111
+ return sqlgraph.NewStep(
112
+ sqlgraph.From(Table, AccountColumn),
113
+ sqlgraph.To(AccountInverseTable, AccountFieldID),
114
+ sqlgraph.Edge(sqlgraph.M2O, false, AccountTable, AccountColumn),
115
+ )
116
+ }
117
+ func newGroupStep() *sqlgraph.Step {
118
+ return sqlgraph.NewStep(
119
+ sqlgraph.From(Table, GroupColumn),
120
+ sqlgraph.To(GroupInverseTable, GroupFieldID),
121
+ sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn),
122
+ )
123
+ }
backend/ent/accountgroup/where.go ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package accountgroup
4
+
5
+ import (
6
+ "time"
7
+
8
+ "entgo.io/ent/dialect/sql"
9
+ "entgo.io/ent/dialect/sql/sqlgraph"
10
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
11
+ )
12
+
13
+ // AccountID applies equality check predicate on the "account_id" field. It's identical to AccountIDEQ.
14
+ func AccountID(v int64) predicate.AccountGroup {
15
+ return predicate.AccountGroup(sql.FieldEQ(FieldAccountID, v))
16
+ }
17
+
18
+ // GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
19
+ func GroupID(v int64) predicate.AccountGroup {
20
+ return predicate.AccountGroup(sql.FieldEQ(FieldGroupID, v))
21
+ }
22
+
23
+ // Priority applies equality check predicate on the "priority" field. It's identical to PriorityEQ.
24
+ func Priority(v int) predicate.AccountGroup {
25
+ return predicate.AccountGroup(sql.FieldEQ(FieldPriority, v))
26
+ }
27
+
28
+ // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
29
+ func CreatedAt(v time.Time) predicate.AccountGroup {
30
+ return predicate.AccountGroup(sql.FieldEQ(FieldCreatedAt, v))
31
+ }
32
+
33
+ // AccountIDEQ applies the EQ predicate on the "account_id" field.
34
+ func AccountIDEQ(v int64) predicate.AccountGroup {
35
+ return predicate.AccountGroup(sql.FieldEQ(FieldAccountID, v))
36
+ }
37
+
38
+ // AccountIDNEQ applies the NEQ predicate on the "account_id" field.
39
+ func AccountIDNEQ(v int64) predicate.AccountGroup {
40
+ return predicate.AccountGroup(sql.FieldNEQ(FieldAccountID, v))
41
+ }
42
+
43
+ // AccountIDIn applies the In predicate on the "account_id" field.
44
+ func AccountIDIn(vs ...int64) predicate.AccountGroup {
45
+ return predicate.AccountGroup(sql.FieldIn(FieldAccountID, vs...))
46
+ }
47
+
48
+ // AccountIDNotIn applies the NotIn predicate on the "account_id" field.
49
+ func AccountIDNotIn(vs ...int64) predicate.AccountGroup {
50
+ return predicate.AccountGroup(sql.FieldNotIn(FieldAccountID, vs...))
51
+ }
52
+
53
+ // GroupIDEQ applies the EQ predicate on the "group_id" field.
54
+ func GroupIDEQ(v int64) predicate.AccountGroup {
55
+ return predicate.AccountGroup(sql.FieldEQ(FieldGroupID, v))
56
+ }
57
+
58
+ // GroupIDNEQ applies the NEQ predicate on the "group_id" field.
59
+ func GroupIDNEQ(v int64) predicate.AccountGroup {
60
+ return predicate.AccountGroup(sql.FieldNEQ(FieldGroupID, v))
61
+ }
62
+
63
+ // GroupIDIn applies the In predicate on the "group_id" field.
64
+ func GroupIDIn(vs ...int64) predicate.AccountGroup {
65
+ return predicate.AccountGroup(sql.FieldIn(FieldGroupID, vs...))
66
+ }
67
+
68
+ // GroupIDNotIn applies the NotIn predicate on the "group_id" field.
69
+ func GroupIDNotIn(vs ...int64) predicate.AccountGroup {
70
+ return predicate.AccountGroup(sql.FieldNotIn(FieldGroupID, vs...))
71
+ }
72
+
73
+ // PriorityEQ applies the EQ predicate on the "priority" field.
74
+ func PriorityEQ(v int) predicate.AccountGroup {
75
+ return predicate.AccountGroup(sql.FieldEQ(FieldPriority, v))
76
+ }
77
+
78
+ // PriorityNEQ applies the NEQ predicate on the "priority" field.
79
+ func PriorityNEQ(v int) predicate.AccountGroup {
80
+ return predicate.AccountGroup(sql.FieldNEQ(FieldPriority, v))
81
+ }
82
+
83
+ // PriorityIn applies the In predicate on the "priority" field.
84
+ func PriorityIn(vs ...int) predicate.AccountGroup {
85
+ return predicate.AccountGroup(sql.FieldIn(FieldPriority, vs...))
86
+ }
87
+
88
+ // PriorityNotIn applies the NotIn predicate on the "priority" field.
89
+ func PriorityNotIn(vs ...int) predicate.AccountGroup {
90
+ return predicate.AccountGroup(sql.FieldNotIn(FieldPriority, vs...))
91
+ }
92
+
93
+ // PriorityGT applies the GT predicate on the "priority" field.
94
+ func PriorityGT(v int) predicate.AccountGroup {
95
+ return predicate.AccountGroup(sql.FieldGT(FieldPriority, v))
96
+ }
97
+
98
+ // PriorityGTE applies the GTE predicate on the "priority" field.
99
+ func PriorityGTE(v int) predicate.AccountGroup {
100
+ return predicate.AccountGroup(sql.FieldGTE(FieldPriority, v))
101
+ }
102
+
103
+ // PriorityLT applies the LT predicate on the "priority" field.
104
+ func PriorityLT(v int) predicate.AccountGroup {
105
+ return predicate.AccountGroup(sql.FieldLT(FieldPriority, v))
106
+ }
107
+
108
+ // PriorityLTE applies the LTE predicate on the "priority" field.
109
+ func PriorityLTE(v int) predicate.AccountGroup {
110
+ return predicate.AccountGroup(sql.FieldLTE(FieldPriority, v))
111
+ }
112
+
113
+ // CreatedAtEQ applies the EQ predicate on the "created_at" field.
114
+ func CreatedAtEQ(v time.Time) predicate.AccountGroup {
115
+ return predicate.AccountGroup(sql.FieldEQ(FieldCreatedAt, v))
116
+ }
117
+
118
+ // CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
119
+ func CreatedAtNEQ(v time.Time) predicate.AccountGroup {
120
+ return predicate.AccountGroup(sql.FieldNEQ(FieldCreatedAt, v))
121
+ }
122
+
123
+ // CreatedAtIn applies the In predicate on the "created_at" field.
124
+ func CreatedAtIn(vs ...time.Time) predicate.AccountGroup {
125
+ return predicate.AccountGroup(sql.FieldIn(FieldCreatedAt, vs...))
126
+ }
127
+
128
+ // CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
129
+ func CreatedAtNotIn(vs ...time.Time) predicate.AccountGroup {
130
+ return predicate.AccountGroup(sql.FieldNotIn(FieldCreatedAt, vs...))
131
+ }
132
+
133
+ // CreatedAtGT applies the GT predicate on the "created_at" field.
134
+ func CreatedAtGT(v time.Time) predicate.AccountGroup {
135
+ return predicate.AccountGroup(sql.FieldGT(FieldCreatedAt, v))
136
+ }
137
+
138
+ // CreatedAtGTE applies the GTE predicate on the "created_at" field.
139
+ func CreatedAtGTE(v time.Time) predicate.AccountGroup {
140
+ return predicate.AccountGroup(sql.FieldGTE(FieldCreatedAt, v))
141
+ }
142
+
143
+ // CreatedAtLT applies the LT predicate on the "created_at" field.
144
+ func CreatedAtLT(v time.Time) predicate.AccountGroup {
145
+ return predicate.AccountGroup(sql.FieldLT(FieldCreatedAt, v))
146
+ }
147
+
148
+ // CreatedAtLTE applies the LTE predicate on the "created_at" field.
149
+ func CreatedAtLTE(v time.Time) predicate.AccountGroup {
150
+ return predicate.AccountGroup(sql.FieldLTE(FieldCreatedAt, v))
151
+ }
152
+
153
+ // HasAccount applies the HasEdge predicate on the "account" edge.
154
+ func HasAccount() predicate.AccountGroup {
155
+ return predicate.AccountGroup(func(s *sql.Selector) {
156
+ step := sqlgraph.NewStep(
157
+ sqlgraph.From(Table, AccountColumn),
158
+ sqlgraph.Edge(sqlgraph.M2O, false, AccountTable, AccountColumn),
159
+ )
160
+ sqlgraph.HasNeighbors(s, step)
161
+ })
162
+ }
163
+
164
+ // HasAccountWith applies the HasEdge predicate on the "account" edge with a given conditions (other predicates).
165
+ func HasAccountWith(preds ...predicate.Account) predicate.AccountGroup {
166
+ return predicate.AccountGroup(func(s *sql.Selector) {
167
+ step := newAccountStep()
168
+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
169
+ for _, p := range preds {
170
+ p(s)
171
+ }
172
+ })
173
+ })
174
+ }
175
+
176
+ // HasGroup applies the HasEdge predicate on the "group" edge.
177
+ func HasGroup() predicate.AccountGroup {
178
+ return predicate.AccountGroup(func(s *sql.Selector) {
179
+ step := sqlgraph.NewStep(
180
+ sqlgraph.From(Table, GroupColumn),
181
+ sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn),
182
+ )
183
+ sqlgraph.HasNeighbors(s, step)
184
+ })
185
+ }
186
+
187
+ // HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates).
188
+ func HasGroupWith(preds ...predicate.Group) predicate.AccountGroup {
189
+ return predicate.AccountGroup(func(s *sql.Selector) {
190
+ step := newGroupStep()
191
+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
192
+ for _, p := range preds {
193
+ p(s)
194
+ }
195
+ })
196
+ })
197
+ }
198
+
199
+ // And groups predicates with the AND operator between them.
200
+ func And(predicates ...predicate.AccountGroup) predicate.AccountGroup {
201
+ return predicate.AccountGroup(sql.AndPredicates(predicates...))
202
+ }
203
+
204
+ // Or groups predicates with the OR operator between them.
205
+ func Or(predicates ...predicate.AccountGroup) predicate.AccountGroup {
206
+ return predicate.AccountGroup(sql.OrPredicates(predicates...))
207
+ }
208
+
209
+ // Not applies the not operator on the given predicate.
210
+ func Not(p predicate.AccountGroup) predicate.AccountGroup {
211
+ return predicate.AccountGroup(sql.NotPredicates(p))
212
+ }
backend/ent/accountgroup_create.go ADDED
@@ -0,0 +1,653 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+ "errors"
8
+ "fmt"
9
+ "time"
10
+
11
+ "entgo.io/ent/dialect/sql"
12
+ "entgo.io/ent/dialect/sql/sqlgraph"
13
+ "entgo.io/ent/schema/field"
14
+ "github.com/Wei-Shaw/sub2api/ent/account"
15
+ "github.com/Wei-Shaw/sub2api/ent/accountgroup"
16
+ "github.com/Wei-Shaw/sub2api/ent/group"
17
+ )
18
+
19
+ // AccountGroupCreate is the builder for creating a AccountGroup entity.
20
+ type AccountGroupCreate struct {
21
+ config
22
+ mutation *AccountGroupMutation
23
+ hooks []Hook
24
+ conflict []sql.ConflictOption
25
+ }
26
+
27
+ // SetAccountID sets the "account_id" field.
28
+ func (_c *AccountGroupCreate) SetAccountID(v int64) *AccountGroupCreate {
29
+ _c.mutation.SetAccountID(v)
30
+ return _c
31
+ }
32
+
33
+ // SetGroupID sets the "group_id" field.
34
+ func (_c *AccountGroupCreate) SetGroupID(v int64) *AccountGroupCreate {
35
+ _c.mutation.SetGroupID(v)
36
+ return _c
37
+ }
38
+
39
+ // SetPriority sets the "priority" field.
40
+ func (_c *AccountGroupCreate) SetPriority(v int) *AccountGroupCreate {
41
+ _c.mutation.SetPriority(v)
42
+ return _c
43
+ }
44
+
45
+ // SetNillablePriority sets the "priority" field if the given value is not nil.
46
+ func (_c *AccountGroupCreate) SetNillablePriority(v *int) *AccountGroupCreate {
47
+ if v != nil {
48
+ _c.SetPriority(*v)
49
+ }
50
+ return _c
51
+ }
52
+
53
+ // SetCreatedAt sets the "created_at" field.
54
+ func (_c *AccountGroupCreate) SetCreatedAt(v time.Time) *AccountGroupCreate {
55
+ _c.mutation.SetCreatedAt(v)
56
+ return _c
57
+ }
58
+
59
+ // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
60
+ func (_c *AccountGroupCreate) SetNillableCreatedAt(v *time.Time) *AccountGroupCreate {
61
+ if v != nil {
62
+ _c.SetCreatedAt(*v)
63
+ }
64
+ return _c
65
+ }
66
+
67
+ // SetAccount sets the "account" edge to the Account entity.
68
+ func (_c *AccountGroupCreate) SetAccount(v *Account) *AccountGroupCreate {
69
+ return _c.SetAccountID(v.ID)
70
+ }
71
+
72
+ // SetGroup sets the "group" edge to the Group entity.
73
+ func (_c *AccountGroupCreate) SetGroup(v *Group) *AccountGroupCreate {
74
+ return _c.SetGroupID(v.ID)
75
+ }
76
+
77
+ // Mutation returns the AccountGroupMutation object of the builder.
78
+ func (_c *AccountGroupCreate) Mutation() *AccountGroupMutation {
79
+ return _c.mutation
80
+ }
81
+
82
+ // Save creates the AccountGroup in the database.
83
+ func (_c *AccountGroupCreate) Save(ctx context.Context) (*AccountGroup, error) {
84
+ _c.defaults()
85
+ return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
86
+ }
87
+
88
+ // SaveX calls Save and panics if Save returns an error.
89
+ func (_c *AccountGroupCreate) SaveX(ctx context.Context) *AccountGroup {
90
+ v, err := _c.Save(ctx)
91
+ if err != nil {
92
+ panic(err)
93
+ }
94
+ return v
95
+ }
96
+
97
+ // Exec executes the query.
98
+ func (_c *AccountGroupCreate) Exec(ctx context.Context) error {
99
+ _, err := _c.Save(ctx)
100
+ return err
101
+ }
102
+
103
+ // ExecX is like Exec, but panics if an error occurs.
104
+ func (_c *AccountGroupCreate) ExecX(ctx context.Context) {
105
+ if err := _c.Exec(ctx); err != nil {
106
+ panic(err)
107
+ }
108
+ }
109
+
110
+ // defaults sets the default values of the builder before save.
111
+ func (_c *AccountGroupCreate) defaults() {
112
+ if _, ok := _c.mutation.Priority(); !ok {
113
+ v := accountgroup.DefaultPriority
114
+ _c.mutation.SetPriority(v)
115
+ }
116
+ if _, ok := _c.mutation.CreatedAt(); !ok {
117
+ v := accountgroup.DefaultCreatedAt()
118
+ _c.mutation.SetCreatedAt(v)
119
+ }
120
+ }
121
+
122
+ // check runs all checks and user-defined validators on the builder.
123
+ func (_c *AccountGroupCreate) check() error {
124
+ if _, ok := _c.mutation.AccountID(); !ok {
125
+ return &ValidationError{Name: "account_id", err: errors.New(`ent: missing required field "AccountGroup.account_id"`)}
126
+ }
127
+ if _, ok := _c.mutation.GroupID(); !ok {
128
+ return &ValidationError{Name: "group_id", err: errors.New(`ent: missing required field "AccountGroup.group_id"`)}
129
+ }
130
+ if _, ok := _c.mutation.Priority(); !ok {
131
+ return &ValidationError{Name: "priority", err: errors.New(`ent: missing required field "AccountGroup.priority"`)}
132
+ }
133
+ if _, ok := _c.mutation.CreatedAt(); !ok {
134
+ return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AccountGroup.created_at"`)}
135
+ }
136
+ if len(_c.mutation.AccountIDs()) == 0 {
137
+ return &ValidationError{Name: "account", err: errors.New(`ent: missing required edge "AccountGroup.account"`)}
138
+ }
139
+ if len(_c.mutation.GroupIDs()) == 0 {
140
+ return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "AccountGroup.group"`)}
141
+ }
142
+ return nil
143
+ }
144
+
145
+ func (_c *AccountGroupCreate) sqlSave(ctx context.Context) (*AccountGroup, error) {
146
+ if err := _c.check(); err != nil {
147
+ return nil, err
148
+ }
149
+ _node, _spec := _c.createSpec()
150
+ if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
151
+ if sqlgraph.IsConstraintError(err) {
152
+ err = &ConstraintError{msg: err.Error(), wrap: err}
153
+ }
154
+ return nil, err
155
+ }
156
+ return _node, nil
157
+ }
158
+
159
+ func (_c *AccountGroupCreate) createSpec() (*AccountGroup, *sqlgraph.CreateSpec) {
160
+ var (
161
+ _node = &AccountGroup{config: _c.config}
162
+ _spec = sqlgraph.NewCreateSpec(accountgroup.Table, nil)
163
+ )
164
+ _spec.OnConflict = _c.conflict
165
+ if value, ok := _c.mutation.Priority(); ok {
166
+ _spec.SetField(accountgroup.FieldPriority, field.TypeInt, value)
167
+ _node.Priority = value
168
+ }
169
+ if value, ok := _c.mutation.CreatedAt(); ok {
170
+ _spec.SetField(accountgroup.FieldCreatedAt, field.TypeTime, value)
171
+ _node.CreatedAt = value
172
+ }
173
+ if nodes := _c.mutation.AccountIDs(); len(nodes) > 0 {
174
+ edge := &sqlgraph.EdgeSpec{
175
+ Rel: sqlgraph.M2O,
176
+ Inverse: false,
177
+ Table: accountgroup.AccountTable,
178
+ Columns: []string{accountgroup.AccountColumn},
179
+ Bidi: false,
180
+ Target: &sqlgraph.EdgeTarget{
181
+ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
182
+ },
183
+ }
184
+ for _, k := range nodes {
185
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
186
+ }
187
+ _node.AccountID = nodes[0]
188
+ _spec.Edges = append(_spec.Edges, edge)
189
+ }
190
+ if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
191
+ edge := &sqlgraph.EdgeSpec{
192
+ Rel: sqlgraph.M2O,
193
+ Inverse: false,
194
+ Table: accountgroup.GroupTable,
195
+ Columns: []string{accountgroup.GroupColumn},
196
+ Bidi: false,
197
+ Target: &sqlgraph.EdgeTarget{
198
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
199
+ },
200
+ }
201
+ for _, k := range nodes {
202
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
203
+ }
204
+ _node.GroupID = nodes[0]
205
+ _spec.Edges = append(_spec.Edges, edge)
206
+ }
207
+ return _node, _spec
208
+ }
209
+
210
+ // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
211
+ // of the `INSERT` statement. For example:
212
+ //
213
+ // client.AccountGroup.Create().
214
+ // SetAccountID(v).
215
+ // OnConflict(
216
+ // // Update the row with the new values
217
+ // // the was proposed for insertion.
218
+ // sql.ResolveWithNewValues(),
219
+ // ).
220
+ // // Override some of the fields with custom
221
+ // // update values.
222
+ // Update(func(u *ent.AccountGroupUpsert) {
223
+ // SetAccountID(v+v).
224
+ // }).
225
+ // Exec(ctx)
226
+ func (_c *AccountGroupCreate) OnConflict(opts ...sql.ConflictOption) *AccountGroupUpsertOne {
227
+ _c.conflict = opts
228
+ return &AccountGroupUpsertOne{
229
+ create: _c,
230
+ }
231
+ }
232
+
233
+ // OnConflictColumns calls `OnConflict` and configures the columns
234
+ // as conflict target. Using this option is equivalent to using:
235
+ //
236
+ // client.AccountGroup.Create().
237
+ // OnConflict(sql.ConflictColumns(columns...)).
238
+ // Exec(ctx)
239
+ func (_c *AccountGroupCreate) OnConflictColumns(columns ...string) *AccountGroupUpsertOne {
240
+ _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
241
+ return &AccountGroupUpsertOne{
242
+ create: _c,
243
+ }
244
+ }
245
+
246
+ type (
247
+ // AccountGroupUpsertOne is the builder for "upsert"-ing
248
+ // one AccountGroup node.
249
+ AccountGroupUpsertOne struct {
250
+ create *AccountGroupCreate
251
+ }
252
+
253
+ // AccountGroupUpsert is the "OnConflict" setter.
254
+ AccountGroupUpsert struct {
255
+ *sql.UpdateSet
256
+ }
257
+ )
258
+
259
+ // SetAccountID sets the "account_id" field.
260
+ func (u *AccountGroupUpsert) SetAccountID(v int64) *AccountGroupUpsert {
261
+ u.Set(accountgroup.FieldAccountID, v)
262
+ return u
263
+ }
264
+
265
+ // UpdateAccountID sets the "account_id" field to the value that was provided on create.
266
+ func (u *AccountGroupUpsert) UpdateAccountID() *AccountGroupUpsert {
267
+ u.SetExcluded(accountgroup.FieldAccountID)
268
+ return u
269
+ }
270
+
271
+ // SetGroupID sets the "group_id" field.
272
+ func (u *AccountGroupUpsert) SetGroupID(v int64) *AccountGroupUpsert {
273
+ u.Set(accountgroup.FieldGroupID, v)
274
+ return u
275
+ }
276
+
277
+ // UpdateGroupID sets the "group_id" field to the value that was provided on create.
278
+ func (u *AccountGroupUpsert) UpdateGroupID() *AccountGroupUpsert {
279
+ u.SetExcluded(accountgroup.FieldGroupID)
280
+ return u
281
+ }
282
+
283
+ // SetPriority sets the "priority" field.
284
+ func (u *AccountGroupUpsert) SetPriority(v int) *AccountGroupUpsert {
285
+ u.Set(accountgroup.FieldPriority, v)
286
+ return u
287
+ }
288
+
289
+ // UpdatePriority sets the "priority" field to the value that was provided on create.
290
+ func (u *AccountGroupUpsert) UpdatePriority() *AccountGroupUpsert {
291
+ u.SetExcluded(accountgroup.FieldPriority)
292
+ return u
293
+ }
294
+
295
+ // AddPriority adds v to the "priority" field.
296
+ func (u *AccountGroupUpsert) AddPriority(v int) *AccountGroupUpsert {
297
+ u.Add(accountgroup.FieldPriority, v)
298
+ return u
299
+ }
300
+
301
+ // UpdateNewValues updates the mutable fields using the new values that were set on create.
302
+ // Using this option is equivalent to using:
303
+ //
304
+ // client.AccountGroup.Create().
305
+ // OnConflict(
306
+ // sql.ResolveWithNewValues(),
307
+ // ).
308
+ // Exec(ctx)
309
+ func (u *AccountGroupUpsertOne) UpdateNewValues() *AccountGroupUpsertOne {
310
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
311
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
312
+ if _, exists := u.create.mutation.CreatedAt(); exists {
313
+ s.SetIgnore(accountgroup.FieldCreatedAt)
314
+ }
315
+ }))
316
+ return u
317
+ }
318
+
319
+ // Ignore sets each column to itself in case of conflict.
320
+ // Using this option is equivalent to using:
321
+ //
322
+ // client.AccountGroup.Create().
323
+ // OnConflict(sql.ResolveWithIgnore()).
324
+ // Exec(ctx)
325
+ func (u *AccountGroupUpsertOne) Ignore() *AccountGroupUpsertOne {
326
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
327
+ return u
328
+ }
329
+
330
+ // DoNothing configures the conflict_action to `DO NOTHING`.
331
+ // Supported only by SQLite and PostgreSQL.
332
+ func (u *AccountGroupUpsertOne) DoNothing() *AccountGroupUpsertOne {
333
+ u.create.conflict = append(u.create.conflict, sql.DoNothing())
334
+ return u
335
+ }
336
+
337
+ // Update allows overriding fields `UPDATE` values. See the AccountGroupCreate.OnConflict
338
+ // documentation for more info.
339
+ func (u *AccountGroupUpsertOne) Update(set func(*AccountGroupUpsert)) *AccountGroupUpsertOne {
340
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
341
+ set(&AccountGroupUpsert{UpdateSet: update})
342
+ }))
343
+ return u
344
+ }
345
+
346
+ // SetAccountID sets the "account_id" field.
347
+ func (u *AccountGroupUpsertOne) SetAccountID(v int64) *AccountGroupUpsertOne {
348
+ return u.Update(func(s *AccountGroupUpsert) {
349
+ s.SetAccountID(v)
350
+ })
351
+ }
352
+
353
+ // UpdateAccountID sets the "account_id" field to the value that was provided on create.
354
+ func (u *AccountGroupUpsertOne) UpdateAccountID() *AccountGroupUpsertOne {
355
+ return u.Update(func(s *AccountGroupUpsert) {
356
+ s.UpdateAccountID()
357
+ })
358
+ }
359
+
360
+ // SetGroupID sets the "group_id" field.
361
+ func (u *AccountGroupUpsertOne) SetGroupID(v int64) *AccountGroupUpsertOne {
362
+ return u.Update(func(s *AccountGroupUpsert) {
363
+ s.SetGroupID(v)
364
+ })
365
+ }
366
+
367
+ // UpdateGroupID sets the "group_id" field to the value that was provided on create.
368
+ func (u *AccountGroupUpsertOne) UpdateGroupID() *AccountGroupUpsertOne {
369
+ return u.Update(func(s *AccountGroupUpsert) {
370
+ s.UpdateGroupID()
371
+ })
372
+ }
373
+
374
+ // SetPriority sets the "priority" field.
375
+ func (u *AccountGroupUpsertOne) SetPriority(v int) *AccountGroupUpsertOne {
376
+ return u.Update(func(s *AccountGroupUpsert) {
377
+ s.SetPriority(v)
378
+ })
379
+ }
380
+
381
+ // AddPriority adds v to the "priority" field.
382
+ func (u *AccountGroupUpsertOne) AddPriority(v int) *AccountGroupUpsertOne {
383
+ return u.Update(func(s *AccountGroupUpsert) {
384
+ s.AddPriority(v)
385
+ })
386
+ }
387
+
388
+ // UpdatePriority sets the "priority" field to the value that was provided on create.
389
+ func (u *AccountGroupUpsertOne) UpdatePriority() *AccountGroupUpsertOne {
390
+ return u.Update(func(s *AccountGroupUpsert) {
391
+ s.UpdatePriority()
392
+ })
393
+ }
394
+
395
+ // Exec executes the query.
396
+ func (u *AccountGroupUpsertOne) Exec(ctx context.Context) error {
397
+ if len(u.create.conflict) == 0 {
398
+ return errors.New("ent: missing options for AccountGroupCreate.OnConflict")
399
+ }
400
+ return u.create.Exec(ctx)
401
+ }
402
+
403
+ // ExecX is like Exec, but panics if an error occurs.
404
+ func (u *AccountGroupUpsertOne) ExecX(ctx context.Context) {
405
+ if err := u.create.Exec(ctx); err != nil {
406
+ panic(err)
407
+ }
408
+ }
409
+
410
+ // AccountGroupCreateBulk is the builder for creating many AccountGroup entities in bulk.
411
+ type AccountGroupCreateBulk struct {
412
+ config
413
+ err error
414
+ builders []*AccountGroupCreate
415
+ conflict []sql.ConflictOption
416
+ }
417
+
418
+ // Save creates the AccountGroup entities in the database.
419
+ func (_c *AccountGroupCreateBulk) Save(ctx context.Context) ([]*AccountGroup, error) {
420
+ if _c.err != nil {
421
+ return nil, _c.err
422
+ }
423
+ specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
424
+ nodes := make([]*AccountGroup, len(_c.builders))
425
+ mutators := make([]Mutator, len(_c.builders))
426
+ for i := range _c.builders {
427
+ func(i int, root context.Context) {
428
+ builder := _c.builders[i]
429
+ builder.defaults()
430
+ var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
431
+ mutation, ok := m.(*AccountGroupMutation)
432
+ if !ok {
433
+ return nil, fmt.Errorf("unexpected mutation type %T", m)
434
+ }
435
+ if err := builder.check(); err != nil {
436
+ return nil, err
437
+ }
438
+ builder.mutation = mutation
439
+ var err error
440
+ nodes[i], specs[i] = builder.createSpec()
441
+ if i < len(mutators)-1 {
442
+ _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
443
+ } else {
444
+ spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
445
+ spec.OnConflict = _c.conflict
446
+ // Invoke the actual operation on the latest mutation in the chain.
447
+ if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
448
+ if sqlgraph.IsConstraintError(err) {
449
+ err = &ConstraintError{msg: err.Error(), wrap: err}
450
+ }
451
+ }
452
+ }
453
+ if err != nil {
454
+ return nil, err
455
+ }
456
+ mutation.done = true
457
+ return nodes[i], nil
458
+ })
459
+ for i := len(builder.hooks) - 1; i >= 0; i-- {
460
+ mut = builder.hooks[i](mut)
461
+ }
462
+ mutators[i] = mut
463
+ }(i, ctx)
464
+ }
465
+ if len(mutators) > 0 {
466
+ if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
467
+ return nil, err
468
+ }
469
+ }
470
+ return nodes, nil
471
+ }
472
+
473
+ // SaveX is like Save, but panics if an error occurs.
474
+ func (_c *AccountGroupCreateBulk) SaveX(ctx context.Context) []*AccountGroup {
475
+ v, err := _c.Save(ctx)
476
+ if err != nil {
477
+ panic(err)
478
+ }
479
+ return v
480
+ }
481
+
482
+ // Exec executes the query.
483
+ func (_c *AccountGroupCreateBulk) Exec(ctx context.Context) error {
484
+ _, err := _c.Save(ctx)
485
+ return err
486
+ }
487
+
488
+ // ExecX is like Exec, but panics if an error occurs.
489
+ func (_c *AccountGroupCreateBulk) ExecX(ctx context.Context) {
490
+ if err := _c.Exec(ctx); err != nil {
491
+ panic(err)
492
+ }
493
+ }
494
+
495
+ // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
496
+ // of the `INSERT` statement. For example:
497
+ //
498
+ // client.AccountGroup.CreateBulk(builders...).
499
+ // OnConflict(
500
+ // // Update the row with the new values
501
+ // // the was proposed for insertion.
502
+ // sql.ResolveWithNewValues(),
503
+ // ).
504
+ // // Override some of the fields with custom
505
+ // // update values.
506
+ // Update(func(u *ent.AccountGroupUpsert) {
507
+ // SetAccountID(v+v).
508
+ // }).
509
+ // Exec(ctx)
510
+ func (_c *AccountGroupCreateBulk) OnConflict(opts ...sql.ConflictOption) *AccountGroupUpsertBulk {
511
+ _c.conflict = opts
512
+ return &AccountGroupUpsertBulk{
513
+ create: _c,
514
+ }
515
+ }
516
+
517
+ // OnConflictColumns calls `OnConflict` and configures the columns
518
+ // as conflict target. Using this option is equivalent to using:
519
+ //
520
+ // client.AccountGroup.Create().
521
+ // OnConflict(sql.ConflictColumns(columns...)).
522
+ // Exec(ctx)
523
+ func (_c *AccountGroupCreateBulk) OnConflictColumns(columns ...string) *AccountGroupUpsertBulk {
524
+ _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
525
+ return &AccountGroupUpsertBulk{
526
+ create: _c,
527
+ }
528
+ }
529
+
530
+ // AccountGroupUpsertBulk is the builder for "upsert"-ing
531
+ // a bulk of AccountGroup nodes.
532
+ type AccountGroupUpsertBulk struct {
533
+ create *AccountGroupCreateBulk
534
+ }
535
+
536
+ // UpdateNewValues updates the mutable fields using the new values that
537
+ // were set on create. Using this option is equivalent to using:
538
+ //
539
+ // client.AccountGroup.Create().
540
+ // OnConflict(
541
+ // sql.ResolveWithNewValues(),
542
+ // ).
543
+ // Exec(ctx)
544
+ func (u *AccountGroupUpsertBulk) UpdateNewValues() *AccountGroupUpsertBulk {
545
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
546
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
547
+ for _, b := range u.create.builders {
548
+ if _, exists := b.mutation.CreatedAt(); exists {
549
+ s.SetIgnore(accountgroup.FieldCreatedAt)
550
+ }
551
+ }
552
+ }))
553
+ return u
554
+ }
555
+
556
+ // Ignore sets each column to itself in case of conflict.
557
+ // Using this option is equivalent to using:
558
+ //
559
+ // client.AccountGroup.Create().
560
+ // OnConflict(sql.ResolveWithIgnore()).
561
+ // Exec(ctx)
562
+ func (u *AccountGroupUpsertBulk) Ignore() *AccountGroupUpsertBulk {
563
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
564
+ return u
565
+ }
566
+
567
+ // DoNothing configures the conflict_action to `DO NOTHING`.
568
+ // Supported only by SQLite and PostgreSQL.
569
+ func (u *AccountGroupUpsertBulk) DoNothing() *AccountGroupUpsertBulk {
570
+ u.create.conflict = append(u.create.conflict, sql.DoNothing())
571
+ return u
572
+ }
573
+
574
+ // Update allows overriding fields `UPDATE` values. See the AccountGroupCreateBulk.OnConflict
575
+ // documentation for more info.
576
+ func (u *AccountGroupUpsertBulk) Update(set func(*AccountGroupUpsert)) *AccountGroupUpsertBulk {
577
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
578
+ set(&AccountGroupUpsert{UpdateSet: update})
579
+ }))
580
+ return u
581
+ }
582
+
583
+ // SetAccountID sets the "account_id" field.
584
+ func (u *AccountGroupUpsertBulk) SetAccountID(v int64) *AccountGroupUpsertBulk {
585
+ return u.Update(func(s *AccountGroupUpsert) {
586
+ s.SetAccountID(v)
587
+ })
588
+ }
589
+
590
+ // UpdateAccountID sets the "account_id" field to the value that was provided on create.
591
+ func (u *AccountGroupUpsertBulk) UpdateAccountID() *AccountGroupUpsertBulk {
592
+ return u.Update(func(s *AccountGroupUpsert) {
593
+ s.UpdateAccountID()
594
+ })
595
+ }
596
+
597
+ // SetGroupID sets the "group_id" field.
598
+ func (u *AccountGroupUpsertBulk) SetGroupID(v int64) *AccountGroupUpsertBulk {
599
+ return u.Update(func(s *AccountGroupUpsert) {
600
+ s.SetGroupID(v)
601
+ })
602
+ }
603
+
604
+ // UpdateGroupID sets the "group_id" field to the value that was provided on create.
605
+ func (u *AccountGroupUpsertBulk) UpdateGroupID() *AccountGroupUpsertBulk {
606
+ return u.Update(func(s *AccountGroupUpsert) {
607
+ s.UpdateGroupID()
608
+ })
609
+ }
610
+
611
+ // SetPriority sets the "priority" field.
612
+ func (u *AccountGroupUpsertBulk) SetPriority(v int) *AccountGroupUpsertBulk {
613
+ return u.Update(func(s *AccountGroupUpsert) {
614
+ s.SetPriority(v)
615
+ })
616
+ }
617
+
618
+ // AddPriority adds v to the "priority" field.
619
+ func (u *AccountGroupUpsertBulk) AddPriority(v int) *AccountGroupUpsertBulk {
620
+ return u.Update(func(s *AccountGroupUpsert) {
621
+ s.AddPriority(v)
622
+ })
623
+ }
624
+
625
+ // UpdatePriority sets the "priority" field to the value that was provided on create.
626
+ func (u *AccountGroupUpsertBulk) UpdatePriority() *AccountGroupUpsertBulk {
627
+ return u.Update(func(s *AccountGroupUpsert) {
628
+ s.UpdatePriority()
629
+ })
630
+ }
631
+
632
+ // Exec executes the query.
633
+ func (u *AccountGroupUpsertBulk) Exec(ctx context.Context) error {
634
+ if u.create.err != nil {
635
+ return u.create.err
636
+ }
637
+ for i, b := range u.create.builders {
638
+ if len(b.conflict) != 0 {
639
+ return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AccountGroupCreateBulk instead", i)
640
+ }
641
+ }
642
+ if len(u.create.conflict) == 0 {
643
+ return errors.New("ent: missing options for AccountGroupCreateBulk.OnConflict")
644
+ }
645
+ return u.create.Exec(ctx)
646
+ }
647
+
648
+ // ExecX is like Exec, but panics if an error occurs.
649
+ func (u *AccountGroupUpsertBulk) ExecX(ctx context.Context) {
650
+ if err := u.create.Exec(ctx); err != nil {
651
+ panic(err)
652
+ }
653
+ }
backend/ent/accountgroup_delete.go ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+
8
+ "entgo.io/ent/dialect/sql"
9
+ "entgo.io/ent/dialect/sql/sqlgraph"
10
+ "github.com/Wei-Shaw/sub2api/ent/accountgroup"
11
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
12
+ )
13
+
14
+ // AccountGroupDelete is the builder for deleting a AccountGroup entity.
15
+ type AccountGroupDelete struct {
16
+ config
17
+ hooks []Hook
18
+ mutation *AccountGroupMutation
19
+ }
20
+
21
+ // Where appends a list predicates to the AccountGroupDelete builder.
22
+ func (_d *AccountGroupDelete) Where(ps ...predicate.AccountGroup) *AccountGroupDelete {
23
+ _d.mutation.Where(ps...)
24
+ return _d
25
+ }
26
+
27
+ // Exec executes the deletion query and returns how many vertices were deleted.
28
+ func (_d *AccountGroupDelete) Exec(ctx context.Context) (int, error) {
29
+ return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
30
+ }
31
+
32
+ // ExecX is like Exec, but panics if an error occurs.
33
+ func (_d *AccountGroupDelete) ExecX(ctx context.Context) int {
34
+ n, err := _d.Exec(ctx)
35
+ if err != nil {
36
+ panic(err)
37
+ }
38
+ return n
39
+ }
40
+
41
+ func (_d *AccountGroupDelete) sqlExec(ctx context.Context) (int, error) {
42
+ _spec := sqlgraph.NewDeleteSpec(accountgroup.Table, nil)
43
+ if ps := _d.mutation.predicates; len(ps) > 0 {
44
+ _spec.Predicate = func(selector *sql.Selector) {
45
+ for i := range ps {
46
+ ps[i](selector)
47
+ }
48
+ }
49
+ }
50
+ affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
51
+ if err != nil && sqlgraph.IsConstraintError(err) {
52
+ err = &ConstraintError{msg: err.Error(), wrap: err}
53
+ }
54
+ _d.mutation.done = true
55
+ return affected, err
56
+ }
57
+
58
+ // AccountGroupDeleteOne is the builder for deleting a single AccountGroup entity.
59
+ type AccountGroupDeleteOne struct {
60
+ _d *AccountGroupDelete
61
+ }
62
+
63
+ // Where appends a list predicates to the AccountGroupDelete builder.
64
+ func (_d *AccountGroupDeleteOne) Where(ps ...predicate.AccountGroup) *AccountGroupDeleteOne {
65
+ _d._d.mutation.Where(ps...)
66
+ return _d
67
+ }
68
+
69
+ // Exec executes the deletion query.
70
+ func (_d *AccountGroupDeleteOne) Exec(ctx context.Context) error {
71
+ n, err := _d._d.Exec(ctx)
72
+ switch {
73
+ case err != nil:
74
+ return err
75
+ case n == 0:
76
+ return &NotFoundError{accountgroup.Label}
77
+ default:
78
+ return nil
79
+ }
80
+ }
81
+
82
+ // ExecX is like Exec, but panics if an error occurs.
83
+ func (_d *AccountGroupDeleteOne) ExecX(ctx context.Context) {
84
+ if err := _d.Exec(ctx); err != nil {
85
+ panic(err)
86
+ }
87
+ }
backend/ent/accountgroup_query.go ADDED
@@ -0,0 +1,640 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+ "fmt"
8
+ "math"
9
+
10
+ "entgo.io/ent"
11
+ "entgo.io/ent/dialect"
12
+ "entgo.io/ent/dialect/sql"
13
+ "entgo.io/ent/dialect/sql/sqlgraph"
14
+ "github.com/Wei-Shaw/sub2api/ent/account"
15
+ "github.com/Wei-Shaw/sub2api/ent/accountgroup"
16
+ "github.com/Wei-Shaw/sub2api/ent/group"
17
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
18
+ )
19
+
20
+ // AccountGroupQuery is the builder for querying AccountGroup entities.
21
+ type AccountGroupQuery struct {
22
+ config
23
+ ctx *QueryContext
24
+ order []accountgroup.OrderOption
25
+ inters []Interceptor
26
+ predicates []predicate.AccountGroup
27
+ withAccount *AccountQuery
28
+ withGroup *GroupQuery
29
+ modifiers []func(*sql.Selector)
30
+ // intermediate query (i.e. traversal path).
31
+ sql *sql.Selector
32
+ path func(context.Context) (*sql.Selector, error)
33
+ }
34
+
35
+ // Where adds a new predicate for the AccountGroupQuery builder.
36
+ func (_q *AccountGroupQuery) Where(ps ...predicate.AccountGroup) *AccountGroupQuery {
37
+ _q.predicates = append(_q.predicates, ps...)
38
+ return _q
39
+ }
40
+
41
+ // Limit the number of records to be returned by this query.
42
+ func (_q *AccountGroupQuery) Limit(limit int) *AccountGroupQuery {
43
+ _q.ctx.Limit = &limit
44
+ return _q
45
+ }
46
+
47
+ // Offset to start from.
48
+ func (_q *AccountGroupQuery) Offset(offset int) *AccountGroupQuery {
49
+ _q.ctx.Offset = &offset
50
+ return _q
51
+ }
52
+
53
+ // Unique configures the query builder to filter duplicate records on query.
54
+ // By default, unique is set to true, and can be disabled using this method.
55
+ func (_q *AccountGroupQuery) Unique(unique bool) *AccountGroupQuery {
56
+ _q.ctx.Unique = &unique
57
+ return _q
58
+ }
59
+
60
+ // Order specifies how the records should be ordered.
61
+ func (_q *AccountGroupQuery) Order(o ...accountgroup.OrderOption) *AccountGroupQuery {
62
+ _q.order = append(_q.order, o...)
63
+ return _q
64
+ }
65
+
66
+ // QueryAccount chains the current query on the "account" edge.
67
+ func (_q *AccountGroupQuery) QueryAccount() *AccountQuery {
68
+ query := (&AccountClient{config: _q.config}).Query()
69
+ query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
70
+ if err := _q.prepareQuery(ctx); err != nil {
71
+ return nil, err
72
+ }
73
+ selector := _q.sqlQuery(ctx)
74
+ if err := selector.Err(); err != nil {
75
+ return nil, err
76
+ }
77
+ step := sqlgraph.NewStep(
78
+ sqlgraph.From(accountgroup.Table, accountgroup.AccountColumn, selector),
79
+ sqlgraph.To(account.Table, account.FieldID),
80
+ sqlgraph.Edge(sqlgraph.M2O, false, accountgroup.AccountTable, accountgroup.AccountColumn),
81
+ )
82
+ fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
83
+ return fromU, nil
84
+ }
85
+ return query
86
+ }
87
+
88
+ // QueryGroup chains the current query on the "group" edge.
89
+ func (_q *AccountGroupQuery) QueryGroup() *GroupQuery {
90
+ query := (&GroupClient{config: _q.config}).Query()
91
+ query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
92
+ if err := _q.prepareQuery(ctx); err != nil {
93
+ return nil, err
94
+ }
95
+ selector := _q.sqlQuery(ctx)
96
+ if err := selector.Err(); err != nil {
97
+ return nil, err
98
+ }
99
+ step := sqlgraph.NewStep(
100
+ sqlgraph.From(accountgroup.Table, accountgroup.GroupColumn, selector),
101
+ sqlgraph.To(group.Table, group.FieldID),
102
+ sqlgraph.Edge(sqlgraph.M2O, false, accountgroup.GroupTable, accountgroup.GroupColumn),
103
+ )
104
+ fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
105
+ return fromU, nil
106
+ }
107
+ return query
108
+ }
109
+
110
+ // First returns the first AccountGroup entity from the query.
111
+ // Returns a *NotFoundError when no AccountGroup was found.
112
+ func (_q *AccountGroupQuery) First(ctx context.Context) (*AccountGroup, error) {
113
+ nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
114
+ if err != nil {
115
+ return nil, err
116
+ }
117
+ if len(nodes) == 0 {
118
+ return nil, &NotFoundError{accountgroup.Label}
119
+ }
120
+ return nodes[0], nil
121
+ }
122
+
123
+ // FirstX is like First, but panics if an error occurs.
124
+ func (_q *AccountGroupQuery) FirstX(ctx context.Context) *AccountGroup {
125
+ node, err := _q.First(ctx)
126
+ if err != nil && !IsNotFound(err) {
127
+ panic(err)
128
+ }
129
+ return node
130
+ }
131
+
132
+ // Only returns a single AccountGroup entity found by the query, ensuring it only returns one.
133
+ // Returns a *NotSingularError when more than one AccountGroup entity is found.
134
+ // Returns a *NotFoundError when no AccountGroup entities are found.
135
+ func (_q *AccountGroupQuery) Only(ctx context.Context) (*AccountGroup, error) {
136
+ nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
137
+ if err != nil {
138
+ return nil, err
139
+ }
140
+ switch len(nodes) {
141
+ case 1:
142
+ return nodes[0], nil
143
+ case 0:
144
+ return nil, &NotFoundError{accountgroup.Label}
145
+ default:
146
+ return nil, &NotSingularError{accountgroup.Label}
147
+ }
148
+ }
149
+
150
+ // OnlyX is like Only, but panics if an error occurs.
151
+ func (_q *AccountGroupQuery) OnlyX(ctx context.Context) *AccountGroup {
152
+ node, err := _q.Only(ctx)
153
+ if err != nil {
154
+ panic(err)
155
+ }
156
+ return node
157
+ }
158
+
159
+ // All executes the query and returns a list of AccountGroups.
160
+ func (_q *AccountGroupQuery) All(ctx context.Context) ([]*AccountGroup, error) {
161
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
162
+ if err := _q.prepareQuery(ctx); err != nil {
163
+ return nil, err
164
+ }
165
+ qr := querierAll[[]*AccountGroup, *AccountGroupQuery]()
166
+ return withInterceptors[[]*AccountGroup](ctx, _q, qr, _q.inters)
167
+ }
168
+
169
+ // AllX is like All, but panics if an error occurs.
170
+ func (_q *AccountGroupQuery) AllX(ctx context.Context) []*AccountGroup {
171
+ nodes, err := _q.All(ctx)
172
+ if err != nil {
173
+ panic(err)
174
+ }
175
+ return nodes
176
+ }
177
+
178
+ // Count returns the count of the given query.
179
+ func (_q *AccountGroupQuery) Count(ctx context.Context) (int, error) {
180
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
181
+ if err := _q.prepareQuery(ctx); err != nil {
182
+ return 0, err
183
+ }
184
+ return withInterceptors[int](ctx, _q, querierCount[*AccountGroupQuery](), _q.inters)
185
+ }
186
+
187
+ // CountX is like Count, but panics if an error occurs.
188
+ func (_q *AccountGroupQuery) CountX(ctx context.Context) int {
189
+ count, err := _q.Count(ctx)
190
+ if err != nil {
191
+ panic(err)
192
+ }
193
+ return count
194
+ }
195
+
196
+ // Exist returns true if the query has elements in the graph.
197
+ func (_q *AccountGroupQuery) Exist(ctx context.Context) (bool, error) {
198
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
199
+ switch _, err := _q.First(ctx); {
200
+ case IsNotFound(err):
201
+ return false, nil
202
+ case err != nil:
203
+ return false, fmt.Errorf("ent: check existence: %w", err)
204
+ default:
205
+ return true, nil
206
+ }
207
+ }
208
+
209
+ // ExistX is like Exist, but panics if an error occurs.
210
+ func (_q *AccountGroupQuery) ExistX(ctx context.Context) bool {
211
+ exist, err := _q.Exist(ctx)
212
+ if err != nil {
213
+ panic(err)
214
+ }
215
+ return exist
216
+ }
217
+
218
+ // Clone returns a duplicate of the AccountGroupQuery builder, including all associated steps. It can be
219
+ // used to prepare common query builders and use them differently after the clone is made.
220
+ func (_q *AccountGroupQuery) Clone() *AccountGroupQuery {
221
+ if _q == nil {
222
+ return nil
223
+ }
224
+ return &AccountGroupQuery{
225
+ config: _q.config,
226
+ ctx: _q.ctx.Clone(),
227
+ order: append([]accountgroup.OrderOption{}, _q.order...),
228
+ inters: append([]Interceptor{}, _q.inters...),
229
+ predicates: append([]predicate.AccountGroup{}, _q.predicates...),
230
+ withAccount: _q.withAccount.Clone(),
231
+ withGroup: _q.withGroup.Clone(),
232
+ // clone intermediate query.
233
+ sql: _q.sql.Clone(),
234
+ path: _q.path,
235
+ }
236
+ }
237
+
238
+ // WithAccount tells the query-builder to eager-load the nodes that are connected to
239
+ // the "account" edge. The optional arguments are used to configure the query builder of the edge.
240
+ func (_q *AccountGroupQuery) WithAccount(opts ...func(*AccountQuery)) *AccountGroupQuery {
241
+ query := (&AccountClient{config: _q.config}).Query()
242
+ for _, opt := range opts {
243
+ opt(query)
244
+ }
245
+ _q.withAccount = query
246
+ return _q
247
+ }
248
+
249
+ // WithGroup tells the query-builder to eager-load the nodes that are connected to
250
+ // the "group" edge. The optional arguments are used to configure the query builder of the edge.
251
+ func (_q *AccountGroupQuery) WithGroup(opts ...func(*GroupQuery)) *AccountGroupQuery {
252
+ query := (&GroupClient{config: _q.config}).Query()
253
+ for _, opt := range opts {
254
+ opt(query)
255
+ }
256
+ _q.withGroup = query
257
+ return _q
258
+ }
259
+
260
+ // GroupBy is used to group vertices by one or more fields/columns.
261
+ // It is often used with aggregate functions, like: count, max, mean, min, sum.
262
+ //
263
+ // Example:
264
+ //
265
+ // var v []struct {
266
+ // AccountID int64 `json:"account_id,omitempty"`
267
+ // Count int `json:"count,omitempty"`
268
+ // }
269
+ //
270
+ // client.AccountGroup.Query().
271
+ // GroupBy(accountgroup.FieldAccountID).
272
+ // Aggregate(ent.Count()).
273
+ // Scan(ctx, &v)
274
+ func (_q *AccountGroupQuery) GroupBy(field string, fields ...string) *AccountGroupGroupBy {
275
+ _q.ctx.Fields = append([]string{field}, fields...)
276
+ grbuild := &AccountGroupGroupBy{build: _q}
277
+ grbuild.flds = &_q.ctx.Fields
278
+ grbuild.label = accountgroup.Label
279
+ grbuild.scan = grbuild.Scan
280
+ return grbuild
281
+ }
282
+
283
+ // Select allows the selection one or more fields/columns for the given query,
284
+ // instead of selecting all fields in the entity.
285
+ //
286
+ // Example:
287
+ //
288
+ // var v []struct {
289
+ // AccountID int64 `json:"account_id,omitempty"`
290
+ // }
291
+ //
292
+ // client.AccountGroup.Query().
293
+ // Select(accountgroup.FieldAccountID).
294
+ // Scan(ctx, &v)
295
+ func (_q *AccountGroupQuery) Select(fields ...string) *AccountGroupSelect {
296
+ _q.ctx.Fields = append(_q.ctx.Fields, fields...)
297
+ sbuild := &AccountGroupSelect{AccountGroupQuery: _q}
298
+ sbuild.label = accountgroup.Label
299
+ sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
300
+ return sbuild
301
+ }
302
+
303
+ // Aggregate returns a AccountGroupSelect configured with the given aggregations.
304
+ func (_q *AccountGroupQuery) Aggregate(fns ...AggregateFunc) *AccountGroupSelect {
305
+ return _q.Select().Aggregate(fns...)
306
+ }
307
+
308
+ func (_q *AccountGroupQuery) prepareQuery(ctx context.Context) error {
309
+ for _, inter := range _q.inters {
310
+ if inter == nil {
311
+ return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
312
+ }
313
+ if trv, ok := inter.(Traverser); ok {
314
+ if err := trv.Traverse(ctx, _q); err != nil {
315
+ return err
316
+ }
317
+ }
318
+ }
319
+ for _, f := range _q.ctx.Fields {
320
+ if !accountgroup.ValidColumn(f) {
321
+ return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
322
+ }
323
+ }
324
+ if _q.path != nil {
325
+ prev, err := _q.path(ctx)
326
+ if err != nil {
327
+ return err
328
+ }
329
+ _q.sql = prev
330
+ }
331
+ return nil
332
+ }
333
+
334
+ func (_q *AccountGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AccountGroup, error) {
335
+ var (
336
+ nodes = []*AccountGroup{}
337
+ _spec = _q.querySpec()
338
+ loadedTypes = [2]bool{
339
+ _q.withAccount != nil,
340
+ _q.withGroup != nil,
341
+ }
342
+ )
343
+ _spec.ScanValues = func(columns []string) ([]any, error) {
344
+ return (*AccountGroup).scanValues(nil, columns)
345
+ }
346
+ _spec.Assign = func(columns []string, values []any) error {
347
+ node := &AccountGroup{config: _q.config}
348
+ nodes = append(nodes, node)
349
+ node.Edges.loadedTypes = loadedTypes
350
+ return node.assignValues(columns, values)
351
+ }
352
+ if len(_q.modifiers) > 0 {
353
+ _spec.Modifiers = _q.modifiers
354
+ }
355
+ for i := range hooks {
356
+ hooks[i](ctx, _spec)
357
+ }
358
+ if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
359
+ return nil, err
360
+ }
361
+ if len(nodes) == 0 {
362
+ return nodes, nil
363
+ }
364
+ if query := _q.withAccount; query != nil {
365
+ if err := _q.loadAccount(ctx, query, nodes, nil,
366
+ func(n *AccountGroup, e *Account) { n.Edges.Account = e }); err != nil {
367
+ return nil, err
368
+ }
369
+ }
370
+ if query := _q.withGroup; query != nil {
371
+ if err := _q.loadGroup(ctx, query, nodes, nil,
372
+ func(n *AccountGroup, e *Group) { n.Edges.Group = e }); err != nil {
373
+ return nil, err
374
+ }
375
+ }
376
+ return nodes, nil
377
+ }
378
+
379
+ func (_q *AccountGroupQuery) loadAccount(ctx context.Context, query *AccountQuery, nodes []*AccountGroup, init func(*AccountGroup), assign func(*AccountGroup, *Account)) error {
380
+ ids := make([]int64, 0, len(nodes))
381
+ nodeids := make(map[int64][]*AccountGroup)
382
+ for i := range nodes {
383
+ fk := nodes[i].AccountID
384
+ if _, ok := nodeids[fk]; !ok {
385
+ ids = append(ids, fk)
386
+ }
387
+ nodeids[fk] = append(nodeids[fk], nodes[i])
388
+ }
389
+ if len(ids) == 0 {
390
+ return nil
391
+ }
392
+ query.Where(account.IDIn(ids...))
393
+ neighbors, err := query.All(ctx)
394
+ if err != nil {
395
+ return err
396
+ }
397
+ for _, n := range neighbors {
398
+ nodes, ok := nodeids[n.ID]
399
+ if !ok {
400
+ return fmt.Errorf(`unexpected foreign-key "account_id" returned %v`, n.ID)
401
+ }
402
+ for i := range nodes {
403
+ assign(nodes[i], n)
404
+ }
405
+ }
406
+ return nil
407
+ }
408
+ func (_q *AccountGroupQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*AccountGroup, init func(*AccountGroup), assign func(*AccountGroup, *Group)) error {
409
+ ids := make([]int64, 0, len(nodes))
410
+ nodeids := make(map[int64][]*AccountGroup)
411
+ for i := range nodes {
412
+ fk := nodes[i].GroupID
413
+ if _, ok := nodeids[fk]; !ok {
414
+ ids = append(ids, fk)
415
+ }
416
+ nodeids[fk] = append(nodeids[fk], nodes[i])
417
+ }
418
+ if len(ids) == 0 {
419
+ return nil
420
+ }
421
+ query.Where(group.IDIn(ids...))
422
+ neighbors, err := query.All(ctx)
423
+ if err != nil {
424
+ return err
425
+ }
426
+ for _, n := range neighbors {
427
+ nodes, ok := nodeids[n.ID]
428
+ if !ok {
429
+ return fmt.Errorf(`unexpected foreign-key "group_id" returned %v`, n.ID)
430
+ }
431
+ for i := range nodes {
432
+ assign(nodes[i], n)
433
+ }
434
+ }
435
+ return nil
436
+ }
437
+
438
+ func (_q *AccountGroupQuery) sqlCount(ctx context.Context) (int, error) {
439
+ _spec := _q.querySpec()
440
+ if len(_q.modifiers) > 0 {
441
+ _spec.Modifiers = _q.modifiers
442
+ }
443
+ _spec.Unique = false
444
+ _spec.Node.Columns = nil
445
+ return sqlgraph.CountNodes(ctx, _q.driver, _spec)
446
+ }
447
+
448
+ func (_q *AccountGroupQuery) querySpec() *sqlgraph.QuerySpec {
449
+ _spec := sqlgraph.NewQuerySpec(accountgroup.Table, accountgroup.Columns, nil)
450
+ _spec.From = _q.sql
451
+ if unique := _q.ctx.Unique; unique != nil {
452
+ _spec.Unique = *unique
453
+ } else if _q.path != nil {
454
+ _spec.Unique = true
455
+ }
456
+ if fields := _q.ctx.Fields; len(fields) > 0 {
457
+ _spec.Node.Columns = make([]string, 0, len(fields))
458
+ for i := range fields {
459
+ _spec.Node.Columns = append(_spec.Node.Columns, fields[i])
460
+ }
461
+ if _q.withAccount != nil {
462
+ _spec.Node.AddColumnOnce(accountgroup.FieldAccountID)
463
+ }
464
+ if _q.withGroup != nil {
465
+ _spec.Node.AddColumnOnce(accountgroup.FieldGroupID)
466
+ }
467
+ }
468
+ if ps := _q.predicates; len(ps) > 0 {
469
+ _spec.Predicate = func(selector *sql.Selector) {
470
+ for i := range ps {
471
+ ps[i](selector)
472
+ }
473
+ }
474
+ }
475
+ if limit := _q.ctx.Limit; limit != nil {
476
+ _spec.Limit = *limit
477
+ }
478
+ if offset := _q.ctx.Offset; offset != nil {
479
+ _spec.Offset = *offset
480
+ }
481
+ if ps := _q.order; len(ps) > 0 {
482
+ _spec.Order = func(selector *sql.Selector) {
483
+ for i := range ps {
484
+ ps[i](selector)
485
+ }
486
+ }
487
+ }
488
+ return _spec
489
+ }
490
+
491
+ func (_q *AccountGroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
492
+ builder := sql.Dialect(_q.driver.Dialect())
493
+ t1 := builder.Table(accountgroup.Table)
494
+ columns := _q.ctx.Fields
495
+ if len(columns) == 0 {
496
+ columns = accountgroup.Columns
497
+ }
498
+ selector := builder.Select(t1.Columns(columns...)...).From(t1)
499
+ if _q.sql != nil {
500
+ selector = _q.sql
501
+ selector.Select(selector.Columns(columns...)...)
502
+ }
503
+ if _q.ctx.Unique != nil && *_q.ctx.Unique {
504
+ selector.Distinct()
505
+ }
506
+ for _, m := range _q.modifiers {
507
+ m(selector)
508
+ }
509
+ for _, p := range _q.predicates {
510
+ p(selector)
511
+ }
512
+ for _, p := range _q.order {
513
+ p(selector)
514
+ }
515
+ if offset := _q.ctx.Offset; offset != nil {
516
+ // limit is mandatory for offset clause. We start
517
+ // with default value, and override it below if needed.
518
+ selector.Offset(*offset).Limit(math.MaxInt32)
519
+ }
520
+ if limit := _q.ctx.Limit; limit != nil {
521
+ selector.Limit(*limit)
522
+ }
523
+ return selector
524
+ }
525
+
526
+ // ForUpdate locks the selected rows against concurrent updates, and prevent them from being
527
+ // updated, deleted or "selected ... for update" by other sessions, until the transaction is
528
+ // either committed or rolled-back.
529
+ func (_q *AccountGroupQuery) ForUpdate(opts ...sql.LockOption) *AccountGroupQuery {
530
+ if _q.driver.Dialect() == dialect.Postgres {
531
+ _q.Unique(false)
532
+ }
533
+ _q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
534
+ s.ForUpdate(opts...)
535
+ })
536
+ return _q
537
+ }
538
+
539
+ // ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
540
+ // on any rows that are read. Other sessions can read the rows, but cannot modify them
541
+ // until your transaction commits.
542
+ func (_q *AccountGroupQuery) ForShare(opts ...sql.LockOption) *AccountGroupQuery {
543
+ if _q.driver.Dialect() == dialect.Postgres {
544
+ _q.Unique(false)
545
+ }
546
+ _q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
547
+ s.ForShare(opts...)
548
+ })
549
+ return _q
550
+ }
551
+
552
+ // AccountGroupGroupBy is the group-by builder for AccountGroup entities.
553
+ type AccountGroupGroupBy struct {
554
+ selector
555
+ build *AccountGroupQuery
556
+ }
557
+
558
+ // Aggregate adds the given aggregation functions to the group-by query.
559
+ func (_g *AccountGroupGroupBy) Aggregate(fns ...AggregateFunc) *AccountGroupGroupBy {
560
+ _g.fns = append(_g.fns, fns...)
561
+ return _g
562
+ }
563
+
564
+ // Scan applies the selector query and scans the result into the given value.
565
+ func (_g *AccountGroupGroupBy) Scan(ctx context.Context, v any) error {
566
+ ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
567
+ if err := _g.build.prepareQuery(ctx); err != nil {
568
+ return err
569
+ }
570
+ return scanWithInterceptors[*AccountGroupQuery, *AccountGroupGroupBy](ctx, _g.build, _g, _g.build.inters, v)
571
+ }
572
+
573
+ func (_g *AccountGroupGroupBy) sqlScan(ctx context.Context, root *AccountGroupQuery, v any) error {
574
+ selector := root.sqlQuery(ctx).Select()
575
+ aggregation := make([]string, 0, len(_g.fns))
576
+ for _, fn := range _g.fns {
577
+ aggregation = append(aggregation, fn(selector))
578
+ }
579
+ if len(selector.SelectedColumns()) == 0 {
580
+ columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
581
+ for _, f := range *_g.flds {
582
+ columns = append(columns, selector.C(f))
583
+ }
584
+ columns = append(columns, aggregation...)
585
+ selector.Select(columns...)
586
+ }
587
+ selector.GroupBy(selector.Columns(*_g.flds...)...)
588
+ if err := selector.Err(); err != nil {
589
+ return err
590
+ }
591
+ rows := &sql.Rows{}
592
+ query, args := selector.Query()
593
+ if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
594
+ return err
595
+ }
596
+ defer rows.Close()
597
+ return sql.ScanSlice(rows, v)
598
+ }
599
+
600
+ // AccountGroupSelect is the builder for selecting fields of AccountGroup entities.
601
+ type AccountGroupSelect struct {
602
+ *AccountGroupQuery
603
+ selector
604
+ }
605
+
606
+ // Aggregate adds the given aggregation functions to the selector query.
607
+ func (_s *AccountGroupSelect) Aggregate(fns ...AggregateFunc) *AccountGroupSelect {
608
+ _s.fns = append(_s.fns, fns...)
609
+ return _s
610
+ }
611
+
612
+ // Scan applies the selector query and scans the result into the given value.
613
+ func (_s *AccountGroupSelect) Scan(ctx context.Context, v any) error {
614
+ ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
615
+ if err := _s.prepareQuery(ctx); err != nil {
616
+ return err
617
+ }
618
+ return scanWithInterceptors[*AccountGroupQuery, *AccountGroupSelect](ctx, _s.AccountGroupQuery, _s, _s.inters, v)
619
+ }
620
+
621
+ func (_s *AccountGroupSelect) sqlScan(ctx context.Context, root *AccountGroupQuery, v any) error {
622
+ selector := root.sqlQuery(ctx)
623
+ aggregation := make([]string, 0, len(_s.fns))
624
+ for _, fn := range _s.fns {
625
+ aggregation = append(aggregation, fn(selector))
626
+ }
627
+ switch n := len(*_s.selector.flds); {
628
+ case n == 0 && len(aggregation) > 0:
629
+ selector.Select(aggregation...)
630
+ case n != 0 && len(aggregation) > 0:
631
+ selector.AppendSelect(aggregation...)
632
+ }
633
+ rows := &sql.Rows{}
634
+ query, args := selector.Query()
635
+ if err := _s.driver.Query(ctx, query, args, rows); err != nil {
636
+ return err
637
+ }
638
+ defer rows.Close()
639
+ return sql.ScanSlice(rows, v)
640
+ }
backend/ent/accountgroup_update.go ADDED
@@ -0,0 +1,477 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+ "errors"
8
+ "fmt"
9
+
10
+ "entgo.io/ent/dialect/sql"
11
+ "entgo.io/ent/dialect/sql/sqlgraph"
12
+ "entgo.io/ent/schema/field"
13
+ "github.com/Wei-Shaw/sub2api/ent/account"
14
+ "github.com/Wei-Shaw/sub2api/ent/accountgroup"
15
+ "github.com/Wei-Shaw/sub2api/ent/group"
16
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
17
+ )
18
+
19
+ // AccountGroupUpdate is the builder for updating AccountGroup entities.
20
+ type AccountGroupUpdate struct {
21
+ config
22
+ hooks []Hook
23
+ mutation *AccountGroupMutation
24
+ }
25
+
26
+ // Where appends a list predicates to the AccountGroupUpdate builder.
27
+ func (_u *AccountGroupUpdate) Where(ps ...predicate.AccountGroup) *AccountGroupUpdate {
28
+ _u.mutation.Where(ps...)
29
+ return _u
30
+ }
31
+
32
+ // SetAccountID sets the "account_id" field.
33
+ func (_u *AccountGroupUpdate) SetAccountID(v int64) *AccountGroupUpdate {
34
+ _u.mutation.SetAccountID(v)
35
+ return _u
36
+ }
37
+
38
+ // SetNillableAccountID sets the "account_id" field if the given value is not nil.
39
+ func (_u *AccountGroupUpdate) SetNillableAccountID(v *int64) *AccountGroupUpdate {
40
+ if v != nil {
41
+ _u.SetAccountID(*v)
42
+ }
43
+ return _u
44
+ }
45
+
46
+ // SetGroupID sets the "group_id" field.
47
+ func (_u *AccountGroupUpdate) SetGroupID(v int64) *AccountGroupUpdate {
48
+ _u.mutation.SetGroupID(v)
49
+ return _u
50
+ }
51
+
52
+ // SetNillableGroupID sets the "group_id" field if the given value is not nil.
53
+ func (_u *AccountGroupUpdate) SetNillableGroupID(v *int64) *AccountGroupUpdate {
54
+ if v != nil {
55
+ _u.SetGroupID(*v)
56
+ }
57
+ return _u
58
+ }
59
+
60
+ // SetPriority sets the "priority" field.
61
+ func (_u *AccountGroupUpdate) SetPriority(v int) *AccountGroupUpdate {
62
+ _u.mutation.ResetPriority()
63
+ _u.mutation.SetPriority(v)
64
+ return _u
65
+ }
66
+
67
+ // SetNillablePriority sets the "priority" field if the given value is not nil.
68
+ func (_u *AccountGroupUpdate) SetNillablePriority(v *int) *AccountGroupUpdate {
69
+ if v != nil {
70
+ _u.SetPriority(*v)
71
+ }
72
+ return _u
73
+ }
74
+
75
+ // AddPriority adds value to the "priority" field.
76
+ func (_u *AccountGroupUpdate) AddPriority(v int) *AccountGroupUpdate {
77
+ _u.mutation.AddPriority(v)
78
+ return _u
79
+ }
80
+
81
+ // SetAccount sets the "account" edge to the Account entity.
82
+ func (_u *AccountGroupUpdate) SetAccount(v *Account) *AccountGroupUpdate {
83
+ return _u.SetAccountID(v.ID)
84
+ }
85
+
86
+ // SetGroup sets the "group" edge to the Group entity.
87
+ func (_u *AccountGroupUpdate) SetGroup(v *Group) *AccountGroupUpdate {
88
+ return _u.SetGroupID(v.ID)
89
+ }
90
+
91
+ // Mutation returns the AccountGroupMutation object of the builder.
92
+ func (_u *AccountGroupUpdate) Mutation() *AccountGroupMutation {
93
+ return _u.mutation
94
+ }
95
+
96
+ // ClearAccount clears the "account" edge to the Account entity.
97
+ func (_u *AccountGroupUpdate) ClearAccount() *AccountGroupUpdate {
98
+ _u.mutation.ClearAccount()
99
+ return _u
100
+ }
101
+
102
+ // ClearGroup clears the "group" edge to the Group entity.
103
+ func (_u *AccountGroupUpdate) ClearGroup() *AccountGroupUpdate {
104
+ _u.mutation.ClearGroup()
105
+ return _u
106
+ }
107
+
108
+ // Save executes the query and returns the number of nodes affected by the update operation.
109
+ func (_u *AccountGroupUpdate) Save(ctx context.Context) (int, error) {
110
+ return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
111
+ }
112
+
113
+ // SaveX is like Save, but panics if an error occurs.
114
+ func (_u *AccountGroupUpdate) SaveX(ctx context.Context) int {
115
+ affected, err := _u.Save(ctx)
116
+ if err != nil {
117
+ panic(err)
118
+ }
119
+ return affected
120
+ }
121
+
122
+ // Exec executes the query.
123
+ func (_u *AccountGroupUpdate) Exec(ctx context.Context) error {
124
+ _, err := _u.Save(ctx)
125
+ return err
126
+ }
127
+
128
+ // ExecX is like Exec, but panics if an error occurs.
129
+ func (_u *AccountGroupUpdate) ExecX(ctx context.Context) {
130
+ if err := _u.Exec(ctx); err != nil {
131
+ panic(err)
132
+ }
133
+ }
134
+
135
+ // check runs all checks and user-defined validators on the builder.
136
+ func (_u *AccountGroupUpdate) check() error {
137
+ if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
138
+ return errors.New(`ent: clearing a required unique edge "AccountGroup.account"`)
139
+ }
140
+ if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
141
+ return errors.New(`ent: clearing a required unique edge "AccountGroup.group"`)
142
+ }
143
+ return nil
144
+ }
145
+
146
+ func (_u *AccountGroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
147
+ if err := _u.check(); err != nil {
148
+ return _node, err
149
+ }
150
+ _spec := sqlgraph.NewUpdateSpec(accountgroup.Table, accountgroup.Columns, sqlgraph.NewFieldSpec(accountgroup.FieldAccountID, field.TypeInt64), sqlgraph.NewFieldSpec(accountgroup.FieldGroupID, field.TypeInt64))
151
+ if ps := _u.mutation.predicates; len(ps) > 0 {
152
+ _spec.Predicate = func(selector *sql.Selector) {
153
+ for i := range ps {
154
+ ps[i](selector)
155
+ }
156
+ }
157
+ }
158
+ if value, ok := _u.mutation.Priority(); ok {
159
+ _spec.SetField(accountgroup.FieldPriority, field.TypeInt, value)
160
+ }
161
+ if value, ok := _u.mutation.AddedPriority(); ok {
162
+ _spec.AddField(accountgroup.FieldPriority, field.TypeInt, value)
163
+ }
164
+ if _u.mutation.AccountCleared() {
165
+ edge := &sqlgraph.EdgeSpec{
166
+ Rel: sqlgraph.M2O,
167
+ Inverse: false,
168
+ Table: accountgroup.AccountTable,
169
+ Columns: []string{accountgroup.AccountColumn},
170
+ Bidi: false,
171
+ Target: &sqlgraph.EdgeTarget{
172
+ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
173
+ },
174
+ }
175
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
176
+ }
177
+ if nodes := _u.mutation.AccountIDs(); len(nodes) > 0 {
178
+ edge := &sqlgraph.EdgeSpec{
179
+ Rel: sqlgraph.M2O,
180
+ Inverse: false,
181
+ Table: accountgroup.AccountTable,
182
+ Columns: []string{accountgroup.AccountColumn},
183
+ Bidi: false,
184
+ Target: &sqlgraph.EdgeTarget{
185
+ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
186
+ },
187
+ }
188
+ for _, k := range nodes {
189
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
190
+ }
191
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
192
+ }
193
+ if _u.mutation.GroupCleared() {
194
+ edge := &sqlgraph.EdgeSpec{
195
+ Rel: sqlgraph.M2O,
196
+ Inverse: false,
197
+ Table: accountgroup.GroupTable,
198
+ Columns: []string{accountgroup.GroupColumn},
199
+ Bidi: false,
200
+ Target: &sqlgraph.EdgeTarget{
201
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
202
+ },
203
+ }
204
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
205
+ }
206
+ if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
207
+ edge := &sqlgraph.EdgeSpec{
208
+ Rel: sqlgraph.M2O,
209
+ Inverse: false,
210
+ Table: accountgroup.GroupTable,
211
+ Columns: []string{accountgroup.GroupColumn},
212
+ Bidi: false,
213
+ Target: &sqlgraph.EdgeTarget{
214
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
215
+ },
216
+ }
217
+ for _, k := range nodes {
218
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
219
+ }
220
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
221
+ }
222
+ if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
223
+ if _, ok := err.(*sqlgraph.NotFoundError); ok {
224
+ err = &NotFoundError{accountgroup.Label}
225
+ } else if sqlgraph.IsConstraintError(err) {
226
+ err = &ConstraintError{msg: err.Error(), wrap: err}
227
+ }
228
+ return 0, err
229
+ }
230
+ _u.mutation.done = true
231
+ return _node, nil
232
+ }
233
+
234
+ // AccountGroupUpdateOne is the builder for updating a single AccountGroup entity.
235
+ type AccountGroupUpdateOne struct {
236
+ config
237
+ fields []string
238
+ hooks []Hook
239
+ mutation *AccountGroupMutation
240
+ }
241
+
242
+ // SetAccountID sets the "account_id" field.
243
+ func (_u *AccountGroupUpdateOne) SetAccountID(v int64) *AccountGroupUpdateOne {
244
+ _u.mutation.SetAccountID(v)
245
+ return _u
246
+ }
247
+
248
+ // SetNillableAccountID sets the "account_id" field if the given value is not nil.
249
+ func (_u *AccountGroupUpdateOne) SetNillableAccountID(v *int64) *AccountGroupUpdateOne {
250
+ if v != nil {
251
+ _u.SetAccountID(*v)
252
+ }
253
+ return _u
254
+ }
255
+
256
+ // SetGroupID sets the "group_id" field.
257
+ func (_u *AccountGroupUpdateOne) SetGroupID(v int64) *AccountGroupUpdateOne {
258
+ _u.mutation.SetGroupID(v)
259
+ return _u
260
+ }
261
+
262
+ // SetNillableGroupID sets the "group_id" field if the given value is not nil.
263
+ func (_u *AccountGroupUpdateOne) SetNillableGroupID(v *int64) *AccountGroupUpdateOne {
264
+ if v != nil {
265
+ _u.SetGroupID(*v)
266
+ }
267
+ return _u
268
+ }
269
+
270
+ // SetPriority sets the "priority" field.
271
+ func (_u *AccountGroupUpdateOne) SetPriority(v int) *AccountGroupUpdateOne {
272
+ _u.mutation.ResetPriority()
273
+ _u.mutation.SetPriority(v)
274
+ return _u
275
+ }
276
+
277
+ // SetNillablePriority sets the "priority" field if the given value is not nil.
278
+ func (_u *AccountGroupUpdateOne) SetNillablePriority(v *int) *AccountGroupUpdateOne {
279
+ if v != nil {
280
+ _u.SetPriority(*v)
281
+ }
282
+ return _u
283
+ }
284
+
285
+ // AddPriority adds value to the "priority" field.
286
+ func (_u *AccountGroupUpdateOne) AddPriority(v int) *AccountGroupUpdateOne {
287
+ _u.mutation.AddPriority(v)
288
+ return _u
289
+ }
290
+
291
+ // SetAccount sets the "account" edge to the Account entity.
292
+ func (_u *AccountGroupUpdateOne) SetAccount(v *Account) *AccountGroupUpdateOne {
293
+ return _u.SetAccountID(v.ID)
294
+ }
295
+
296
+ // SetGroup sets the "group" edge to the Group entity.
297
+ func (_u *AccountGroupUpdateOne) SetGroup(v *Group) *AccountGroupUpdateOne {
298
+ return _u.SetGroupID(v.ID)
299
+ }
300
+
301
+ // Mutation returns the AccountGroupMutation object of the builder.
302
+ func (_u *AccountGroupUpdateOne) Mutation() *AccountGroupMutation {
303
+ return _u.mutation
304
+ }
305
+
306
+ // ClearAccount clears the "account" edge to the Account entity.
307
+ func (_u *AccountGroupUpdateOne) ClearAccount() *AccountGroupUpdateOne {
308
+ _u.mutation.ClearAccount()
309
+ return _u
310
+ }
311
+
312
+ // ClearGroup clears the "group" edge to the Group entity.
313
+ func (_u *AccountGroupUpdateOne) ClearGroup() *AccountGroupUpdateOne {
314
+ _u.mutation.ClearGroup()
315
+ return _u
316
+ }
317
+
318
+ // Where appends a list predicates to the AccountGroupUpdate builder.
319
+ func (_u *AccountGroupUpdateOne) Where(ps ...predicate.AccountGroup) *AccountGroupUpdateOne {
320
+ _u.mutation.Where(ps...)
321
+ return _u
322
+ }
323
+
324
+ // Select allows selecting one or more fields (columns) of the returned entity.
325
+ // The default is selecting all fields defined in the entity schema.
326
+ func (_u *AccountGroupUpdateOne) Select(field string, fields ...string) *AccountGroupUpdateOne {
327
+ _u.fields = append([]string{field}, fields...)
328
+ return _u
329
+ }
330
+
331
+ // Save executes the query and returns the updated AccountGroup entity.
332
+ func (_u *AccountGroupUpdateOne) Save(ctx context.Context) (*AccountGroup, error) {
333
+ return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
334
+ }
335
+
336
+ // SaveX is like Save, but panics if an error occurs.
337
+ func (_u *AccountGroupUpdateOne) SaveX(ctx context.Context) *AccountGroup {
338
+ node, err := _u.Save(ctx)
339
+ if err != nil {
340
+ panic(err)
341
+ }
342
+ return node
343
+ }
344
+
345
+ // Exec executes the query on the entity.
346
+ func (_u *AccountGroupUpdateOne) Exec(ctx context.Context) error {
347
+ _, err := _u.Save(ctx)
348
+ return err
349
+ }
350
+
351
+ // ExecX is like Exec, but panics if an error occurs.
352
+ func (_u *AccountGroupUpdateOne) ExecX(ctx context.Context) {
353
+ if err := _u.Exec(ctx); err != nil {
354
+ panic(err)
355
+ }
356
+ }
357
+
358
+ // check runs all checks and user-defined validators on the builder.
359
+ func (_u *AccountGroupUpdateOne) check() error {
360
+ if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
361
+ return errors.New(`ent: clearing a required unique edge "AccountGroup.account"`)
362
+ }
363
+ if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
364
+ return errors.New(`ent: clearing a required unique edge "AccountGroup.group"`)
365
+ }
366
+ return nil
367
+ }
368
+
369
+ func (_u *AccountGroupUpdateOne) sqlSave(ctx context.Context) (_node *AccountGroup, err error) {
370
+ if err := _u.check(); err != nil {
371
+ return _node, err
372
+ }
373
+ _spec := sqlgraph.NewUpdateSpec(accountgroup.Table, accountgroup.Columns, sqlgraph.NewFieldSpec(accountgroup.FieldAccountID, field.TypeInt64), sqlgraph.NewFieldSpec(accountgroup.FieldGroupID, field.TypeInt64))
374
+ if id, ok := _u.mutation.AccountID(); !ok {
375
+ return nil, &ValidationError{Name: "account_id", err: errors.New(`ent: missing "AccountGroup.account_id" for update`)}
376
+ } else {
377
+ _spec.Node.CompositeID[0].Value = id
378
+ }
379
+ if id, ok := _u.mutation.GroupID(); !ok {
380
+ return nil, &ValidationError{Name: "group_id", err: errors.New(`ent: missing "AccountGroup.group_id" for update`)}
381
+ } else {
382
+ _spec.Node.CompositeID[1].Value = id
383
+ }
384
+ if fields := _u.fields; len(fields) > 0 {
385
+ _spec.Node.Columns = make([]string, len(fields))
386
+ for i, f := range fields {
387
+ if !accountgroup.ValidColumn(f) {
388
+ return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
389
+ }
390
+ _spec.Node.Columns[i] = f
391
+ }
392
+ }
393
+ if ps := _u.mutation.predicates; len(ps) > 0 {
394
+ _spec.Predicate = func(selector *sql.Selector) {
395
+ for i := range ps {
396
+ ps[i](selector)
397
+ }
398
+ }
399
+ }
400
+ if value, ok := _u.mutation.Priority(); ok {
401
+ _spec.SetField(accountgroup.FieldPriority, field.TypeInt, value)
402
+ }
403
+ if value, ok := _u.mutation.AddedPriority(); ok {
404
+ _spec.AddField(accountgroup.FieldPriority, field.TypeInt, value)
405
+ }
406
+ if _u.mutation.AccountCleared() {
407
+ edge := &sqlgraph.EdgeSpec{
408
+ Rel: sqlgraph.M2O,
409
+ Inverse: false,
410
+ Table: accountgroup.AccountTable,
411
+ Columns: []string{accountgroup.AccountColumn},
412
+ Bidi: false,
413
+ Target: &sqlgraph.EdgeTarget{
414
+ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
415
+ },
416
+ }
417
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
418
+ }
419
+ if nodes := _u.mutation.AccountIDs(); len(nodes) > 0 {
420
+ edge := &sqlgraph.EdgeSpec{
421
+ Rel: sqlgraph.M2O,
422
+ Inverse: false,
423
+ Table: accountgroup.AccountTable,
424
+ Columns: []string{accountgroup.AccountColumn},
425
+ Bidi: false,
426
+ Target: &sqlgraph.EdgeTarget{
427
+ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
428
+ },
429
+ }
430
+ for _, k := range nodes {
431
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
432
+ }
433
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
434
+ }
435
+ if _u.mutation.GroupCleared() {
436
+ edge := &sqlgraph.EdgeSpec{
437
+ Rel: sqlgraph.M2O,
438
+ Inverse: false,
439
+ Table: accountgroup.GroupTable,
440
+ Columns: []string{accountgroup.GroupColumn},
441
+ Bidi: false,
442
+ Target: &sqlgraph.EdgeTarget{
443
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
444
+ },
445
+ }
446
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
447
+ }
448
+ if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
449
+ edge := &sqlgraph.EdgeSpec{
450
+ Rel: sqlgraph.M2O,
451
+ Inverse: false,
452
+ Table: accountgroup.GroupTable,
453
+ Columns: []string{accountgroup.GroupColumn},
454
+ Bidi: false,
455
+ Target: &sqlgraph.EdgeTarget{
456
+ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
457
+ },
458
+ }
459
+ for _, k := range nodes {
460
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
461
+ }
462
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
463
+ }
464
+ _node = &AccountGroup{config: _u.config}
465
+ _spec.Assign = _node.assignValues
466
+ _spec.ScanValues = _node.scanValues
467
+ if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
468
+ if _, ok := err.(*sqlgraph.NotFoundError); ok {
469
+ err = &NotFoundError{accountgroup.Label}
470
+ } else if sqlgraph.IsConstraintError(err) {
471
+ err = &ConstraintError{msg: err.Error(), wrap: err}
472
+ }
473
+ return nil, err
474
+ }
475
+ _u.mutation.done = true
476
+ return _node, nil
477
+ }
backend/ent/announcement.go ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "encoding/json"
7
+ "fmt"
8
+ "strings"
9
+ "time"
10
+
11
+ "entgo.io/ent"
12
+ "entgo.io/ent/dialect/sql"
13
+ "github.com/Wei-Shaw/sub2api/ent/announcement"
14
+ "github.com/Wei-Shaw/sub2api/internal/domain"
15
+ )
16
+
17
+ // Announcement is the model entity for the Announcement schema.
18
+ type Announcement struct {
19
+ config `json:"-"`
20
+ // ID of the ent.
21
+ ID int64 `json:"id,omitempty"`
22
+ // 公告标题
23
+ Title string `json:"title,omitempty"`
24
+ // 公告内容(支持 Markdown)
25
+ Content string `json:"content,omitempty"`
26
+ // 状态: draft, active, archived
27
+ Status string `json:"status,omitempty"`
28
+ // 通知模式: silent(仅铃铛), popup(弹窗提醒)
29
+ NotifyMode string `json:"notify_mode,omitempty"`
30
+ // 展示条件(JSON 规则)
31
+ Targeting domain.AnnouncementTargeting `json:"targeting,omitempty"`
32
+ // 开始展示时间(为空表示立即生效)
33
+ StartsAt *time.Time `json:"starts_at,omitempty"`
34
+ // 结束展示时间(为空表示永久生效)
35
+ EndsAt *time.Time `json:"ends_at,omitempty"`
36
+ // 创建人用户ID(管理员)
37
+ CreatedBy *int64 `json:"created_by,omitempty"`
38
+ // 更新人用户ID(管理员)
39
+ UpdatedBy *int64 `json:"updated_by,omitempty"`
40
+ // CreatedAt holds the value of the "created_at" field.
41
+ CreatedAt time.Time `json:"created_at,omitempty"`
42
+ // UpdatedAt holds the value of the "updated_at" field.
43
+ UpdatedAt time.Time `json:"updated_at,omitempty"`
44
+ // Edges holds the relations/edges for other nodes in the graph.
45
+ // The values are being populated by the AnnouncementQuery when eager-loading is set.
46
+ Edges AnnouncementEdges `json:"edges"`
47
+ selectValues sql.SelectValues
48
+ }
49
+
50
+ // AnnouncementEdges holds the relations/edges for other nodes in the graph.
51
+ type AnnouncementEdges struct {
52
+ // Reads holds the value of the reads edge.
53
+ Reads []*AnnouncementRead `json:"reads,omitempty"`
54
+ // loadedTypes holds the information for reporting if a
55
+ // type was loaded (or requested) in eager-loading or not.
56
+ loadedTypes [1]bool
57
+ }
58
+
59
+ // ReadsOrErr returns the Reads value or an error if the edge
60
+ // was not loaded in eager-loading.
61
+ func (e AnnouncementEdges) ReadsOrErr() ([]*AnnouncementRead, error) {
62
+ if e.loadedTypes[0] {
63
+ return e.Reads, nil
64
+ }
65
+ return nil, &NotLoadedError{edge: "reads"}
66
+ }
67
+
68
+ // scanValues returns the types for scanning values from sql.Rows.
69
+ func (*Announcement) scanValues(columns []string) ([]any, error) {
70
+ values := make([]any, len(columns))
71
+ for i := range columns {
72
+ switch columns[i] {
73
+ case announcement.FieldTargeting:
74
+ values[i] = new([]byte)
75
+ case announcement.FieldID, announcement.FieldCreatedBy, announcement.FieldUpdatedBy:
76
+ values[i] = new(sql.NullInt64)
77
+ case announcement.FieldTitle, announcement.FieldContent, announcement.FieldStatus, announcement.FieldNotifyMode:
78
+ values[i] = new(sql.NullString)
79
+ case announcement.FieldStartsAt, announcement.FieldEndsAt, announcement.FieldCreatedAt, announcement.FieldUpdatedAt:
80
+ values[i] = new(sql.NullTime)
81
+ default:
82
+ values[i] = new(sql.UnknownType)
83
+ }
84
+ }
85
+ return values, nil
86
+ }
87
+
88
+ // assignValues assigns the values that were returned from sql.Rows (after scanning)
89
+ // to the Announcement fields.
90
+ func (_m *Announcement) assignValues(columns []string, values []any) error {
91
+ if m, n := len(values), len(columns); m < n {
92
+ return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
93
+ }
94
+ for i := range columns {
95
+ switch columns[i] {
96
+ case announcement.FieldID:
97
+ value, ok := values[i].(*sql.NullInt64)
98
+ if !ok {
99
+ return fmt.Errorf("unexpected type %T for field id", value)
100
+ }
101
+ _m.ID = int64(value.Int64)
102
+ case announcement.FieldTitle:
103
+ if value, ok := values[i].(*sql.NullString); !ok {
104
+ return fmt.Errorf("unexpected type %T for field title", values[i])
105
+ } else if value.Valid {
106
+ _m.Title = value.String
107
+ }
108
+ case announcement.FieldContent:
109
+ if value, ok := values[i].(*sql.NullString); !ok {
110
+ return fmt.Errorf("unexpected type %T for field content", values[i])
111
+ } else if value.Valid {
112
+ _m.Content = value.String
113
+ }
114
+ case announcement.FieldStatus:
115
+ if value, ok := values[i].(*sql.NullString); !ok {
116
+ return fmt.Errorf("unexpected type %T for field status", values[i])
117
+ } else if value.Valid {
118
+ _m.Status = value.String
119
+ }
120
+ case announcement.FieldNotifyMode:
121
+ if value, ok := values[i].(*sql.NullString); !ok {
122
+ return fmt.Errorf("unexpected type %T for field notify_mode", values[i])
123
+ } else if value.Valid {
124
+ _m.NotifyMode = value.String
125
+ }
126
+ case announcement.FieldTargeting:
127
+ if value, ok := values[i].(*[]byte); !ok {
128
+ return fmt.Errorf("unexpected type %T for field targeting", values[i])
129
+ } else if value != nil && len(*value) > 0 {
130
+ if err := json.Unmarshal(*value, &_m.Targeting); err != nil {
131
+ return fmt.Errorf("unmarshal field targeting: %w", err)
132
+ }
133
+ }
134
+ case announcement.FieldStartsAt:
135
+ if value, ok := values[i].(*sql.NullTime); !ok {
136
+ return fmt.Errorf("unexpected type %T for field starts_at", values[i])
137
+ } else if value.Valid {
138
+ _m.StartsAt = new(time.Time)
139
+ *_m.StartsAt = value.Time
140
+ }
141
+ case announcement.FieldEndsAt:
142
+ if value, ok := values[i].(*sql.NullTime); !ok {
143
+ return fmt.Errorf("unexpected type %T for field ends_at", values[i])
144
+ } else if value.Valid {
145
+ _m.EndsAt = new(time.Time)
146
+ *_m.EndsAt = value.Time
147
+ }
148
+ case announcement.FieldCreatedBy:
149
+ if value, ok := values[i].(*sql.NullInt64); !ok {
150
+ return fmt.Errorf("unexpected type %T for field created_by", values[i])
151
+ } else if value.Valid {
152
+ _m.CreatedBy = new(int64)
153
+ *_m.CreatedBy = value.Int64
154
+ }
155
+ case announcement.FieldUpdatedBy:
156
+ if value, ok := values[i].(*sql.NullInt64); !ok {
157
+ return fmt.Errorf("unexpected type %T for field updated_by", values[i])
158
+ } else if value.Valid {
159
+ _m.UpdatedBy = new(int64)
160
+ *_m.UpdatedBy = value.Int64
161
+ }
162
+ case announcement.FieldCreatedAt:
163
+ if value, ok := values[i].(*sql.NullTime); !ok {
164
+ return fmt.Errorf("unexpected type %T for field created_at", values[i])
165
+ } else if value.Valid {
166
+ _m.CreatedAt = value.Time
167
+ }
168
+ case announcement.FieldUpdatedAt:
169
+ if value, ok := values[i].(*sql.NullTime); !ok {
170
+ return fmt.Errorf("unexpected type %T for field updated_at", values[i])
171
+ } else if value.Valid {
172
+ _m.UpdatedAt = value.Time
173
+ }
174
+ default:
175
+ _m.selectValues.Set(columns[i], values[i])
176
+ }
177
+ }
178
+ return nil
179
+ }
180
+
181
+ // Value returns the ent.Value that was dynamically selected and assigned to the Announcement.
182
+ // This includes values selected through modifiers, order, etc.
183
+ func (_m *Announcement) Value(name string) (ent.Value, error) {
184
+ return _m.selectValues.Get(name)
185
+ }
186
+
187
+ // QueryReads queries the "reads" edge of the Announcement entity.
188
+ func (_m *Announcement) QueryReads() *AnnouncementReadQuery {
189
+ return NewAnnouncementClient(_m.config).QueryReads(_m)
190
+ }
191
+
192
+ // Update returns a builder for updating this Announcement.
193
+ // Note that you need to call Announcement.Unwrap() before calling this method if this Announcement
194
+ // was returned from a transaction, and the transaction was committed or rolled back.
195
+ func (_m *Announcement) Update() *AnnouncementUpdateOne {
196
+ return NewAnnouncementClient(_m.config).UpdateOne(_m)
197
+ }
198
+
199
+ // Unwrap unwraps the Announcement entity that was returned from a transaction after it was closed,
200
+ // so that all future queries will be executed through the driver which created the transaction.
201
+ func (_m *Announcement) Unwrap() *Announcement {
202
+ _tx, ok := _m.config.driver.(*txDriver)
203
+ if !ok {
204
+ panic("ent: Announcement is not a transactional entity")
205
+ }
206
+ _m.config.driver = _tx.drv
207
+ return _m
208
+ }
209
+
210
+ // String implements the fmt.Stringer.
211
+ func (_m *Announcement) String() string {
212
+ var builder strings.Builder
213
+ builder.WriteString("Announcement(")
214
+ builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
215
+ builder.WriteString("title=")
216
+ builder.WriteString(_m.Title)
217
+ builder.WriteString(", ")
218
+ builder.WriteString("content=")
219
+ builder.WriteString(_m.Content)
220
+ builder.WriteString(", ")
221
+ builder.WriteString("status=")
222
+ builder.WriteString(_m.Status)
223
+ builder.WriteString(", ")
224
+ builder.WriteString("notify_mode=")
225
+ builder.WriteString(_m.NotifyMode)
226
+ builder.WriteString(", ")
227
+ builder.WriteString("targeting=")
228
+ builder.WriteString(fmt.Sprintf("%v", _m.Targeting))
229
+ builder.WriteString(", ")
230
+ if v := _m.StartsAt; v != nil {
231
+ builder.WriteString("starts_at=")
232
+ builder.WriteString(v.Format(time.ANSIC))
233
+ }
234
+ builder.WriteString(", ")
235
+ if v := _m.EndsAt; v != nil {
236
+ builder.WriteString("ends_at=")
237
+ builder.WriteString(v.Format(time.ANSIC))
238
+ }
239
+ builder.WriteString(", ")
240
+ if v := _m.CreatedBy; v != nil {
241
+ builder.WriteString("created_by=")
242
+ builder.WriteString(fmt.Sprintf("%v", *v))
243
+ }
244
+ builder.WriteString(", ")
245
+ if v := _m.UpdatedBy; v != nil {
246
+ builder.WriteString("updated_by=")
247
+ builder.WriteString(fmt.Sprintf("%v", *v))
248
+ }
249
+ builder.WriteString(", ")
250
+ builder.WriteString("created_at=")
251
+ builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
252
+ builder.WriteString(", ")
253
+ builder.WriteString("updated_at=")
254
+ builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
255
+ builder.WriteByte(')')
256
+ return builder.String()
257
+ }
258
+
259
+ // Announcements is a parsable slice of Announcement.
260
+ type Announcements []*Announcement
backend/ent/announcement/announcement.go ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package announcement
4
+
5
+ import (
6
+ "time"
7
+
8
+ "entgo.io/ent/dialect/sql"
9
+ "entgo.io/ent/dialect/sql/sqlgraph"
10
+ )
11
+
12
+ const (
13
+ // Label holds the string label denoting the announcement type in the database.
14
+ Label = "announcement"
15
+ // FieldID holds the string denoting the id field in the database.
16
+ FieldID = "id"
17
+ // FieldTitle holds the string denoting the title field in the database.
18
+ FieldTitle = "title"
19
+ // FieldContent holds the string denoting the content field in the database.
20
+ FieldContent = "content"
21
+ // FieldStatus holds the string denoting the status field in the database.
22
+ FieldStatus = "status"
23
+ // FieldNotifyMode holds the string denoting the notify_mode field in the database.
24
+ FieldNotifyMode = "notify_mode"
25
+ // FieldTargeting holds the string denoting the targeting field in the database.
26
+ FieldTargeting = "targeting"
27
+ // FieldStartsAt holds the string denoting the starts_at field in the database.
28
+ FieldStartsAt = "starts_at"
29
+ // FieldEndsAt holds the string denoting the ends_at field in the database.
30
+ FieldEndsAt = "ends_at"
31
+ // FieldCreatedBy holds the string denoting the created_by field in the database.
32
+ FieldCreatedBy = "created_by"
33
+ // FieldUpdatedBy holds the string denoting the updated_by field in the database.
34
+ FieldUpdatedBy = "updated_by"
35
+ // FieldCreatedAt holds the string denoting the created_at field in the database.
36
+ FieldCreatedAt = "created_at"
37
+ // FieldUpdatedAt holds the string denoting the updated_at field in the database.
38
+ FieldUpdatedAt = "updated_at"
39
+ // EdgeReads holds the string denoting the reads edge name in mutations.
40
+ EdgeReads = "reads"
41
+ // Table holds the table name of the announcement in the database.
42
+ Table = "announcements"
43
+ // ReadsTable is the table that holds the reads relation/edge.
44
+ ReadsTable = "announcement_reads"
45
+ // ReadsInverseTable is the table name for the AnnouncementRead entity.
46
+ // It exists in this package in order to avoid circular dependency with the "announcementread" package.
47
+ ReadsInverseTable = "announcement_reads"
48
+ // ReadsColumn is the table column denoting the reads relation/edge.
49
+ ReadsColumn = "announcement_id"
50
+ )
51
+
52
+ // Columns holds all SQL columns for announcement fields.
53
+ var Columns = []string{
54
+ FieldID,
55
+ FieldTitle,
56
+ FieldContent,
57
+ FieldStatus,
58
+ FieldNotifyMode,
59
+ FieldTargeting,
60
+ FieldStartsAt,
61
+ FieldEndsAt,
62
+ FieldCreatedBy,
63
+ FieldUpdatedBy,
64
+ FieldCreatedAt,
65
+ FieldUpdatedAt,
66
+ }
67
+
68
+ // ValidColumn reports if the column name is valid (part of the table columns).
69
+ func ValidColumn(column string) bool {
70
+ for i := range Columns {
71
+ if column == Columns[i] {
72
+ return true
73
+ }
74
+ }
75
+ return false
76
+ }
77
+
78
+ var (
79
+ // TitleValidator is a validator for the "title" field. It is called by the builders before save.
80
+ TitleValidator func(string) error
81
+ // ContentValidator is a validator for the "content" field. It is called by the builders before save.
82
+ ContentValidator func(string) error
83
+ // DefaultStatus holds the default value on creation for the "status" field.
84
+ DefaultStatus string
85
+ // StatusValidator is a validator for the "status" field. It is called by the builders before save.
86
+ StatusValidator func(string) error
87
+ // DefaultNotifyMode holds the default value on creation for the "notify_mode" field.
88
+ DefaultNotifyMode string
89
+ // NotifyModeValidator is a validator for the "notify_mode" field. It is called by the builders before save.
90
+ NotifyModeValidator func(string) error
91
+ // DefaultCreatedAt holds the default value on creation for the "created_at" field.
92
+ DefaultCreatedAt func() time.Time
93
+ // DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
94
+ DefaultUpdatedAt func() time.Time
95
+ // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
96
+ UpdateDefaultUpdatedAt func() time.Time
97
+ )
98
+
99
+ // OrderOption defines the ordering options for the Announcement queries.
100
+ type OrderOption func(*sql.Selector)
101
+
102
+ // ByID orders the results by the id field.
103
+ func ByID(opts ...sql.OrderTermOption) OrderOption {
104
+ return sql.OrderByField(FieldID, opts...).ToFunc()
105
+ }
106
+
107
+ // ByTitle orders the results by the title field.
108
+ func ByTitle(opts ...sql.OrderTermOption) OrderOption {
109
+ return sql.OrderByField(FieldTitle, opts...).ToFunc()
110
+ }
111
+
112
+ // ByContent orders the results by the content field.
113
+ func ByContent(opts ...sql.OrderTermOption) OrderOption {
114
+ return sql.OrderByField(FieldContent, opts...).ToFunc()
115
+ }
116
+
117
+ // ByStatus orders the results by the status field.
118
+ func ByStatus(opts ...sql.OrderTermOption) OrderOption {
119
+ return sql.OrderByField(FieldStatus, opts...).ToFunc()
120
+ }
121
+
122
+ // ByNotifyMode orders the results by the notify_mode field.
123
+ func ByNotifyMode(opts ...sql.OrderTermOption) OrderOption {
124
+ return sql.OrderByField(FieldNotifyMode, opts...).ToFunc()
125
+ }
126
+
127
+ // ByStartsAt orders the results by the starts_at field.
128
+ func ByStartsAt(opts ...sql.OrderTermOption) OrderOption {
129
+ return sql.OrderByField(FieldStartsAt, opts...).ToFunc()
130
+ }
131
+
132
+ // ByEndsAt orders the results by the ends_at field.
133
+ func ByEndsAt(opts ...sql.OrderTermOption) OrderOption {
134
+ return sql.OrderByField(FieldEndsAt, opts...).ToFunc()
135
+ }
136
+
137
+ // ByCreatedBy orders the results by the created_by field.
138
+ func ByCreatedBy(opts ...sql.OrderTermOption) OrderOption {
139
+ return sql.OrderByField(FieldCreatedBy, opts...).ToFunc()
140
+ }
141
+
142
+ // ByUpdatedBy orders the results by the updated_by field.
143
+ func ByUpdatedBy(opts ...sql.OrderTermOption) OrderOption {
144
+ return sql.OrderByField(FieldUpdatedBy, opts...).ToFunc()
145
+ }
146
+
147
+ // ByCreatedAt orders the results by the created_at field.
148
+ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
149
+ return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
150
+ }
151
+
152
+ // ByUpdatedAt orders the results by the updated_at field.
153
+ func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
154
+ return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
155
+ }
156
+
157
+ // ByReadsCount orders the results by reads count.
158
+ func ByReadsCount(opts ...sql.OrderTermOption) OrderOption {
159
+ return func(s *sql.Selector) {
160
+ sqlgraph.OrderByNeighborsCount(s, newReadsStep(), opts...)
161
+ }
162
+ }
163
+
164
+ // ByReads orders the results by reads terms.
165
+ func ByReads(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
166
+ return func(s *sql.Selector) {
167
+ sqlgraph.OrderByNeighborTerms(s, newReadsStep(), append([]sql.OrderTerm{term}, terms...)...)
168
+ }
169
+ }
170
+ func newReadsStep() *sqlgraph.Step {
171
+ return sqlgraph.NewStep(
172
+ sqlgraph.From(Table, FieldID),
173
+ sqlgraph.To(ReadsInverseTable, FieldID),
174
+ sqlgraph.Edge(sqlgraph.O2M, false, ReadsTable, ReadsColumn),
175
+ )
176
+ }
backend/ent/announcement/where.go ADDED
@@ -0,0 +1,694 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package announcement
4
+
5
+ import (
6
+ "time"
7
+
8
+ "entgo.io/ent/dialect/sql"
9
+ "entgo.io/ent/dialect/sql/sqlgraph"
10
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
11
+ )
12
+
13
+ // ID filters vertices based on their ID field.
14
+ func ID(id int64) predicate.Announcement {
15
+ return predicate.Announcement(sql.FieldEQ(FieldID, id))
16
+ }
17
+
18
+ // IDEQ applies the EQ predicate on the ID field.
19
+ func IDEQ(id int64) predicate.Announcement {
20
+ return predicate.Announcement(sql.FieldEQ(FieldID, id))
21
+ }
22
+
23
+ // IDNEQ applies the NEQ predicate on the ID field.
24
+ func IDNEQ(id int64) predicate.Announcement {
25
+ return predicate.Announcement(sql.FieldNEQ(FieldID, id))
26
+ }
27
+
28
+ // IDIn applies the In predicate on the ID field.
29
+ func IDIn(ids ...int64) predicate.Announcement {
30
+ return predicate.Announcement(sql.FieldIn(FieldID, ids...))
31
+ }
32
+
33
+ // IDNotIn applies the NotIn predicate on the ID field.
34
+ func IDNotIn(ids ...int64) predicate.Announcement {
35
+ return predicate.Announcement(sql.FieldNotIn(FieldID, ids...))
36
+ }
37
+
38
+ // IDGT applies the GT predicate on the ID field.
39
+ func IDGT(id int64) predicate.Announcement {
40
+ return predicate.Announcement(sql.FieldGT(FieldID, id))
41
+ }
42
+
43
+ // IDGTE applies the GTE predicate on the ID field.
44
+ func IDGTE(id int64) predicate.Announcement {
45
+ return predicate.Announcement(sql.FieldGTE(FieldID, id))
46
+ }
47
+
48
+ // IDLT applies the LT predicate on the ID field.
49
+ func IDLT(id int64) predicate.Announcement {
50
+ return predicate.Announcement(sql.FieldLT(FieldID, id))
51
+ }
52
+
53
+ // IDLTE applies the LTE predicate on the ID field.
54
+ func IDLTE(id int64) predicate.Announcement {
55
+ return predicate.Announcement(sql.FieldLTE(FieldID, id))
56
+ }
57
+
58
+ // Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
59
+ func Title(v string) predicate.Announcement {
60
+ return predicate.Announcement(sql.FieldEQ(FieldTitle, v))
61
+ }
62
+
63
+ // Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
64
+ func Content(v string) predicate.Announcement {
65
+ return predicate.Announcement(sql.FieldEQ(FieldContent, v))
66
+ }
67
+
68
+ // Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
69
+ func Status(v string) predicate.Announcement {
70
+ return predicate.Announcement(sql.FieldEQ(FieldStatus, v))
71
+ }
72
+
73
+ // NotifyMode applies equality check predicate on the "notify_mode" field. It's identical to NotifyModeEQ.
74
+ func NotifyMode(v string) predicate.Announcement {
75
+ return predicate.Announcement(sql.FieldEQ(FieldNotifyMode, v))
76
+ }
77
+
78
+ // StartsAt applies equality check predicate on the "starts_at" field. It's identical to StartsAtEQ.
79
+ func StartsAt(v time.Time) predicate.Announcement {
80
+ return predicate.Announcement(sql.FieldEQ(FieldStartsAt, v))
81
+ }
82
+
83
+ // EndsAt applies equality check predicate on the "ends_at" field. It's identical to EndsAtEQ.
84
+ func EndsAt(v time.Time) predicate.Announcement {
85
+ return predicate.Announcement(sql.FieldEQ(FieldEndsAt, v))
86
+ }
87
+
88
+ // CreatedBy applies equality check predicate on the "created_by" field. It's identical to CreatedByEQ.
89
+ func CreatedBy(v int64) predicate.Announcement {
90
+ return predicate.Announcement(sql.FieldEQ(FieldCreatedBy, v))
91
+ }
92
+
93
+ // UpdatedBy applies equality check predicate on the "updated_by" field. It's identical to UpdatedByEQ.
94
+ func UpdatedBy(v int64) predicate.Announcement {
95
+ return predicate.Announcement(sql.FieldEQ(FieldUpdatedBy, v))
96
+ }
97
+
98
+ // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
99
+ func CreatedAt(v time.Time) predicate.Announcement {
100
+ return predicate.Announcement(sql.FieldEQ(FieldCreatedAt, v))
101
+ }
102
+
103
+ // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
104
+ func UpdatedAt(v time.Time) predicate.Announcement {
105
+ return predicate.Announcement(sql.FieldEQ(FieldUpdatedAt, v))
106
+ }
107
+
108
+ // TitleEQ applies the EQ predicate on the "title" field.
109
+ func TitleEQ(v string) predicate.Announcement {
110
+ return predicate.Announcement(sql.FieldEQ(FieldTitle, v))
111
+ }
112
+
113
+ // TitleNEQ applies the NEQ predicate on the "title" field.
114
+ func TitleNEQ(v string) predicate.Announcement {
115
+ return predicate.Announcement(sql.FieldNEQ(FieldTitle, v))
116
+ }
117
+
118
+ // TitleIn applies the In predicate on the "title" field.
119
+ func TitleIn(vs ...string) predicate.Announcement {
120
+ return predicate.Announcement(sql.FieldIn(FieldTitle, vs...))
121
+ }
122
+
123
+ // TitleNotIn applies the NotIn predicate on the "title" field.
124
+ func TitleNotIn(vs ...string) predicate.Announcement {
125
+ return predicate.Announcement(sql.FieldNotIn(FieldTitle, vs...))
126
+ }
127
+
128
+ // TitleGT applies the GT predicate on the "title" field.
129
+ func TitleGT(v string) predicate.Announcement {
130
+ return predicate.Announcement(sql.FieldGT(FieldTitle, v))
131
+ }
132
+
133
+ // TitleGTE applies the GTE predicate on the "title" field.
134
+ func TitleGTE(v string) predicate.Announcement {
135
+ return predicate.Announcement(sql.FieldGTE(FieldTitle, v))
136
+ }
137
+
138
+ // TitleLT applies the LT predicate on the "title" field.
139
+ func TitleLT(v string) predicate.Announcement {
140
+ return predicate.Announcement(sql.FieldLT(FieldTitle, v))
141
+ }
142
+
143
+ // TitleLTE applies the LTE predicate on the "title" field.
144
+ func TitleLTE(v string) predicate.Announcement {
145
+ return predicate.Announcement(sql.FieldLTE(FieldTitle, v))
146
+ }
147
+
148
+ // TitleContains applies the Contains predicate on the "title" field.
149
+ func TitleContains(v string) predicate.Announcement {
150
+ return predicate.Announcement(sql.FieldContains(FieldTitle, v))
151
+ }
152
+
153
+ // TitleHasPrefix applies the HasPrefix predicate on the "title" field.
154
+ func TitleHasPrefix(v string) predicate.Announcement {
155
+ return predicate.Announcement(sql.FieldHasPrefix(FieldTitle, v))
156
+ }
157
+
158
+ // TitleHasSuffix applies the HasSuffix predicate on the "title" field.
159
+ func TitleHasSuffix(v string) predicate.Announcement {
160
+ return predicate.Announcement(sql.FieldHasSuffix(FieldTitle, v))
161
+ }
162
+
163
+ // TitleEqualFold applies the EqualFold predicate on the "title" field.
164
+ func TitleEqualFold(v string) predicate.Announcement {
165
+ return predicate.Announcement(sql.FieldEqualFold(FieldTitle, v))
166
+ }
167
+
168
+ // TitleContainsFold applies the ContainsFold predicate on the "title" field.
169
+ func TitleContainsFold(v string) predicate.Announcement {
170
+ return predicate.Announcement(sql.FieldContainsFold(FieldTitle, v))
171
+ }
172
+
173
+ // ContentEQ applies the EQ predicate on the "content" field.
174
+ func ContentEQ(v string) predicate.Announcement {
175
+ return predicate.Announcement(sql.FieldEQ(FieldContent, v))
176
+ }
177
+
178
+ // ContentNEQ applies the NEQ predicate on the "content" field.
179
+ func ContentNEQ(v string) predicate.Announcement {
180
+ return predicate.Announcement(sql.FieldNEQ(FieldContent, v))
181
+ }
182
+
183
+ // ContentIn applies the In predicate on the "content" field.
184
+ func ContentIn(vs ...string) predicate.Announcement {
185
+ return predicate.Announcement(sql.FieldIn(FieldContent, vs...))
186
+ }
187
+
188
+ // ContentNotIn applies the NotIn predicate on the "content" field.
189
+ func ContentNotIn(vs ...string) predicate.Announcement {
190
+ return predicate.Announcement(sql.FieldNotIn(FieldContent, vs...))
191
+ }
192
+
193
+ // ContentGT applies the GT predicate on the "content" field.
194
+ func ContentGT(v string) predicate.Announcement {
195
+ return predicate.Announcement(sql.FieldGT(FieldContent, v))
196
+ }
197
+
198
+ // ContentGTE applies the GTE predicate on the "content" field.
199
+ func ContentGTE(v string) predicate.Announcement {
200
+ return predicate.Announcement(sql.FieldGTE(FieldContent, v))
201
+ }
202
+
203
+ // ContentLT applies the LT predicate on the "content" field.
204
+ func ContentLT(v string) predicate.Announcement {
205
+ return predicate.Announcement(sql.FieldLT(FieldContent, v))
206
+ }
207
+
208
+ // ContentLTE applies the LTE predicate on the "content" field.
209
+ func ContentLTE(v string) predicate.Announcement {
210
+ return predicate.Announcement(sql.FieldLTE(FieldContent, v))
211
+ }
212
+
213
+ // ContentContains applies the Contains predicate on the "content" field.
214
+ func ContentContains(v string) predicate.Announcement {
215
+ return predicate.Announcement(sql.FieldContains(FieldContent, v))
216
+ }
217
+
218
+ // ContentHasPrefix applies the HasPrefix predicate on the "content" field.
219
+ func ContentHasPrefix(v string) predicate.Announcement {
220
+ return predicate.Announcement(sql.FieldHasPrefix(FieldContent, v))
221
+ }
222
+
223
+ // ContentHasSuffix applies the HasSuffix predicate on the "content" field.
224
+ func ContentHasSuffix(v string) predicate.Announcement {
225
+ return predicate.Announcement(sql.FieldHasSuffix(FieldContent, v))
226
+ }
227
+
228
+ // ContentEqualFold applies the EqualFold predicate on the "content" field.
229
+ func ContentEqualFold(v string) predicate.Announcement {
230
+ return predicate.Announcement(sql.FieldEqualFold(FieldContent, v))
231
+ }
232
+
233
+ // ContentContainsFold applies the ContainsFold predicate on the "content" field.
234
+ func ContentContainsFold(v string) predicate.Announcement {
235
+ return predicate.Announcement(sql.FieldContainsFold(FieldContent, v))
236
+ }
237
+
238
+ // StatusEQ applies the EQ predicate on the "status" field.
239
+ func StatusEQ(v string) predicate.Announcement {
240
+ return predicate.Announcement(sql.FieldEQ(FieldStatus, v))
241
+ }
242
+
243
+ // StatusNEQ applies the NEQ predicate on the "status" field.
244
+ func StatusNEQ(v string) predicate.Announcement {
245
+ return predicate.Announcement(sql.FieldNEQ(FieldStatus, v))
246
+ }
247
+
248
+ // StatusIn applies the In predicate on the "status" field.
249
+ func StatusIn(vs ...string) predicate.Announcement {
250
+ return predicate.Announcement(sql.FieldIn(FieldStatus, vs...))
251
+ }
252
+
253
+ // StatusNotIn applies the NotIn predicate on the "status" field.
254
+ func StatusNotIn(vs ...string) predicate.Announcement {
255
+ return predicate.Announcement(sql.FieldNotIn(FieldStatus, vs...))
256
+ }
257
+
258
+ // StatusGT applies the GT predicate on the "status" field.
259
+ func StatusGT(v string) predicate.Announcement {
260
+ return predicate.Announcement(sql.FieldGT(FieldStatus, v))
261
+ }
262
+
263
+ // StatusGTE applies the GTE predicate on the "status" field.
264
+ func StatusGTE(v string) predicate.Announcement {
265
+ return predicate.Announcement(sql.FieldGTE(FieldStatus, v))
266
+ }
267
+
268
+ // StatusLT applies the LT predicate on the "status" field.
269
+ func StatusLT(v string) predicate.Announcement {
270
+ return predicate.Announcement(sql.FieldLT(FieldStatus, v))
271
+ }
272
+
273
+ // StatusLTE applies the LTE predicate on the "status" field.
274
+ func StatusLTE(v string) predicate.Announcement {
275
+ return predicate.Announcement(sql.FieldLTE(FieldStatus, v))
276
+ }
277
+
278
+ // StatusContains applies the Contains predicate on the "status" field.
279
+ func StatusContains(v string) predicate.Announcement {
280
+ return predicate.Announcement(sql.FieldContains(FieldStatus, v))
281
+ }
282
+
283
+ // StatusHasPrefix applies the HasPrefix predicate on the "status" field.
284
+ func StatusHasPrefix(v string) predicate.Announcement {
285
+ return predicate.Announcement(sql.FieldHasPrefix(FieldStatus, v))
286
+ }
287
+
288
+ // StatusHasSuffix applies the HasSuffix predicate on the "status" field.
289
+ func StatusHasSuffix(v string) predicate.Announcement {
290
+ return predicate.Announcement(sql.FieldHasSuffix(FieldStatus, v))
291
+ }
292
+
293
+ // StatusEqualFold applies the EqualFold predicate on the "status" field.
294
+ func StatusEqualFold(v string) predicate.Announcement {
295
+ return predicate.Announcement(sql.FieldEqualFold(FieldStatus, v))
296
+ }
297
+
298
+ // StatusContainsFold applies the ContainsFold predicate on the "status" field.
299
+ func StatusContainsFold(v string) predicate.Announcement {
300
+ return predicate.Announcement(sql.FieldContainsFold(FieldStatus, v))
301
+ }
302
+
303
+ // NotifyModeEQ applies the EQ predicate on the "notify_mode" field.
304
+ func NotifyModeEQ(v string) predicate.Announcement {
305
+ return predicate.Announcement(sql.FieldEQ(FieldNotifyMode, v))
306
+ }
307
+
308
+ // NotifyModeNEQ applies the NEQ predicate on the "notify_mode" field.
309
+ func NotifyModeNEQ(v string) predicate.Announcement {
310
+ return predicate.Announcement(sql.FieldNEQ(FieldNotifyMode, v))
311
+ }
312
+
313
+ // NotifyModeIn applies the In predicate on the "notify_mode" field.
314
+ func NotifyModeIn(vs ...string) predicate.Announcement {
315
+ return predicate.Announcement(sql.FieldIn(FieldNotifyMode, vs...))
316
+ }
317
+
318
+ // NotifyModeNotIn applies the NotIn predicate on the "notify_mode" field.
319
+ func NotifyModeNotIn(vs ...string) predicate.Announcement {
320
+ return predicate.Announcement(sql.FieldNotIn(FieldNotifyMode, vs...))
321
+ }
322
+
323
+ // NotifyModeGT applies the GT predicate on the "notify_mode" field.
324
+ func NotifyModeGT(v string) predicate.Announcement {
325
+ return predicate.Announcement(sql.FieldGT(FieldNotifyMode, v))
326
+ }
327
+
328
+ // NotifyModeGTE applies the GTE predicate on the "notify_mode" field.
329
+ func NotifyModeGTE(v string) predicate.Announcement {
330
+ return predicate.Announcement(sql.FieldGTE(FieldNotifyMode, v))
331
+ }
332
+
333
+ // NotifyModeLT applies the LT predicate on the "notify_mode" field.
334
+ func NotifyModeLT(v string) predicate.Announcement {
335
+ return predicate.Announcement(sql.FieldLT(FieldNotifyMode, v))
336
+ }
337
+
338
+ // NotifyModeLTE applies the LTE predicate on the "notify_mode" field.
339
+ func NotifyModeLTE(v string) predicate.Announcement {
340
+ return predicate.Announcement(sql.FieldLTE(FieldNotifyMode, v))
341
+ }
342
+
343
+ // NotifyModeContains applies the Contains predicate on the "notify_mode" field.
344
+ func NotifyModeContains(v string) predicate.Announcement {
345
+ return predicate.Announcement(sql.FieldContains(FieldNotifyMode, v))
346
+ }
347
+
348
+ // NotifyModeHasPrefix applies the HasPrefix predicate on the "notify_mode" field.
349
+ func NotifyModeHasPrefix(v string) predicate.Announcement {
350
+ return predicate.Announcement(sql.FieldHasPrefix(FieldNotifyMode, v))
351
+ }
352
+
353
+ // NotifyModeHasSuffix applies the HasSuffix predicate on the "notify_mode" field.
354
+ func NotifyModeHasSuffix(v string) predicate.Announcement {
355
+ return predicate.Announcement(sql.FieldHasSuffix(FieldNotifyMode, v))
356
+ }
357
+
358
+ // NotifyModeEqualFold applies the EqualFold predicate on the "notify_mode" field.
359
+ func NotifyModeEqualFold(v string) predicate.Announcement {
360
+ return predicate.Announcement(sql.FieldEqualFold(FieldNotifyMode, v))
361
+ }
362
+
363
+ // NotifyModeContainsFold applies the ContainsFold predicate on the "notify_mode" field.
364
+ func NotifyModeContainsFold(v string) predicate.Announcement {
365
+ return predicate.Announcement(sql.FieldContainsFold(FieldNotifyMode, v))
366
+ }
367
+
368
+ // TargetingIsNil applies the IsNil predicate on the "targeting" field.
369
+ func TargetingIsNil() predicate.Announcement {
370
+ return predicate.Announcement(sql.FieldIsNull(FieldTargeting))
371
+ }
372
+
373
+ // TargetingNotNil applies the NotNil predicate on the "targeting" field.
374
+ func TargetingNotNil() predicate.Announcement {
375
+ return predicate.Announcement(sql.FieldNotNull(FieldTargeting))
376
+ }
377
+
378
+ // StartsAtEQ applies the EQ predicate on the "starts_at" field.
379
+ func StartsAtEQ(v time.Time) predicate.Announcement {
380
+ return predicate.Announcement(sql.FieldEQ(FieldStartsAt, v))
381
+ }
382
+
383
+ // StartsAtNEQ applies the NEQ predicate on the "starts_at" field.
384
+ func StartsAtNEQ(v time.Time) predicate.Announcement {
385
+ return predicate.Announcement(sql.FieldNEQ(FieldStartsAt, v))
386
+ }
387
+
388
+ // StartsAtIn applies the In predicate on the "starts_at" field.
389
+ func StartsAtIn(vs ...time.Time) predicate.Announcement {
390
+ return predicate.Announcement(sql.FieldIn(FieldStartsAt, vs...))
391
+ }
392
+
393
+ // StartsAtNotIn applies the NotIn predicate on the "starts_at" field.
394
+ func StartsAtNotIn(vs ...time.Time) predicate.Announcement {
395
+ return predicate.Announcement(sql.FieldNotIn(FieldStartsAt, vs...))
396
+ }
397
+
398
+ // StartsAtGT applies the GT predicate on the "starts_at" field.
399
+ func StartsAtGT(v time.Time) predicate.Announcement {
400
+ return predicate.Announcement(sql.FieldGT(FieldStartsAt, v))
401
+ }
402
+
403
+ // StartsAtGTE applies the GTE predicate on the "starts_at" field.
404
+ func StartsAtGTE(v time.Time) predicate.Announcement {
405
+ return predicate.Announcement(sql.FieldGTE(FieldStartsAt, v))
406
+ }
407
+
408
+ // StartsAtLT applies the LT predicate on the "starts_at" field.
409
+ func StartsAtLT(v time.Time) predicate.Announcement {
410
+ return predicate.Announcement(sql.FieldLT(FieldStartsAt, v))
411
+ }
412
+
413
+ // StartsAtLTE applies the LTE predicate on the "starts_at" field.
414
+ func StartsAtLTE(v time.Time) predicate.Announcement {
415
+ return predicate.Announcement(sql.FieldLTE(FieldStartsAt, v))
416
+ }
417
+
418
+ // StartsAtIsNil applies the IsNil predicate on the "starts_at" field.
419
+ func StartsAtIsNil() predicate.Announcement {
420
+ return predicate.Announcement(sql.FieldIsNull(FieldStartsAt))
421
+ }
422
+
423
+ // StartsAtNotNil applies the NotNil predicate on the "starts_at" field.
424
+ func StartsAtNotNil() predicate.Announcement {
425
+ return predicate.Announcement(sql.FieldNotNull(FieldStartsAt))
426
+ }
427
+
428
+ // EndsAtEQ applies the EQ predicate on the "ends_at" field.
429
+ func EndsAtEQ(v time.Time) predicate.Announcement {
430
+ return predicate.Announcement(sql.FieldEQ(FieldEndsAt, v))
431
+ }
432
+
433
+ // EndsAtNEQ applies the NEQ predicate on the "ends_at" field.
434
+ func EndsAtNEQ(v time.Time) predicate.Announcement {
435
+ return predicate.Announcement(sql.FieldNEQ(FieldEndsAt, v))
436
+ }
437
+
438
+ // EndsAtIn applies the In predicate on the "ends_at" field.
439
+ func EndsAtIn(vs ...time.Time) predicate.Announcement {
440
+ return predicate.Announcement(sql.FieldIn(FieldEndsAt, vs...))
441
+ }
442
+
443
+ // EndsAtNotIn applies the NotIn predicate on the "ends_at" field.
444
+ func EndsAtNotIn(vs ...time.Time) predicate.Announcement {
445
+ return predicate.Announcement(sql.FieldNotIn(FieldEndsAt, vs...))
446
+ }
447
+
448
+ // EndsAtGT applies the GT predicate on the "ends_at" field.
449
+ func EndsAtGT(v time.Time) predicate.Announcement {
450
+ return predicate.Announcement(sql.FieldGT(FieldEndsAt, v))
451
+ }
452
+
453
+ // EndsAtGTE applies the GTE predicate on the "ends_at" field.
454
+ func EndsAtGTE(v time.Time) predicate.Announcement {
455
+ return predicate.Announcement(sql.FieldGTE(FieldEndsAt, v))
456
+ }
457
+
458
+ // EndsAtLT applies the LT predicate on the "ends_at" field.
459
+ func EndsAtLT(v time.Time) predicate.Announcement {
460
+ return predicate.Announcement(sql.FieldLT(FieldEndsAt, v))
461
+ }
462
+
463
+ // EndsAtLTE applies the LTE predicate on the "ends_at" field.
464
+ func EndsAtLTE(v time.Time) predicate.Announcement {
465
+ return predicate.Announcement(sql.FieldLTE(FieldEndsAt, v))
466
+ }
467
+
468
+ // EndsAtIsNil applies the IsNil predicate on the "ends_at" field.
469
+ func EndsAtIsNil() predicate.Announcement {
470
+ return predicate.Announcement(sql.FieldIsNull(FieldEndsAt))
471
+ }
472
+
473
+ // EndsAtNotNil applies the NotNil predicate on the "ends_at" field.
474
+ func EndsAtNotNil() predicate.Announcement {
475
+ return predicate.Announcement(sql.FieldNotNull(FieldEndsAt))
476
+ }
477
+
478
+ // CreatedByEQ applies the EQ predicate on the "created_by" field.
479
+ func CreatedByEQ(v int64) predicate.Announcement {
480
+ return predicate.Announcement(sql.FieldEQ(FieldCreatedBy, v))
481
+ }
482
+
483
+ // CreatedByNEQ applies the NEQ predicate on the "created_by" field.
484
+ func CreatedByNEQ(v int64) predicate.Announcement {
485
+ return predicate.Announcement(sql.FieldNEQ(FieldCreatedBy, v))
486
+ }
487
+
488
+ // CreatedByIn applies the In predicate on the "created_by" field.
489
+ func CreatedByIn(vs ...int64) predicate.Announcement {
490
+ return predicate.Announcement(sql.FieldIn(FieldCreatedBy, vs...))
491
+ }
492
+
493
+ // CreatedByNotIn applies the NotIn predicate on the "created_by" field.
494
+ func CreatedByNotIn(vs ...int64) predicate.Announcement {
495
+ return predicate.Announcement(sql.FieldNotIn(FieldCreatedBy, vs...))
496
+ }
497
+
498
+ // CreatedByGT applies the GT predicate on the "created_by" field.
499
+ func CreatedByGT(v int64) predicate.Announcement {
500
+ return predicate.Announcement(sql.FieldGT(FieldCreatedBy, v))
501
+ }
502
+
503
+ // CreatedByGTE applies the GTE predicate on the "created_by" field.
504
+ func CreatedByGTE(v int64) predicate.Announcement {
505
+ return predicate.Announcement(sql.FieldGTE(FieldCreatedBy, v))
506
+ }
507
+
508
+ // CreatedByLT applies the LT predicate on the "created_by" field.
509
+ func CreatedByLT(v int64) predicate.Announcement {
510
+ return predicate.Announcement(sql.FieldLT(FieldCreatedBy, v))
511
+ }
512
+
513
+ // CreatedByLTE applies the LTE predicate on the "created_by" field.
514
+ func CreatedByLTE(v int64) predicate.Announcement {
515
+ return predicate.Announcement(sql.FieldLTE(FieldCreatedBy, v))
516
+ }
517
+
518
+ // CreatedByIsNil applies the IsNil predicate on the "created_by" field.
519
+ func CreatedByIsNil() predicate.Announcement {
520
+ return predicate.Announcement(sql.FieldIsNull(FieldCreatedBy))
521
+ }
522
+
523
+ // CreatedByNotNil applies the NotNil predicate on the "created_by" field.
524
+ func CreatedByNotNil() predicate.Announcement {
525
+ return predicate.Announcement(sql.FieldNotNull(FieldCreatedBy))
526
+ }
527
+
528
+ // UpdatedByEQ applies the EQ predicate on the "updated_by" field.
529
+ func UpdatedByEQ(v int64) predicate.Announcement {
530
+ return predicate.Announcement(sql.FieldEQ(FieldUpdatedBy, v))
531
+ }
532
+
533
+ // UpdatedByNEQ applies the NEQ predicate on the "updated_by" field.
534
+ func UpdatedByNEQ(v int64) predicate.Announcement {
535
+ return predicate.Announcement(sql.FieldNEQ(FieldUpdatedBy, v))
536
+ }
537
+
538
+ // UpdatedByIn applies the In predicate on the "updated_by" field.
539
+ func UpdatedByIn(vs ...int64) predicate.Announcement {
540
+ return predicate.Announcement(sql.FieldIn(FieldUpdatedBy, vs...))
541
+ }
542
+
543
+ // UpdatedByNotIn applies the NotIn predicate on the "updated_by" field.
544
+ func UpdatedByNotIn(vs ...int64) predicate.Announcement {
545
+ return predicate.Announcement(sql.FieldNotIn(FieldUpdatedBy, vs...))
546
+ }
547
+
548
+ // UpdatedByGT applies the GT predicate on the "updated_by" field.
549
+ func UpdatedByGT(v int64) predicate.Announcement {
550
+ return predicate.Announcement(sql.FieldGT(FieldUpdatedBy, v))
551
+ }
552
+
553
+ // UpdatedByGTE applies the GTE predicate on the "updated_by" field.
554
+ func UpdatedByGTE(v int64) predicate.Announcement {
555
+ return predicate.Announcement(sql.FieldGTE(FieldUpdatedBy, v))
556
+ }
557
+
558
+ // UpdatedByLT applies the LT predicate on the "updated_by" field.
559
+ func UpdatedByLT(v int64) predicate.Announcement {
560
+ return predicate.Announcement(sql.FieldLT(FieldUpdatedBy, v))
561
+ }
562
+
563
+ // UpdatedByLTE applies the LTE predicate on the "updated_by" field.
564
+ func UpdatedByLTE(v int64) predicate.Announcement {
565
+ return predicate.Announcement(sql.FieldLTE(FieldUpdatedBy, v))
566
+ }
567
+
568
+ // UpdatedByIsNil applies the IsNil predicate on the "updated_by" field.
569
+ func UpdatedByIsNil() predicate.Announcement {
570
+ return predicate.Announcement(sql.FieldIsNull(FieldUpdatedBy))
571
+ }
572
+
573
+ // UpdatedByNotNil applies the NotNil predicate on the "updated_by" field.
574
+ func UpdatedByNotNil() predicate.Announcement {
575
+ return predicate.Announcement(sql.FieldNotNull(FieldUpdatedBy))
576
+ }
577
+
578
+ // CreatedAtEQ applies the EQ predicate on the "created_at" field.
579
+ func CreatedAtEQ(v time.Time) predicate.Announcement {
580
+ return predicate.Announcement(sql.FieldEQ(FieldCreatedAt, v))
581
+ }
582
+
583
+ // CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
584
+ func CreatedAtNEQ(v time.Time) predicate.Announcement {
585
+ return predicate.Announcement(sql.FieldNEQ(FieldCreatedAt, v))
586
+ }
587
+
588
+ // CreatedAtIn applies the In predicate on the "created_at" field.
589
+ func CreatedAtIn(vs ...time.Time) predicate.Announcement {
590
+ return predicate.Announcement(sql.FieldIn(FieldCreatedAt, vs...))
591
+ }
592
+
593
+ // CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
594
+ func CreatedAtNotIn(vs ...time.Time) predicate.Announcement {
595
+ return predicate.Announcement(sql.FieldNotIn(FieldCreatedAt, vs...))
596
+ }
597
+
598
+ // CreatedAtGT applies the GT predicate on the "created_at" field.
599
+ func CreatedAtGT(v time.Time) predicate.Announcement {
600
+ return predicate.Announcement(sql.FieldGT(FieldCreatedAt, v))
601
+ }
602
+
603
+ // CreatedAtGTE applies the GTE predicate on the "created_at" field.
604
+ func CreatedAtGTE(v time.Time) predicate.Announcement {
605
+ return predicate.Announcement(sql.FieldGTE(FieldCreatedAt, v))
606
+ }
607
+
608
+ // CreatedAtLT applies the LT predicate on the "created_at" field.
609
+ func CreatedAtLT(v time.Time) predicate.Announcement {
610
+ return predicate.Announcement(sql.FieldLT(FieldCreatedAt, v))
611
+ }
612
+
613
+ // CreatedAtLTE applies the LTE predicate on the "created_at" field.
614
+ func CreatedAtLTE(v time.Time) predicate.Announcement {
615
+ return predicate.Announcement(sql.FieldLTE(FieldCreatedAt, v))
616
+ }
617
+
618
+ // UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
619
+ func UpdatedAtEQ(v time.Time) predicate.Announcement {
620
+ return predicate.Announcement(sql.FieldEQ(FieldUpdatedAt, v))
621
+ }
622
+
623
+ // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
624
+ func UpdatedAtNEQ(v time.Time) predicate.Announcement {
625
+ return predicate.Announcement(sql.FieldNEQ(FieldUpdatedAt, v))
626
+ }
627
+
628
+ // UpdatedAtIn applies the In predicate on the "updated_at" field.
629
+ func UpdatedAtIn(vs ...time.Time) predicate.Announcement {
630
+ return predicate.Announcement(sql.FieldIn(FieldUpdatedAt, vs...))
631
+ }
632
+
633
+ // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
634
+ func UpdatedAtNotIn(vs ...time.Time) predicate.Announcement {
635
+ return predicate.Announcement(sql.FieldNotIn(FieldUpdatedAt, vs...))
636
+ }
637
+
638
+ // UpdatedAtGT applies the GT predicate on the "updated_at" field.
639
+ func UpdatedAtGT(v time.Time) predicate.Announcement {
640
+ return predicate.Announcement(sql.FieldGT(FieldUpdatedAt, v))
641
+ }
642
+
643
+ // UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
644
+ func UpdatedAtGTE(v time.Time) predicate.Announcement {
645
+ return predicate.Announcement(sql.FieldGTE(FieldUpdatedAt, v))
646
+ }
647
+
648
+ // UpdatedAtLT applies the LT predicate on the "updated_at" field.
649
+ func UpdatedAtLT(v time.Time) predicate.Announcement {
650
+ return predicate.Announcement(sql.FieldLT(FieldUpdatedAt, v))
651
+ }
652
+
653
+ // UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
654
+ func UpdatedAtLTE(v time.Time) predicate.Announcement {
655
+ return predicate.Announcement(sql.FieldLTE(FieldUpdatedAt, v))
656
+ }
657
+
658
+ // HasReads applies the HasEdge predicate on the "reads" edge.
659
+ func HasReads() predicate.Announcement {
660
+ return predicate.Announcement(func(s *sql.Selector) {
661
+ step := sqlgraph.NewStep(
662
+ sqlgraph.From(Table, FieldID),
663
+ sqlgraph.Edge(sqlgraph.O2M, false, ReadsTable, ReadsColumn),
664
+ )
665
+ sqlgraph.HasNeighbors(s, step)
666
+ })
667
+ }
668
+
669
+ // HasReadsWith applies the HasEdge predicate on the "reads" edge with a given conditions (other predicates).
670
+ func HasReadsWith(preds ...predicate.AnnouncementRead) predicate.Announcement {
671
+ return predicate.Announcement(func(s *sql.Selector) {
672
+ step := newReadsStep()
673
+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
674
+ for _, p := range preds {
675
+ p(s)
676
+ }
677
+ })
678
+ })
679
+ }
680
+
681
+ // And groups predicates with the AND operator between them.
682
+ func And(predicates ...predicate.Announcement) predicate.Announcement {
683
+ return predicate.Announcement(sql.AndPredicates(predicates...))
684
+ }
685
+
686
+ // Or groups predicates with the OR operator between them.
687
+ func Or(predicates ...predicate.Announcement) predicate.Announcement {
688
+ return predicate.Announcement(sql.OrPredicates(predicates...))
689
+ }
690
+
691
+ // Not applies the not operator on the given predicate.
692
+ func Not(p predicate.Announcement) predicate.Announcement {
693
+ return predicate.Announcement(sql.NotPredicates(p))
694
+ }
backend/ent/announcement_create.go ADDED
@@ -0,0 +1,1229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+ "errors"
8
+ "fmt"
9
+ "time"
10
+
11
+ "entgo.io/ent/dialect/sql"
12
+ "entgo.io/ent/dialect/sql/sqlgraph"
13
+ "entgo.io/ent/schema/field"
14
+ "github.com/Wei-Shaw/sub2api/ent/announcement"
15
+ "github.com/Wei-Shaw/sub2api/ent/announcementread"
16
+ "github.com/Wei-Shaw/sub2api/internal/domain"
17
+ )
18
+
19
+ // AnnouncementCreate is the builder for creating a Announcement entity.
20
+ type AnnouncementCreate struct {
21
+ config
22
+ mutation *AnnouncementMutation
23
+ hooks []Hook
24
+ conflict []sql.ConflictOption
25
+ }
26
+
27
+ // SetTitle sets the "title" field.
28
+ func (_c *AnnouncementCreate) SetTitle(v string) *AnnouncementCreate {
29
+ _c.mutation.SetTitle(v)
30
+ return _c
31
+ }
32
+
33
+ // SetContent sets the "content" field.
34
+ func (_c *AnnouncementCreate) SetContent(v string) *AnnouncementCreate {
35
+ _c.mutation.SetContent(v)
36
+ return _c
37
+ }
38
+
39
+ // SetStatus sets the "status" field.
40
+ func (_c *AnnouncementCreate) SetStatus(v string) *AnnouncementCreate {
41
+ _c.mutation.SetStatus(v)
42
+ return _c
43
+ }
44
+
45
+ // SetNillableStatus sets the "status" field if the given value is not nil.
46
+ func (_c *AnnouncementCreate) SetNillableStatus(v *string) *AnnouncementCreate {
47
+ if v != nil {
48
+ _c.SetStatus(*v)
49
+ }
50
+ return _c
51
+ }
52
+
53
+ // SetNotifyMode sets the "notify_mode" field.
54
+ func (_c *AnnouncementCreate) SetNotifyMode(v string) *AnnouncementCreate {
55
+ _c.mutation.SetNotifyMode(v)
56
+ return _c
57
+ }
58
+
59
+ // SetNillableNotifyMode sets the "notify_mode" field if the given value is not nil.
60
+ func (_c *AnnouncementCreate) SetNillableNotifyMode(v *string) *AnnouncementCreate {
61
+ if v != nil {
62
+ _c.SetNotifyMode(*v)
63
+ }
64
+ return _c
65
+ }
66
+
67
+ // SetTargeting sets the "targeting" field.
68
+ func (_c *AnnouncementCreate) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementCreate {
69
+ _c.mutation.SetTargeting(v)
70
+ return _c
71
+ }
72
+
73
+ // SetNillableTargeting sets the "targeting" field if the given value is not nil.
74
+ func (_c *AnnouncementCreate) SetNillableTargeting(v *domain.AnnouncementTargeting) *AnnouncementCreate {
75
+ if v != nil {
76
+ _c.SetTargeting(*v)
77
+ }
78
+ return _c
79
+ }
80
+
81
+ // SetStartsAt sets the "starts_at" field.
82
+ func (_c *AnnouncementCreate) SetStartsAt(v time.Time) *AnnouncementCreate {
83
+ _c.mutation.SetStartsAt(v)
84
+ return _c
85
+ }
86
+
87
+ // SetNillableStartsAt sets the "starts_at" field if the given value is not nil.
88
+ func (_c *AnnouncementCreate) SetNillableStartsAt(v *time.Time) *AnnouncementCreate {
89
+ if v != nil {
90
+ _c.SetStartsAt(*v)
91
+ }
92
+ return _c
93
+ }
94
+
95
+ // SetEndsAt sets the "ends_at" field.
96
+ func (_c *AnnouncementCreate) SetEndsAt(v time.Time) *AnnouncementCreate {
97
+ _c.mutation.SetEndsAt(v)
98
+ return _c
99
+ }
100
+
101
+ // SetNillableEndsAt sets the "ends_at" field if the given value is not nil.
102
+ func (_c *AnnouncementCreate) SetNillableEndsAt(v *time.Time) *AnnouncementCreate {
103
+ if v != nil {
104
+ _c.SetEndsAt(*v)
105
+ }
106
+ return _c
107
+ }
108
+
109
+ // SetCreatedBy sets the "created_by" field.
110
+ func (_c *AnnouncementCreate) SetCreatedBy(v int64) *AnnouncementCreate {
111
+ _c.mutation.SetCreatedBy(v)
112
+ return _c
113
+ }
114
+
115
+ // SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
116
+ func (_c *AnnouncementCreate) SetNillableCreatedBy(v *int64) *AnnouncementCreate {
117
+ if v != nil {
118
+ _c.SetCreatedBy(*v)
119
+ }
120
+ return _c
121
+ }
122
+
123
+ // SetUpdatedBy sets the "updated_by" field.
124
+ func (_c *AnnouncementCreate) SetUpdatedBy(v int64) *AnnouncementCreate {
125
+ _c.mutation.SetUpdatedBy(v)
126
+ return _c
127
+ }
128
+
129
+ // SetNillableUpdatedBy sets the "updated_by" field if the given value is not nil.
130
+ func (_c *AnnouncementCreate) SetNillableUpdatedBy(v *int64) *AnnouncementCreate {
131
+ if v != nil {
132
+ _c.SetUpdatedBy(*v)
133
+ }
134
+ return _c
135
+ }
136
+
137
+ // SetCreatedAt sets the "created_at" field.
138
+ func (_c *AnnouncementCreate) SetCreatedAt(v time.Time) *AnnouncementCreate {
139
+ _c.mutation.SetCreatedAt(v)
140
+ return _c
141
+ }
142
+
143
+ // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
144
+ func (_c *AnnouncementCreate) SetNillableCreatedAt(v *time.Time) *AnnouncementCreate {
145
+ if v != nil {
146
+ _c.SetCreatedAt(*v)
147
+ }
148
+ return _c
149
+ }
150
+
151
+ // SetUpdatedAt sets the "updated_at" field.
152
+ func (_c *AnnouncementCreate) SetUpdatedAt(v time.Time) *AnnouncementCreate {
153
+ _c.mutation.SetUpdatedAt(v)
154
+ return _c
155
+ }
156
+
157
+ // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
158
+ func (_c *AnnouncementCreate) SetNillableUpdatedAt(v *time.Time) *AnnouncementCreate {
159
+ if v != nil {
160
+ _c.SetUpdatedAt(*v)
161
+ }
162
+ return _c
163
+ }
164
+
165
+ // AddReadIDs adds the "reads" edge to the AnnouncementRead entity by IDs.
166
+ func (_c *AnnouncementCreate) AddReadIDs(ids ...int64) *AnnouncementCreate {
167
+ _c.mutation.AddReadIDs(ids...)
168
+ return _c
169
+ }
170
+
171
+ // AddReads adds the "reads" edges to the AnnouncementRead entity.
172
+ func (_c *AnnouncementCreate) AddReads(v ...*AnnouncementRead) *AnnouncementCreate {
173
+ ids := make([]int64, len(v))
174
+ for i := range v {
175
+ ids[i] = v[i].ID
176
+ }
177
+ return _c.AddReadIDs(ids...)
178
+ }
179
+
180
+ // Mutation returns the AnnouncementMutation object of the builder.
181
+ func (_c *AnnouncementCreate) Mutation() *AnnouncementMutation {
182
+ return _c.mutation
183
+ }
184
+
185
+ // Save creates the Announcement in the database.
186
+ func (_c *AnnouncementCreate) Save(ctx context.Context) (*Announcement, error) {
187
+ _c.defaults()
188
+ return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
189
+ }
190
+
191
+ // SaveX calls Save and panics if Save returns an error.
192
+ func (_c *AnnouncementCreate) SaveX(ctx context.Context) *Announcement {
193
+ v, err := _c.Save(ctx)
194
+ if err != nil {
195
+ panic(err)
196
+ }
197
+ return v
198
+ }
199
+
200
+ // Exec executes the query.
201
+ func (_c *AnnouncementCreate) Exec(ctx context.Context) error {
202
+ _, err := _c.Save(ctx)
203
+ return err
204
+ }
205
+
206
+ // ExecX is like Exec, but panics if an error occurs.
207
+ func (_c *AnnouncementCreate) ExecX(ctx context.Context) {
208
+ if err := _c.Exec(ctx); err != nil {
209
+ panic(err)
210
+ }
211
+ }
212
+
213
+ // defaults sets the default values of the builder before save.
214
+ func (_c *AnnouncementCreate) defaults() {
215
+ if _, ok := _c.mutation.Status(); !ok {
216
+ v := announcement.DefaultStatus
217
+ _c.mutation.SetStatus(v)
218
+ }
219
+ if _, ok := _c.mutation.NotifyMode(); !ok {
220
+ v := announcement.DefaultNotifyMode
221
+ _c.mutation.SetNotifyMode(v)
222
+ }
223
+ if _, ok := _c.mutation.CreatedAt(); !ok {
224
+ v := announcement.DefaultCreatedAt()
225
+ _c.mutation.SetCreatedAt(v)
226
+ }
227
+ if _, ok := _c.mutation.UpdatedAt(); !ok {
228
+ v := announcement.DefaultUpdatedAt()
229
+ _c.mutation.SetUpdatedAt(v)
230
+ }
231
+ }
232
+
233
+ // check runs all checks and user-defined validators on the builder.
234
+ func (_c *AnnouncementCreate) check() error {
235
+ if _, ok := _c.mutation.Title(); !ok {
236
+ return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Announcement.title"`)}
237
+ }
238
+ if v, ok := _c.mutation.Title(); ok {
239
+ if err := announcement.TitleValidator(v); err != nil {
240
+ return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Announcement.title": %w`, err)}
241
+ }
242
+ }
243
+ if _, ok := _c.mutation.Content(); !ok {
244
+ return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "Announcement.content"`)}
245
+ }
246
+ if v, ok := _c.mutation.Content(); ok {
247
+ if err := announcement.ContentValidator(v); err != nil {
248
+ return &ValidationError{Name: "content", err: fmt.Errorf(`ent: validator failed for field "Announcement.content": %w`, err)}
249
+ }
250
+ }
251
+ if _, ok := _c.mutation.Status(); !ok {
252
+ return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Announcement.status"`)}
253
+ }
254
+ if v, ok := _c.mutation.Status(); ok {
255
+ if err := announcement.StatusValidator(v); err != nil {
256
+ return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Announcement.status": %w`, err)}
257
+ }
258
+ }
259
+ if _, ok := _c.mutation.NotifyMode(); !ok {
260
+ return &ValidationError{Name: "notify_mode", err: errors.New(`ent: missing required field "Announcement.notify_mode"`)}
261
+ }
262
+ if v, ok := _c.mutation.NotifyMode(); ok {
263
+ if err := announcement.NotifyModeValidator(v); err != nil {
264
+ return &ValidationError{Name: "notify_mode", err: fmt.Errorf(`ent: validator failed for field "Announcement.notify_mode": %w`, err)}
265
+ }
266
+ }
267
+ if _, ok := _c.mutation.CreatedAt(); !ok {
268
+ return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Announcement.created_at"`)}
269
+ }
270
+ if _, ok := _c.mutation.UpdatedAt(); !ok {
271
+ return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Announcement.updated_at"`)}
272
+ }
273
+ return nil
274
+ }
275
+
276
+ func (_c *AnnouncementCreate) sqlSave(ctx context.Context) (*Announcement, error) {
277
+ if err := _c.check(); err != nil {
278
+ return nil, err
279
+ }
280
+ _node, _spec := _c.createSpec()
281
+ if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
282
+ if sqlgraph.IsConstraintError(err) {
283
+ err = &ConstraintError{msg: err.Error(), wrap: err}
284
+ }
285
+ return nil, err
286
+ }
287
+ id := _spec.ID.Value.(int64)
288
+ _node.ID = int64(id)
289
+ _c.mutation.id = &_node.ID
290
+ _c.mutation.done = true
291
+ return _node, nil
292
+ }
293
+
294
+ func (_c *AnnouncementCreate) createSpec() (*Announcement, *sqlgraph.CreateSpec) {
295
+ var (
296
+ _node = &Announcement{config: _c.config}
297
+ _spec = sqlgraph.NewCreateSpec(announcement.Table, sqlgraph.NewFieldSpec(announcement.FieldID, field.TypeInt64))
298
+ )
299
+ _spec.OnConflict = _c.conflict
300
+ if value, ok := _c.mutation.Title(); ok {
301
+ _spec.SetField(announcement.FieldTitle, field.TypeString, value)
302
+ _node.Title = value
303
+ }
304
+ if value, ok := _c.mutation.Content(); ok {
305
+ _spec.SetField(announcement.FieldContent, field.TypeString, value)
306
+ _node.Content = value
307
+ }
308
+ if value, ok := _c.mutation.Status(); ok {
309
+ _spec.SetField(announcement.FieldStatus, field.TypeString, value)
310
+ _node.Status = value
311
+ }
312
+ if value, ok := _c.mutation.NotifyMode(); ok {
313
+ _spec.SetField(announcement.FieldNotifyMode, field.TypeString, value)
314
+ _node.NotifyMode = value
315
+ }
316
+ if value, ok := _c.mutation.Targeting(); ok {
317
+ _spec.SetField(announcement.FieldTargeting, field.TypeJSON, value)
318
+ _node.Targeting = value
319
+ }
320
+ if value, ok := _c.mutation.StartsAt(); ok {
321
+ _spec.SetField(announcement.FieldStartsAt, field.TypeTime, value)
322
+ _node.StartsAt = &value
323
+ }
324
+ if value, ok := _c.mutation.EndsAt(); ok {
325
+ _spec.SetField(announcement.FieldEndsAt, field.TypeTime, value)
326
+ _node.EndsAt = &value
327
+ }
328
+ if value, ok := _c.mutation.CreatedBy(); ok {
329
+ _spec.SetField(announcement.FieldCreatedBy, field.TypeInt64, value)
330
+ _node.CreatedBy = &value
331
+ }
332
+ if value, ok := _c.mutation.UpdatedBy(); ok {
333
+ _spec.SetField(announcement.FieldUpdatedBy, field.TypeInt64, value)
334
+ _node.UpdatedBy = &value
335
+ }
336
+ if value, ok := _c.mutation.CreatedAt(); ok {
337
+ _spec.SetField(announcement.FieldCreatedAt, field.TypeTime, value)
338
+ _node.CreatedAt = value
339
+ }
340
+ if value, ok := _c.mutation.UpdatedAt(); ok {
341
+ _spec.SetField(announcement.FieldUpdatedAt, field.TypeTime, value)
342
+ _node.UpdatedAt = value
343
+ }
344
+ if nodes := _c.mutation.ReadsIDs(); len(nodes) > 0 {
345
+ edge := &sqlgraph.EdgeSpec{
346
+ Rel: sqlgraph.O2M,
347
+ Inverse: false,
348
+ Table: announcement.ReadsTable,
349
+ Columns: []string{announcement.ReadsColumn},
350
+ Bidi: false,
351
+ Target: &sqlgraph.EdgeTarget{
352
+ IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
353
+ },
354
+ }
355
+ for _, k := range nodes {
356
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
357
+ }
358
+ _spec.Edges = append(_spec.Edges, edge)
359
+ }
360
+ return _node, _spec
361
+ }
362
+
363
+ // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
364
+ // of the `INSERT` statement. For example:
365
+ //
366
+ // client.Announcement.Create().
367
+ // SetTitle(v).
368
+ // OnConflict(
369
+ // // Update the row with the new values
370
+ // // the was proposed for insertion.
371
+ // sql.ResolveWithNewValues(),
372
+ // ).
373
+ // // Override some of the fields with custom
374
+ // // update values.
375
+ // Update(func(u *ent.AnnouncementUpsert) {
376
+ // SetTitle(v+v).
377
+ // }).
378
+ // Exec(ctx)
379
+ func (_c *AnnouncementCreate) OnConflict(opts ...sql.ConflictOption) *AnnouncementUpsertOne {
380
+ _c.conflict = opts
381
+ return &AnnouncementUpsertOne{
382
+ create: _c,
383
+ }
384
+ }
385
+
386
+ // OnConflictColumns calls `OnConflict` and configures the columns
387
+ // as conflict target. Using this option is equivalent to using:
388
+ //
389
+ // client.Announcement.Create().
390
+ // OnConflict(sql.ConflictColumns(columns...)).
391
+ // Exec(ctx)
392
+ func (_c *AnnouncementCreate) OnConflictColumns(columns ...string) *AnnouncementUpsertOne {
393
+ _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
394
+ return &AnnouncementUpsertOne{
395
+ create: _c,
396
+ }
397
+ }
398
+
399
+ type (
400
+ // AnnouncementUpsertOne is the builder for "upsert"-ing
401
+ // one Announcement node.
402
+ AnnouncementUpsertOne struct {
403
+ create *AnnouncementCreate
404
+ }
405
+
406
+ // AnnouncementUpsert is the "OnConflict" setter.
407
+ AnnouncementUpsert struct {
408
+ *sql.UpdateSet
409
+ }
410
+ )
411
+
412
+ // SetTitle sets the "title" field.
413
+ func (u *AnnouncementUpsert) SetTitle(v string) *AnnouncementUpsert {
414
+ u.Set(announcement.FieldTitle, v)
415
+ return u
416
+ }
417
+
418
+ // UpdateTitle sets the "title" field to the value that was provided on create.
419
+ func (u *AnnouncementUpsert) UpdateTitle() *AnnouncementUpsert {
420
+ u.SetExcluded(announcement.FieldTitle)
421
+ return u
422
+ }
423
+
424
+ // SetContent sets the "content" field.
425
+ func (u *AnnouncementUpsert) SetContent(v string) *AnnouncementUpsert {
426
+ u.Set(announcement.FieldContent, v)
427
+ return u
428
+ }
429
+
430
+ // UpdateContent sets the "content" field to the value that was provided on create.
431
+ func (u *AnnouncementUpsert) UpdateContent() *AnnouncementUpsert {
432
+ u.SetExcluded(announcement.FieldContent)
433
+ return u
434
+ }
435
+
436
+ // SetStatus sets the "status" field.
437
+ func (u *AnnouncementUpsert) SetStatus(v string) *AnnouncementUpsert {
438
+ u.Set(announcement.FieldStatus, v)
439
+ return u
440
+ }
441
+
442
+ // UpdateStatus sets the "status" field to the value that was provided on create.
443
+ func (u *AnnouncementUpsert) UpdateStatus() *AnnouncementUpsert {
444
+ u.SetExcluded(announcement.FieldStatus)
445
+ return u
446
+ }
447
+
448
+ // SetNotifyMode sets the "notify_mode" field.
449
+ func (u *AnnouncementUpsert) SetNotifyMode(v string) *AnnouncementUpsert {
450
+ u.Set(announcement.FieldNotifyMode, v)
451
+ return u
452
+ }
453
+
454
+ // UpdateNotifyMode sets the "notify_mode" field to the value that was provided on create.
455
+ func (u *AnnouncementUpsert) UpdateNotifyMode() *AnnouncementUpsert {
456
+ u.SetExcluded(announcement.FieldNotifyMode)
457
+ return u
458
+ }
459
+
460
+ // SetTargeting sets the "targeting" field.
461
+ func (u *AnnouncementUpsert) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpsert {
462
+ u.Set(announcement.FieldTargeting, v)
463
+ return u
464
+ }
465
+
466
+ // UpdateTargeting sets the "targeting" field to the value that was provided on create.
467
+ func (u *AnnouncementUpsert) UpdateTargeting() *AnnouncementUpsert {
468
+ u.SetExcluded(announcement.FieldTargeting)
469
+ return u
470
+ }
471
+
472
+ // ClearTargeting clears the value of the "targeting" field.
473
+ func (u *AnnouncementUpsert) ClearTargeting() *AnnouncementUpsert {
474
+ u.SetNull(announcement.FieldTargeting)
475
+ return u
476
+ }
477
+
478
+ // SetStartsAt sets the "starts_at" field.
479
+ func (u *AnnouncementUpsert) SetStartsAt(v time.Time) *AnnouncementUpsert {
480
+ u.Set(announcement.FieldStartsAt, v)
481
+ return u
482
+ }
483
+
484
+ // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
485
+ func (u *AnnouncementUpsert) UpdateStartsAt() *AnnouncementUpsert {
486
+ u.SetExcluded(announcement.FieldStartsAt)
487
+ return u
488
+ }
489
+
490
+ // ClearStartsAt clears the value of the "starts_at" field.
491
+ func (u *AnnouncementUpsert) ClearStartsAt() *AnnouncementUpsert {
492
+ u.SetNull(announcement.FieldStartsAt)
493
+ return u
494
+ }
495
+
496
+ // SetEndsAt sets the "ends_at" field.
497
+ func (u *AnnouncementUpsert) SetEndsAt(v time.Time) *AnnouncementUpsert {
498
+ u.Set(announcement.FieldEndsAt, v)
499
+ return u
500
+ }
501
+
502
+ // UpdateEndsAt sets the "ends_at" field to the value that was provided on create.
503
+ func (u *AnnouncementUpsert) UpdateEndsAt() *AnnouncementUpsert {
504
+ u.SetExcluded(announcement.FieldEndsAt)
505
+ return u
506
+ }
507
+
508
+ // ClearEndsAt clears the value of the "ends_at" field.
509
+ func (u *AnnouncementUpsert) ClearEndsAt() *AnnouncementUpsert {
510
+ u.SetNull(announcement.FieldEndsAt)
511
+ return u
512
+ }
513
+
514
+ // SetCreatedBy sets the "created_by" field.
515
+ func (u *AnnouncementUpsert) SetCreatedBy(v int64) *AnnouncementUpsert {
516
+ u.Set(announcement.FieldCreatedBy, v)
517
+ return u
518
+ }
519
+
520
+ // UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
521
+ func (u *AnnouncementUpsert) UpdateCreatedBy() *AnnouncementUpsert {
522
+ u.SetExcluded(announcement.FieldCreatedBy)
523
+ return u
524
+ }
525
+
526
+ // AddCreatedBy adds v to the "created_by" field.
527
+ func (u *AnnouncementUpsert) AddCreatedBy(v int64) *AnnouncementUpsert {
528
+ u.Add(announcement.FieldCreatedBy, v)
529
+ return u
530
+ }
531
+
532
+ // ClearCreatedBy clears the value of the "created_by" field.
533
+ func (u *AnnouncementUpsert) ClearCreatedBy() *AnnouncementUpsert {
534
+ u.SetNull(announcement.FieldCreatedBy)
535
+ return u
536
+ }
537
+
538
+ // SetUpdatedBy sets the "updated_by" field.
539
+ func (u *AnnouncementUpsert) SetUpdatedBy(v int64) *AnnouncementUpsert {
540
+ u.Set(announcement.FieldUpdatedBy, v)
541
+ return u
542
+ }
543
+
544
+ // UpdateUpdatedBy sets the "updated_by" field to the value that was provided on create.
545
+ func (u *AnnouncementUpsert) UpdateUpdatedBy() *AnnouncementUpsert {
546
+ u.SetExcluded(announcement.FieldUpdatedBy)
547
+ return u
548
+ }
549
+
550
+ // AddUpdatedBy adds v to the "updated_by" field.
551
+ func (u *AnnouncementUpsert) AddUpdatedBy(v int64) *AnnouncementUpsert {
552
+ u.Add(announcement.FieldUpdatedBy, v)
553
+ return u
554
+ }
555
+
556
+ // ClearUpdatedBy clears the value of the "updated_by" field.
557
+ func (u *AnnouncementUpsert) ClearUpdatedBy() *AnnouncementUpsert {
558
+ u.SetNull(announcement.FieldUpdatedBy)
559
+ return u
560
+ }
561
+
562
+ // SetUpdatedAt sets the "updated_at" field.
563
+ func (u *AnnouncementUpsert) SetUpdatedAt(v time.Time) *AnnouncementUpsert {
564
+ u.Set(announcement.FieldUpdatedAt, v)
565
+ return u
566
+ }
567
+
568
+ // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
569
+ func (u *AnnouncementUpsert) UpdateUpdatedAt() *AnnouncementUpsert {
570
+ u.SetExcluded(announcement.FieldUpdatedAt)
571
+ return u
572
+ }
573
+
574
+ // UpdateNewValues updates the mutable fields using the new values that were set on create.
575
+ // Using this option is equivalent to using:
576
+ //
577
+ // client.Announcement.Create().
578
+ // OnConflict(
579
+ // sql.ResolveWithNewValues(),
580
+ // ).
581
+ // Exec(ctx)
582
+ func (u *AnnouncementUpsertOne) UpdateNewValues() *AnnouncementUpsertOne {
583
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
584
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
585
+ if _, exists := u.create.mutation.CreatedAt(); exists {
586
+ s.SetIgnore(announcement.FieldCreatedAt)
587
+ }
588
+ }))
589
+ return u
590
+ }
591
+
592
+ // Ignore sets each column to itself in case of conflict.
593
+ // Using this option is equivalent to using:
594
+ //
595
+ // client.Announcement.Create().
596
+ // OnConflict(sql.ResolveWithIgnore()).
597
+ // Exec(ctx)
598
+ func (u *AnnouncementUpsertOne) Ignore() *AnnouncementUpsertOne {
599
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
600
+ return u
601
+ }
602
+
603
+ // DoNothing configures the conflict_action to `DO NOTHING`.
604
+ // Supported only by SQLite and PostgreSQL.
605
+ func (u *AnnouncementUpsertOne) DoNothing() *AnnouncementUpsertOne {
606
+ u.create.conflict = append(u.create.conflict, sql.DoNothing())
607
+ return u
608
+ }
609
+
610
+ // Update allows overriding fields `UPDATE` values. See the AnnouncementCreate.OnConflict
611
+ // documentation for more info.
612
+ func (u *AnnouncementUpsertOne) Update(set func(*AnnouncementUpsert)) *AnnouncementUpsertOne {
613
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
614
+ set(&AnnouncementUpsert{UpdateSet: update})
615
+ }))
616
+ return u
617
+ }
618
+
619
+ // SetTitle sets the "title" field.
620
+ func (u *AnnouncementUpsertOne) SetTitle(v string) *AnnouncementUpsertOne {
621
+ return u.Update(func(s *AnnouncementUpsert) {
622
+ s.SetTitle(v)
623
+ })
624
+ }
625
+
626
+ // UpdateTitle sets the "title" field to the value that was provided on create.
627
+ func (u *AnnouncementUpsertOne) UpdateTitle() *AnnouncementUpsertOne {
628
+ return u.Update(func(s *AnnouncementUpsert) {
629
+ s.UpdateTitle()
630
+ })
631
+ }
632
+
633
+ // SetContent sets the "content" field.
634
+ func (u *AnnouncementUpsertOne) SetContent(v string) *AnnouncementUpsertOne {
635
+ return u.Update(func(s *AnnouncementUpsert) {
636
+ s.SetContent(v)
637
+ })
638
+ }
639
+
640
+ // UpdateContent sets the "content" field to the value that was provided on create.
641
+ func (u *AnnouncementUpsertOne) UpdateContent() *AnnouncementUpsertOne {
642
+ return u.Update(func(s *AnnouncementUpsert) {
643
+ s.UpdateContent()
644
+ })
645
+ }
646
+
647
+ // SetStatus sets the "status" field.
648
+ func (u *AnnouncementUpsertOne) SetStatus(v string) *AnnouncementUpsertOne {
649
+ return u.Update(func(s *AnnouncementUpsert) {
650
+ s.SetStatus(v)
651
+ })
652
+ }
653
+
654
+ // UpdateStatus sets the "status" field to the value that was provided on create.
655
+ func (u *AnnouncementUpsertOne) UpdateStatus() *AnnouncementUpsertOne {
656
+ return u.Update(func(s *AnnouncementUpsert) {
657
+ s.UpdateStatus()
658
+ })
659
+ }
660
+
661
+ // SetNotifyMode sets the "notify_mode" field.
662
+ func (u *AnnouncementUpsertOne) SetNotifyMode(v string) *AnnouncementUpsertOne {
663
+ return u.Update(func(s *AnnouncementUpsert) {
664
+ s.SetNotifyMode(v)
665
+ })
666
+ }
667
+
668
+ // UpdateNotifyMode sets the "notify_mode" field to the value that was provided on create.
669
+ func (u *AnnouncementUpsertOne) UpdateNotifyMode() *AnnouncementUpsertOne {
670
+ return u.Update(func(s *AnnouncementUpsert) {
671
+ s.UpdateNotifyMode()
672
+ })
673
+ }
674
+
675
+ // SetTargeting sets the "targeting" field.
676
+ func (u *AnnouncementUpsertOne) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpsertOne {
677
+ return u.Update(func(s *AnnouncementUpsert) {
678
+ s.SetTargeting(v)
679
+ })
680
+ }
681
+
682
+ // UpdateTargeting sets the "targeting" field to the value that was provided on create.
683
+ func (u *AnnouncementUpsertOne) UpdateTargeting() *AnnouncementUpsertOne {
684
+ return u.Update(func(s *AnnouncementUpsert) {
685
+ s.UpdateTargeting()
686
+ })
687
+ }
688
+
689
+ // ClearTargeting clears the value of the "targeting" field.
690
+ func (u *AnnouncementUpsertOne) ClearTargeting() *AnnouncementUpsertOne {
691
+ return u.Update(func(s *AnnouncementUpsert) {
692
+ s.ClearTargeting()
693
+ })
694
+ }
695
+
696
+ // SetStartsAt sets the "starts_at" field.
697
+ func (u *AnnouncementUpsertOne) SetStartsAt(v time.Time) *AnnouncementUpsertOne {
698
+ return u.Update(func(s *AnnouncementUpsert) {
699
+ s.SetStartsAt(v)
700
+ })
701
+ }
702
+
703
+ // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
704
+ func (u *AnnouncementUpsertOne) UpdateStartsAt() *AnnouncementUpsertOne {
705
+ return u.Update(func(s *AnnouncementUpsert) {
706
+ s.UpdateStartsAt()
707
+ })
708
+ }
709
+
710
+ // ClearStartsAt clears the value of the "starts_at" field.
711
+ func (u *AnnouncementUpsertOne) ClearStartsAt() *AnnouncementUpsertOne {
712
+ return u.Update(func(s *AnnouncementUpsert) {
713
+ s.ClearStartsAt()
714
+ })
715
+ }
716
+
717
+ // SetEndsAt sets the "ends_at" field.
718
+ func (u *AnnouncementUpsertOne) SetEndsAt(v time.Time) *AnnouncementUpsertOne {
719
+ return u.Update(func(s *AnnouncementUpsert) {
720
+ s.SetEndsAt(v)
721
+ })
722
+ }
723
+
724
+ // UpdateEndsAt sets the "ends_at" field to the value that was provided on create.
725
+ func (u *AnnouncementUpsertOne) UpdateEndsAt() *AnnouncementUpsertOne {
726
+ return u.Update(func(s *AnnouncementUpsert) {
727
+ s.UpdateEndsAt()
728
+ })
729
+ }
730
+
731
+ // ClearEndsAt clears the value of the "ends_at" field.
732
+ func (u *AnnouncementUpsertOne) ClearEndsAt() *AnnouncementUpsertOne {
733
+ return u.Update(func(s *AnnouncementUpsert) {
734
+ s.ClearEndsAt()
735
+ })
736
+ }
737
+
738
+ // SetCreatedBy sets the "created_by" field.
739
+ func (u *AnnouncementUpsertOne) SetCreatedBy(v int64) *AnnouncementUpsertOne {
740
+ return u.Update(func(s *AnnouncementUpsert) {
741
+ s.SetCreatedBy(v)
742
+ })
743
+ }
744
+
745
+ // AddCreatedBy adds v to the "created_by" field.
746
+ func (u *AnnouncementUpsertOne) AddCreatedBy(v int64) *AnnouncementUpsertOne {
747
+ return u.Update(func(s *AnnouncementUpsert) {
748
+ s.AddCreatedBy(v)
749
+ })
750
+ }
751
+
752
+ // UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
753
+ func (u *AnnouncementUpsertOne) UpdateCreatedBy() *AnnouncementUpsertOne {
754
+ return u.Update(func(s *AnnouncementUpsert) {
755
+ s.UpdateCreatedBy()
756
+ })
757
+ }
758
+
759
+ // ClearCreatedBy clears the value of the "created_by" field.
760
+ func (u *AnnouncementUpsertOne) ClearCreatedBy() *AnnouncementUpsertOne {
761
+ return u.Update(func(s *AnnouncementUpsert) {
762
+ s.ClearCreatedBy()
763
+ })
764
+ }
765
+
766
+ // SetUpdatedBy sets the "updated_by" field.
767
+ func (u *AnnouncementUpsertOne) SetUpdatedBy(v int64) *AnnouncementUpsertOne {
768
+ return u.Update(func(s *AnnouncementUpsert) {
769
+ s.SetUpdatedBy(v)
770
+ })
771
+ }
772
+
773
+ // AddUpdatedBy adds v to the "updated_by" field.
774
+ func (u *AnnouncementUpsertOne) AddUpdatedBy(v int64) *AnnouncementUpsertOne {
775
+ return u.Update(func(s *AnnouncementUpsert) {
776
+ s.AddUpdatedBy(v)
777
+ })
778
+ }
779
+
780
+ // UpdateUpdatedBy sets the "updated_by" field to the value that was provided on create.
781
+ func (u *AnnouncementUpsertOne) UpdateUpdatedBy() *AnnouncementUpsertOne {
782
+ return u.Update(func(s *AnnouncementUpsert) {
783
+ s.UpdateUpdatedBy()
784
+ })
785
+ }
786
+
787
+ // ClearUpdatedBy clears the value of the "updated_by" field.
788
+ func (u *AnnouncementUpsertOne) ClearUpdatedBy() *AnnouncementUpsertOne {
789
+ return u.Update(func(s *AnnouncementUpsert) {
790
+ s.ClearUpdatedBy()
791
+ })
792
+ }
793
+
794
+ // SetUpdatedAt sets the "updated_at" field.
795
+ func (u *AnnouncementUpsertOne) SetUpdatedAt(v time.Time) *AnnouncementUpsertOne {
796
+ return u.Update(func(s *AnnouncementUpsert) {
797
+ s.SetUpdatedAt(v)
798
+ })
799
+ }
800
+
801
+ // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
802
+ func (u *AnnouncementUpsertOne) UpdateUpdatedAt() *AnnouncementUpsertOne {
803
+ return u.Update(func(s *AnnouncementUpsert) {
804
+ s.UpdateUpdatedAt()
805
+ })
806
+ }
807
+
808
+ // Exec executes the query.
809
+ func (u *AnnouncementUpsertOne) Exec(ctx context.Context) error {
810
+ if len(u.create.conflict) == 0 {
811
+ return errors.New("ent: missing options for AnnouncementCreate.OnConflict")
812
+ }
813
+ return u.create.Exec(ctx)
814
+ }
815
+
816
+ // ExecX is like Exec, but panics if an error occurs.
817
+ func (u *AnnouncementUpsertOne) ExecX(ctx context.Context) {
818
+ if err := u.create.Exec(ctx); err != nil {
819
+ panic(err)
820
+ }
821
+ }
822
+
823
+ // Exec executes the UPSERT query and returns the inserted/updated ID.
824
+ func (u *AnnouncementUpsertOne) ID(ctx context.Context) (id int64, err error) {
825
+ node, err := u.create.Save(ctx)
826
+ if err != nil {
827
+ return id, err
828
+ }
829
+ return node.ID, nil
830
+ }
831
+
832
+ // IDX is like ID, but panics if an error occurs.
833
+ func (u *AnnouncementUpsertOne) IDX(ctx context.Context) int64 {
834
+ id, err := u.ID(ctx)
835
+ if err != nil {
836
+ panic(err)
837
+ }
838
+ return id
839
+ }
840
+
841
+ // AnnouncementCreateBulk is the builder for creating many Announcement entities in bulk.
842
+ type AnnouncementCreateBulk struct {
843
+ config
844
+ err error
845
+ builders []*AnnouncementCreate
846
+ conflict []sql.ConflictOption
847
+ }
848
+
849
+ // Save creates the Announcement entities in the database.
850
+ func (_c *AnnouncementCreateBulk) Save(ctx context.Context) ([]*Announcement, error) {
851
+ if _c.err != nil {
852
+ return nil, _c.err
853
+ }
854
+ specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
855
+ nodes := make([]*Announcement, len(_c.builders))
856
+ mutators := make([]Mutator, len(_c.builders))
857
+ for i := range _c.builders {
858
+ func(i int, root context.Context) {
859
+ builder := _c.builders[i]
860
+ builder.defaults()
861
+ var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
862
+ mutation, ok := m.(*AnnouncementMutation)
863
+ if !ok {
864
+ return nil, fmt.Errorf("unexpected mutation type %T", m)
865
+ }
866
+ if err := builder.check(); err != nil {
867
+ return nil, err
868
+ }
869
+ builder.mutation = mutation
870
+ var err error
871
+ nodes[i], specs[i] = builder.createSpec()
872
+ if i < len(mutators)-1 {
873
+ _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
874
+ } else {
875
+ spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
876
+ spec.OnConflict = _c.conflict
877
+ // Invoke the actual operation on the latest mutation in the chain.
878
+ if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
879
+ if sqlgraph.IsConstraintError(err) {
880
+ err = &ConstraintError{msg: err.Error(), wrap: err}
881
+ }
882
+ }
883
+ }
884
+ if err != nil {
885
+ return nil, err
886
+ }
887
+ mutation.id = &nodes[i].ID
888
+ if specs[i].ID.Value != nil {
889
+ id := specs[i].ID.Value.(int64)
890
+ nodes[i].ID = int64(id)
891
+ }
892
+ mutation.done = true
893
+ return nodes[i], nil
894
+ })
895
+ for i := len(builder.hooks) - 1; i >= 0; i-- {
896
+ mut = builder.hooks[i](mut)
897
+ }
898
+ mutators[i] = mut
899
+ }(i, ctx)
900
+ }
901
+ if len(mutators) > 0 {
902
+ if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
903
+ return nil, err
904
+ }
905
+ }
906
+ return nodes, nil
907
+ }
908
+
909
+ // SaveX is like Save, but panics if an error occurs.
910
+ func (_c *AnnouncementCreateBulk) SaveX(ctx context.Context) []*Announcement {
911
+ v, err := _c.Save(ctx)
912
+ if err != nil {
913
+ panic(err)
914
+ }
915
+ return v
916
+ }
917
+
918
+ // Exec executes the query.
919
+ func (_c *AnnouncementCreateBulk) Exec(ctx context.Context) error {
920
+ _, err := _c.Save(ctx)
921
+ return err
922
+ }
923
+
924
+ // ExecX is like Exec, but panics if an error occurs.
925
+ func (_c *AnnouncementCreateBulk) ExecX(ctx context.Context) {
926
+ if err := _c.Exec(ctx); err != nil {
927
+ panic(err)
928
+ }
929
+ }
930
+
931
+ // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
932
+ // of the `INSERT` statement. For example:
933
+ //
934
+ // client.Announcement.CreateBulk(builders...).
935
+ // OnConflict(
936
+ // // Update the row with the new values
937
+ // // the was proposed for insertion.
938
+ // sql.ResolveWithNewValues(),
939
+ // ).
940
+ // // Override some of the fields with custom
941
+ // // update values.
942
+ // Update(func(u *ent.AnnouncementUpsert) {
943
+ // SetTitle(v+v).
944
+ // }).
945
+ // Exec(ctx)
946
+ func (_c *AnnouncementCreateBulk) OnConflict(opts ...sql.ConflictOption) *AnnouncementUpsertBulk {
947
+ _c.conflict = opts
948
+ return &AnnouncementUpsertBulk{
949
+ create: _c,
950
+ }
951
+ }
952
+
953
+ // OnConflictColumns calls `OnConflict` and configures the columns
954
+ // as conflict target. Using this option is equivalent to using:
955
+ //
956
+ // client.Announcement.Create().
957
+ // OnConflict(sql.ConflictColumns(columns...)).
958
+ // Exec(ctx)
959
+ func (_c *AnnouncementCreateBulk) OnConflictColumns(columns ...string) *AnnouncementUpsertBulk {
960
+ _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
961
+ return &AnnouncementUpsertBulk{
962
+ create: _c,
963
+ }
964
+ }
965
+
966
+ // AnnouncementUpsertBulk is the builder for "upsert"-ing
967
+ // a bulk of Announcement nodes.
968
+ type AnnouncementUpsertBulk struct {
969
+ create *AnnouncementCreateBulk
970
+ }
971
+
972
+ // UpdateNewValues updates the mutable fields using the new values that
973
+ // were set on create. Using this option is equivalent to using:
974
+ //
975
+ // client.Announcement.Create().
976
+ // OnConflict(
977
+ // sql.ResolveWithNewValues(),
978
+ // ).
979
+ // Exec(ctx)
980
+ func (u *AnnouncementUpsertBulk) UpdateNewValues() *AnnouncementUpsertBulk {
981
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
982
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
983
+ for _, b := range u.create.builders {
984
+ if _, exists := b.mutation.CreatedAt(); exists {
985
+ s.SetIgnore(announcement.FieldCreatedAt)
986
+ }
987
+ }
988
+ }))
989
+ return u
990
+ }
991
+
992
+ // Ignore sets each column to itself in case of conflict.
993
+ // Using this option is equivalent to using:
994
+ //
995
+ // client.Announcement.Create().
996
+ // OnConflict(sql.ResolveWithIgnore()).
997
+ // Exec(ctx)
998
+ func (u *AnnouncementUpsertBulk) Ignore() *AnnouncementUpsertBulk {
999
+ u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
1000
+ return u
1001
+ }
1002
+
1003
+ // DoNothing configures the conflict_action to `DO NOTHING`.
1004
+ // Supported only by SQLite and PostgreSQL.
1005
+ func (u *AnnouncementUpsertBulk) DoNothing() *AnnouncementUpsertBulk {
1006
+ u.create.conflict = append(u.create.conflict, sql.DoNothing())
1007
+ return u
1008
+ }
1009
+
1010
+ // Update allows overriding fields `UPDATE` values. See the AnnouncementCreateBulk.OnConflict
1011
+ // documentation for more info.
1012
+ func (u *AnnouncementUpsertBulk) Update(set func(*AnnouncementUpsert)) *AnnouncementUpsertBulk {
1013
+ u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
1014
+ set(&AnnouncementUpsert{UpdateSet: update})
1015
+ }))
1016
+ return u
1017
+ }
1018
+
1019
+ // SetTitle sets the "title" field.
1020
+ func (u *AnnouncementUpsertBulk) SetTitle(v string) *AnnouncementUpsertBulk {
1021
+ return u.Update(func(s *AnnouncementUpsert) {
1022
+ s.SetTitle(v)
1023
+ })
1024
+ }
1025
+
1026
+ // UpdateTitle sets the "title" field to the value that was provided on create.
1027
+ func (u *AnnouncementUpsertBulk) UpdateTitle() *AnnouncementUpsertBulk {
1028
+ return u.Update(func(s *AnnouncementUpsert) {
1029
+ s.UpdateTitle()
1030
+ })
1031
+ }
1032
+
1033
+ // SetContent sets the "content" field.
1034
+ func (u *AnnouncementUpsertBulk) SetContent(v string) *AnnouncementUpsertBulk {
1035
+ return u.Update(func(s *AnnouncementUpsert) {
1036
+ s.SetContent(v)
1037
+ })
1038
+ }
1039
+
1040
+ // UpdateContent sets the "content" field to the value that was provided on create.
1041
+ func (u *AnnouncementUpsertBulk) UpdateContent() *AnnouncementUpsertBulk {
1042
+ return u.Update(func(s *AnnouncementUpsert) {
1043
+ s.UpdateContent()
1044
+ })
1045
+ }
1046
+
1047
+ // SetStatus sets the "status" field.
1048
+ func (u *AnnouncementUpsertBulk) SetStatus(v string) *AnnouncementUpsertBulk {
1049
+ return u.Update(func(s *AnnouncementUpsert) {
1050
+ s.SetStatus(v)
1051
+ })
1052
+ }
1053
+
1054
+ // UpdateStatus sets the "status" field to the value that was provided on create.
1055
+ func (u *AnnouncementUpsertBulk) UpdateStatus() *AnnouncementUpsertBulk {
1056
+ return u.Update(func(s *AnnouncementUpsert) {
1057
+ s.UpdateStatus()
1058
+ })
1059
+ }
1060
+
1061
+ // SetNotifyMode sets the "notify_mode" field.
1062
+ func (u *AnnouncementUpsertBulk) SetNotifyMode(v string) *AnnouncementUpsertBulk {
1063
+ return u.Update(func(s *AnnouncementUpsert) {
1064
+ s.SetNotifyMode(v)
1065
+ })
1066
+ }
1067
+
1068
+ // UpdateNotifyMode sets the "notify_mode" field to the value that was provided on create.
1069
+ func (u *AnnouncementUpsertBulk) UpdateNotifyMode() *AnnouncementUpsertBulk {
1070
+ return u.Update(func(s *AnnouncementUpsert) {
1071
+ s.UpdateNotifyMode()
1072
+ })
1073
+ }
1074
+
1075
+ // SetTargeting sets the "targeting" field.
1076
+ func (u *AnnouncementUpsertBulk) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpsertBulk {
1077
+ return u.Update(func(s *AnnouncementUpsert) {
1078
+ s.SetTargeting(v)
1079
+ })
1080
+ }
1081
+
1082
+ // UpdateTargeting sets the "targeting" field to the value that was provided on create.
1083
+ func (u *AnnouncementUpsertBulk) UpdateTargeting() *AnnouncementUpsertBulk {
1084
+ return u.Update(func(s *AnnouncementUpsert) {
1085
+ s.UpdateTargeting()
1086
+ })
1087
+ }
1088
+
1089
+ // ClearTargeting clears the value of the "targeting" field.
1090
+ func (u *AnnouncementUpsertBulk) ClearTargeting() *AnnouncementUpsertBulk {
1091
+ return u.Update(func(s *AnnouncementUpsert) {
1092
+ s.ClearTargeting()
1093
+ })
1094
+ }
1095
+
1096
+ // SetStartsAt sets the "starts_at" field.
1097
+ func (u *AnnouncementUpsertBulk) SetStartsAt(v time.Time) *AnnouncementUpsertBulk {
1098
+ return u.Update(func(s *AnnouncementUpsert) {
1099
+ s.SetStartsAt(v)
1100
+ })
1101
+ }
1102
+
1103
+ // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
1104
+ func (u *AnnouncementUpsertBulk) UpdateStartsAt() *AnnouncementUpsertBulk {
1105
+ return u.Update(func(s *AnnouncementUpsert) {
1106
+ s.UpdateStartsAt()
1107
+ })
1108
+ }
1109
+
1110
+ // ClearStartsAt clears the value of the "starts_at" field.
1111
+ func (u *AnnouncementUpsertBulk) ClearStartsAt() *AnnouncementUpsertBulk {
1112
+ return u.Update(func(s *AnnouncementUpsert) {
1113
+ s.ClearStartsAt()
1114
+ })
1115
+ }
1116
+
1117
+ // SetEndsAt sets the "ends_at" field.
1118
+ func (u *AnnouncementUpsertBulk) SetEndsAt(v time.Time) *AnnouncementUpsertBulk {
1119
+ return u.Update(func(s *AnnouncementUpsert) {
1120
+ s.SetEndsAt(v)
1121
+ })
1122
+ }
1123
+
1124
+ // UpdateEndsAt sets the "ends_at" field to the value that was provided on create.
1125
+ func (u *AnnouncementUpsertBulk) UpdateEndsAt() *AnnouncementUpsertBulk {
1126
+ return u.Update(func(s *AnnouncementUpsert) {
1127
+ s.UpdateEndsAt()
1128
+ })
1129
+ }
1130
+
1131
+ // ClearEndsAt clears the value of the "ends_at" field.
1132
+ func (u *AnnouncementUpsertBulk) ClearEndsAt() *AnnouncementUpsertBulk {
1133
+ return u.Update(func(s *AnnouncementUpsert) {
1134
+ s.ClearEndsAt()
1135
+ })
1136
+ }
1137
+
1138
+ // SetCreatedBy sets the "created_by" field.
1139
+ func (u *AnnouncementUpsertBulk) SetCreatedBy(v int64) *AnnouncementUpsertBulk {
1140
+ return u.Update(func(s *AnnouncementUpsert) {
1141
+ s.SetCreatedBy(v)
1142
+ })
1143
+ }
1144
+
1145
+ // AddCreatedBy adds v to the "created_by" field.
1146
+ func (u *AnnouncementUpsertBulk) AddCreatedBy(v int64) *AnnouncementUpsertBulk {
1147
+ return u.Update(func(s *AnnouncementUpsert) {
1148
+ s.AddCreatedBy(v)
1149
+ })
1150
+ }
1151
+
1152
+ // UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
1153
+ func (u *AnnouncementUpsertBulk) UpdateCreatedBy() *AnnouncementUpsertBulk {
1154
+ return u.Update(func(s *AnnouncementUpsert) {
1155
+ s.UpdateCreatedBy()
1156
+ })
1157
+ }
1158
+
1159
+ // ClearCreatedBy clears the value of the "created_by" field.
1160
+ func (u *AnnouncementUpsertBulk) ClearCreatedBy() *AnnouncementUpsertBulk {
1161
+ return u.Update(func(s *AnnouncementUpsert) {
1162
+ s.ClearCreatedBy()
1163
+ })
1164
+ }
1165
+
1166
+ // SetUpdatedBy sets the "updated_by" field.
1167
+ func (u *AnnouncementUpsertBulk) SetUpdatedBy(v int64) *AnnouncementUpsertBulk {
1168
+ return u.Update(func(s *AnnouncementUpsert) {
1169
+ s.SetUpdatedBy(v)
1170
+ })
1171
+ }
1172
+
1173
+ // AddUpdatedBy adds v to the "updated_by" field.
1174
+ func (u *AnnouncementUpsertBulk) AddUpdatedBy(v int64) *AnnouncementUpsertBulk {
1175
+ return u.Update(func(s *AnnouncementUpsert) {
1176
+ s.AddUpdatedBy(v)
1177
+ })
1178
+ }
1179
+
1180
+ // UpdateUpdatedBy sets the "updated_by" field to the value that was provided on create.
1181
+ func (u *AnnouncementUpsertBulk) UpdateUpdatedBy() *AnnouncementUpsertBulk {
1182
+ return u.Update(func(s *AnnouncementUpsert) {
1183
+ s.UpdateUpdatedBy()
1184
+ })
1185
+ }
1186
+
1187
+ // ClearUpdatedBy clears the value of the "updated_by" field.
1188
+ func (u *AnnouncementUpsertBulk) ClearUpdatedBy() *AnnouncementUpsertBulk {
1189
+ return u.Update(func(s *AnnouncementUpsert) {
1190
+ s.ClearUpdatedBy()
1191
+ })
1192
+ }
1193
+
1194
+ // SetUpdatedAt sets the "updated_at" field.
1195
+ func (u *AnnouncementUpsertBulk) SetUpdatedAt(v time.Time) *AnnouncementUpsertBulk {
1196
+ return u.Update(func(s *AnnouncementUpsert) {
1197
+ s.SetUpdatedAt(v)
1198
+ })
1199
+ }
1200
+
1201
+ // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
1202
+ func (u *AnnouncementUpsertBulk) UpdateUpdatedAt() *AnnouncementUpsertBulk {
1203
+ return u.Update(func(s *AnnouncementUpsert) {
1204
+ s.UpdateUpdatedAt()
1205
+ })
1206
+ }
1207
+
1208
+ // Exec executes the query.
1209
+ func (u *AnnouncementUpsertBulk) Exec(ctx context.Context) error {
1210
+ if u.create.err != nil {
1211
+ return u.create.err
1212
+ }
1213
+ for i, b := range u.create.builders {
1214
+ if len(b.conflict) != 0 {
1215
+ return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AnnouncementCreateBulk instead", i)
1216
+ }
1217
+ }
1218
+ if len(u.create.conflict) == 0 {
1219
+ return errors.New("ent: missing options for AnnouncementCreateBulk.OnConflict")
1220
+ }
1221
+ return u.create.Exec(ctx)
1222
+ }
1223
+
1224
+ // ExecX is like Exec, but panics if an error occurs.
1225
+ func (u *AnnouncementUpsertBulk) ExecX(ctx context.Context) {
1226
+ if err := u.create.Exec(ctx); err != nil {
1227
+ panic(err)
1228
+ }
1229
+ }
backend/ent/announcement_delete.go ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+
8
+ "entgo.io/ent/dialect/sql"
9
+ "entgo.io/ent/dialect/sql/sqlgraph"
10
+ "entgo.io/ent/schema/field"
11
+ "github.com/Wei-Shaw/sub2api/ent/announcement"
12
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
13
+ )
14
+
15
+ // AnnouncementDelete is the builder for deleting a Announcement entity.
16
+ type AnnouncementDelete struct {
17
+ config
18
+ hooks []Hook
19
+ mutation *AnnouncementMutation
20
+ }
21
+
22
+ // Where appends a list predicates to the AnnouncementDelete builder.
23
+ func (_d *AnnouncementDelete) Where(ps ...predicate.Announcement) *AnnouncementDelete {
24
+ _d.mutation.Where(ps...)
25
+ return _d
26
+ }
27
+
28
+ // Exec executes the deletion query and returns how many vertices were deleted.
29
+ func (_d *AnnouncementDelete) Exec(ctx context.Context) (int, error) {
30
+ return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
31
+ }
32
+
33
+ // ExecX is like Exec, but panics if an error occurs.
34
+ func (_d *AnnouncementDelete) ExecX(ctx context.Context) int {
35
+ n, err := _d.Exec(ctx)
36
+ if err != nil {
37
+ panic(err)
38
+ }
39
+ return n
40
+ }
41
+
42
+ func (_d *AnnouncementDelete) sqlExec(ctx context.Context) (int, error) {
43
+ _spec := sqlgraph.NewDeleteSpec(announcement.Table, sqlgraph.NewFieldSpec(announcement.FieldID, field.TypeInt64))
44
+ if ps := _d.mutation.predicates; len(ps) > 0 {
45
+ _spec.Predicate = func(selector *sql.Selector) {
46
+ for i := range ps {
47
+ ps[i](selector)
48
+ }
49
+ }
50
+ }
51
+ affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
52
+ if err != nil && sqlgraph.IsConstraintError(err) {
53
+ err = &ConstraintError{msg: err.Error(), wrap: err}
54
+ }
55
+ _d.mutation.done = true
56
+ return affected, err
57
+ }
58
+
59
+ // AnnouncementDeleteOne is the builder for deleting a single Announcement entity.
60
+ type AnnouncementDeleteOne struct {
61
+ _d *AnnouncementDelete
62
+ }
63
+
64
+ // Where appends a list predicates to the AnnouncementDelete builder.
65
+ func (_d *AnnouncementDeleteOne) Where(ps ...predicate.Announcement) *AnnouncementDeleteOne {
66
+ _d._d.mutation.Where(ps...)
67
+ return _d
68
+ }
69
+
70
+ // Exec executes the deletion query.
71
+ func (_d *AnnouncementDeleteOne) Exec(ctx context.Context) error {
72
+ n, err := _d._d.Exec(ctx)
73
+ switch {
74
+ case err != nil:
75
+ return err
76
+ case n == 0:
77
+ return &NotFoundError{announcement.Label}
78
+ default:
79
+ return nil
80
+ }
81
+ }
82
+
83
+ // ExecX is like Exec, but panics if an error occurs.
84
+ func (_d *AnnouncementDeleteOne) ExecX(ctx context.Context) {
85
+ if err := _d.Exec(ctx); err != nil {
86
+ panic(err)
87
+ }
88
+ }
backend/ent/announcement_query.go ADDED
@@ -0,0 +1,643 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+ "database/sql/driver"
8
+ "fmt"
9
+ "math"
10
+
11
+ "entgo.io/ent"
12
+ "entgo.io/ent/dialect"
13
+ "entgo.io/ent/dialect/sql"
14
+ "entgo.io/ent/dialect/sql/sqlgraph"
15
+ "entgo.io/ent/schema/field"
16
+ "github.com/Wei-Shaw/sub2api/ent/announcement"
17
+ "github.com/Wei-Shaw/sub2api/ent/announcementread"
18
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
19
+ )
20
+
21
+ // AnnouncementQuery is the builder for querying Announcement entities.
22
+ type AnnouncementQuery struct {
23
+ config
24
+ ctx *QueryContext
25
+ order []announcement.OrderOption
26
+ inters []Interceptor
27
+ predicates []predicate.Announcement
28
+ withReads *AnnouncementReadQuery
29
+ modifiers []func(*sql.Selector)
30
+ // intermediate query (i.e. traversal path).
31
+ sql *sql.Selector
32
+ path func(context.Context) (*sql.Selector, error)
33
+ }
34
+
35
+ // Where adds a new predicate for the AnnouncementQuery builder.
36
+ func (_q *AnnouncementQuery) Where(ps ...predicate.Announcement) *AnnouncementQuery {
37
+ _q.predicates = append(_q.predicates, ps...)
38
+ return _q
39
+ }
40
+
41
+ // Limit the number of records to be returned by this query.
42
+ func (_q *AnnouncementQuery) Limit(limit int) *AnnouncementQuery {
43
+ _q.ctx.Limit = &limit
44
+ return _q
45
+ }
46
+
47
+ // Offset to start from.
48
+ func (_q *AnnouncementQuery) Offset(offset int) *AnnouncementQuery {
49
+ _q.ctx.Offset = &offset
50
+ return _q
51
+ }
52
+
53
+ // Unique configures the query builder to filter duplicate records on query.
54
+ // By default, unique is set to true, and can be disabled using this method.
55
+ func (_q *AnnouncementQuery) Unique(unique bool) *AnnouncementQuery {
56
+ _q.ctx.Unique = &unique
57
+ return _q
58
+ }
59
+
60
+ // Order specifies how the records should be ordered.
61
+ func (_q *AnnouncementQuery) Order(o ...announcement.OrderOption) *AnnouncementQuery {
62
+ _q.order = append(_q.order, o...)
63
+ return _q
64
+ }
65
+
66
+ // QueryReads chains the current query on the "reads" edge.
67
+ func (_q *AnnouncementQuery) QueryReads() *AnnouncementReadQuery {
68
+ query := (&AnnouncementReadClient{config: _q.config}).Query()
69
+ query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
70
+ if err := _q.prepareQuery(ctx); err != nil {
71
+ return nil, err
72
+ }
73
+ selector := _q.sqlQuery(ctx)
74
+ if err := selector.Err(); err != nil {
75
+ return nil, err
76
+ }
77
+ step := sqlgraph.NewStep(
78
+ sqlgraph.From(announcement.Table, announcement.FieldID, selector),
79
+ sqlgraph.To(announcementread.Table, announcementread.FieldID),
80
+ sqlgraph.Edge(sqlgraph.O2M, false, announcement.ReadsTable, announcement.ReadsColumn),
81
+ )
82
+ fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
83
+ return fromU, nil
84
+ }
85
+ return query
86
+ }
87
+
88
+ // First returns the first Announcement entity from the query.
89
+ // Returns a *NotFoundError when no Announcement was found.
90
+ func (_q *AnnouncementQuery) First(ctx context.Context) (*Announcement, error) {
91
+ nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
92
+ if err != nil {
93
+ return nil, err
94
+ }
95
+ if len(nodes) == 0 {
96
+ return nil, &NotFoundError{announcement.Label}
97
+ }
98
+ return nodes[0], nil
99
+ }
100
+
101
+ // FirstX is like First, but panics if an error occurs.
102
+ func (_q *AnnouncementQuery) FirstX(ctx context.Context) *Announcement {
103
+ node, err := _q.First(ctx)
104
+ if err != nil && !IsNotFound(err) {
105
+ panic(err)
106
+ }
107
+ return node
108
+ }
109
+
110
+ // FirstID returns the first Announcement ID from the query.
111
+ // Returns a *NotFoundError when no Announcement ID was found.
112
+ func (_q *AnnouncementQuery) FirstID(ctx context.Context) (id int64, err error) {
113
+ var ids []int64
114
+ if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
115
+ return
116
+ }
117
+ if len(ids) == 0 {
118
+ err = &NotFoundError{announcement.Label}
119
+ return
120
+ }
121
+ return ids[0], nil
122
+ }
123
+
124
+ // FirstIDX is like FirstID, but panics if an error occurs.
125
+ func (_q *AnnouncementQuery) FirstIDX(ctx context.Context) int64 {
126
+ id, err := _q.FirstID(ctx)
127
+ if err != nil && !IsNotFound(err) {
128
+ panic(err)
129
+ }
130
+ return id
131
+ }
132
+
133
+ // Only returns a single Announcement entity found by the query, ensuring it only returns one.
134
+ // Returns a *NotSingularError when more than one Announcement entity is found.
135
+ // Returns a *NotFoundError when no Announcement entities are found.
136
+ func (_q *AnnouncementQuery) Only(ctx context.Context) (*Announcement, error) {
137
+ nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
138
+ if err != nil {
139
+ return nil, err
140
+ }
141
+ switch len(nodes) {
142
+ case 1:
143
+ return nodes[0], nil
144
+ case 0:
145
+ return nil, &NotFoundError{announcement.Label}
146
+ default:
147
+ return nil, &NotSingularError{announcement.Label}
148
+ }
149
+ }
150
+
151
+ // OnlyX is like Only, but panics if an error occurs.
152
+ func (_q *AnnouncementQuery) OnlyX(ctx context.Context) *Announcement {
153
+ node, err := _q.Only(ctx)
154
+ if err != nil {
155
+ panic(err)
156
+ }
157
+ return node
158
+ }
159
+
160
+ // OnlyID is like Only, but returns the only Announcement ID in the query.
161
+ // Returns a *NotSingularError when more than one Announcement ID is found.
162
+ // Returns a *NotFoundError when no entities are found.
163
+ func (_q *AnnouncementQuery) OnlyID(ctx context.Context) (id int64, err error) {
164
+ var ids []int64
165
+ if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
166
+ return
167
+ }
168
+ switch len(ids) {
169
+ case 1:
170
+ id = ids[0]
171
+ case 0:
172
+ err = &NotFoundError{announcement.Label}
173
+ default:
174
+ err = &NotSingularError{announcement.Label}
175
+ }
176
+ return
177
+ }
178
+
179
+ // OnlyIDX is like OnlyID, but panics if an error occurs.
180
+ func (_q *AnnouncementQuery) OnlyIDX(ctx context.Context) int64 {
181
+ id, err := _q.OnlyID(ctx)
182
+ if err != nil {
183
+ panic(err)
184
+ }
185
+ return id
186
+ }
187
+
188
+ // All executes the query and returns a list of Announcements.
189
+ func (_q *AnnouncementQuery) All(ctx context.Context) ([]*Announcement, error) {
190
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
191
+ if err := _q.prepareQuery(ctx); err != nil {
192
+ return nil, err
193
+ }
194
+ qr := querierAll[[]*Announcement, *AnnouncementQuery]()
195
+ return withInterceptors[[]*Announcement](ctx, _q, qr, _q.inters)
196
+ }
197
+
198
+ // AllX is like All, but panics if an error occurs.
199
+ func (_q *AnnouncementQuery) AllX(ctx context.Context) []*Announcement {
200
+ nodes, err := _q.All(ctx)
201
+ if err != nil {
202
+ panic(err)
203
+ }
204
+ return nodes
205
+ }
206
+
207
+ // IDs executes the query and returns a list of Announcement IDs.
208
+ func (_q *AnnouncementQuery) IDs(ctx context.Context) (ids []int64, err error) {
209
+ if _q.ctx.Unique == nil && _q.path != nil {
210
+ _q.Unique(true)
211
+ }
212
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
213
+ if err = _q.Select(announcement.FieldID).Scan(ctx, &ids); err != nil {
214
+ return nil, err
215
+ }
216
+ return ids, nil
217
+ }
218
+
219
+ // IDsX is like IDs, but panics if an error occurs.
220
+ func (_q *AnnouncementQuery) IDsX(ctx context.Context) []int64 {
221
+ ids, err := _q.IDs(ctx)
222
+ if err != nil {
223
+ panic(err)
224
+ }
225
+ return ids
226
+ }
227
+
228
+ // Count returns the count of the given query.
229
+ func (_q *AnnouncementQuery) Count(ctx context.Context) (int, error) {
230
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
231
+ if err := _q.prepareQuery(ctx); err != nil {
232
+ return 0, err
233
+ }
234
+ return withInterceptors[int](ctx, _q, querierCount[*AnnouncementQuery](), _q.inters)
235
+ }
236
+
237
+ // CountX is like Count, but panics if an error occurs.
238
+ func (_q *AnnouncementQuery) CountX(ctx context.Context) int {
239
+ count, err := _q.Count(ctx)
240
+ if err != nil {
241
+ panic(err)
242
+ }
243
+ return count
244
+ }
245
+
246
+ // Exist returns true if the query has elements in the graph.
247
+ func (_q *AnnouncementQuery) Exist(ctx context.Context) (bool, error) {
248
+ ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
249
+ switch _, err := _q.FirstID(ctx); {
250
+ case IsNotFound(err):
251
+ return false, nil
252
+ case err != nil:
253
+ return false, fmt.Errorf("ent: check existence: %w", err)
254
+ default:
255
+ return true, nil
256
+ }
257
+ }
258
+
259
+ // ExistX is like Exist, but panics if an error occurs.
260
+ func (_q *AnnouncementQuery) ExistX(ctx context.Context) bool {
261
+ exist, err := _q.Exist(ctx)
262
+ if err != nil {
263
+ panic(err)
264
+ }
265
+ return exist
266
+ }
267
+
268
+ // Clone returns a duplicate of the AnnouncementQuery builder, including all associated steps. It can be
269
+ // used to prepare common query builders and use them differently after the clone is made.
270
+ func (_q *AnnouncementQuery) Clone() *AnnouncementQuery {
271
+ if _q == nil {
272
+ return nil
273
+ }
274
+ return &AnnouncementQuery{
275
+ config: _q.config,
276
+ ctx: _q.ctx.Clone(),
277
+ order: append([]announcement.OrderOption{}, _q.order...),
278
+ inters: append([]Interceptor{}, _q.inters...),
279
+ predicates: append([]predicate.Announcement{}, _q.predicates...),
280
+ withReads: _q.withReads.Clone(),
281
+ // clone intermediate query.
282
+ sql: _q.sql.Clone(),
283
+ path: _q.path,
284
+ }
285
+ }
286
+
287
+ // WithReads tells the query-builder to eager-load the nodes that are connected to
288
+ // the "reads" edge. The optional arguments are used to configure the query builder of the edge.
289
+ func (_q *AnnouncementQuery) WithReads(opts ...func(*AnnouncementReadQuery)) *AnnouncementQuery {
290
+ query := (&AnnouncementReadClient{config: _q.config}).Query()
291
+ for _, opt := range opts {
292
+ opt(query)
293
+ }
294
+ _q.withReads = query
295
+ return _q
296
+ }
297
+
298
+ // GroupBy is used to group vertices by one or more fields/columns.
299
+ // It is often used with aggregate functions, like: count, max, mean, min, sum.
300
+ //
301
+ // Example:
302
+ //
303
+ // var v []struct {
304
+ // Title string `json:"title,omitempty"`
305
+ // Count int `json:"count,omitempty"`
306
+ // }
307
+ //
308
+ // client.Announcement.Query().
309
+ // GroupBy(announcement.FieldTitle).
310
+ // Aggregate(ent.Count()).
311
+ // Scan(ctx, &v)
312
+ func (_q *AnnouncementQuery) GroupBy(field string, fields ...string) *AnnouncementGroupBy {
313
+ _q.ctx.Fields = append([]string{field}, fields...)
314
+ grbuild := &AnnouncementGroupBy{build: _q}
315
+ grbuild.flds = &_q.ctx.Fields
316
+ grbuild.label = announcement.Label
317
+ grbuild.scan = grbuild.Scan
318
+ return grbuild
319
+ }
320
+
321
+ // Select allows the selection one or more fields/columns for the given query,
322
+ // instead of selecting all fields in the entity.
323
+ //
324
+ // Example:
325
+ //
326
+ // var v []struct {
327
+ // Title string `json:"title,omitempty"`
328
+ // }
329
+ //
330
+ // client.Announcement.Query().
331
+ // Select(announcement.FieldTitle).
332
+ // Scan(ctx, &v)
333
+ func (_q *AnnouncementQuery) Select(fields ...string) *AnnouncementSelect {
334
+ _q.ctx.Fields = append(_q.ctx.Fields, fields...)
335
+ sbuild := &AnnouncementSelect{AnnouncementQuery: _q}
336
+ sbuild.label = announcement.Label
337
+ sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
338
+ return sbuild
339
+ }
340
+
341
+ // Aggregate returns a AnnouncementSelect configured with the given aggregations.
342
+ func (_q *AnnouncementQuery) Aggregate(fns ...AggregateFunc) *AnnouncementSelect {
343
+ return _q.Select().Aggregate(fns...)
344
+ }
345
+
346
+ func (_q *AnnouncementQuery) prepareQuery(ctx context.Context) error {
347
+ for _, inter := range _q.inters {
348
+ if inter == nil {
349
+ return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
350
+ }
351
+ if trv, ok := inter.(Traverser); ok {
352
+ if err := trv.Traverse(ctx, _q); err != nil {
353
+ return err
354
+ }
355
+ }
356
+ }
357
+ for _, f := range _q.ctx.Fields {
358
+ if !announcement.ValidColumn(f) {
359
+ return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
360
+ }
361
+ }
362
+ if _q.path != nil {
363
+ prev, err := _q.path(ctx)
364
+ if err != nil {
365
+ return err
366
+ }
367
+ _q.sql = prev
368
+ }
369
+ return nil
370
+ }
371
+
372
+ func (_q *AnnouncementQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Announcement, error) {
373
+ var (
374
+ nodes = []*Announcement{}
375
+ _spec = _q.querySpec()
376
+ loadedTypes = [1]bool{
377
+ _q.withReads != nil,
378
+ }
379
+ )
380
+ _spec.ScanValues = func(columns []string) ([]any, error) {
381
+ return (*Announcement).scanValues(nil, columns)
382
+ }
383
+ _spec.Assign = func(columns []string, values []any) error {
384
+ node := &Announcement{config: _q.config}
385
+ nodes = append(nodes, node)
386
+ node.Edges.loadedTypes = loadedTypes
387
+ return node.assignValues(columns, values)
388
+ }
389
+ if len(_q.modifiers) > 0 {
390
+ _spec.Modifiers = _q.modifiers
391
+ }
392
+ for i := range hooks {
393
+ hooks[i](ctx, _spec)
394
+ }
395
+ if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
396
+ return nil, err
397
+ }
398
+ if len(nodes) == 0 {
399
+ return nodes, nil
400
+ }
401
+ if query := _q.withReads; query != nil {
402
+ if err := _q.loadReads(ctx, query, nodes,
403
+ func(n *Announcement) { n.Edges.Reads = []*AnnouncementRead{} },
404
+ func(n *Announcement, e *AnnouncementRead) { n.Edges.Reads = append(n.Edges.Reads, e) }); err != nil {
405
+ return nil, err
406
+ }
407
+ }
408
+ return nodes, nil
409
+ }
410
+
411
+ func (_q *AnnouncementQuery) loadReads(ctx context.Context, query *AnnouncementReadQuery, nodes []*Announcement, init func(*Announcement), assign func(*Announcement, *AnnouncementRead)) error {
412
+ fks := make([]driver.Value, 0, len(nodes))
413
+ nodeids := make(map[int64]*Announcement)
414
+ for i := range nodes {
415
+ fks = append(fks, nodes[i].ID)
416
+ nodeids[nodes[i].ID] = nodes[i]
417
+ if init != nil {
418
+ init(nodes[i])
419
+ }
420
+ }
421
+ if len(query.ctx.Fields) > 0 {
422
+ query.ctx.AppendFieldOnce(announcementread.FieldAnnouncementID)
423
+ }
424
+ query.Where(predicate.AnnouncementRead(func(s *sql.Selector) {
425
+ s.Where(sql.InValues(s.C(announcement.ReadsColumn), fks...))
426
+ }))
427
+ neighbors, err := query.All(ctx)
428
+ if err != nil {
429
+ return err
430
+ }
431
+ for _, n := range neighbors {
432
+ fk := n.AnnouncementID
433
+ node, ok := nodeids[fk]
434
+ if !ok {
435
+ return fmt.Errorf(`unexpected referenced foreign-key "announcement_id" returned %v for node %v`, fk, n.ID)
436
+ }
437
+ assign(node, n)
438
+ }
439
+ return nil
440
+ }
441
+
442
+ func (_q *AnnouncementQuery) sqlCount(ctx context.Context) (int, error) {
443
+ _spec := _q.querySpec()
444
+ if len(_q.modifiers) > 0 {
445
+ _spec.Modifiers = _q.modifiers
446
+ }
447
+ _spec.Node.Columns = _q.ctx.Fields
448
+ if len(_q.ctx.Fields) > 0 {
449
+ _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
450
+ }
451
+ return sqlgraph.CountNodes(ctx, _q.driver, _spec)
452
+ }
453
+
454
+ func (_q *AnnouncementQuery) querySpec() *sqlgraph.QuerySpec {
455
+ _spec := sqlgraph.NewQuerySpec(announcement.Table, announcement.Columns, sqlgraph.NewFieldSpec(announcement.FieldID, field.TypeInt64))
456
+ _spec.From = _q.sql
457
+ if unique := _q.ctx.Unique; unique != nil {
458
+ _spec.Unique = *unique
459
+ } else if _q.path != nil {
460
+ _spec.Unique = true
461
+ }
462
+ if fields := _q.ctx.Fields; len(fields) > 0 {
463
+ _spec.Node.Columns = make([]string, 0, len(fields))
464
+ _spec.Node.Columns = append(_spec.Node.Columns, announcement.FieldID)
465
+ for i := range fields {
466
+ if fields[i] != announcement.FieldID {
467
+ _spec.Node.Columns = append(_spec.Node.Columns, fields[i])
468
+ }
469
+ }
470
+ }
471
+ if ps := _q.predicates; len(ps) > 0 {
472
+ _spec.Predicate = func(selector *sql.Selector) {
473
+ for i := range ps {
474
+ ps[i](selector)
475
+ }
476
+ }
477
+ }
478
+ if limit := _q.ctx.Limit; limit != nil {
479
+ _spec.Limit = *limit
480
+ }
481
+ if offset := _q.ctx.Offset; offset != nil {
482
+ _spec.Offset = *offset
483
+ }
484
+ if ps := _q.order; len(ps) > 0 {
485
+ _spec.Order = func(selector *sql.Selector) {
486
+ for i := range ps {
487
+ ps[i](selector)
488
+ }
489
+ }
490
+ }
491
+ return _spec
492
+ }
493
+
494
+ func (_q *AnnouncementQuery) sqlQuery(ctx context.Context) *sql.Selector {
495
+ builder := sql.Dialect(_q.driver.Dialect())
496
+ t1 := builder.Table(announcement.Table)
497
+ columns := _q.ctx.Fields
498
+ if len(columns) == 0 {
499
+ columns = announcement.Columns
500
+ }
501
+ selector := builder.Select(t1.Columns(columns...)...).From(t1)
502
+ if _q.sql != nil {
503
+ selector = _q.sql
504
+ selector.Select(selector.Columns(columns...)...)
505
+ }
506
+ if _q.ctx.Unique != nil && *_q.ctx.Unique {
507
+ selector.Distinct()
508
+ }
509
+ for _, m := range _q.modifiers {
510
+ m(selector)
511
+ }
512
+ for _, p := range _q.predicates {
513
+ p(selector)
514
+ }
515
+ for _, p := range _q.order {
516
+ p(selector)
517
+ }
518
+ if offset := _q.ctx.Offset; offset != nil {
519
+ // limit is mandatory for offset clause. We start
520
+ // with default value, and override it below if needed.
521
+ selector.Offset(*offset).Limit(math.MaxInt32)
522
+ }
523
+ if limit := _q.ctx.Limit; limit != nil {
524
+ selector.Limit(*limit)
525
+ }
526
+ return selector
527
+ }
528
+
529
+ // ForUpdate locks the selected rows against concurrent updates, and prevent them from being
530
+ // updated, deleted or "selected ... for update" by other sessions, until the transaction is
531
+ // either committed or rolled-back.
532
+ func (_q *AnnouncementQuery) ForUpdate(opts ...sql.LockOption) *AnnouncementQuery {
533
+ if _q.driver.Dialect() == dialect.Postgres {
534
+ _q.Unique(false)
535
+ }
536
+ _q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
537
+ s.ForUpdate(opts...)
538
+ })
539
+ return _q
540
+ }
541
+
542
+ // ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
543
+ // on any rows that are read. Other sessions can read the rows, but cannot modify them
544
+ // until your transaction commits.
545
+ func (_q *AnnouncementQuery) ForShare(opts ...sql.LockOption) *AnnouncementQuery {
546
+ if _q.driver.Dialect() == dialect.Postgres {
547
+ _q.Unique(false)
548
+ }
549
+ _q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
550
+ s.ForShare(opts...)
551
+ })
552
+ return _q
553
+ }
554
+
555
+ // AnnouncementGroupBy is the group-by builder for Announcement entities.
556
+ type AnnouncementGroupBy struct {
557
+ selector
558
+ build *AnnouncementQuery
559
+ }
560
+
561
+ // Aggregate adds the given aggregation functions to the group-by query.
562
+ func (_g *AnnouncementGroupBy) Aggregate(fns ...AggregateFunc) *AnnouncementGroupBy {
563
+ _g.fns = append(_g.fns, fns...)
564
+ return _g
565
+ }
566
+
567
+ // Scan applies the selector query and scans the result into the given value.
568
+ func (_g *AnnouncementGroupBy) Scan(ctx context.Context, v any) error {
569
+ ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
570
+ if err := _g.build.prepareQuery(ctx); err != nil {
571
+ return err
572
+ }
573
+ return scanWithInterceptors[*AnnouncementQuery, *AnnouncementGroupBy](ctx, _g.build, _g, _g.build.inters, v)
574
+ }
575
+
576
+ func (_g *AnnouncementGroupBy) sqlScan(ctx context.Context, root *AnnouncementQuery, v any) error {
577
+ selector := root.sqlQuery(ctx).Select()
578
+ aggregation := make([]string, 0, len(_g.fns))
579
+ for _, fn := range _g.fns {
580
+ aggregation = append(aggregation, fn(selector))
581
+ }
582
+ if len(selector.SelectedColumns()) == 0 {
583
+ columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
584
+ for _, f := range *_g.flds {
585
+ columns = append(columns, selector.C(f))
586
+ }
587
+ columns = append(columns, aggregation...)
588
+ selector.Select(columns...)
589
+ }
590
+ selector.GroupBy(selector.Columns(*_g.flds...)...)
591
+ if err := selector.Err(); err != nil {
592
+ return err
593
+ }
594
+ rows := &sql.Rows{}
595
+ query, args := selector.Query()
596
+ if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
597
+ return err
598
+ }
599
+ defer rows.Close()
600
+ return sql.ScanSlice(rows, v)
601
+ }
602
+
603
+ // AnnouncementSelect is the builder for selecting fields of Announcement entities.
604
+ type AnnouncementSelect struct {
605
+ *AnnouncementQuery
606
+ selector
607
+ }
608
+
609
+ // Aggregate adds the given aggregation functions to the selector query.
610
+ func (_s *AnnouncementSelect) Aggregate(fns ...AggregateFunc) *AnnouncementSelect {
611
+ _s.fns = append(_s.fns, fns...)
612
+ return _s
613
+ }
614
+
615
+ // Scan applies the selector query and scans the result into the given value.
616
+ func (_s *AnnouncementSelect) Scan(ctx context.Context, v any) error {
617
+ ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
618
+ if err := _s.prepareQuery(ctx); err != nil {
619
+ return err
620
+ }
621
+ return scanWithInterceptors[*AnnouncementQuery, *AnnouncementSelect](ctx, _s.AnnouncementQuery, _s, _s.inters, v)
622
+ }
623
+
624
+ func (_s *AnnouncementSelect) sqlScan(ctx context.Context, root *AnnouncementQuery, v any) error {
625
+ selector := root.sqlQuery(ctx)
626
+ aggregation := make([]string, 0, len(_s.fns))
627
+ for _, fn := range _s.fns {
628
+ aggregation = append(aggregation, fn(selector))
629
+ }
630
+ switch n := len(*_s.selector.flds); {
631
+ case n == 0 && len(aggregation) > 0:
632
+ selector.Select(aggregation...)
633
+ case n != 0 && len(aggregation) > 0:
634
+ selector.AppendSelect(aggregation...)
635
+ }
636
+ rows := &sql.Rows{}
637
+ query, args := selector.Query()
638
+ if err := _s.driver.Query(ctx, query, args, rows); err != nil {
639
+ return err
640
+ }
641
+ defer rows.Close()
642
+ return sql.ScanSlice(rows, v)
643
+ }
backend/ent/announcement_update.go ADDED
@@ -0,0 +1,868 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "context"
7
+ "errors"
8
+ "fmt"
9
+ "time"
10
+
11
+ "entgo.io/ent/dialect/sql"
12
+ "entgo.io/ent/dialect/sql/sqlgraph"
13
+ "entgo.io/ent/schema/field"
14
+ "github.com/Wei-Shaw/sub2api/ent/announcement"
15
+ "github.com/Wei-Shaw/sub2api/ent/announcementread"
16
+ "github.com/Wei-Shaw/sub2api/ent/predicate"
17
+ "github.com/Wei-Shaw/sub2api/internal/domain"
18
+ )
19
+
20
+ // AnnouncementUpdate is the builder for updating Announcement entities.
21
+ type AnnouncementUpdate struct {
22
+ config
23
+ hooks []Hook
24
+ mutation *AnnouncementMutation
25
+ }
26
+
27
+ // Where appends a list predicates to the AnnouncementUpdate builder.
28
+ func (_u *AnnouncementUpdate) Where(ps ...predicate.Announcement) *AnnouncementUpdate {
29
+ _u.mutation.Where(ps...)
30
+ return _u
31
+ }
32
+
33
+ // SetTitle sets the "title" field.
34
+ func (_u *AnnouncementUpdate) SetTitle(v string) *AnnouncementUpdate {
35
+ _u.mutation.SetTitle(v)
36
+ return _u
37
+ }
38
+
39
+ // SetNillableTitle sets the "title" field if the given value is not nil.
40
+ func (_u *AnnouncementUpdate) SetNillableTitle(v *string) *AnnouncementUpdate {
41
+ if v != nil {
42
+ _u.SetTitle(*v)
43
+ }
44
+ return _u
45
+ }
46
+
47
+ // SetContent sets the "content" field.
48
+ func (_u *AnnouncementUpdate) SetContent(v string) *AnnouncementUpdate {
49
+ _u.mutation.SetContent(v)
50
+ return _u
51
+ }
52
+
53
+ // SetNillableContent sets the "content" field if the given value is not nil.
54
+ func (_u *AnnouncementUpdate) SetNillableContent(v *string) *AnnouncementUpdate {
55
+ if v != nil {
56
+ _u.SetContent(*v)
57
+ }
58
+ return _u
59
+ }
60
+
61
+ // SetStatus sets the "status" field.
62
+ func (_u *AnnouncementUpdate) SetStatus(v string) *AnnouncementUpdate {
63
+ _u.mutation.SetStatus(v)
64
+ return _u
65
+ }
66
+
67
+ // SetNillableStatus sets the "status" field if the given value is not nil.
68
+ func (_u *AnnouncementUpdate) SetNillableStatus(v *string) *AnnouncementUpdate {
69
+ if v != nil {
70
+ _u.SetStatus(*v)
71
+ }
72
+ return _u
73
+ }
74
+
75
+ // SetNotifyMode sets the "notify_mode" field.
76
+ func (_u *AnnouncementUpdate) SetNotifyMode(v string) *AnnouncementUpdate {
77
+ _u.mutation.SetNotifyMode(v)
78
+ return _u
79
+ }
80
+
81
+ // SetNillableNotifyMode sets the "notify_mode" field if the given value is not nil.
82
+ func (_u *AnnouncementUpdate) SetNillableNotifyMode(v *string) *AnnouncementUpdate {
83
+ if v != nil {
84
+ _u.SetNotifyMode(*v)
85
+ }
86
+ return _u
87
+ }
88
+
89
+ // SetTargeting sets the "targeting" field.
90
+ func (_u *AnnouncementUpdate) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpdate {
91
+ _u.mutation.SetTargeting(v)
92
+ return _u
93
+ }
94
+
95
+ // SetNillableTargeting sets the "targeting" field if the given value is not nil.
96
+ func (_u *AnnouncementUpdate) SetNillableTargeting(v *domain.AnnouncementTargeting) *AnnouncementUpdate {
97
+ if v != nil {
98
+ _u.SetTargeting(*v)
99
+ }
100
+ return _u
101
+ }
102
+
103
+ // ClearTargeting clears the value of the "targeting" field.
104
+ func (_u *AnnouncementUpdate) ClearTargeting() *AnnouncementUpdate {
105
+ _u.mutation.ClearTargeting()
106
+ return _u
107
+ }
108
+
109
+ // SetStartsAt sets the "starts_at" field.
110
+ func (_u *AnnouncementUpdate) SetStartsAt(v time.Time) *AnnouncementUpdate {
111
+ _u.mutation.SetStartsAt(v)
112
+ return _u
113
+ }
114
+
115
+ // SetNillableStartsAt sets the "starts_at" field if the given value is not nil.
116
+ func (_u *AnnouncementUpdate) SetNillableStartsAt(v *time.Time) *AnnouncementUpdate {
117
+ if v != nil {
118
+ _u.SetStartsAt(*v)
119
+ }
120
+ return _u
121
+ }
122
+
123
+ // ClearStartsAt clears the value of the "starts_at" field.
124
+ func (_u *AnnouncementUpdate) ClearStartsAt() *AnnouncementUpdate {
125
+ _u.mutation.ClearStartsAt()
126
+ return _u
127
+ }
128
+
129
+ // SetEndsAt sets the "ends_at" field.
130
+ func (_u *AnnouncementUpdate) SetEndsAt(v time.Time) *AnnouncementUpdate {
131
+ _u.mutation.SetEndsAt(v)
132
+ return _u
133
+ }
134
+
135
+ // SetNillableEndsAt sets the "ends_at" field if the given value is not nil.
136
+ func (_u *AnnouncementUpdate) SetNillableEndsAt(v *time.Time) *AnnouncementUpdate {
137
+ if v != nil {
138
+ _u.SetEndsAt(*v)
139
+ }
140
+ return _u
141
+ }
142
+
143
+ // ClearEndsAt clears the value of the "ends_at" field.
144
+ func (_u *AnnouncementUpdate) ClearEndsAt() *AnnouncementUpdate {
145
+ _u.mutation.ClearEndsAt()
146
+ return _u
147
+ }
148
+
149
+ // SetCreatedBy sets the "created_by" field.
150
+ func (_u *AnnouncementUpdate) SetCreatedBy(v int64) *AnnouncementUpdate {
151
+ _u.mutation.ResetCreatedBy()
152
+ _u.mutation.SetCreatedBy(v)
153
+ return _u
154
+ }
155
+
156
+ // SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
157
+ func (_u *AnnouncementUpdate) SetNillableCreatedBy(v *int64) *AnnouncementUpdate {
158
+ if v != nil {
159
+ _u.SetCreatedBy(*v)
160
+ }
161
+ return _u
162
+ }
163
+
164
+ // AddCreatedBy adds value to the "created_by" field.
165
+ func (_u *AnnouncementUpdate) AddCreatedBy(v int64) *AnnouncementUpdate {
166
+ _u.mutation.AddCreatedBy(v)
167
+ return _u
168
+ }
169
+
170
+ // ClearCreatedBy clears the value of the "created_by" field.
171
+ func (_u *AnnouncementUpdate) ClearCreatedBy() *AnnouncementUpdate {
172
+ _u.mutation.ClearCreatedBy()
173
+ return _u
174
+ }
175
+
176
+ // SetUpdatedBy sets the "updated_by" field.
177
+ func (_u *AnnouncementUpdate) SetUpdatedBy(v int64) *AnnouncementUpdate {
178
+ _u.mutation.ResetUpdatedBy()
179
+ _u.mutation.SetUpdatedBy(v)
180
+ return _u
181
+ }
182
+
183
+ // SetNillableUpdatedBy sets the "updated_by" field if the given value is not nil.
184
+ func (_u *AnnouncementUpdate) SetNillableUpdatedBy(v *int64) *AnnouncementUpdate {
185
+ if v != nil {
186
+ _u.SetUpdatedBy(*v)
187
+ }
188
+ return _u
189
+ }
190
+
191
+ // AddUpdatedBy adds value to the "updated_by" field.
192
+ func (_u *AnnouncementUpdate) AddUpdatedBy(v int64) *AnnouncementUpdate {
193
+ _u.mutation.AddUpdatedBy(v)
194
+ return _u
195
+ }
196
+
197
+ // ClearUpdatedBy clears the value of the "updated_by" field.
198
+ func (_u *AnnouncementUpdate) ClearUpdatedBy() *AnnouncementUpdate {
199
+ _u.mutation.ClearUpdatedBy()
200
+ return _u
201
+ }
202
+
203
+ // SetUpdatedAt sets the "updated_at" field.
204
+ func (_u *AnnouncementUpdate) SetUpdatedAt(v time.Time) *AnnouncementUpdate {
205
+ _u.mutation.SetUpdatedAt(v)
206
+ return _u
207
+ }
208
+
209
+ // AddReadIDs adds the "reads" edge to the AnnouncementRead entity by IDs.
210
+ func (_u *AnnouncementUpdate) AddReadIDs(ids ...int64) *AnnouncementUpdate {
211
+ _u.mutation.AddReadIDs(ids...)
212
+ return _u
213
+ }
214
+
215
+ // AddReads adds the "reads" edges to the AnnouncementRead entity.
216
+ func (_u *AnnouncementUpdate) AddReads(v ...*AnnouncementRead) *AnnouncementUpdate {
217
+ ids := make([]int64, len(v))
218
+ for i := range v {
219
+ ids[i] = v[i].ID
220
+ }
221
+ return _u.AddReadIDs(ids...)
222
+ }
223
+
224
+ // Mutation returns the AnnouncementMutation object of the builder.
225
+ func (_u *AnnouncementUpdate) Mutation() *AnnouncementMutation {
226
+ return _u.mutation
227
+ }
228
+
229
+ // ClearReads clears all "reads" edges to the AnnouncementRead entity.
230
+ func (_u *AnnouncementUpdate) ClearReads() *AnnouncementUpdate {
231
+ _u.mutation.ClearReads()
232
+ return _u
233
+ }
234
+
235
+ // RemoveReadIDs removes the "reads" edge to AnnouncementRead entities by IDs.
236
+ func (_u *AnnouncementUpdate) RemoveReadIDs(ids ...int64) *AnnouncementUpdate {
237
+ _u.mutation.RemoveReadIDs(ids...)
238
+ return _u
239
+ }
240
+
241
+ // RemoveReads removes "reads" edges to AnnouncementRead entities.
242
+ func (_u *AnnouncementUpdate) RemoveReads(v ...*AnnouncementRead) *AnnouncementUpdate {
243
+ ids := make([]int64, len(v))
244
+ for i := range v {
245
+ ids[i] = v[i].ID
246
+ }
247
+ return _u.RemoveReadIDs(ids...)
248
+ }
249
+
250
+ // Save executes the query and returns the number of nodes affected by the update operation.
251
+ func (_u *AnnouncementUpdate) Save(ctx context.Context) (int, error) {
252
+ _u.defaults()
253
+ return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
254
+ }
255
+
256
+ // SaveX is like Save, but panics if an error occurs.
257
+ func (_u *AnnouncementUpdate) SaveX(ctx context.Context) int {
258
+ affected, err := _u.Save(ctx)
259
+ if err != nil {
260
+ panic(err)
261
+ }
262
+ return affected
263
+ }
264
+
265
+ // Exec executes the query.
266
+ func (_u *AnnouncementUpdate) Exec(ctx context.Context) error {
267
+ _, err := _u.Save(ctx)
268
+ return err
269
+ }
270
+
271
+ // ExecX is like Exec, but panics if an error occurs.
272
+ func (_u *AnnouncementUpdate) ExecX(ctx context.Context) {
273
+ if err := _u.Exec(ctx); err != nil {
274
+ panic(err)
275
+ }
276
+ }
277
+
278
+ // defaults sets the default values of the builder before save.
279
+ func (_u *AnnouncementUpdate) defaults() {
280
+ if _, ok := _u.mutation.UpdatedAt(); !ok {
281
+ v := announcement.UpdateDefaultUpdatedAt()
282
+ _u.mutation.SetUpdatedAt(v)
283
+ }
284
+ }
285
+
286
+ // check runs all checks and user-defined validators on the builder.
287
+ func (_u *AnnouncementUpdate) check() error {
288
+ if v, ok := _u.mutation.Title(); ok {
289
+ if err := announcement.TitleValidator(v); err != nil {
290
+ return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Announcement.title": %w`, err)}
291
+ }
292
+ }
293
+ if v, ok := _u.mutation.Content(); ok {
294
+ if err := announcement.ContentValidator(v); err != nil {
295
+ return &ValidationError{Name: "content", err: fmt.Errorf(`ent: validator failed for field "Announcement.content": %w`, err)}
296
+ }
297
+ }
298
+ if v, ok := _u.mutation.Status(); ok {
299
+ if err := announcement.StatusValidator(v); err != nil {
300
+ return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Announcement.status": %w`, err)}
301
+ }
302
+ }
303
+ if v, ok := _u.mutation.NotifyMode(); ok {
304
+ if err := announcement.NotifyModeValidator(v); err != nil {
305
+ return &ValidationError{Name: "notify_mode", err: fmt.Errorf(`ent: validator failed for field "Announcement.notify_mode": %w`, err)}
306
+ }
307
+ }
308
+ return nil
309
+ }
310
+
311
+ func (_u *AnnouncementUpdate) sqlSave(ctx context.Context) (_node int, err error) {
312
+ if err := _u.check(); err != nil {
313
+ return _node, err
314
+ }
315
+ _spec := sqlgraph.NewUpdateSpec(announcement.Table, announcement.Columns, sqlgraph.NewFieldSpec(announcement.FieldID, field.TypeInt64))
316
+ if ps := _u.mutation.predicates; len(ps) > 0 {
317
+ _spec.Predicate = func(selector *sql.Selector) {
318
+ for i := range ps {
319
+ ps[i](selector)
320
+ }
321
+ }
322
+ }
323
+ if value, ok := _u.mutation.Title(); ok {
324
+ _spec.SetField(announcement.FieldTitle, field.TypeString, value)
325
+ }
326
+ if value, ok := _u.mutation.Content(); ok {
327
+ _spec.SetField(announcement.FieldContent, field.TypeString, value)
328
+ }
329
+ if value, ok := _u.mutation.Status(); ok {
330
+ _spec.SetField(announcement.FieldStatus, field.TypeString, value)
331
+ }
332
+ if value, ok := _u.mutation.NotifyMode(); ok {
333
+ _spec.SetField(announcement.FieldNotifyMode, field.TypeString, value)
334
+ }
335
+ if value, ok := _u.mutation.Targeting(); ok {
336
+ _spec.SetField(announcement.FieldTargeting, field.TypeJSON, value)
337
+ }
338
+ if _u.mutation.TargetingCleared() {
339
+ _spec.ClearField(announcement.FieldTargeting, field.TypeJSON)
340
+ }
341
+ if value, ok := _u.mutation.StartsAt(); ok {
342
+ _spec.SetField(announcement.FieldStartsAt, field.TypeTime, value)
343
+ }
344
+ if _u.mutation.StartsAtCleared() {
345
+ _spec.ClearField(announcement.FieldStartsAt, field.TypeTime)
346
+ }
347
+ if value, ok := _u.mutation.EndsAt(); ok {
348
+ _spec.SetField(announcement.FieldEndsAt, field.TypeTime, value)
349
+ }
350
+ if _u.mutation.EndsAtCleared() {
351
+ _spec.ClearField(announcement.FieldEndsAt, field.TypeTime)
352
+ }
353
+ if value, ok := _u.mutation.CreatedBy(); ok {
354
+ _spec.SetField(announcement.FieldCreatedBy, field.TypeInt64, value)
355
+ }
356
+ if value, ok := _u.mutation.AddedCreatedBy(); ok {
357
+ _spec.AddField(announcement.FieldCreatedBy, field.TypeInt64, value)
358
+ }
359
+ if _u.mutation.CreatedByCleared() {
360
+ _spec.ClearField(announcement.FieldCreatedBy, field.TypeInt64)
361
+ }
362
+ if value, ok := _u.mutation.UpdatedBy(); ok {
363
+ _spec.SetField(announcement.FieldUpdatedBy, field.TypeInt64, value)
364
+ }
365
+ if value, ok := _u.mutation.AddedUpdatedBy(); ok {
366
+ _spec.AddField(announcement.FieldUpdatedBy, field.TypeInt64, value)
367
+ }
368
+ if _u.mutation.UpdatedByCleared() {
369
+ _spec.ClearField(announcement.FieldUpdatedBy, field.TypeInt64)
370
+ }
371
+ if value, ok := _u.mutation.UpdatedAt(); ok {
372
+ _spec.SetField(announcement.FieldUpdatedAt, field.TypeTime, value)
373
+ }
374
+ if _u.mutation.ReadsCleared() {
375
+ edge := &sqlgraph.EdgeSpec{
376
+ Rel: sqlgraph.O2M,
377
+ Inverse: false,
378
+ Table: announcement.ReadsTable,
379
+ Columns: []string{announcement.ReadsColumn},
380
+ Bidi: false,
381
+ Target: &sqlgraph.EdgeTarget{
382
+ IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
383
+ },
384
+ }
385
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
386
+ }
387
+ if nodes := _u.mutation.RemovedReadsIDs(); len(nodes) > 0 && !_u.mutation.ReadsCleared() {
388
+ edge := &sqlgraph.EdgeSpec{
389
+ Rel: sqlgraph.O2M,
390
+ Inverse: false,
391
+ Table: announcement.ReadsTable,
392
+ Columns: []string{announcement.ReadsColumn},
393
+ Bidi: false,
394
+ Target: &sqlgraph.EdgeTarget{
395
+ IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
396
+ },
397
+ }
398
+ for _, k := range nodes {
399
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
400
+ }
401
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
402
+ }
403
+ if nodes := _u.mutation.ReadsIDs(); len(nodes) > 0 {
404
+ edge := &sqlgraph.EdgeSpec{
405
+ Rel: sqlgraph.O2M,
406
+ Inverse: false,
407
+ Table: announcement.ReadsTable,
408
+ Columns: []string{announcement.ReadsColumn},
409
+ Bidi: false,
410
+ Target: &sqlgraph.EdgeTarget{
411
+ IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
412
+ },
413
+ }
414
+ for _, k := range nodes {
415
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
416
+ }
417
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
418
+ }
419
+ if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
420
+ if _, ok := err.(*sqlgraph.NotFoundError); ok {
421
+ err = &NotFoundError{announcement.Label}
422
+ } else if sqlgraph.IsConstraintError(err) {
423
+ err = &ConstraintError{msg: err.Error(), wrap: err}
424
+ }
425
+ return 0, err
426
+ }
427
+ _u.mutation.done = true
428
+ return _node, nil
429
+ }
430
+
431
+ // AnnouncementUpdateOne is the builder for updating a single Announcement entity.
432
+ type AnnouncementUpdateOne struct {
433
+ config
434
+ fields []string
435
+ hooks []Hook
436
+ mutation *AnnouncementMutation
437
+ }
438
+
439
+ // SetTitle sets the "title" field.
440
+ func (_u *AnnouncementUpdateOne) SetTitle(v string) *AnnouncementUpdateOne {
441
+ _u.mutation.SetTitle(v)
442
+ return _u
443
+ }
444
+
445
+ // SetNillableTitle sets the "title" field if the given value is not nil.
446
+ func (_u *AnnouncementUpdateOne) SetNillableTitle(v *string) *AnnouncementUpdateOne {
447
+ if v != nil {
448
+ _u.SetTitle(*v)
449
+ }
450
+ return _u
451
+ }
452
+
453
+ // SetContent sets the "content" field.
454
+ func (_u *AnnouncementUpdateOne) SetContent(v string) *AnnouncementUpdateOne {
455
+ _u.mutation.SetContent(v)
456
+ return _u
457
+ }
458
+
459
+ // SetNillableContent sets the "content" field if the given value is not nil.
460
+ func (_u *AnnouncementUpdateOne) SetNillableContent(v *string) *AnnouncementUpdateOne {
461
+ if v != nil {
462
+ _u.SetContent(*v)
463
+ }
464
+ return _u
465
+ }
466
+
467
+ // SetStatus sets the "status" field.
468
+ func (_u *AnnouncementUpdateOne) SetStatus(v string) *AnnouncementUpdateOne {
469
+ _u.mutation.SetStatus(v)
470
+ return _u
471
+ }
472
+
473
+ // SetNillableStatus sets the "status" field if the given value is not nil.
474
+ func (_u *AnnouncementUpdateOne) SetNillableStatus(v *string) *AnnouncementUpdateOne {
475
+ if v != nil {
476
+ _u.SetStatus(*v)
477
+ }
478
+ return _u
479
+ }
480
+
481
+ // SetNotifyMode sets the "notify_mode" field.
482
+ func (_u *AnnouncementUpdateOne) SetNotifyMode(v string) *AnnouncementUpdateOne {
483
+ _u.mutation.SetNotifyMode(v)
484
+ return _u
485
+ }
486
+
487
+ // SetNillableNotifyMode sets the "notify_mode" field if the given value is not nil.
488
+ func (_u *AnnouncementUpdateOne) SetNillableNotifyMode(v *string) *AnnouncementUpdateOne {
489
+ if v != nil {
490
+ _u.SetNotifyMode(*v)
491
+ }
492
+ return _u
493
+ }
494
+
495
+ // SetTargeting sets the "targeting" field.
496
+ func (_u *AnnouncementUpdateOne) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpdateOne {
497
+ _u.mutation.SetTargeting(v)
498
+ return _u
499
+ }
500
+
501
+ // SetNillableTargeting sets the "targeting" field if the given value is not nil.
502
+ func (_u *AnnouncementUpdateOne) SetNillableTargeting(v *domain.AnnouncementTargeting) *AnnouncementUpdateOne {
503
+ if v != nil {
504
+ _u.SetTargeting(*v)
505
+ }
506
+ return _u
507
+ }
508
+
509
+ // ClearTargeting clears the value of the "targeting" field.
510
+ func (_u *AnnouncementUpdateOne) ClearTargeting() *AnnouncementUpdateOne {
511
+ _u.mutation.ClearTargeting()
512
+ return _u
513
+ }
514
+
515
+ // SetStartsAt sets the "starts_at" field.
516
+ func (_u *AnnouncementUpdateOne) SetStartsAt(v time.Time) *AnnouncementUpdateOne {
517
+ _u.mutation.SetStartsAt(v)
518
+ return _u
519
+ }
520
+
521
+ // SetNillableStartsAt sets the "starts_at" field if the given value is not nil.
522
+ func (_u *AnnouncementUpdateOne) SetNillableStartsAt(v *time.Time) *AnnouncementUpdateOne {
523
+ if v != nil {
524
+ _u.SetStartsAt(*v)
525
+ }
526
+ return _u
527
+ }
528
+
529
+ // ClearStartsAt clears the value of the "starts_at" field.
530
+ func (_u *AnnouncementUpdateOne) ClearStartsAt() *AnnouncementUpdateOne {
531
+ _u.mutation.ClearStartsAt()
532
+ return _u
533
+ }
534
+
535
+ // SetEndsAt sets the "ends_at" field.
536
+ func (_u *AnnouncementUpdateOne) SetEndsAt(v time.Time) *AnnouncementUpdateOne {
537
+ _u.mutation.SetEndsAt(v)
538
+ return _u
539
+ }
540
+
541
+ // SetNillableEndsAt sets the "ends_at" field if the given value is not nil.
542
+ func (_u *AnnouncementUpdateOne) SetNillableEndsAt(v *time.Time) *AnnouncementUpdateOne {
543
+ if v != nil {
544
+ _u.SetEndsAt(*v)
545
+ }
546
+ return _u
547
+ }
548
+
549
+ // ClearEndsAt clears the value of the "ends_at" field.
550
+ func (_u *AnnouncementUpdateOne) ClearEndsAt() *AnnouncementUpdateOne {
551
+ _u.mutation.ClearEndsAt()
552
+ return _u
553
+ }
554
+
555
+ // SetCreatedBy sets the "created_by" field.
556
+ func (_u *AnnouncementUpdateOne) SetCreatedBy(v int64) *AnnouncementUpdateOne {
557
+ _u.mutation.ResetCreatedBy()
558
+ _u.mutation.SetCreatedBy(v)
559
+ return _u
560
+ }
561
+
562
+ // SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
563
+ func (_u *AnnouncementUpdateOne) SetNillableCreatedBy(v *int64) *AnnouncementUpdateOne {
564
+ if v != nil {
565
+ _u.SetCreatedBy(*v)
566
+ }
567
+ return _u
568
+ }
569
+
570
+ // AddCreatedBy adds value to the "created_by" field.
571
+ func (_u *AnnouncementUpdateOne) AddCreatedBy(v int64) *AnnouncementUpdateOne {
572
+ _u.mutation.AddCreatedBy(v)
573
+ return _u
574
+ }
575
+
576
+ // ClearCreatedBy clears the value of the "created_by" field.
577
+ func (_u *AnnouncementUpdateOne) ClearCreatedBy() *AnnouncementUpdateOne {
578
+ _u.mutation.ClearCreatedBy()
579
+ return _u
580
+ }
581
+
582
+ // SetUpdatedBy sets the "updated_by" field.
583
+ func (_u *AnnouncementUpdateOne) SetUpdatedBy(v int64) *AnnouncementUpdateOne {
584
+ _u.mutation.ResetUpdatedBy()
585
+ _u.mutation.SetUpdatedBy(v)
586
+ return _u
587
+ }
588
+
589
+ // SetNillableUpdatedBy sets the "updated_by" field if the given value is not nil.
590
+ func (_u *AnnouncementUpdateOne) SetNillableUpdatedBy(v *int64) *AnnouncementUpdateOne {
591
+ if v != nil {
592
+ _u.SetUpdatedBy(*v)
593
+ }
594
+ return _u
595
+ }
596
+
597
+ // AddUpdatedBy adds value to the "updated_by" field.
598
+ func (_u *AnnouncementUpdateOne) AddUpdatedBy(v int64) *AnnouncementUpdateOne {
599
+ _u.mutation.AddUpdatedBy(v)
600
+ return _u
601
+ }
602
+
603
+ // ClearUpdatedBy clears the value of the "updated_by" field.
604
+ func (_u *AnnouncementUpdateOne) ClearUpdatedBy() *AnnouncementUpdateOne {
605
+ _u.mutation.ClearUpdatedBy()
606
+ return _u
607
+ }
608
+
609
+ // SetUpdatedAt sets the "updated_at" field.
610
+ func (_u *AnnouncementUpdateOne) SetUpdatedAt(v time.Time) *AnnouncementUpdateOne {
611
+ _u.mutation.SetUpdatedAt(v)
612
+ return _u
613
+ }
614
+
615
+ // AddReadIDs adds the "reads" edge to the AnnouncementRead entity by IDs.
616
+ func (_u *AnnouncementUpdateOne) AddReadIDs(ids ...int64) *AnnouncementUpdateOne {
617
+ _u.mutation.AddReadIDs(ids...)
618
+ return _u
619
+ }
620
+
621
+ // AddReads adds the "reads" edges to the AnnouncementRead entity.
622
+ func (_u *AnnouncementUpdateOne) AddReads(v ...*AnnouncementRead) *AnnouncementUpdateOne {
623
+ ids := make([]int64, len(v))
624
+ for i := range v {
625
+ ids[i] = v[i].ID
626
+ }
627
+ return _u.AddReadIDs(ids...)
628
+ }
629
+
630
+ // Mutation returns the AnnouncementMutation object of the builder.
631
+ func (_u *AnnouncementUpdateOne) Mutation() *AnnouncementMutation {
632
+ return _u.mutation
633
+ }
634
+
635
+ // ClearReads clears all "reads" edges to the AnnouncementRead entity.
636
+ func (_u *AnnouncementUpdateOne) ClearReads() *AnnouncementUpdateOne {
637
+ _u.mutation.ClearReads()
638
+ return _u
639
+ }
640
+
641
+ // RemoveReadIDs removes the "reads" edge to AnnouncementRead entities by IDs.
642
+ func (_u *AnnouncementUpdateOne) RemoveReadIDs(ids ...int64) *AnnouncementUpdateOne {
643
+ _u.mutation.RemoveReadIDs(ids...)
644
+ return _u
645
+ }
646
+
647
+ // RemoveReads removes "reads" edges to AnnouncementRead entities.
648
+ func (_u *AnnouncementUpdateOne) RemoveReads(v ...*AnnouncementRead) *AnnouncementUpdateOne {
649
+ ids := make([]int64, len(v))
650
+ for i := range v {
651
+ ids[i] = v[i].ID
652
+ }
653
+ return _u.RemoveReadIDs(ids...)
654
+ }
655
+
656
+ // Where appends a list predicates to the AnnouncementUpdate builder.
657
+ func (_u *AnnouncementUpdateOne) Where(ps ...predicate.Announcement) *AnnouncementUpdateOne {
658
+ _u.mutation.Where(ps...)
659
+ return _u
660
+ }
661
+
662
+ // Select allows selecting one or more fields (columns) of the returned entity.
663
+ // The default is selecting all fields defined in the entity schema.
664
+ func (_u *AnnouncementUpdateOne) Select(field string, fields ...string) *AnnouncementUpdateOne {
665
+ _u.fields = append([]string{field}, fields...)
666
+ return _u
667
+ }
668
+
669
+ // Save executes the query and returns the updated Announcement entity.
670
+ func (_u *AnnouncementUpdateOne) Save(ctx context.Context) (*Announcement, error) {
671
+ _u.defaults()
672
+ return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
673
+ }
674
+
675
+ // SaveX is like Save, but panics if an error occurs.
676
+ func (_u *AnnouncementUpdateOne) SaveX(ctx context.Context) *Announcement {
677
+ node, err := _u.Save(ctx)
678
+ if err != nil {
679
+ panic(err)
680
+ }
681
+ return node
682
+ }
683
+
684
+ // Exec executes the query on the entity.
685
+ func (_u *AnnouncementUpdateOne) Exec(ctx context.Context) error {
686
+ _, err := _u.Save(ctx)
687
+ return err
688
+ }
689
+
690
+ // ExecX is like Exec, but panics if an error occurs.
691
+ func (_u *AnnouncementUpdateOne) ExecX(ctx context.Context) {
692
+ if err := _u.Exec(ctx); err != nil {
693
+ panic(err)
694
+ }
695
+ }
696
+
697
+ // defaults sets the default values of the builder before save.
698
+ func (_u *AnnouncementUpdateOne) defaults() {
699
+ if _, ok := _u.mutation.UpdatedAt(); !ok {
700
+ v := announcement.UpdateDefaultUpdatedAt()
701
+ _u.mutation.SetUpdatedAt(v)
702
+ }
703
+ }
704
+
705
+ // check runs all checks and user-defined validators on the builder.
706
+ func (_u *AnnouncementUpdateOne) check() error {
707
+ if v, ok := _u.mutation.Title(); ok {
708
+ if err := announcement.TitleValidator(v); err != nil {
709
+ return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Announcement.title": %w`, err)}
710
+ }
711
+ }
712
+ if v, ok := _u.mutation.Content(); ok {
713
+ if err := announcement.ContentValidator(v); err != nil {
714
+ return &ValidationError{Name: "content", err: fmt.Errorf(`ent: validator failed for field "Announcement.content": %w`, err)}
715
+ }
716
+ }
717
+ if v, ok := _u.mutation.Status(); ok {
718
+ if err := announcement.StatusValidator(v); err != nil {
719
+ return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Announcement.status": %w`, err)}
720
+ }
721
+ }
722
+ if v, ok := _u.mutation.NotifyMode(); ok {
723
+ if err := announcement.NotifyModeValidator(v); err != nil {
724
+ return &ValidationError{Name: "notify_mode", err: fmt.Errorf(`ent: validator failed for field "Announcement.notify_mode": %w`, err)}
725
+ }
726
+ }
727
+ return nil
728
+ }
729
+
730
+ func (_u *AnnouncementUpdateOne) sqlSave(ctx context.Context) (_node *Announcement, err error) {
731
+ if err := _u.check(); err != nil {
732
+ return _node, err
733
+ }
734
+ _spec := sqlgraph.NewUpdateSpec(announcement.Table, announcement.Columns, sqlgraph.NewFieldSpec(announcement.FieldID, field.TypeInt64))
735
+ id, ok := _u.mutation.ID()
736
+ if !ok {
737
+ return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Announcement.id" for update`)}
738
+ }
739
+ _spec.Node.ID.Value = id
740
+ if fields := _u.fields; len(fields) > 0 {
741
+ _spec.Node.Columns = make([]string, 0, len(fields))
742
+ _spec.Node.Columns = append(_spec.Node.Columns, announcement.FieldID)
743
+ for _, f := range fields {
744
+ if !announcement.ValidColumn(f) {
745
+ return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
746
+ }
747
+ if f != announcement.FieldID {
748
+ _spec.Node.Columns = append(_spec.Node.Columns, f)
749
+ }
750
+ }
751
+ }
752
+ if ps := _u.mutation.predicates; len(ps) > 0 {
753
+ _spec.Predicate = func(selector *sql.Selector) {
754
+ for i := range ps {
755
+ ps[i](selector)
756
+ }
757
+ }
758
+ }
759
+ if value, ok := _u.mutation.Title(); ok {
760
+ _spec.SetField(announcement.FieldTitle, field.TypeString, value)
761
+ }
762
+ if value, ok := _u.mutation.Content(); ok {
763
+ _spec.SetField(announcement.FieldContent, field.TypeString, value)
764
+ }
765
+ if value, ok := _u.mutation.Status(); ok {
766
+ _spec.SetField(announcement.FieldStatus, field.TypeString, value)
767
+ }
768
+ if value, ok := _u.mutation.NotifyMode(); ok {
769
+ _spec.SetField(announcement.FieldNotifyMode, field.TypeString, value)
770
+ }
771
+ if value, ok := _u.mutation.Targeting(); ok {
772
+ _spec.SetField(announcement.FieldTargeting, field.TypeJSON, value)
773
+ }
774
+ if _u.mutation.TargetingCleared() {
775
+ _spec.ClearField(announcement.FieldTargeting, field.TypeJSON)
776
+ }
777
+ if value, ok := _u.mutation.StartsAt(); ok {
778
+ _spec.SetField(announcement.FieldStartsAt, field.TypeTime, value)
779
+ }
780
+ if _u.mutation.StartsAtCleared() {
781
+ _spec.ClearField(announcement.FieldStartsAt, field.TypeTime)
782
+ }
783
+ if value, ok := _u.mutation.EndsAt(); ok {
784
+ _spec.SetField(announcement.FieldEndsAt, field.TypeTime, value)
785
+ }
786
+ if _u.mutation.EndsAtCleared() {
787
+ _spec.ClearField(announcement.FieldEndsAt, field.TypeTime)
788
+ }
789
+ if value, ok := _u.mutation.CreatedBy(); ok {
790
+ _spec.SetField(announcement.FieldCreatedBy, field.TypeInt64, value)
791
+ }
792
+ if value, ok := _u.mutation.AddedCreatedBy(); ok {
793
+ _spec.AddField(announcement.FieldCreatedBy, field.TypeInt64, value)
794
+ }
795
+ if _u.mutation.CreatedByCleared() {
796
+ _spec.ClearField(announcement.FieldCreatedBy, field.TypeInt64)
797
+ }
798
+ if value, ok := _u.mutation.UpdatedBy(); ok {
799
+ _spec.SetField(announcement.FieldUpdatedBy, field.TypeInt64, value)
800
+ }
801
+ if value, ok := _u.mutation.AddedUpdatedBy(); ok {
802
+ _spec.AddField(announcement.FieldUpdatedBy, field.TypeInt64, value)
803
+ }
804
+ if _u.mutation.UpdatedByCleared() {
805
+ _spec.ClearField(announcement.FieldUpdatedBy, field.TypeInt64)
806
+ }
807
+ if value, ok := _u.mutation.UpdatedAt(); ok {
808
+ _spec.SetField(announcement.FieldUpdatedAt, field.TypeTime, value)
809
+ }
810
+ if _u.mutation.ReadsCleared() {
811
+ edge := &sqlgraph.EdgeSpec{
812
+ Rel: sqlgraph.O2M,
813
+ Inverse: false,
814
+ Table: announcement.ReadsTable,
815
+ Columns: []string{announcement.ReadsColumn},
816
+ Bidi: false,
817
+ Target: &sqlgraph.EdgeTarget{
818
+ IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
819
+ },
820
+ }
821
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
822
+ }
823
+ if nodes := _u.mutation.RemovedReadsIDs(); len(nodes) > 0 && !_u.mutation.ReadsCleared() {
824
+ edge := &sqlgraph.EdgeSpec{
825
+ Rel: sqlgraph.O2M,
826
+ Inverse: false,
827
+ Table: announcement.ReadsTable,
828
+ Columns: []string{announcement.ReadsColumn},
829
+ Bidi: false,
830
+ Target: &sqlgraph.EdgeTarget{
831
+ IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
832
+ },
833
+ }
834
+ for _, k := range nodes {
835
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
836
+ }
837
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
838
+ }
839
+ if nodes := _u.mutation.ReadsIDs(); len(nodes) > 0 {
840
+ edge := &sqlgraph.EdgeSpec{
841
+ Rel: sqlgraph.O2M,
842
+ Inverse: false,
843
+ Table: announcement.ReadsTable,
844
+ Columns: []string{announcement.ReadsColumn},
845
+ Bidi: false,
846
+ Target: &sqlgraph.EdgeTarget{
847
+ IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
848
+ },
849
+ }
850
+ for _, k := range nodes {
851
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
852
+ }
853
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
854
+ }
855
+ _node = &Announcement{config: _u.config}
856
+ _spec.Assign = _node.assignValues
857
+ _spec.ScanValues = _node.scanValues
858
+ if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
859
+ if _, ok := err.(*sqlgraph.NotFoundError); ok {
860
+ err = &NotFoundError{announcement.Label}
861
+ } else if sqlgraph.IsConstraintError(err) {
862
+ err = &ConstraintError{msg: err.Error(), wrap: err}
863
+ }
864
+ return nil, err
865
+ }
866
+ _u.mutation.done = true
867
+ return _node, nil
868
+ }
backend/ent/announcementread.go ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package ent
4
+
5
+ import (
6
+ "fmt"
7
+ "strings"
8
+ "time"
9
+
10
+ "entgo.io/ent"
11
+ "entgo.io/ent/dialect/sql"
12
+ "github.com/Wei-Shaw/sub2api/ent/announcement"
13
+ "github.com/Wei-Shaw/sub2api/ent/announcementread"
14
+ "github.com/Wei-Shaw/sub2api/ent/user"
15
+ )
16
+
17
+ // AnnouncementRead is the model entity for the AnnouncementRead schema.
18
+ type AnnouncementRead struct {
19
+ config `json:"-"`
20
+ // ID of the ent.
21
+ ID int64 `json:"id,omitempty"`
22
+ // AnnouncementID holds the value of the "announcement_id" field.
23
+ AnnouncementID int64 `json:"announcement_id,omitempty"`
24
+ // UserID holds the value of the "user_id" field.
25
+ UserID int64 `json:"user_id,omitempty"`
26
+ // 用户首次已读时间
27
+ ReadAt time.Time `json:"read_at,omitempty"`
28
+ // CreatedAt holds the value of the "created_at" field.
29
+ CreatedAt time.Time `json:"created_at,omitempty"`
30
+ // Edges holds the relations/edges for other nodes in the graph.
31
+ // The values are being populated by the AnnouncementReadQuery when eager-loading is set.
32
+ Edges AnnouncementReadEdges `json:"edges"`
33
+ selectValues sql.SelectValues
34
+ }
35
+
36
+ // AnnouncementReadEdges holds the relations/edges for other nodes in the graph.
37
+ type AnnouncementReadEdges struct {
38
+ // Announcement holds the value of the announcement edge.
39
+ Announcement *Announcement `json:"announcement,omitempty"`
40
+ // User holds the value of the user edge.
41
+ User *User `json:"user,omitempty"`
42
+ // loadedTypes holds the information for reporting if a
43
+ // type was loaded (or requested) in eager-loading or not.
44
+ loadedTypes [2]bool
45
+ }
46
+
47
+ // AnnouncementOrErr returns the Announcement value or an error if the edge
48
+ // was not loaded in eager-loading, or loaded but was not found.
49
+ func (e AnnouncementReadEdges) AnnouncementOrErr() (*Announcement, error) {
50
+ if e.Announcement != nil {
51
+ return e.Announcement, nil
52
+ } else if e.loadedTypes[0] {
53
+ return nil, &NotFoundError{label: announcement.Label}
54
+ }
55
+ return nil, &NotLoadedError{edge: "announcement"}
56
+ }
57
+
58
+ // UserOrErr returns the User value or an error if the edge
59
+ // was not loaded in eager-loading, or loaded but was not found.
60
+ func (e AnnouncementReadEdges) UserOrErr() (*User, error) {
61
+ if e.User != nil {
62
+ return e.User, nil
63
+ } else if e.loadedTypes[1] {
64
+ return nil, &NotFoundError{label: user.Label}
65
+ }
66
+ return nil, &NotLoadedError{edge: "user"}
67
+ }
68
+
69
+ // scanValues returns the types for scanning values from sql.Rows.
70
+ func (*AnnouncementRead) scanValues(columns []string) ([]any, error) {
71
+ values := make([]any, len(columns))
72
+ for i := range columns {
73
+ switch columns[i] {
74
+ case announcementread.FieldID, announcementread.FieldAnnouncementID, announcementread.FieldUserID:
75
+ values[i] = new(sql.NullInt64)
76
+ case announcementread.FieldReadAt, announcementread.FieldCreatedAt:
77
+ values[i] = new(sql.NullTime)
78
+ default:
79
+ values[i] = new(sql.UnknownType)
80
+ }
81
+ }
82
+ return values, nil
83
+ }
84
+
85
+ // assignValues assigns the values that were returned from sql.Rows (after scanning)
86
+ // to the AnnouncementRead fields.
87
+ func (_m *AnnouncementRead) assignValues(columns []string, values []any) error {
88
+ if m, n := len(values), len(columns); m < n {
89
+ return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
90
+ }
91
+ for i := range columns {
92
+ switch columns[i] {
93
+ case announcementread.FieldID:
94
+ value, ok := values[i].(*sql.NullInt64)
95
+ if !ok {
96
+ return fmt.Errorf("unexpected type %T for field id", value)
97
+ }
98
+ _m.ID = int64(value.Int64)
99
+ case announcementread.FieldAnnouncementID:
100
+ if value, ok := values[i].(*sql.NullInt64); !ok {
101
+ return fmt.Errorf("unexpected type %T for field announcement_id", values[i])
102
+ } else if value.Valid {
103
+ _m.AnnouncementID = value.Int64
104
+ }
105
+ case announcementread.FieldUserID:
106
+ if value, ok := values[i].(*sql.NullInt64); !ok {
107
+ return fmt.Errorf("unexpected type %T for field user_id", values[i])
108
+ } else if value.Valid {
109
+ _m.UserID = value.Int64
110
+ }
111
+ case announcementread.FieldReadAt:
112
+ if value, ok := values[i].(*sql.NullTime); !ok {
113
+ return fmt.Errorf("unexpected type %T for field read_at", values[i])
114
+ } else if value.Valid {
115
+ _m.ReadAt = value.Time
116
+ }
117
+ case announcementread.FieldCreatedAt:
118
+ if value, ok := values[i].(*sql.NullTime); !ok {
119
+ return fmt.Errorf("unexpected type %T for field created_at", values[i])
120
+ } else if value.Valid {
121
+ _m.CreatedAt = value.Time
122
+ }
123
+ default:
124
+ _m.selectValues.Set(columns[i], values[i])
125
+ }
126
+ }
127
+ return nil
128
+ }
129
+
130
+ // Value returns the ent.Value that was dynamically selected and assigned to the AnnouncementRead.
131
+ // This includes values selected through modifiers, order, etc.
132
+ func (_m *AnnouncementRead) Value(name string) (ent.Value, error) {
133
+ return _m.selectValues.Get(name)
134
+ }
135
+
136
+ // QueryAnnouncement queries the "announcement" edge of the AnnouncementRead entity.
137
+ func (_m *AnnouncementRead) QueryAnnouncement() *AnnouncementQuery {
138
+ return NewAnnouncementReadClient(_m.config).QueryAnnouncement(_m)
139
+ }
140
+
141
+ // QueryUser queries the "user" edge of the AnnouncementRead entity.
142
+ func (_m *AnnouncementRead) QueryUser() *UserQuery {
143
+ return NewAnnouncementReadClient(_m.config).QueryUser(_m)
144
+ }
145
+
146
+ // Update returns a builder for updating this AnnouncementRead.
147
+ // Note that you need to call AnnouncementRead.Unwrap() before calling this method if this AnnouncementRead
148
+ // was returned from a transaction, and the transaction was committed or rolled back.
149
+ func (_m *AnnouncementRead) Update() *AnnouncementReadUpdateOne {
150
+ return NewAnnouncementReadClient(_m.config).UpdateOne(_m)
151
+ }
152
+
153
+ // Unwrap unwraps the AnnouncementRead entity that was returned from a transaction after it was closed,
154
+ // so that all future queries will be executed through the driver which created the transaction.
155
+ func (_m *AnnouncementRead) Unwrap() *AnnouncementRead {
156
+ _tx, ok := _m.config.driver.(*txDriver)
157
+ if !ok {
158
+ panic("ent: AnnouncementRead is not a transactional entity")
159
+ }
160
+ _m.config.driver = _tx.drv
161
+ return _m
162
+ }
163
+
164
+ // String implements the fmt.Stringer.
165
+ func (_m *AnnouncementRead) String() string {
166
+ var builder strings.Builder
167
+ builder.WriteString("AnnouncementRead(")
168
+ builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
169
+ builder.WriteString("announcement_id=")
170
+ builder.WriteString(fmt.Sprintf("%v", _m.AnnouncementID))
171
+ builder.WriteString(", ")
172
+ builder.WriteString("user_id=")
173
+ builder.WriteString(fmt.Sprintf("%v", _m.UserID))
174
+ builder.WriteString(", ")
175
+ builder.WriteString("read_at=")
176
+ builder.WriteString(_m.ReadAt.Format(time.ANSIC))
177
+ builder.WriteString(", ")
178
+ builder.WriteString("created_at=")
179
+ builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
180
+ builder.WriteByte(')')
181
+ return builder.String()
182
+ }
183
+
184
+ // AnnouncementReads is a parsable slice of AnnouncementRead.
185
+ type AnnouncementReads []*AnnouncementRead
backend/ent/announcementread/announcementread.go ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by ent, DO NOT EDIT.
2
+
3
+ package announcementread
4
+
5
+ import (
6
+ "time"
7
+
8
+ "entgo.io/ent/dialect/sql"
9
+ "entgo.io/ent/dialect/sql/sqlgraph"
10
+ )
11
+
12
+ const (
13
+ // Label holds the string label denoting the announcementread type in the database.
14
+ Label = "announcement_read"
15
+ // FieldID holds the string denoting the id field in the database.
16
+ FieldID = "id"
17
+ // FieldAnnouncementID holds the string denoting the announcement_id field in the database.
18
+ FieldAnnouncementID = "announcement_id"
19
+ // FieldUserID holds the string denoting the user_id field in the database.
20
+ FieldUserID = "user_id"
21
+ // FieldReadAt holds the string denoting the read_at field in the database.
22
+ FieldReadAt = "read_at"
23
+ // FieldCreatedAt holds the string denoting the created_at field in the database.
24
+ FieldCreatedAt = "created_at"
25
+ // EdgeAnnouncement holds the string denoting the announcement edge name in mutations.
26
+ EdgeAnnouncement = "announcement"
27
+ // EdgeUser holds the string denoting the user edge name in mutations.
28
+ EdgeUser = "user"
29
+ // Table holds the table name of the announcementread in the database.
30
+ Table = "announcement_reads"
31
+ // AnnouncementTable is the table that holds the announcement relation/edge.
32
+ AnnouncementTable = "announcement_reads"
33
+ // AnnouncementInverseTable is the table name for the Announcement entity.
34
+ // It exists in this package in order to avoid circular dependency with the "announcement" package.
35
+ AnnouncementInverseTable = "announcements"
36
+ // AnnouncementColumn is the table column denoting the announcement relation/edge.
37
+ AnnouncementColumn = "announcement_id"
38
+ // UserTable is the table that holds the user relation/edge.
39
+ UserTable = "announcement_reads"
40
+ // UserInverseTable is the table name for the User entity.
41
+ // It exists in this package in order to avoid circular dependency with the "user" package.
42
+ UserInverseTable = "users"
43
+ // UserColumn is the table column denoting the user relation/edge.
44
+ UserColumn = "user_id"
45
+ )
46
+
47
+ // Columns holds all SQL columns for announcementread fields.
48
+ var Columns = []string{
49
+ FieldID,
50
+ FieldAnnouncementID,
51
+ FieldUserID,
52
+ FieldReadAt,
53
+ FieldCreatedAt,
54
+ }
55
+
56
+ // ValidColumn reports if the column name is valid (part of the table columns).
57
+ func ValidColumn(column string) bool {
58
+ for i := range Columns {
59
+ if column == Columns[i] {
60
+ return true
61
+ }
62
+ }
63
+ return false
64
+ }
65
+
66
+ var (
67
+ // DefaultReadAt holds the default value on creation for the "read_at" field.
68
+ DefaultReadAt func() time.Time
69
+ // DefaultCreatedAt holds the default value on creation for the "created_at" field.
70
+ DefaultCreatedAt func() time.Time
71
+ )
72
+
73
+ // OrderOption defines the ordering options for the AnnouncementRead queries.
74
+ type OrderOption func(*sql.Selector)
75
+
76
+ // ByID orders the results by the id field.
77
+ func ByID(opts ...sql.OrderTermOption) OrderOption {
78
+ return sql.OrderByField(FieldID, opts...).ToFunc()
79
+ }
80
+
81
+ // ByAnnouncementID orders the results by the announcement_id field.
82
+ func ByAnnouncementID(opts ...sql.OrderTermOption) OrderOption {
83
+ return sql.OrderByField(FieldAnnouncementID, opts...).ToFunc()
84
+ }
85
+
86
+ // ByUserID orders the results by the user_id field.
87
+ func ByUserID(opts ...sql.OrderTermOption) OrderOption {
88
+ return sql.OrderByField(FieldUserID, opts...).ToFunc()
89
+ }
90
+
91
+ // ByReadAt orders the results by the read_at field.
92
+ func ByReadAt(opts ...sql.OrderTermOption) OrderOption {
93
+ return sql.OrderByField(FieldReadAt, opts...).ToFunc()
94
+ }
95
+
96
+ // ByCreatedAt orders the results by the created_at field.
97
+ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
98
+ return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
99
+ }
100
+
101
+ // ByAnnouncementField orders the results by announcement field.
102
+ func ByAnnouncementField(field string, opts ...sql.OrderTermOption) OrderOption {
103
+ return func(s *sql.Selector) {
104
+ sqlgraph.OrderByNeighborTerms(s, newAnnouncementStep(), sql.OrderByField(field, opts...))
105
+ }
106
+ }
107
+
108
+ // ByUserField orders the results by user field.
109
+ func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
110
+ return func(s *sql.Selector) {
111
+ sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
112
+ }
113
+ }
114
+ func newAnnouncementStep() *sqlgraph.Step {
115
+ return sqlgraph.NewStep(
116
+ sqlgraph.From(Table, FieldID),
117
+ sqlgraph.To(AnnouncementInverseTable, FieldID),
118
+ sqlgraph.Edge(sqlgraph.M2O, true, AnnouncementTable, AnnouncementColumn),
119
+ )
120
+ }
121
+ func newUserStep() *sqlgraph.Step {
122
+ return sqlgraph.NewStep(
123
+ sqlgraph.From(Table, FieldID),
124
+ sqlgraph.To(UserInverseTable, FieldID),
125
+ sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
126
+ )
127
+ }