# Introduction

**pry-pgadapter** is a FiveM resource that bridges FXServer resources with a **PostgreSQL** database. It is built on top of [node-postgres (pg)](https://node-postgres.com/) and exposes a familiar, battle-tested API surface compatible with `oxmysql`, `mysql-async`, and `ghmattimysql` — allowing you to migrate existing MySQL-based resources to PostgreSQL with minimal effort.

***

## Key Features

| Feature                   | Description                                                                            |
| ------------------------- | -------------------------------------------------------------------------------------- |
| PostgreSQL-native         | Full support for PostgreSQL via `node-postgres`. No MySQL emulation layer.             |
| Lua `PG` API              | Global `PG` object with sync (`await`) and async (callback) variants for every method. |
| PGBuilder                 | Fluent Lua query builder for type-safe, composable queries without raw SQL.            |
| TypeScript / JS client    | First-class `pgadapter` module for TypeScript resources.                               |
| Compatibility layer       | Drop-in replacement for `mysql-async` and `ghmattimysql` exports.                      |
| Named & positional params | Supports both `?` positional and `:name` / `@name` named placeholders.                 |
| JSONB support             | Native JSONB operators (`@>`, `jsonb_exists`) accessible from Lua and PGBuilder.       |
| Transactions              | Simple batch transactions and advanced manual `startTransaction`.                      |
| Query profiler            | Slow query detection with configurable threshold and in-game UI dashboard.             |
| Type casting              | Automatic conversion of PostgreSQL types to Lua/JS-native equivalents.                 |

***

## How It Works

pry-pgadapter runs as a server-side FXServer resource. It:

1. Reads the `pg_connection_string` convar at startup.
2. Creates a connection pool via `node-postgres`.
3. Exposes exports (`PG.query`, `PG.insert`, etc.) consumed by other resources.
4. Translates the MySQL-compatible API surface (`?` placeholders, callbacks) into native PostgreSQL wire protocol calls.

Other resources import the shared Lua library (`@pry-pgadapter/lib/PG.lua`) to access the `PG` global, or the TypeScript package for JS-based resources.

***

## License

[LGPL-3.0-or-later](https://www.gnu.org/licenses/lgpl-3.0.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://prysma-studio.gitbook.io/pry-pgadapter/overview/readme.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
