PHPackages                             juanvladimir13/postgres-database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. juanvladimir13/postgres-database

ActiveLibrary[Database &amp; ORM](/categories/database)

juanvladimir13/postgres-database
================================

Conexion native to postgres

v0.1.7(1mo ago)11072MITPHPPHP ^7.4|^8.3

Since Dec 31Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/juanvladimir13/postgres-database)[ Packagist](https://packagist.org/packages/juanvladimir13/postgres-database)[ Docs](https://juanvladimir13.web.app/)[ RSS](/packages/juanvladimir13-postgres-database/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (9)Versions (7)Used By (2)

postgres-database
=================

[](#postgres-database)

A lightweight native PHP package for interacting with PostgreSQL databases. It provides a simple connection wrapper, an environment variable loader, and an Active Record-style base model for building data-driven applications with minimal overhead.

Features
--------

[](#features)

- **Environment Configuration**: `Dotenv` class to securely load database credentials (`DB_HOST`, `DB_PORT`, `DB_DATABASE`, `DB_USERNAME`, `DB_PASSWORD`) from `.env` files or environment variables.
- **PostgreSQL Connection Wrapper**: `Postgres` singleton class providing static methods for queries, inserts, updates, deletes, and fetch operations using associative arrays.
- **Active Record Base Model**: Abstract `Model` class that simplifies CRUD operations, supporting soft deletes, state management (`EDITABLE`), and standardized response formats. `find()`, `findAll()`, and `delete()` are unified — their behavior adapts based on the `SOFT_DELETE` flag.
- **Data Type Casting**: `DataType` constants for mapping request payloads to specific data types (int, float, string, boolean, utf-8, etc.).

Architecture
------------

[](#architecture)

```
src/
├── Dotenv.php              # Environment variable loader & connection string builder
├── Postgres.php            # Singleton wrapper over native PHP pg_* functions
├── Models/
│   ├── Model.php           # Abstract Active Record base class
│   └── DataType.php        # Data type constants for casting
├── Views/                  # Reserved for future view renderers

```

Quick Start
-----------

[](#quick-start)

```
use PGDatabase\Postgres;
use PGDatabase\Dotenv;

// Connection string is auto-generated from .env or environment
$connectionString = Dotenv::connection_string_pg();

// Fetch all rows
$users = Postgres::fetchAll('SELECT * FROM users');

// Fetch with parameters (safe from SQL injection)
$user  = Postgres::fetchAllParams('SELECT * FROM users WHERE id = $1', [1]);

// Insert and get the new ID
$id = Postgres::insert('users', ['name' => 'John', 'email' => 'john@example.com']);

// Update
Postgres::update('users', ['name' => 'Jane'], ['id' => 1]);

// Delete
Postgres::delete('users', ['id' => 1]);
```

Working with Models
-------------------

[](#working-with-models)

Create a model extending `PGDatabase\Models\Model`:

```
use PGDatabase\Models\Model;

class User extends Model
{
    protected $TABLE_NAME = 'users';
    protected $ORDER_BY_COLUMNS = 'id DESC';
    protected $EDITABLE = true;
    protected $SOFT_DELETE = true;

    public function setRequest(array $request): void
    {
        $this->id = (int)($request['id'] ?? 0);
        $this->setValues(self::extractDataValues([
            'name'  => ['datatype' => DataType::STRING],
            'email' => ['datatype' => DataType::STRING],
            'age'   => ['datatype' => DataType::INT],
        ], $request));
    }

    public function getData(): array
    {
        return $this->getValues();
    }
}

$user = new User();
$user->setRequest(['name' => 'John', 'email' => 'john@test.com', 'age' => 30]);
$result = $user->save(); // Insert
$result = $user->save(); // Update (id is set after first save)
```

Available Commands
------------------

[](#available-commands)

```
composer phpstan       # PHPStan static analysis (level 6)
composer psalm         # Psalm static analysis (level 8)
composer phpcs         # Code style check (PSR-12, summary)
composer phpcs-detail  # Code style check (PSR-12, detailed)
composer phpcs-fixer   # Auto-fix code style to PSR-12
composer test          # Run PHPUnit tests
```

Requirements
------------

[](#requirements)

- PHP ^7.4|^8.3
- ext-pgsql (native PostgreSQL extension)

License
-------

[](#license)

MIT

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance88

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~178 days

Recently: every ~223 days

Total

6

Last Release

59d ago

PHP version history (4 changes)0.1.3.x-devPHP ~7.1|~8.3

v0.1.5PHP ~7.4|~8.4

v0.1.6PHP ~7.4|~8.3

v0.1.7PHP ^7.4|^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5018770?v=4)[Juan Vladimir](/maintainers/juanvladimir13)[@juanvladimir13](https://github.com/juanvladimir13)

---

Top Contributors

[![juanvladimir13](https://avatars.githubusercontent.com/u/5018770?v=4)](https://github.com/juanvladimir13 "juanvladimir13 (14 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juanvladimir13-postgres-database/health.svg)

```
[![Health](https://phpackages.com/badges/juanvladimir13-postgres-database/health.svg)](https://phpackages.com/packages/juanvladimir13-postgres-database)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
