From 351f08f453e59d94a680bb6712911ab6da41c38f Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 2 May 2024 21:32:05 +0200 Subject: [PATCH] change expectOne to raise if not exactly one item is encountered --- CHANGELOG.md | 1 + packages/cli/src/generator.ts | 8 +- .../example/src/books/BookService__sql.res | 32 ++--- packages/example/src/books/books__sql.res | 112 +++++++++--------- .../example/src/comments/comments__sql.res | 32 ++--- .../src/notifications/notifications__sql.res | 24 ++-- 6 files changed, 105 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b0fc1fa..5a11e3b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - BREAKING CHANGE: `Null.t` is no longer emitted, all `null` values are autoconverted to `option`. This gives a much more idiomatic ReScript experience. - Emit actually runnable query in module comment for each query, instead of the original non-valid SQL query. - Relax requirement on providing query via `@name` comment. +- Change `expectOne` to panic if not finding a single item. # 2.4.0 diff --git a/packages/cli/src/generator.ts b/packages/cli/src/generator.ts index d77342c4..3553bdf1 100644 --- a/packages/cli/src/generator.ts +++ b/packages/cli/src/generator.ts @@ -397,13 +397,13 @@ module ${ typeDec.query.name }Params) => promise> - /** Returns exactly 1 result. Returns \`Error\` (with an optionally provided \`errorMessage\`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises \`Exn.t\` (with an optionally provided \`errorMessage\`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, ${typeDec.query.name}Params, ~errorMessage: string=? - ) => promise> + ) => promise<${typeDec.query.name}Result> /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -430,8 +430,8 @@ module ${ @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype diff --git a/packages/example/src/books/BookService__sql.res b/packages/example/src/books/BookService__sql.res index 41d92d5b..cd5ab0d3 100644 --- a/packages/example/src/books/BookService__sql.res +++ b/packages/example/src/books/BookService__sql.res @@ -57,13 +57,13 @@ module FindBookById: { @gentype let one: (PgTyped.Pg.Client.t, findBookByIdParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, findBookByIdParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -84,8 +84,8 @@ module FindBookById: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -144,13 +144,13 @@ module Query1: { @gentype let one: (PgTyped.Pg.Client.t, query1Params) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, query1Params, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -171,8 +171,8 @@ module Query1: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -227,13 +227,13 @@ module Query2: { @gentype let one: (PgTyped.Pg.Client.t, query2Params) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, query2Params, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -254,8 +254,8 @@ module Query2: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -310,13 +310,13 @@ module Query3: { @gentype let one: (PgTyped.Pg.Client.t, query3Params) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, query3Params, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -337,8 +337,8 @@ module Query3: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype diff --git a/packages/example/src/books/books__sql.res b/packages/example/src/books/books__sql.res index f76cd487..85036f17 100644 --- a/packages/example/src/books/books__sql.res +++ b/packages/example/src/books/books__sql.res @@ -63,13 +63,13 @@ module FindBookById: { @gentype let one: (PgTyped.Pg.Client.t, findBookByIdParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, findBookByIdParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -90,8 +90,8 @@ module FindBookById: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -148,13 +148,13 @@ module FindBookByCategory: { @gentype let one: (PgTyped.Pg.Client.t, findBookByCategoryParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, findBookByCategoryParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -175,8 +175,8 @@ module FindBookByCategory: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -231,13 +231,13 @@ module FindBookNameOrRank: { @gentype let one: (PgTyped.Pg.Client.t, findBookNameOrRankParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, findBookNameOrRankParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -258,8 +258,8 @@ module FindBookNameOrRank: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -314,13 +314,13 @@ module FindBookUnicode: { @gentype let one: (PgTyped.Pg.Client.t, findBookUnicodeParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, findBookUnicodeParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -341,8 +341,8 @@ module FindBookUnicode: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -401,13 +401,13 @@ module InsertBooks: { @gentype let one: (PgTyped.Pg.Client.t, insertBooksParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, insertBooksParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -428,8 +428,8 @@ module InsertBooks: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -484,13 +484,13 @@ module InsertBook: { @gentype let one: (PgTyped.Pg.Client.t, insertBookParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, insertBookParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -511,8 +511,8 @@ module InsertBook: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -570,13 +570,13 @@ module UpdateBooksCustom: { @gentype let one: (PgTyped.Pg.Client.t, updateBooksCustomParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, updateBooksCustomParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -597,8 +597,8 @@ module UpdateBooksCustom: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -654,13 +654,13 @@ module UpdateBooks: { @gentype let one: (PgTyped.Pg.Client.t, updateBooksParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, updateBooksParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -681,8 +681,8 @@ module UpdateBooks: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -737,13 +737,13 @@ module UpdateBooksRankNotNull: { @gentype let one: (PgTyped.Pg.Client.t, updateBooksRankNotNullParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, updateBooksRankNotNullParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -764,8 +764,8 @@ module UpdateBooksRankNotNull: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -824,13 +824,13 @@ module GetBooksByAuthorName: { @gentype let one: (PgTyped.Pg.Client.t, getBooksByAuthorNameParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, getBooksByAuthorNameParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -851,8 +851,8 @@ module GetBooksByAuthorName: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -904,13 +904,13 @@ module AggregateEmailsAndTest: { @gentype let one: (PgTyped.Pg.Client.t, aggregateEmailsAndTestParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, aggregateEmailsAndTestParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -931,8 +931,8 @@ module AggregateEmailsAndTest: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -982,13 +982,13 @@ module GetBooks: { @gentype let one: (PgTyped.Pg.Client.t, getBooksParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, getBooksParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -1009,8 +1009,8 @@ module GetBooks: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -1059,13 +1059,13 @@ module CountBooks: { @gentype let one: (PgTyped.Pg.Client.t, countBooksParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, countBooksParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -1086,8 +1086,8 @@ module CountBooks: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -1137,13 +1137,13 @@ module GetBookCountries: { @gentype let one: (PgTyped.Pg.Client.t, getBookCountriesParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, getBookCountriesParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -1164,8 +1164,8 @@ module GetBookCountries: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype diff --git a/packages/example/src/comments/comments__sql.res b/packages/example/src/comments/comments__sql.res index d3141bc1..9543d4c9 100644 --- a/packages/example/src/comments/comments__sql.res +++ b/packages/example/src/comments/comments__sql.res @@ -42,13 +42,13 @@ module GetAllComments: { @gentype let one: (PgTyped.Pg.Client.t, getAllCommentsParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, getAllCommentsParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -69,8 +69,8 @@ module GetAllComments: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -124,13 +124,13 @@ module GetAllCommentsByIds: { @gentype let one: (PgTyped.Pg.Client.t, getAllCommentsByIdsParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, getAllCommentsByIdsParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -151,8 +151,8 @@ module GetAllCommentsByIds: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -213,13 +213,13 @@ module InsertComment: { @gentype let one: (PgTyped.Pg.Client.t, insertCommentParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, insertCommentParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -240,8 +240,8 @@ module InsertComment: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -290,13 +290,13 @@ module SelectExistsTest: { @gentype let one: (PgTyped.Pg.Client.t, selectExistsTestParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, selectExistsTestParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -317,8 +317,8 @@ module SelectExistsTest: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype diff --git a/packages/example/src/notifications/notifications__sql.res b/packages/example/src/notifications/notifications__sql.res index ad6666a5..09f480e8 100644 --- a/packages/example/src/notifications/notifications__sql.res +++ b/packages/example/src/notifications/notifications__sql.res @@ -49,13 +49,13 @@ module SendNotifications: { @gentype let one: (PgTyped.Pg.Client.t, sendNotificationsParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, sendNotificationsParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -76,8 +76,8 @@ module SendNotifications: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -136,13 +136,13 @@ module GetNotifications: { @gentype let one: (PgTyped.Pg.Client.t, getNotificationsParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, getNotificationsParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -163,8 +163,8 @@ module GetNotifications: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype @@ -220,13 +220,13 @@ module ThresholdFrogs: { @gentype let one: (PgTyped.Pg.Client.t, thresholdFrogsParams) => promise> - /** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ + /** Returns exactly 1 result. Raises `Exn.t` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */ @gentype let expectOne: ( PgTyped.Pg.Client.t, thresholdFrogsParams, ~errorMessage: string=? - ) => promise> + ) => promise /** Executes the query, but ignores whatever is returned by it. */ @gentype @@ -247,8 +247,8 @@ module ThresholdFrogs: { @gentype let expectOne = async (client, params, ~errorMessage=?) => switch await query(params, ~client) { - | [item] => Ok(item) - | _ => Error(errorMessage->Option.getOr("More or less than one item was returned")) + | [item] => item + | _ => panic(errorMessage->Option.getOr("More or less than one item was returned")) } @gentype