2.0.18 • Published 9 months ago

@sodra/pg v2.0.18

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

@sodra/pg

Install

npm i @sodra/pg

Usage

import PG from '@sodra/pg'

const pg = new PG({
  connectionString: ...,
})

type User = {
  user_id: string
}

const { rows } = await pg.query<User>(`SELECT * FROM users WHERE user_id=$userId`, { userId })

Simple queries

// SELECT * FROM users WHERE user_id=$userId
pg.select('users', { userId })

// SELECT name FROM users WHERE user_id=$userId
pg.select('users', 'name', { userId })

// SELECT count(1) FROM users WHERE user_id=$userId
pg.count('users', { userId })

// INSERT INTO users (user_id, name) VALUES ($userId, $userName)
pg.insert('users', { userId, name })

// UPDATE users SET name=$name WHERE user_id=$userId
pg.update('users', { name }, { userId })

// DELETE FROM users WHERE user_id=$userId
pg.del('users', { userId })

Transactions

const batch = pg.beginBatch()

batch.insert('...'),
batch.update('...'),
batch.del('...')

await batch.exec()
2.0.16

9 months ago

2.0.17

9 months ago

2.0.18

9 months ago

2.0.15

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.13

1 year ago

2.0.5

1 year ago

2.0.14

1 year ago

2.0.4

1 year ago

2.0.11

1 year ago

2.0.7

1 year ago

2.0.12

1 year ago

2.0.6

1 year ago

2.0.9

1 year ago

2.0.10

1 year ago

2.0.8

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago