Skip to content

Commit 9fec53b

Browse files
committed
add extract and ui-url commands to CLI
1 parent b9b9c89 commit 9fec53b

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# master
22

3+
- Add `extract` and `ui-url` commands to CLI.
34
- Emit `@live` annotations for relevant things in generated files.
45
- Latest `rescript-embed-lang`.
56
- Depend on ReScript v11.

cli/Cli.res

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ let usage = `Usage:
2020
[--watch] | Runs this command in watch mode.
2121
2222
unused-selections | Check if we there are unused selections in your EdgeQL queries.
23-
[--ci] | Run in CI mode.`
23+
[--ci] | Run in CI mode.
24+
25+
ui-url | Get the URL for opening the local EdgeDB UI.
26+
27+
extract <filePath> | Extract all %edgeql tags in file at <filePath>.`
2428

2529
type config = {client: EdgeDB.Client.t}
2630

@@ -72,7 +76,7 @@ let main = async () => {
7276
dict
7377
})
7478
->JSON.stringifyAny
75-
->Option.getWithDefault("")
79+
->Option.getOr("")
7680
->NodeJs.Buffer.fromString,
7781
)
7882
}
@@ -169,8 +173,21 @@ let main = async () => {
169173

170174
{client: client}
171175
},
172-
~handleOtherCommand=async ({args, command}) => {
176+
~handleOtherCommand=async ({args, command, config}) => {
173177
switch command {
178+
| "ui-url" =>
179+
let getNormalizedConfig: EdgeDB.Client.t => promise<
180+
'a,
181+
> = %raw(`async function getNormalizedConfig(client) {
182+
return (await client.pool._getNormalizedConnectConfig()).connectionParams
183+
}`)
184+
185+
let connectionConfig = await getNormalizedConfig(config.client)
186+
187+
let url = `http://${connectionConfig["address"]->Array.joinWith(
188+
":",
189+
)}/ui/${connectionConfig["database"]}`
190+
Console.log(url)
174191
| "unused-selections" =>
175192
let ci = args->RescriptEmbedLang.CliArgs.hasArg("--ci")
176193

@@ -198,7 +215,7 @@ let main = async () => {
198215
content
199216
->String.split("# @name ")
200217
->Array.get(1)
201-
->Option.getWithDefault("")
218+
->Option.getOr("")
202219
->String.split(" ")
203220
->Array.get(0)
204221
->Option.map(EdgeDbGenerator__Utils.capitalizeString)
@@ -224,7 +241,7 @@ let main = async () => {
224241
while !break.contents {
225242
let currentLineCount = lineCount.contents
226243
lineCount := currentLineCount + 1
227-
let line = lines->Array.get(currentLineCount)->Option.getWithDefault("")
244+
let line = lines->Array.get(currentLineCount)->Option.getOr("")
228245
if line->String.includes("@name") {
229246
switch line->String.split("# @name ") {
230247
| [before, _after] =>
@@ -350,7 +367,7 @@ let transaction = (transaction: EdgeDB.Transaction.t${hasArgs
350367
let migrations =
351368
(await config.client
352369
->EdgeDB.QueryHelpers.single("select count(schema::Migration)"))
353-
->Option.getWithDefault(-1)
370+
->Option.getOr(-1)
354371

355372
debug(`[schema change detection] Found ${migrations->Int.toString} migrations`)
356373
let currentMigrationsCount = migrationsCount.contents

cli/EdgeDbGenerator.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ module AnalyzeQuery = {
314314
| Exn.Error(err) =>
315315
errorMessage := err->Exn.message
316316
Console.error(
317-
`${CliUtils.colorRed(
318-
"ERROR in file",
319-
)}: ${path}:\n${errorMessage.contents->Option.getWithDefault("-")}`,
317+
`${CliUtils.colorRed("ERROR in file")}: ${path}:\n${errorMessage.contents->Option.getOr(
318+
"-",
319+
)}`,
320320
)
321321
await holder->BaseClientPool.Holder.release
322322
None
@@ -350,7 +350,7 @@ module AnalyzeQuery = {
350350
})
351351
| _ =>
352352
Error(
353-
errorMessage.contents->Option.getWithDefault(
353+
errorMessage.contents->Option.getOr(
354354
"This query has an unknown EdgeDB error. Please check the query and recompile.",
355355
),
356356
)

dbTestProject/test/TestProject.test.res

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ let removeIds = (key, value) => {
1818
describe("fetching data", () => {
1919
testAsync("fetching movies", async () => {
2020
let movies = await client->Movies.allMovies
21-
let movies =
22-
movies->JSON.stringifyAnyWithReplacerAndIndent(removeIds, 2)->Option.getWithDefault("")
21+
let movies = movies->JSON.stringifyAnyWithReplacerAndIndent(removeIds, 2)->Option.getOr("")
2322
expect(movies)->Expect.toMatchSnapshot
2423
})
2524

2625
testAsync("fetching single movie", async () => {
2726
let movie = await client->Movies.movieByTitle(~title="The Great Adventure")
28-
let movie =
29-
movie->JSON.stringifyAnyWithReplacerAndIndent(removeIds, 2)->Option.getWithDefault("")
27+
let movie = movie->JSON.stringifyAnyWithReplacerAndIndent(removeIds, 2)->Option.getOr("")
3028
expect(movie)->Expect.toMatchSnapshot
3129
})
3230

0 commit comments

Comments
 (0)