2017 © Pedro Peláez
 

library dop

An immutable API on top of PDO to compose and execute SQL statements

image

morris/dop

An immutable API on top of PDO to compose and execute SQL statements

  • Monday, January 2, 2017
  • by morris
  • Repository
  • 1 Watchers
  • 5 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 3 % Grown

The README.md

DOP

Build Status Test Coverage, (*1)

DOP is an immutable API on top of PDO to compose and execute SQL statements., (*2)

  • Extended parameters (::param and ??) allow binding to arbitrary values like arrays, null and SQL fragments.
  • Provides helpers for writing common queries, e.g. selects, inserts, updates, deletes.
  • Tested with SQLite, PostgreSQL, and MySQL.

Installation

DOP requires PHP >= 5.3.0 and PDO. Install via composer:, (*3)

composer require morris/dop

Usage

// Connect to a database
$pdo = new PDO('sqlite:blog.sqlite3');
$dop = new Dop\Connection($pdo);

// Find posts by author IDs using DOP parametrization
$authorIds = [1, 2, 3];
$orderByTitle = $dop('ORDER BY title ASC');
$posts = $dop(
    'SELECT * FROM post WHERE author_id IN (??) ??',
    [$authorIds, $orderByTitle]
)->fetchAll();

// Find published posts using DOP helpers for common queries
$posts = $dop->query('post')->where('is_published = ?', [1])->fetchAll();

// Get categorizations of posts using DOP's map function
$categorizations = $dop(
    'SELECT * FROM categorization WHERE post_id IN (??)',
    [$dop->map($posts, 'id')]
)->fetchAll();

// Find posts with more than 3 categorizations using a sub-query as a parameter
$catCount = $dop('SELECT COUNT(*) FROM categorization WHERE post_id = post.id');
$posts = $dop(
    'SELECT * FROM post WHERE (::catCount) >= 3',
    ['catCount' => $catCount]
)->fetchAll();

Internally, ?? and ::named parameters are resolved before statement preparation. Note that due to the current implementation using regular expressions, you should never use quoted strings directly. Always use bound parameters., (*4)

Reference

See API.md for a complete API reference., (*5)

Contributors

Thanks!, (*6)

The Versions

02/01 2017

dev-master

9999999-dev https://github.com/morris/dop

An immutable API on top of PDO to compose and execute SQL statements

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

database sql pdo dop

02/01 2017

v0.2.0

0.2.0.0 https://github.com/morris/dop

An immutable API on top of PDO to compose and execute SQL statements

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

database sql pdo dop

11/11 2016

v0.1.2

0.1.2.0 https://github.com/morris/dop

An immutable API on top of PDO to compose and execute SQL statements

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

database sql pdo dop

25/10 2016

v0.1.1

0.1.1.0 https://github.com/morris/dop

An immutable API on top of PDO to compose and execute SQL statements

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

database sql pdo dop

23/10 2016

v0.1.0

0.1.0.0 https://github.com/morris/dop

An immutable API on top of PDO to compose and execute SQL statements

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

database sql pdo dop