2017 © Pedro Peláez
 

library seed-catalog

Simple ORM.

image

onesimus-systems/seed-catalog

Simple ORM.

  • Sunday, October 25, 2015
  • by dragonrider23
  • Repository
  • 1 Watchers
  • 0 Stars
  • 112 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Seed Catalog

Build Status, (*1)

Seed Catalog is a simple database interface in PHP. It aims to make the most common interactions with the database easier. I've been using it for quite some time. I felt like it's about time I share it., (*2)

Seed Catalog is a fork of the Base project by erusev., (*3)

Features

  • Simple
  • Intuitive
  • Independent
  • Secure
  • Based on PDO
  • Tested in 5.3, 5.4, 5.5, 5.6 and HHVM

Installation

Include SC.php, Collection.php, and 'SCException.php' or install the composer package., (*4)

Examples

Connect to a database:, (*5)

# initialize the connection
# connect() will return false if connecting to the database fails.
# connect($dbtype, $host, $database, $username, $password)

$SC = new SC\SC();
$SC->connect('mysql', 'localhost', 'example', 'username', 'password');

# you can also give it a PDO object to use directly

$SC = new SC\SC($pdo);

Work with records:, (*6)

# read user 1
$SC->readItem('user', 1);
# update the username of user 1
$SC->updateItem('user', 1, ['username' => 'john.doe']);
# create a user
$SC->createItem('user', ['username' => 'jane.doe', 'email' => 'jane@example.com']);
# delete user 1
$SC->deleteItem('user', 1);

Work with collections:, (*7)

# read all users
$SC->find('user')->read();
# read the users that are marked as verified in a desc order
$SC->find('user')->whereEqual('is_verified', 1)->orderDesc('id')->read();
# read the user with the most reputation
$SC->find('user')->limit(1)->orderDesc('reputation')->readRecord();
# mark users 1 and 3 as verified
$SC->find('user')->whereIn('id', [1, 3])->update(['is_verified' => 1]);
# count the users that don't have a location
$SC->find('user')->whereNull('location')->count();
# plain sql conditions are also supported
$SC->find('user')->where('is_verified = ?', [1])->read();

Handle relationships:, (*8)

# read the users that have a featured post
$SC->find('user')->has('post')->whereEqual('post.is_featured', 1)->read();
# read the posts of user 1
$SC->find('post')->belongsTo('user')->whereEqual('user.id', 1)->read();
# read the posts that are tagged "php"
$SC->find('post')->hasAndBelongsTo('tag')->whereEqual('tag.name', 'php')->read();
# unconventional FK names are also supported
$SC->find('user')->has('post', 'author_id')->whereEqual('user.id', 1)->read();

Execute queries:, (*9)

# read all users
$SC->read('SELECT * FROM user');
# read user 1
$SC->readRecord('SELECT * FROM user WHERE id = ?', [1]);
# read the username of user 1
$SC->readField('SELECT username FROM user WHERE id = ?', [1]);
# read all usernames
$SC->readFields('SELECT username FROM user');
# update all users
$SC->update('UPDATE INTO user SET is_verified = ?', [1]);

Notes

  • Relationship methods require that table names are singular - ex: user instead of users.
  • Only tested with MySQL. It may work with Postgres and SQLite, but I haven't tested it yet.

The Versions

25/10 2015

dev-master

9999999-dev https://github.com/onesimus-systems/seed-catalog

Simple ORM.

  Sources   Download

MIT

The Development Requires

orm database pdo

11/10 2015

dev-develop

dev-develop https://github.com/onesimus-systems/seed-catalog

Simple ORM.

  Sources   Download

MIT

The Development Requires

orm database pdo

11/10 2015

1.1.0

1.1.0.0 https://github.com/onesimus-systems/seed-catalog

Simple ORM.

  Sources   Download

MIT

The Development Requires

orm database pdo

25/06 2015

1.0.1

1.0.1.0 https://github.com/onesimus-systems/seed-catalog

Simple ORM.

  Sources   Download

MIT

The Development Requires

orm database pdo

18/06 2015

1.0.0

1.0.0.0 https://github.com/onesimus-systems/seed-catalog

Simple ORM.

  Sources   Download

MIT

The Development Requires

orm database pdo

29/04 2015

0.2.0

0.2.0.0 https://github.com/erusev/base

Simple ORM.

  Sources   Download

MIT

orm database pdo

22/02 2015

0.1.0

0.1.0.0 https://github.com/erusev/base

Simple ORM.

  Sources   Download

MIT

orm database pdo