Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9e8f9f5
feat: added where not null methods
anton-panasenko-k Jul 6, 2022
b127828
feat: up version
anton-panasenko-k Jul 6, 2022
77b9e46
Merge pull request #1 from Admin-149/feature/add-not-null
wowDaiver Jul 6, 2022
3434ad1
add catch method
wowDaiver Aug 19, 2022
1d4cdfb
multiply leftJoin
wowDaiver Sep 25, 2022
bdd5425
where skipEscape
wowDaiver Sep 25, 2022
fea0c53
conflictDoUpdate, conflictDoNothing
wowDaiver Oct 13, 2022
9406a94
added where braces for complex conditions
anton-panasenko-k Jan 13, 2023
822a1db
Merge pull request #2 from wowDaiver/feature/where-braces
wowDaiver Jan 13, 2023
e927b6a
Added .andWhereNotIn
wowDaiver Jan 27, 2023
36c3f5f
Added .setEscape
wowDaiver Jan 27, 2023
3d6f590
Added return deleted rows
anton-panasenko-k Mar 5, 2024
8b46876
Merge pull request #3 from wowDaiver/feature/returning-deleted-rows
wowDaiver Mar 6, 2024
07a5c5a
Added options getLogDuration
wowDaiver May 29, 2024
cc85216
Expand leftJoin to and clause
wowDaiver Jun 4, 2024
9584a4c
Added having
Nov 15, 2024
5b31067
Added having
Nov 15, 2024
4f7ae62
Remove skipEscape in having
Nov 15, 2024
990e149
Merge pull request #4 from wowDaiver/feature/having
DevAndr Nov 15, 2024
4b384eb
Fix ordering having of sql query during conversion
Nov 15, 2024
1cb06b0
Merge pull request #5 from wowDaiver/feature/fix-ordering-having
DevAndr Nov 18, 2024
7b8e9ae
Fix added skipEscape for having
Nov 18, 2024
81b9b75
Merge pull request #6 from wowDaiver/feature/having-skip-escape
DevAndr Nov 18, 2024
f8df3aa
add types
wowDaiver Dec 2, 2024
2dc0b00
Added sub queries
Dec 2, 2024
b94c4e7
Added type and up version
Dec 3, 2024
1f23e48
Merge pull request #7 from wowDaiver/feature/add_scope_with
wowDaiver Dec 3, 2024
c41f304
1.0.2 trx
AlexJVX Apr 22, 2026
b009faa
1.0.3 added parallel
AlexJVX Apr 22, 2026
f7510f1
1.0.3 added parallel
AlexJVX Apr 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,54 @@ await pdo
.where('id', '>', 1)
.execute();
```

###### Transactions

```aidl
await pdo.transaction(async (trxPdo) => {
const user = await trxPdo
.select()
.from('users')
.where('uid', '=', 1)
.forUpdate()
.first()
.execute();

await trxPdo
.update({
name: 'Updated'
})
.table('users')
.where('uid', '=', user.uid)
.execute();
});
```

###### Row Locks

```aidl
const row = await pdo
.select()
.from('jobs')
.where('status', '=', 'pending')
.forUpdate()
.skipLocked()
.first()
.execute();
```

Available helpers:

- `forUpdate()`
- `forShare()`
- `skipLocked()`
- `noWait()`
- `first()`
- `returningOne()`

###### Fork / withClient

```aidl
const trxPdo = pdo.withClient(trx);
const isolatedBuilder = pdo.fork();
```
118 changes: 118 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import postgres = require("postgres");

interface IPdoOptions {
escapeCb?: (sqlUnsavedQuery: string) => string;
unescapeCb?: (sqlUnsavedQuery: string) => string;
getLogDuration?: (query: string, durationMs: number) => void;
}

export class Pdo<T extends { [name: string]: unknown } = any> {
client: postgres.Sql<T>;
escape: (sqlUnsavedQuery: string) => string;

unescape: (sqlUnsavedQuery: string) => string;

constructor(client: postgres.Sql<T>, options: IPdoOptions)

catch(fn: (error: any) => void): Pdo<T>;

setEscape(escape?: (sqlUnsavedQuery: string) => string): Pdo<T>;

withClient(client: postgres.Sql<T> | postgres.TransactionSql<T>): Pdo<T>;

fork(client?: postgres.Sql<T> | postgres.TransactionSql<T>): Pdo<T>;

transaction<TResult>(
fn: (trxPdo: Pdo<T>, trx: postgres.TransactionSql<T>) => Promise<TResult> | TResult
): Promise<TResult>;

clean() : void

select(select?: string[]): Pdo<T>

from(table: string): Pdo<T>


update(pairs: { [key: string]: any } | null): Pdo<T>

set(pairs: { [key: string]: any } ): Pdo<T>;

table(table: string): Pdo<T>;

insert(columns: { [key: string]: any } | string[] | null): Pdo<T>;

returning(id: string | string[]): Pdo<T>;

columns(columns: string[]): Pdo<T>;

values(values: string[]): Pdo<T>;

into(table: string): Pdo<T>;

delete(table: string): Pdo<T>;

leftJoin(joinTable: string, field1: string, cond: string, field2: string, clause?: string, condWhere?: string, value?: any): Pdo<T>;

where(clause: string, cond: string, value: string, skipEscape?: boolean): Pdo<T>;

whereIsNull(clause: string): Pdo<T>;

whereIsNotNull(clause: string): Pdo<T>;

orWhereIsNull(clause: string): Pdo<T>;

orWhereIsNotNull(clause: string): Pdo<T>;

andWhereIsNull(clause: string): Pdo<T>;

andWhereIsNotNull(clause: string): Pdo<T>;

andWhere(clause: string, cond: string, value: string): Pdo<T>;

orWhere(clause: string, cond: string, value: string): Pdo<T>;

whereIn(clause: string, arr: string[]): Pdo<T>;

andWhereIn(clause:string, arr: string[]): Pdo<T>;

andWhereNotIn(clause: string, arr: string[]): Pdo<T>;

andWithBrace() : Pdo<T>;

orWithBrace() : Pdo<T>;

closeBrace() : Pdo<T>;

having(clause: string, cond: string, value: string, skipEscape?: boolean): Pdo<T>;

conflictDoNothing(): Pdo<T>;

conflictDoUpdate(clause: string, pairs: { [key: string]: any }): Pdo<T>;

groupBy(groupBy: string): Pdo<T>;

orderBy(column: string, direction: 'DESC' | 'ASC'): Pdo<T>;

limit(limit: number, offset?: number): Pdo<T>;

with(subQueries: string | string[]): Pdo<T>;

forUpdate(): Pdo<T>;

forShare(): Pdo<T>;

skipLocked(): Pdo<T>;

noWait(): Pdo<T>;

first(): Pdo<T>;

returningOne(id: string | string[]): Pdo<T>;

escapeData(value: any): string;
join(arr: string[]): string;

getQuery(): string | undefined;

execute(): Promise<T[] | T | undefined>;
}
Loading