Skip to content

Commit a436bf7

Browse files
authoredSep 1, 2024
select id from table, many (#31)
* select id from table, many * add \n * update * update
1 parent a899d21 commit a436bf7

14 files changed

+151
-5
lines changed
 

‎.github/workflows/fsharp.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v3
18-
- name: docker-compose
19-
run: docker-compose up -d
18+
- name: docker compose
19+
run: docker compose up -d
2020
working-directory: testdata/gen
2121

2222
- name: show docker ps
23-
run: docker-compose ps
23+
run: docker compose ps
2424
working-directory: testdata/gen
2525

2626
- name: show docker logs
27-
run: docker-compose logs
27+
run: docker compose logs
2828
working-directory: testdata/gen
2929

3030
- name: Setup .NET
@@ -60,7 +60,7 @@ jobs:
6060
echo $DATABASE_URL
6161
dotnet run
6262
working-directory: testdata/gen/sqlc_test
63-
63+
6464
# - name: Test
6565
# - name: Test
6666
# run: dotnet test --no-build --verbosity normal

‎templates/query.tmpl

+4
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ let {{.MethodName}} (db: NpgsqlConnection) {{if .Arg.Pair}} ({{.Arg.Pair}}) {{-
6464
{{range .Comments}}//{{.}}
6565
{{end -}}
6666
let {{.MethodName}} (db: NpgsqlConnection) {{if .Arg.Pair}} ({{.Arg.Pair}}) {{- end }} =
67+
{{- if eq (len .Ret.UniqueFields) 1 }}
68+
let reader = fun (read:RowReader) -> read.{{(index .Ret.UniqueFields 0).Type | type2readerFunc }} "{{(index .Ret.UniqueFields 0).Name}}"
69+
{{ else }}
6770
let reader = fun (read:RowReader) -> {
6871
{{- range $i, $e := .Ret.UniqueFields}}
6972
{{$e.Name | pascalCase }} = read.{{$e.Type | type2readerFunc }} "{{$e.Name}}"
7073
{{- end -}}
7174
}
75+
{{ end }}
7276
db
7377
|> Sql.existingConnection
7478
|> Sql.query {{.ConstantName}}

‎testdata/gen/auth_user.sql.fs

+83
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ let GetAllAuthUsers (db: NpgsqlConnection) =
136136
IsStaff = read.bool "is_staff"
137137
IsActive = read.bool "is_active"
138138
DateJoined = read.dateTime "date_joined"}
139+
139140
db
140141
|> Sql.existingConnection
141142
|> Sql.query getAllAuthUsers
@@ -377,6 +378,7 @@ let GetUserStats (db: NpgsqlConnection) (arg: GetUserStatsParams) =
377378
TotalChatMessages3Days = read.int64 "total_chat_messages_3_days"
378379
TotalTokenCount3Days = read.int64 "total_token_count_3_days"
379380
RateLimit = read.int "rate_limit"}
381+
380382
db
381383
|> Sql.existingConnection
382384
|> Sql.query getUserStats
@@ -395,6 +397,60 @@ let GetUserStats (db: NpgsqlConnection) (arg: GetUserStatsParams) =
395397

396398

397399

400+
let listAuthUserID = """-- name: ListAuthUserID :many
401+
SELECT id FROM auth_user
402+
"""
403+
404+
405+
406+
407+
let ListAuthUserID (db: NpgsqlConnection) =
408+
let reader = fun (read:RowReader) -> read.int "id"
409+
410+
db
411+
|> Sql.existingConnection
412+
|> Sql.query listAuthUserID
413+
|> Sql.execute reader
414+
415+
416+
417+
418+
419+
420+
421+
422+
423+
424+
let listAuthUserIDandEmail = """-- name: ListAuthUserIDandEmail :many
425+
SELECT id, email FROM auth_user
426+
"""
427+
428+
429+
type ListAuthUserIDandEmailRow = {
430+
Id: int32;
431+
Email: string;
432+
}
433+
434+
435+
let ListAuthUserIDandEmail (db: NpgsqlConnection) =
436+
let reader = fun (read:RowReader) -> {
437+
Id = read.int "id"
438+
Email = read.string "email"}
439+
440+
db
441+
|> Sql.existingConnection
442+
|> Sql.query listAuthUserIDandEmail
443+
|> Sql.execute reader
444+
445+
446+
447+
448+
449+
450+
451+
452+
453+
398454
let listAuthUsers = """-- name: ListAuthUsers :many
399455
SELECT id, password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined FROM auth_user ORDER BY id LIMIT @limit OFFSET @offset
400456
"""
@@ -419,6 +475,7 @@ let ListAuthUsers (db: NpgsqlConnection) (arg: ListAuthUsersParams) =
419475
IsStaff = read.bool "is_staff"
420476
IsActive = read.bool "is_active"
421477
DateJoined = read.dateTime "date_joined"}
478+
422479
db
423480
|> Sql.existingConnection
424481
|> Sql.query listAuthUsers
@@ -443,6 +500,32 @@ let ListAuthUsers (db: NpgsqlConnection) (arg: ListAuthUsersParams) =
443500

444501

445502

503+
let totalAuthUsers = """-- name: TotalAuthUsers :one
504+
SELECT COUNT(*) FROM auth_user
505+
"""
506+
507+
508+
509+
let TotalAuthUsers (db: NpgsqlConnection) =
510+
511+
let reader = fun (read:RowReader) -> read.int64 "count"
512+
513+
db
514+
|> Sql.existingConnection
515+
|> Sql.query totalAuthUsers
516+
|> Sql.executeRow reader
517+
518+
519+
520+
521+
522+
523+
524+
525+
526+
527+
528+
446529
let updateAuthUser = """-- name: UpdateAuthUser :one
447530
UPDATE auth_user SET first_name = @first_name, last_name= @last_name, last_login = now()
448531
WHERE id = @id

‎testdata/gen/auth_user_management.sql.fs

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ let GetRateLimit (db: NpgsqlConnection) (userId: int32) =
139139

140140

141141

142+
143+
144+
142145

143146

144147

‎testdata/gen/chat_jwt_secrets.sql.fs

+3
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ let GetJwtSecret (db: NpgsqlConnection) (name: string) =
199199

200200

201201

202+
203+
204+
202205

203206

204207

‎testdata/gen/chat_log.sql.fs

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ let DeleteChatLog (db: NpgsqlConnection) (id: int32) =
171171

172172

173173

174+
175+
174176

175177

176178

@@ -188,6 +190,7 @@ let ListChatLogs (db: NpgsqlConnection) =
188190
Question = read.string "question"
189191
Answer = read.string "answer"
190192
CreatedAt = read.dateTime "created_at"}
193+
191194
db
192195
|> Sql.existingConnection
193196
|> Sql.query listChatLogs
@@ -211,6 +214,7 @@ let ListChatLogs (db: NpgsqlConnection) =
211214

212215

213216

217+
214218

215219

216220
let updateChatLog = """-- name: UpdateChatLog :one

‎testdata/gen/chat_message.sql.fs

+7
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ let GetAllChatMessages (db: NpgsqlConnection) =
198198
IsPin = read.bool "is_pin"
199199
TokenCount = read.int "token_count"
200200
Raw = read.string "raw"}
201+
201202
db
202203
|> Sql.existingConnection
203204
|> Sql.query getAllChatMessages
@@ -394,6 +395,7 @@ let GetChatMessagesBySessionUUID (db: NpgsqlConnection) (arg: GetChatMessagesBy
394395
IsPin = read.bool "is_pin"
395396
TokenCount = read.int "token_count"
396397
Raw = read.string "raw"}
398+
397399
db
398400
|> Sql.existingConnection
399401
|> Sql.query getChatMessagesBySessionUUID
@@ -581,6 +583,7 @@ let GetLastNChatMessages (db: NpgsqlConnection) (arg: GetLastNChatMessagesParam
581583
IsPin = read.bool "is_pin"
582584
TokenCount = read.int "token_count"
583585
Raw = read.string "raw"}
586+
584587
db
585588
|> Sql.existingConnection
586589
|> Sql.query getLastNChatMessages
@@ -640,6 +643,7 @@ let GetLatestMessagesBySessionUUID (db: NpgsqlConnection) (arg: GetLatestMessag
640643
IsPin = read.bool "is_pin"
641644
TokenCount = read.int "token_count"
642645
Raw = read.string "raw"}
646+
643647
db
644648
|> Sql.existingConnection
645649
|> Sql.query getLatestMessagesBySessionUUID
@@ -708,6 +712,9 @@ let HasChatMessagePermission (db: NpgsqlConnection) (arg: HasChatMessagePermiss
708712

709713

710714

715+
716+
717+
711718

712719

713720

‎testdata/gen/chat_model.sql.fs

+5
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ let GetDefaultChatModel (db: NpgsqlConnection) =
261261

262262

263263

264+
265+
264266

265267

266268

@@ -282,6 +284,7 @@ let ListChatModels (db: NpgsqlConnection) =
282284
ApiAuthKey = read.string "api_auth_key"
283285
UserId = read.int "user_id"
284286
EnablePerModeRatelimit = read.bool "enable_per_mode_ratelimit"}
287+
285288
db
286289
|> Sql.existingConnection
287290
|> Sql.query listChatModels
@@ -317,6 +320,7 @@ let ListSystemChatModels (db: NpgsqlConnection) =
317320
ApiAuthKey = read.string "api_auth_key"
318321
UserId = read.int "user_id"
319322
EnablePerModeRatelimit = read.bool "enable_per_mode_ratelimit"}
323+
320324
db
321325
|> Sql.existingConnection
322326
|> Sql.query listSystemChatModels
@@ -341,6 +345,7 @@ let ListSystemChatModels (db: NpgsqlConnection) =
341345

342346

343347

348+
344349

345350

346351
let updateChatModel = """-- name: UpdateChatModel :one

‎testdata/gen/chat_prompt.sql.fs

+7
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ let GetAllChatPrompts (db: NpgsqlConnection) =
171171
UpdatedBy = read.int "updated_by"
172172
IsDeleted = read.bool "is_deleted"
173173
TokenCount = read.int "token_count"}
174+
174175
db
175176
|> Sql.existingConnection
176177
|> Sql.query getAllChatPrompts
@@ -303,6 +304,7 @@ let GetChatPromptsBySessionUUID (db: NpgsqlConnection) (chatSessionUuid: string
303304
UpdatedBy = read.int "updated_by"
304305
IsDeleted = read.bool "is_deleted"
305306
TokenCount = read.int "token_count"}
307+
306308
db
307309
|> Sql.existingConnection
308310
|> Sql.query getChatPromptsBySessionUUID
@@ -343,6 +345,7 @@ let GetChatPromptsByUserID (db: NpgsqlConnection) (userId: int32) =
343345
UpdatedBy = read.int "updated_by"
344346
IsDeleted = read.bool "is_deleted"
345347
TokenCount = read.int "token_count"}
348+
346349
db
347350
|> Sql.existingConnection
348351
|> Sql.query getChatPromptsByUserID
@@ -383,6 +386,7 @@ let GetChatPromptsBysession_uuid (db: NpgsqlConnection) (chatSessionUuid: strin
383386
UpdatedBy = read.int "updated_by"
384387
IsDeleted = read.bool "is_deleted"
385388
TokenCount = read.int "token_count"}
389+
386390
db
387391
|> Sql.existingConnection
388392
|> Sql.query getChatPromptsBysession_uuid
@@ -508,6 +512,9 @@ let HasChatPromptPermission (db: NpgsqlConnection) (arg: HasChatPromptPermissio
508512

509513

510514

515+
516+
517+
511518

512519

513520

‎testdata/gen/chat_session.sql.fs

+5
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ let GetAllChatSessions (db: NpgsqlConnection) =
286286
MaxTokens = read.int "max_tokens"
287287
N = read.int "n"
288288
Debug = read.bool "debug"}
289+
289290
db
290291
|> Sql.existingConnection
291292
|> Sql.query getAllChatSessions
@@ -469,6 +470,7 @@ let GetChatSessionsByUserID (db: NpgsqlConnection) (userId: int32) =
469470
MaxTokens = read.int "max_tokens"
470471
N = read.int "n"
471472
Debug = read.bool "debug"}
473+
472474
db
473475
|> Sql.existingConnection
474476
|> Sql.query getChatSessionsByUserID
@@ -548,6 +550,9 @@ let HasChatSessionPermission (db: NpgsqlConnection) (arg: HasChatSessionPermiss
548550

549551

550552

553+
554+
555+
551556

552557

553558

‎testdata/gen/chat_snapshot.sql.fs

+6
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ let ChatSnapshotMetaByUserID (db: NpgsqlConnection) (userId: int32) =
117117
Summary = read.string "summary"
118118
Tags = read.string "tags"
119119
CreatedAt = read.dateTime "created_at"}
120+
120121
db
121122
|> Sql.existingConnection
122123
|> Sql.query chatSnapshotMetaByUserID
@@ -157,6 +158,7 @@ let ChatSnapshotSearch (db: NpgsqlConnection) (arg: ChatSnapshotSearchParams) =
157158
Uuid = read.string "uuid"
158159
Title = read.string "title"
159160
Rank = read.float "rank"}
161+
160162
db
161163
|> Sql.existingConnection
162164
|> Sql.query chatSnapshotSearch
@@ -331,6 +333,8 @@ let DeleteChatSnapshot (db: NpgsqlConnection) (arg: DeleteChatSnapshotParams)
331333

332334

333335

336+
337+
334338

335339

336340

@@ -355,6 +359,7 @@ let ListChatSnapshots (db: NpgsqlConnection) =
355359
CreatedAt = read.dateTime "created_at"
356360
Text = read.string "text"
357361
SearchVector = read.stringOrNone "search_vector"}
362+
358363
db
359364
|> Sql.existingConnection
360365
|> Sql.query listChatSnapshots
@@ -387,6 +392,7 @@ let ListChatSnapshots (db: NpgsqlConnection) =
387392

388393

389394

395+
390396

391397

392398
let updateChatSnapshot = """-- name: UpdateChatSnapshot :one

0 commit comments

Comments
 (0)