forked from adelsz/pgtyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
35 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
const sql = (_: TemplateStringsArray) => null; | ||
import sql from "@pg-typed/query"; | ||
import { | ||
ISelectAllBooksParams, ISelectAllBooksResult, | ||
IDeleteBooksResult, IDeleteBooksParams, | ||
} from "./queries.types"; | ||
|
||
export const SELECT_ALL_BOOKS = sql`select * from books`; | ||
export const selectAllBooks = sql< | ||
ISelectAllBooksResult, ISelectAllBooksParams | ||
>`select * from books`; | ||
|
||
export const DELETE_BOOKS = sql`delete from books * where id = $id`; | ||
export const deleteBooks = sql< | ||
IDeleteBooksResult, IDeleteBooksParams | ||
>`delete from books * where id = $id`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
/** Types generated for queries found in "./src/books/queries.ts" */ | ||
/** Types generated for queries found in "src/books/queries.ts" */ | ||
|
||
/** 'SELECT_ALL_BOOKS' parameters type */ | ||
/** 'selectAllBooks' parameters type */ | ||
export type ISelectAllBooksParams = void; | ||
|
||
/** 'SELECT_ALL_BOOKS' return type */ | ||
/** 'selectAllBooks' return type */ | ||
export interface ISelectAllBooksResult { | ||
id: string; | ||
name: string | null; | ||
uid: string | null; | ||
} | ||
|
||
/** 'DELETE_BOOKS' parameters type */ | ||
/** 'deleteBooks' parameters type */ | ||
export interface IDeleteBooksParams { | ||
id: string | null; | ||
} | ||
|
||
/** 'DELETE_BOOKS' return type */ | ||
/** 'deleteBooks' return type */ | ||
export type IDeleteBooksResult = void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import sql from "@pg-typed/query"; | ||
import { ISelectAllUsersParams, ISelectAllUsersResult } from "./queries.types"; | ||
import { | ||
ISelectAllUsersParams, ISelectAllUsersResult, | ||
IInsertUsersParams, IInsertUsersResult, | ||
ISelectUserIdsParams, ISelectUserIdsResult, | ||
} from "./queries.types"; | ||
|
||
export const selectAllUsers = sql<ISelectAllUsersResult, ISelectAllUsersParams>`select id, name from users where age in $$ages`; | ||
export const selectAllUsers = sql< | ||
ISelectAllUsersResult, ISelectAllUsersParams | ||
>`select id, name from users where age in $$ages`; | ||
|
||
export const insertUsers = sql`insert into users (name, age) values $users(name, age)`; | ||
export const insertUsers = sql< | ||
IInsertUsersResult, IInsertUsersParams | ||
>`insert into users (name, age) values $users(name, age) returning id, name`; | ||
|
||
export const selectUserIds = sql`select id, note, age from users where id = $id and age = $age`; | ||
export const selectUserIds = sql< | ||
ISelectUserIdsResult, ISelectUserIdsParams | ||
>`select id from users where id = $id and age = $age`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters