Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zth committed May 2, 2024
1 parent 1b6dd26 commit 9aef10a
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 113 deletions.
7 changes: 5 additions & 2 deletions packages/cli/src/parseRescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function parseCode(
content.reverse();

const queries: Array<string> = [];
let unnamedQueriesCount = 0;

content.forEach((v) => {
let query = v.contents.trim();
Expand All @@ -39,21 +40,23 @@ export function parseCode(
}

if (!query.includes('@name')) {
unnamedQueriesCount += 1;
// Handle potentially existing doc comment
if (query.trim().startsWith('/*')) {
const lines = query.split('\n');

let comment = `/* @name Query${queries.length + 1}\n`;
let comment = `/*\n@name Query${unnamedQueriesCount}\n`;
for (let i = 0; i <= lines.length - 1; i += 1) {
const line = lines[i].trim().replace('/*', '');
comment += line + '\n';
if (line.endsWith('*/')) {
query = lines.slice(i + 1).join('\n');
break;
}
}
query = `${comment}\n${query}`;
} else {
query = `/* @name Query${queries.length + 1} */\n${query}`;
query = `/* @name Query${unnamedQueriesCount} */\n${query}`;
}
}

Expand Down
92 changes: 46 additions & 46 deletions packages/example/src/books/BookService__sql.gen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,36 @@ export type arrayJSON_t = JSON_t[];

export type categoryArray = category[];

export type query1Params_notification = {
readonly payload?: JSON_t;
readonly user_id?: number;
readonly type: (undefined | notification_type)
/** 'FindBookById' parameters type */
export type findBookByIdParams = { readonly id?: number };

/** 'FindBookById' return type */
export type findBookByIdResult = {
readonly author_id: (undefined | number);
readonly big_int: (undefined | bigint);
readonly categories: (undefined | categoryArray);
readonly id: number;
readonly meta: (undefined | arrayJSON_t);
readonly name: (undefined | string);
readonly rank: (undefined | number)
};

/** 'FindBookById' query type */
export type findBookByIdQuery = { readonly params: findBookByIdParams; readonly result: findBookByIdResult };

/** 'Query1' parameters type */
export type query1Params = { readonly notification: query1Params_notification };
export type query1Params = { readonly authorName: string };

/** 'Query1' return type */
export type query1Result = void;
export type query1Result = {
readonly author_id: (undefined | number);
readonly big_int: (undefined | bigint);
readonly categories: (undefined | categoryArray);
readonly id: number;
readonly meta: (undefined | arrayJSON_t);
readonly name: (undefined | string);
readonly rank: (undefined | number)
};

/** 'Query1' query type */
export type query1Query = { readonly params: query1Params; readonly result: query1Result };
Expand All @@ -47,39 +66,36 @@ export type query2Result = void;
/** 'Query2' query type */
export type query2Query = { readonly params: query2Params; readonly result: query2Result };

export type query3Params_notification = {
readonly payload?: JSON_t;
readonly user_id?: number;
readonly type: (undefined | notification_type)
};

/** 'Query3' parameters type */
export type query3Params = { readonly authorName: string };
export type query3Params = { readonly notification: query3Params_notification };

/** 'Query3' return type */
export type query3Result = {
readonly author_id: (undefined | number);
readonly big_int: (undefined | bigint);
readonly categories: (undefined | categoryArray);
readonly id: number;
readonly meta: (undefined | arrayJSON_t);
readonly name: (undefined | string);
readonly rank: (undefined | number)
};
export type query3Result = void;

/** 'Query3' query type */
export type query3Query = { readonly params: query3Params; readonly result: query3Result };

/** 'FindBookById' parameters type */
export type findBookByIdParams = { readonly id?: number };
/** Returns an array of all matched results. */
export const FindBookById_many: (_1:PgTyped_Pg_Client_t, _2:findBookByIdParams) => Promise<findBookByIdResult[]> = BookService__sqlJS.FindBookById.many as any;

/** 'FindBookById' return type */
export type findBookByIdResult = {
readonly author_id: (undefined | number);
readonly big_int: (undefined | bigint);
readonly categories: (undefined | categoryArray);
readonly id: number;
readonly meta: (undefined | arrayJSON_t);
readonly name: (undefined | string);
readonly rank: (undefined | number)
};
/** Returns exactly 1 result. Returns `None` if more or less than exactly 1 result is returned. */
export const FindBookById_one: (_1:PgTyped_Pg_Client_t, _2:findBookByIdParams) => Promise<(undefined | findBookByIdResult)> = BookService__sqlJS.FindBookById.one as any;

/** 'FindBookById' query type */
export type findBookByIdQuery = { readonly params: findBookByIdParams; readonly result: findBookByIdResult };
/** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */
export const FindBookById_expectOne: (_1:PgTyped_Pg_Client_t, _2:findBookByIdParams, errorMessage:(undefined | string)) => Promise<
{ TAG: "Ok"; _0: findBookByIdResult }
| { TAG: "Error"; _0: string }> = BookService__sqlJS.FindBookById.expectOne as any;

/** Executes the query, but ignores whatever is returned by it. */
export const FindBookById_execute: (_1:PgTyped_Pg_Client_t, _2:findBookByIdParams) => Promise<void> = BookService__sqlJS.FindBookById.execute as any;

export const findBookById: (params:findBookByIdParams, client:PgTyped_Pg_Client_t) => Promise<findBookByIdResult[]> = BookService__sqlJS.findBookById as any;

/** Returns an array of all matched results. */
export const Query1_many: (_1:PgTyped_Pg_Client_t, _2:query1Params) => Promise<query1Result[]> = BookService__sqlJS.Query1.many as any;
Expand Down Expand Up @@ -129,22 +145,6 @@ export const Query3_execute: (_1:PgTyped_Pg_Client_t, _2:query3Params) => Promis

export const query3: (params:query3Params, client:PgTyped_Pg_Client_t) => Promise<query3Result[]> = BookService__sqlJS.query3 as any;

/** Returns an array of all matched results. */
export const FindBookById_many: (_1:PgTyped_Pg_Client_t, _2:findBookByIdParams) => Promise<findBookByIdResult[]> = BookService__sqlJS.FindBookById.many as any;

/** Returns exactly 1 result. Returns `None` if more or less than exactly 1 result is returned. */
export const FindBookById_one: (_1:PgTyped_Pg_Client_t, _2:findBookByIdParams) => Promise<(undefined | findBookByIdResult)> = BookService__sqlJS.FindBookById.one as any;

/** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */
export const FindBookById_expectOne: (_1:PgTyped_Pg_Client_t, _2:findBookByIdParams, errorMessage:(undefined | string)) => Promise<
{ TAG: "Ok"; _0: findBookByIdResult }
| { TAG: "Error"; _0: string }> = BookService__sqlJS.FindBookById.expectOne as any;

/** Executes the query, but ignores whatever is returned by it. */
export const FindBookById_execute: (_1:PgTyped_Pg_Client_t, _2:findBookByIdParams) => Promise<void> = BookService__sqlJS.FindBookById.execute as any;

export const findBookById: (params:findBookByIdParams, client:PgTyped_Pg_Client_t) => Promise<findBookByIdResult[]> = BookService__sqlJS.findBookById as any;

export const FindBookById: {
/** Returns exactly 1 result. Returns `Error` (with an optionally provided `errorMessage`) if more or less than exactly 1 result is returned. */
expectOne: (_1:PgTyped_Pg_Client_t, _2:findBookByIdParams, errorMessage:(undefined | string)) => Promise<
Expand Down
Loading

0 comments on commit 9aef10a

Please sign in to comment.