Skip to content

Commit 5019dd4

Browse files
committed
more
1 parent c9a894c commit 5019dd4

7 files changed

+766
-1
lines changed

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func ProtoToJSON(msg proto.Message) (string, error) {
2424

2525
func main() {
2626
if err := run(); err != nil {
27-
fmt.Fprintf(os.Stderr, "error generating typescript: %s", err)
27+
fmt.Fprintf(os.Stderr, "error generating F#: %s", err)
2828
os.Exit(2)
2929
}
3030
}

testdata/gen/author.sql.fs

+15
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ let CreateAuthor db: NpgsqlConnection arg: CreateAuthorParams) =
3636

3737

3838

39+
40+
41+
3942
let deleteAuthor = """-- name: DeleteAuthor :exec
4043
DELETE FROM authors
4144
WHERE id = ?
@@ -60,6 +63,8 @@ let DeleteAuthor (db: NpgsqlConnection) (id: int32) =
6063

6164

6265

66+
67+
6368
let getAuthor = """-- name: GetAuthor :one
6469
SELECT id, name, bio FROM authors
6570
WHERE id = ? LIMIT 1
@@ -96,6 +101,7 @@ let GetAuthor (db: NpgsqlConnection) (id: int32) =
96101

97102

98103

104+
99105
let listAuthors = """-- name: ListAuthors :many
100106
SELECT id, name, bio FROM authors
101107
ORDER BY name
@@ -130,3 +136,12 @@ let ListAuthors (db: NpgsqlConnection) () =
130136

131137

132138

139+
140+
141+
142+
143+
144+
145+
146+
147+

testdata/gen/jwt_secrets.sql.fs

+15
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ let CreateJwtSecret (db: NpgsqlConnection) (arg: CreateJwtSecretParams) =
4949

5050

5151

52+
53+
54+
55+
56+
5257
let getJwtSecret = """-- name: GetJwtSecret :one
5358
SELECT id, name, secret, audience FROM jwt_secrets WHERE name = @name
5459
"""
@@ -83,6 +88,16 @@ let GetJwtSecret (db: NpgsqlConnection) (name: string) =
8388

8489

8590

91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
86101

87102

88103

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
// Code generated by sqlc. DO NOT EDIT.
2+
// source: user_active_chat_session.sql
3+
4+
open Npgsql.FSharp
5+
6+
7+
8+
9+
let createOrUpdateUserActiveChatSession = """-- name: CreateOrUpdateUserActiveChatSession :one
10+
INSERT INTO user_active_chat_session(user_id, chat_session_uuid)
11+
VALUES (@user_id, @chat_session_uuid)
12+
ON CONFLICT (user_id)
13+
DO UPDATE SET
14+
chat_session_uuid = EXCLUDED.chat_session_uuid,
15+
updated_at = now()
16+
returning id, user_id, chat_session_uuid, created_at, updated_at
17+
"""
18+
19+
20+
type CreateOrUpdateUserActiveChatSessionParams = {
21+
UserID: int32;
22+
ChatSessionUuid: string;
23+
}
24+
type CreateOrUpdateUserActiveChatSessionRow = {
25+
ID: int32;
26+
UserID: int32;
27+
ChatSessionUuid: string;
28+
CreatedAt: DateTime;
29+
UpdatedAt: DateTime;
30+
}
31+
32+
let CreateOrUpdateUserActiveChatSession (db: NpgsqlConnection) (arg: CreateOrUpdateUserActiveChatSessionParams) =
33+
let reader = fun (read:RowReader) -> {
34+
ID = read.int "id"
35+
UserID = read.int "user_id"
36+
ChatSessionUuid = read.string "chat_session_uuid"
37+
CreatedAt = read.DateTime "created_at"
38+
UpdatedAt = read.DateTime "updated_at"}
39+
40+
db
41+
|> Sql.existingConnection
42+
|> Sql.query createOrUpdateUserActiveChatSession
43+
|> Sql.parameters [ "@user_id", Sql.int arg.user_id, "@chat_session_uuid", Sql.string arg.chat_session_uuid ]
44+
|> Sql.execute reader
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
let createUserActiveChatSession = """-- name: CreateUserActiveChatSession :one
58+
INSERT INTO user_active_chat_session (user_id, chat_session_uuid)
59+
VALUES (@user_id, @chat_session_uuid)
60+
RETURNING id, user_id, chat_session_uuid, created_at, updated_at
61+
"""
62+
63+
64+
type CreateUserActiveChatSessionParams = {
65+
UserID: int32;
66+
ChatSessionUuid: string;
67+
}
68+
type CreateUserActiveChatSessionRow = {
69+
ID: int32;
70+
UserID: int32;
71+
ChatSessionUuid: string;
72+
CreatedAt: DateTime;
73+
UpdatedAt: DateTime;
74+
}
75+
76+
let CreateUserActiveChatSession (db: NpgsqlConnection) (arg: CreateUserActiveChatSessionParams) =
77+
let reader = fun (read:RowReader) -> {
78+
ID = read.int "id"
79+
UserID = read.int "user_id"
80+
ChatSessionUuid = read.string "chat_session_uuid"
81+
CreatedAt = read.DateTime "created_at"
82+
UpdatedAt = read.DateTime "updated_at"}
83+
84+
db
85+
|> Sql.existingConnection
86+
|> Sql.query createUserActiveChatSession
87+
|> Sql.parameters [ "@user_id", Sql.int arg.user_id, "@chat_session_uuid", Sql.string arg.chat_session_uuid ]
88+
|> Sql.execute reader
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
let deleteUserActiveChatSession = """-- name: DeleteUserActiveChatSession :exec
104+
DELETE FROM user_active_chat_session WHERE user_id = @user_id
105+
"""
106+
107+
108+
109+
110+
111+
112+
let DeleteUserActiveChatSession (db: NpgsqlConnection) (userID: int32) =
113+
db
114+
|> Sql.existingConnection
115+
|> Sql.query deleteUserActiveChatSession
116+
|> Sql.parameters [ "@user_id", Sql.int user_id ]
117+
|> Sql.executeNonQuery
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+
let getUserActiveChatSession = """-- name: GetUserActiveChatSession :one
130+
SELECT id, user_id, chat_session_uuid, created_at, updated_at FROM user_active_chat_session WHERE user_id = @user_id
131+
"""
132+
133+
134+
type GetUserActiveChatSessionRow = {
135+
ID: int32;
136+
UserID: int32;
137+
ChatSessionUuid: string;
138+
CreatedAt: DateTime;
139+
UpdatedAt: DateTime;
140+
}
141+
142+
let GetUserActiveChatSession (db: NpgsqlConnection) (userID: int32) =
143+
let reader = fun (read:RowReader) -> {
144+
ID = read.int "id"
145+
UserID = read.int "user_id"
146+
ChatSessionUuid = read.string "chat_session_uuid"
147+
CreatedAt = read.DateTime "created_at"
148+
UpdatedAt = read.DateTime "updated_at"}
149+
150+
db
151+
|> Sql.existingConnection
152+
|> Sql.query getUserActiveChatSession
153+
|> Sql.parameters [ "@user_id", Sql.int user_id ]
154+
|> Sql.execute reader
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+
let listUserActiveChatSessions = """-- name: ListUserActiveChatSessions :many
169+
SELECT id, user_id, chat_session_uuid, created_at, updated_at FROM user_active_chat_session ORDER BY id
170+
"""
171+
172+
173+
type ListUserActiveChatSessionsRow = {
174+
ID: int32;
175+
UserID: int32;
176+
ChatSessionUuid: string;
177+
CreatedAt: DateTime;
178+
UpdatedAt: DateTime;
179+
}
180+
181+
182+
let ListUserActiveChatSessions (db: NpgsqlConnection) () =
183+
let reader = fun (read:RowReader) -> {
184+
ID = read.int "id"
185+
UserID = read.int "user_id"
186+
ChatSessionUuid = read.string "chat_session_uuid"
187+
CreatedAt = read.DateTime "created_at"
188+
UpdatedAt = read.DateTime "updated_at"}
189+
db
190+
|> Sql.existingConnection
191+
|> sql.query listUserActiveChatSessions
192+
|> listUserActiveChatSessions
193+
|> Sql.execute reader
194+
195+
196+
197+
198+
199+
200+
201+
202+
203+
204+
205+
206+
207+
208+
let updateUserActiveChatSession = """-- name: UpdateUserActiveChatSession :one
209+
UPDATE user_active_chat_session SET chat_session_uuid = @chat_session_uuid, updated_at = now()
210+
WHERE user_id = @user_id
211+
RETURNING id, user_id, chat_session_uuid, created_at, updated_at
212+
"""
213+
214+
215+
type UpdateUserActiveChatSessionParams = {
216+
ChatSessionUuid: string;
217+
UserID: int32;
218+
}
219+
type UpdateUserActiveChatSessionRow = {
220+
ID: int32;
221+
UserID: int32;
222+
ChatSessionUuid: string;
223+
CreatedAt: DateTime;
224+
UpdatedAt: DateTime;
225+
}
226+
227+
let UpdateUserActiveChatSession (db: NpgsqlConnection) (arg: UpdateUserActiveChatSessionParams) =
228+
let reader = fun (read:RowReader) -> {
229+
ID = read.int "id"
230+
UserID = read.int "user_id"
231+
ChatSessionUuid = read.string "chat_session_uuid"
232+
CreatedAt = read.DateTime "created_at"
233+
UpdatedAt = read.DateTime "updated_at"}
234+
235+
db
236+
|> Sql.existingConnection
237+
|> Sql.query updateUserActiveChatSession
238+
|> Sql.parameters [ "@chat_session_uuid", Sql.string arg.chat_session_uuid, "@user_id", Sql.int arg.user_id ]
239+
|> Sql.execute reader
240+
241+
242+
243+
244+
245+
246+
247+
248+
249+
250+
251+
252+
253+
254+
255+

0 commit comments

Comments
 (0)