Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/fsharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: docker-compose
run: docker-compose up -d
- name: docker compose
run: docker compose up -d
working-directory: testdata/gen

- name: show docker ps
run: docker-compose ps
run: docker compose ps
working-directory: testdata/gen

- name: show docker logs
run: docker-compose logs
run: docker compose logs
working-directory: testdata/gen

- name: Setup .NET
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
echo $DATABASE_URL
dotnet run
working-directory: testdata/gen/sqlc_test

# - name: Test
# - name: Test
# run: dotnet test --no-build --verbosity normal
4 changes: 4 additions & 0 deletions templates/query.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ let {{.MethodName}} (db: NpgsqlConnection) {{if .Arg.Pair}} ({{.Arg.Pair}}) {{-
{{range .Comments}}//{{.}}
{{end -}}
let {{.MethodName}} (db: NpgsqlConnection) {{if .Arg.Pair}} ({{.Arg.Pair}}) {{- end }} =
{{- if eq (len .Ret.UniqueFields) 1 }}
let reader = fun (read:RowReader) -> read.{{(index .Ret.UniqueFields 0).Type | type2readerFunc }} "{{(index .Ret.UniqueFields 0).Name}}"
{{ else }}
let reader = fun (read:RowReader) -> {
{{- range $i, $e := .Ret.UniqueFields}}
{{$e.Name | pascalCase }} = read.{{$e.Type | type2readerFunc }} "{{$e.Name}}"
{{- end -}}
}
{{ end }}
db
|> Sql.existingConnection
|> Sql.query {{.ConstantName}}
Expand Down
83 changes: 83 additions & 0 deletions testdata/gen/auth_user.sql.fs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ let GetAllAuthUsers (db: NpgsqlConnection) =
IsStaff = read.bool "is_staff"
IsActive = read.bool "is_active"
DateJoined = read.dateTime "date_joined"}

db
|> Sql.existingConnection
|> Sql.query getAllAuthUsers
Expand Down Expand Up @@ -377,6 +378,7 @@ let GetUserStats (db: NpgsqlConnection) (arg: GetUserStatsParams) =
TotalChatMessages3Days = read.int64 "total_chat_messages_3_days"
TotalTokenCount3Days = read.int64 "total_token_count_3_days"
RateLimit = read.int "rate_limit"}

db
|> Sql.existingConnection
|> Sql.query getUserStats
Expand All @@ -395,6 +397,60 @@ let GetUserStats (db: NpgsqlConnection) (arg: GetUserStatsParams) =



let listAuthUserID = """-- name: ListAuthUserID :many
SELECT id FROM auth_user
"""




let ListAuthUserID (db: NpgsqlConnection) =
let reader = fun (read:RowReader) -> read.int "id"

db
|> Sql.existingConnection
|> Sql.query listAuthUserID
|> Sql.execute reader










let listAuthUserIDandEmail = """-- name: ListAuthUserIDandEmail :many
SELECT id, email FROM auth_user
"""


type ListAuthUserIDandEmailRow = {
Id: int32;
Email: string;
}


let ListAuthUserIDandEmail (db: NpgsqlConnection) =
let reader = fun (read:RowReader) -> {
Id = read.int "id"
Email = read.string "email"}

db
|> Sql.existingConnection
|> Sql.query listAuthUserIDandEmail
|> Sql.execute reader










let listAuthUsers = """-- name: ListAuthUsers :many
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
"""
Expand All @@ -419,6 +475,7 @@ let ListAuthUsers (db: NpgsqlConnection) (arg: ListAuthUsersParams) =
IsStaff = read.bool "is_staff"
IsActive = read.bool "is_active"
DateJoined = read.dateTime "date_joined"}

db
|> Sql.existingConnection
|> Sql.query listAuthUsers
Expand All @@ -443,6 +500,32 @@ let ListAuthUsers (db: NpgsqlConnection) (arg: ListAuthUsersParams) =



let totalAuthUsers = """-- name: TotalAuthUsers :one
SELECT COUNT(*) FROM auth_user
"""



let TotalAuthUsers (db: NpgsqlConnection) =

let reader = fun (read:RowReader) -> read.int64 "count"

db
|> Sql.existingConnection
|> Sql.query totalAuthUsers
|> Sql.executeRow reader












let updateAuthUser = """-- name: UpdateAuthUser :one
UPDATE auth_user SET first_name = @first_name, last_name= @last_name, last_login = now()
WHERE id = @id
Expand Down
3 changes: 3 additions & 0 deletions testdata/gen/auth_user_management.sql.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ let GetRateLimit (db: NpgsqlConnection) (userId: int32) =









Expand Down
3 changes: 3 additions & 0 deletions testdata/gen/chat_jwt_secrets.sql.fs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ let GetJwtSecret (db: NpgsqlConnection) (name: string) =









Expand Down
4 changes: 4 additions & 0 deletions testdata/gen/chat_log.sql.fs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ let DeleteChatLog (db: NpgsqlConnection) (id: int32) =








Expand All @@ -188,6 +190,7 @@ let ListChatLogs (db: NpgsqlConnection) =
Question = read.string "question"
Answer = read.string "answer"
CreatedAt = read.dateTime "created_at"}

db
|> Sql.existingConnection
|> Sql.query listChatLogs
Expand All @@ -211,6 +214,7 @@ let ListChatLogs (db: NpgsqlConnection) =






let updateChatLog = """-- name: UpdateChatLog :one
Expand Down
7 changes: 7 additions & 0 deletions testdata/gen/chat_message.sql.fs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ let GetAllChatMessages (db: NpgsqlConnection) =
IsPin = read.bool "is_pin"
TokenCount = read.int "token_count"
Raw = read.string "raw"}

db
|> Sql.existingConnection
|> Sql.query getAllChatMessages
Expand Down Expand Up @@ -394,6 +395,7 @@ let GetChatMessagesBySessionUUID (db: NpgsqlConnection) (arg: GetChatMessagesBy
IsPin = read.bool "is_pin"
TokenCount = read.int "token_count"
Raw = read.string "raw"}

db
|> Sql.existingConnection
|> Sql.query getChatMessagesBySessionUUID
Expand Down Expand Up @@ -581,6 +583,7 @@ let GetLastNChatMessages (db: NpgsqlConnection) (arg: GetLastNChatMessagesParam
IsPin = read.bool "is_pin"
TokenCount = read.int "token_count"
Raw = read.string "raw"}

db
|> Sql.existingConnection
|> Sql.query getLastNChatMessages
Expand Down Expand Up @@ -640,6 +643,7 @@ let GetLatestMessagesBySessionUUID (db: NpgsqlConnection) (arg: GetLatestMessag
IsPin = read.bool "is_pin"
TokenCount = read.int "token_count"
Raw = read.string "raw"}

db
|> Sql.existingConnection
|> Sql.query getLatestMessagesBySessionUUID
Expand Down Expand Up @@ -708,6 +712,9 @@ let HasChatMessagePermission (db: NpgsqlConnection) (arg: HasChatMessagePermiss









Expand Down
5 changes: 5 additions & 0 deletions testdata/gen/chat_model.sql.fs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ let GetDefaultChatModel (db: NpgsqlConnection) =








Expand All @@ -282,6 +284,7 @@ let ListChatModels (db: NpgsqlConnection) =
ApiAuthKey = read.string "api_auth_key"
UserId = read.int "user_id"
EnablePerModeRatelimit = read.bool "enable_per_mode_ratelimit"}

db
|> Sql.existingConnection
|> Sql.query listChatModels
Expand Down Expand Up @@ -317,6 +320,7 @@ let ListSystemChatModels (db: NpgsqlConnection) =
ApiAuthKey = read.string "api_auth_key"
UserId = read.int "user_id"
EnablePerModeRatelimit = read.bool "enable_per_mode_ratelimit"}

db
|> Sql.existingConnection
|> Sql.query listSystemChatModels
Expand All @@ -341,6 +345,7 @@ let ListSystemChatModels (db: NpgsqlConnection) =






let updateChatModel = """-- name: UpdateChatModel :one
Expand Down
7 changes: 7 additions & 0 deletions testdata/gen/chat_prompt.sql.fs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ let GetAllChatPrompts (db: NpgsqlConnection) =
UpdatedBy = read.int "updated_by"
IsDeleted = read.bool "is_deleted"
TokenCount = read.int "token_count"}

db
|> Sql.existingConnection
|> Sql.query getAllChatPrompts
Expand Down Expand Up @@ -303,6 +304,7 @@ let GetChatPromptsBySessionUUID (db: NpgsqlConnection) (chatSessionUuid: string
UpdatedBy = read.int "updated_by"
IsDeleted = read.bool "is_deleted"
TokenCount = read.int "token_count"}

db
|> Sql.existingConnection
|> Sql.query getChatPromptsBySessionUUID
Expand Down Expand Up @@ -343,6 +345,7 @@ let GetChatPromptsByUserID (db: NpgsqlConnection) (userId: int32) =
UpdatedBy = read.int "updated_by"
IsDeleted = read.bool "is_deleted"
TokenCount = read.int "token_count"}

db
|> Sql.existingConnection
|> Sql.query getChatPromptsByUserID
Expand Down Expand Up @@ -383,6 +386,7 @@ let GetChatPromptsBysession_uuid (db: NpgsqlConnection) (chatSessionUuid: strin
UpdatedBy = read.int "updated_by"
IsDeleted = read.bool "is_deleted"
TokenCount = read.int "token_count"}

db
|> Sql.existingConnection
|> Sql.query getChatPromptsBysession_uuid
Expand Down Expand Up @@ -508,6 +512,9 @@ let HasChatPromptPermission (db: NpgsqlConnection) (arg: HasChatPromptPermissio









Expand Down
5 changes: 5 additions & 0 deletions testdata/gen/chat_session.sql.fs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ let GetAllChatSessions (db: NpgsqlConnection) =
MaxTokens = read.int "max_tokens"
N = read.int "n"
Debug = read.bool "debug"}

db
|> Sql.existingConnection
|> Sql.query getAllChatSessions
Expand Down Expand Up @@ -469,6 +470,7 @@ let GetChatSessionsByUserID (db: NpgsqlConnection) (userId: int32) =
MaxTokens = read.int "max_tokens"
N = read.int "n"
Debug = read.bool "debug"}

db
|> Sql.existingConnection
|> Sql.query getChatSessionsByUserID
Expand Down Expand Up @@ -548,6 +550,9 @@ let HasChatSessionPermission (db: NpgsqlConnection) (arg: HasChatSessionPermiss









Expand Down
6 changes: 6 additions & 0 deletions testdata/gen/chat_snapshot.sql.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ let ChatSnapshotMetaByUserID (db: NpgsqlConnection) (userId: int32) =
Summary = read.string "summary"
Tags = read.string "tags"
CreatedAt = read.dateTime "created_at"}

db
|> Sql.existingConnection
|> Sql.query chatSnapshotMetaByUserID
Expand Down Expand Up @@ -157,6 +158,7 @@ let ChatSnapshotSearch (db: NpgsqlConnection) (arg: ChatSnapshotSearchParams) =
Uuid = read.string "uuid"
Title = read.string "title"
Rank = read.float "rank"}

db
|> Sql.existingConnection
|> Sql.query chatSnapshotSearch
Expand Down Expand Up @@ -331,6 +333,8 @@ let DeleteChatSnapshot (db: NpgsqlConnection) (arg: DeleteChatSnapshotParams)








Expand All @@ -355,6 +359,7 @@ let ListChatSnapshots (db: NpgsqlConnection) =
CreatedAt = read.dateTime "created_at"
Text = read.string "text"
SearchVector = read.stringOrNone "search_vector"}

db
|> Sql.existingConnection
|> Sql.query listChatSnapshots
Expand Down Expand Up @@ -387,6 +392,7 @@ let ListChatSnapshots (db: NpgsqlConnection) =






let updateChatSnapshot = """-- name: UpdateChatSnapshot :one
Expand Down
Loading