Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weierophinney/phlyql_resource
Toy PHP library for prototyping persistence for RESTful resources
https://github.com/weierophinney/phlyql_resource
Last synced: 15 days ago
JSON representation
Toy PHP library for prototyping persistence for RESTful resources
- Host: GitHub
- URL: https://github.com/weierophinney/phlyql_resource
- Owner: weierophinney
- Created: 2013-05-24T21:48:40.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-05-29T21:51:47.000Z (over 11 years ago)
- Last Synced: 2024-12-20T18:13:10.961Z (21 days ago)
- Language: PHP
- Size: 113 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Phly\SqliteResource
===================This is a "toy" library designed to make it easy to prototype persistence for
RESTful APIs. It essentially allows you to create a SQLite database with the
following columns:- **id**, which represents an identifier. This is autogenerated by the library,
and will be a 32 character hexidecimal string (i.e. characters 0-9 and a-f).
- **data**, a JSON-encoded string representing a resource. This will always be
returned as an associative array.Installation
------------The easiest way to install is via [Composer](http://getcomposer.org). Download
the composer installer, and create a `composer.json` file as follows:```json
{
"minimum-stability": "dev",
"require": {
"phly/sqlite-resource": "dev-master"
}
}
```Then run `composer install`.
Schema
------A schema is available in [schema.sqlite.sql](schema.sqlite.sql). Essentially:
```sql
CREATE TABLE IF NOT EXISTS collection (
id CHARACTER(32) PRIMARY KEY,
data BLOB NOT NULL
);
```Alter it as you see fit to change the table name.
Initialization
--------------In order to instantiate `Phly\SqliteResource\SqliteResource`, you will need an
instance of PDO. Typical instantiation will look like this:```php
use PDO;
use Phly\SqliteResource\SqliteResource;$pdo = new PDO('sqlite:/path/to/database.db');
$resource = new SqliteResource($pdo, 'table-name');
```API
---The API supports the following operations:
- **create(array $data)** - Inserts the resource into the database and returns
it, with a new "id" key with the newly created identifier.
- **fetch($id)** - Fetches the resource with the given identifier. If no
resource is found, an exception is thrown.
- **fetchAll($limit = null, $offset = null)** - Fetches all resources from the
database, returning an array of arrays. If a limit is given, returns only the
number of resources indicated; if an offset is given along with a limit,
returns resources from that offset
- **patch($id, array $data)** - Merges the provided `$data` with the record that
already exists in the database identified by `$id` and saves it. The merged
resource is returned.
- **update($id, array $data)** - Replaces the resource identified by `$id` with
the `$data`. Returns the resource.
- **delete($id)** - Deletes the resource identified by `$id`.Caveats
-------Do not use this in production. Use a document database, or a relational database
with a real schema that maps to the fields in your resources.LICENSE
=======This module is licensed using the BSD 2-Clause License:
```
Copyright (c) 2013, Matthew Weier O'Phinney
All rights reserved.Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```