> ## Documentation Index
> Fetch the complete documentation index at: https://tygress.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Client methods

This is an overview of the basic methods available on the <Tooltip tip="PostgresClient class, main interface with Tygress">client</Tooltip>.

# select

Executes a SELECT query, returning entitites as a result

```typescript theme={null}
// SQL: SELECT u.* FROM users u 
await DB.select(Users, {})

// [
//   Users {
//    id: 5,
//    firstName: 'John',
//    lastName: 'Doe',
//  }
// ]
```

# selectOne

Executes a SELECT query, returning the first entity or `null`.\
Does **not** add a `LIMIT 1` to your SQL query so the whole result will be retrieved from Postgres.

```typescript theme={null}
// SQL: SELECT u.* FROM users u 
await DB.selectOne(Users, {})

// Users {
//  id: 5,
//  firstName: 'John',
//  lastName: 'Doe',
// }
```

# insert

Runs an INSERT statement using the provided values.\
Optionally returns inserted rows as <Tooltip tip="Classes and decorators that define your schema">entities</Tooltip>.

```typescript theme={null}
// SQL: INSERT INTO users (first_name, last_name) (VALUES ('John', 'Doe'))
await DB.insert(Users, [
  {
    firstName: "John",
    lastName: "Doe",
  },
]);
// [
//   Users { 
//    firstName: "John", 
//    lastName: "Doe" 
//   }
// ]
```

# update

Executes an UPDATE statement using the provided values and WHERE condition. \
Optionally returns updated rows as <Tooltip tip="Classes and decorators that define your schema">entities</Tooltip>

```typescript theme={null}
// SQL: UPDATE users SET first_name = 'Joe' WHERE first_name = 'John'
await DB.update(Users, [
  {
    firstName: "Joe",
  },
  {
    firstName: "John"
  }
]);
// [
//   Users { 
//    firstName: "Joe", 
//    lastName: "Doe" 
//   }
// ]
```

# delete

Executes a DELETE statement using the provided WHERE condition. \
Optionally returns deleted rows as <Tooltip tip="Classes and decorators that define your schema">entities</Tooltip>

```typescript theme={null}
// SQL: DELETE FROM users WHERE first_name = 'Joe'
await DB.insert(Users, [
  {
    firstName: "Joe",
  },
]);
// []
// No rows left 😭
```

# query

Executes the exact `SQL` string passed as argument. Supports params referenced by `$1, $2...` in `SQL`, values can be passed as second argument.
Returns result directly from pg driver.

```typescript theme={null}
await DB.query("SELECT 1 AS number");
// {
//   rows: [
//     {"number": 1}
//   ]
// }
```
