Fix a bug for image proxy and update dependencies

This commit is contained in:
Frédéric Guillot 2014-12-29 16:52:36 -05:00
parent 3fe424999f
commit c43d9dd773
12 changed files with 213 additions and 105 deletions

View File

@ -88,5 +88,5 @@ Router\get_action('proxy', function() {
}
Response\content_type($type);
echo $content;
Response\raw($content);
});

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e::getLoader();
return ComposerAutoloaderInitdeb23075faf85ef9ce52dd731739836e::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e
class ComposerAutoloaderInitdeb23075faf85ef9ce52dd731739836e
{
private static $loader;
@ -19,9 +19,9 @@ class ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitdeb23075faf85ef9ce52dd731739836e', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitdeb23075faf85ef9ce52dd731739836e', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
@ -42,14 +42,14 @@ class ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e
$includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) {
composerRequireafa19cf4aabbde48e28a8081b9102b7e($file);
composerRequiredeb23075faf85ef9ce52dd731739836e($file);
}
return $loader;
}
}
function composerRequireafa19cf4aabbde48e28a8081b9102b7e($file)
function composerRequiredeb23075faf85ef9ce52dd731739836e($file)
{
require $file;
}

View File

@ -77,84 +77,6 @@
"description": "A simple Json-RPC client/server library that just works",
"homepage": "https://github.com/fguillot/JsonRPC"
},
{
"name": "fguillot/picodb",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoDb.git",
"reference": "ebe721de0002b7ff86b7f66df0065224bf896eb2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoDb/zipball/ebe721de0002b7ff86b7f66df0065224bf896eb2",
"reference": "ebe721de0002b7ff86b7f66df0065224bf896eb2",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2014-11-22 04:15:43",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoDb": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"WTFPL"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Minimalist database query builder",
"homepage": "https://github.com/fguillot/picoDb"
},
{
"name": "fguillot/picofarad",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoFarad.git",
"reference": "df30333d5bf3b02f8f654c988c7c43305d5e6662"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoFarad/zipball/df30333d5bf3b02f8f654c988c7c43305d5e6662",
"reference": "df30333d5bf3b02f8f654c988c7c43305d5e6662",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2014-11-01 15:01:02",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoFarad": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Unlicense"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Minimalist micro-framework",
"homepage": "https://github.com/fguillot/picoFarad"
},
{
"name": "fguillot/picofeed",
"version": "dev-master",
@ -193,5 +115,83 @@
],
"description": "Modern library to write or read feeds (RSS/Atom)",
"homepage": "http://fguillot.github.io/picoFeed"
},
{
"name": "fguillot/picodb",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoDb.git",
"reference": "5d1d8d6e898975fc30a241614d9bf06d5728db7d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoDb/zipball/5d1d8d6e898975fc30a241614d9bf06d5728db7d",
"reference": "5d1d8d6e898975fc30a241614d9bf06d5728db7d",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2014-12-26 17:10:34",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoDb": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"WTFPL"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Minimalist database query builder",
"homepage": "https://github.com/fguillot/picoDb"
},
{
"name": "fguillot/picofarad",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoFarad.git",
"reference": "070e1a90d71f403e75ac5464109eb7904daed9f3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoFarad/zipball/070e1a90d71f403e75ac5464109eb7904daed9f3",
"reference": "070e1a90d71f403e75ac5464109eb7904daed9f3",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2014-12-29 21:34:25",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoFarad": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Unlicense"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Minimalist micro-framework",
"homepage": "https://github.com/fguillot/picoFarad"
}
]

View File

@ -1,7 +1,7 @@
PicoDb
======
PicoDb is a minimalist database query builder for PHP
PicoDb is a minimalist database query builder for PHP.
**It's not an ORM**.
Features
@ -23,14 +23,14 @@ Requirements
Todo
----
- Add driver for Postgresql
- Add support for Distinct...
- Add support for Distinct and group by
Documentation
-------------
## Connect to your database
```php
use PicoDb\Database;
// Sqlite driver
@ -46,29 +46,38 @@ Documentation
'database' => 'my_db_name',
'charset' => 'utf8',
));
```
## Execute a SQL request
```php
$db->execute('CREATE TABLE toto (column1 TEXT)');
```
## Insert some data
```php
$db->table('toto')->save(['column1' => 'hey']);
```
## Transations
```php
$db->transaction(function($db) {
$db->table('toto')->save(['column1' => 'foo']);
$db->table('toto')->save(['column1' => 'bar']);
});
```
## Fetch all data
```php
$records = $db->table('toto')->findAll();
foreach ($records as $record) {
var_dump($record['column1']);
}
```
## Update something
@ -78,111 +87,158 @@ You just need to add a condition to perform an update.
## Remove rows
```php
$db->table('toto')->lowerThan('column1', 10)->remove();
```
## Sorting
```php
$db->table('toto')->asc('column1')->findAll();
```
or
```php
$db->table('toto')->desc('column1')->findAll();
```
## Limit and offset
```php
$db->table('toto')->limit(10)->offset(5)->findAll();
```
## Fetch only some columns
```php
$db->table('toto')->columns('column1', 'column2')->findAll();
```
## Conditions
### Equals condition
```php
$db->table('toto')
->equals('column1', 'hey')
->findAll();
```
or
```php
$db->table('toto')
->eq('column1', 'hey')
->findAll();
```
Yout got: 'SELECT * FROM toto WHERE column1=?'
### IN condition
```php
$db->table('toto')
->in('column1', ['hey', 'bla'])
->findAll();
```
### Like condition
Case-sensitive (only Mysql and Postgres):
```php
$db->table('toto')
->like('column1', '%hey%')
->like('column1', '%Foo%')
->findAll();
```
Not case-sensitive:
```php
$db->table('toto')
->ilike('column1', '%foo%')
->findAll();
```
### Lower than
```php
$db->table('toto')
->lowerThan('column1', 2)
->findAll();
```
or
```php
$db->table('toto')
->lt('column1', 2)
->findAll();
```
### Lower than or equals
```php
$db->table('toto')
->lowerThanOrEquals('column1', 2)
->findAll();
```
or
```php
$db->table('toto')
->lte('column1', 2)
->findAll();
```
### Greater than
```php
$db->table('toto')
->greaterThan('column1', 3)
->findAll();
```
or
```php
$db->table('toto')
->gt('column1', 3)
->findAll();
```
### Greater than or equals
```php
$db->table('toto')
->greaterThanOrEquals('column1', 3)
->findAll();
```
or
```php
$db->table('toto')
->gte('column1', 3)
->findAll();
```
### Multiple conditions
Each condition is joined by a AND.
```php
$db->table('toto')
->like('column2', '%toto')
->gte('column1', 3)
->findAll();
```
How to make a OR condition:
```php
$db->table('toto')
->beginOr()
->like('column2', '%toto')
@ -190,6 +246,7 @@ How to make a OR condition:
->closeOr()
->eq('column5', 'titi')
->findAll();
```
## Schema migrations
@ -201,6 +258,7 @@ How to make a OR condition:
Example:
```php
namespace Schema;
function version_1($pdo)
@ -225,6 +283,7 @@ Example:
)
');
}
```
### Run schema update automatically
@ -235,6 +294,7 @@ Example:
Example:
```php
$last_schema_version = 5;
$db = new PicoDb\Database(array(
@ -250,11 +310,13 @@ Example:
die('Unable to migrate database schema.');
}
```
### Use a singleton to handle database instances
Setup a new instance:
```php
PicoDb\Database::bootstrap('myinstance', function() {
$db = new PicoDb\Database(array(
@ -269,7 +331,10 @@ Setup a new instance:
die('Unable to migrate database schema.');
}
});
```
Get this instance anywhere in your code:
```php
PicoDb\Database::get('myinstance')->table(...)
```

View File

@ -38,7 +38,6 @@ class Mysql extends PDO
}
}
public function getSchemaVersion()
{
$this->exec("CREATE TABLE IF NOT EXISTS `".$this->schema_table."` (`version` INT DEFAULT '0')");
@ -57,22 +56,29 @@ class Mysql extends PDO
return 0;
}
public function setSchemaVersion($version)
{
$rq = $this->prepare('UPDATE `'.$this->schema_table.'` SET `version`=?');
$rq->execute(array($version));
}
public function getLastId()
{
return $this->lastInsertId();
}
public function escapeIdentifier($value)
{
return '`'.$value.'`';
}
public function operatorLikeCaseSensitive()
{
return 'LIKE BINARY';
}
public function operatorLikeNotCaseSensitive()
{
return 'LIKE';
}
}

View File

@ -9,7 +9,6 @@ class Postgres extends PDO
{
private $schema_table = 'schema_version';
public function __construct(array $settings)
{
$required_atttributes = array(
@ -34,7 +33,6 @@ class Postgres extends PDO
}
}
public function getSchemaVersion()
{
$this->exec("CREATE TABLE IF NOT EXISTS ".$this->schema_table." (version SMALLINT DEFAULT 0)");
@ -53,14 +51,12 @@ class Postgres extends PDO
return 0;
}
public function setSchemaVersion($version)
{
$rq = $this->prepare('UPDATE '.$this->schema_table.' SET version=?');
$rq->execute(array($version));
}
public function getLastId()
{
$rq = $this->prepare('SELECT LASTVAL()');
@ -68,9 +64,18 @@ class Postgres extends PDO
return $rq->fetchColumn();
}
public function escapeIdentifier($value)
{
return $value;
}
public function operatorLikeCaseSensitive()
{
return 'LIKE';
}
public function operatorLikeNotCaseSensitive()
{
return 'ILIKE';
}
}

View File

@ -24,7 +24,6 @@ class Sqlite extends PDO
$this->exec('PRAGMA foreign_keys = ON');
}
public function getSchemaVersion()
{
$rq = $this->prepare('PRAGMA user_version');
@ -38,21 +37,28 @@ class Sqlite extends PDO
return 0;
}
public function setSchemaVersion($version)
{
$this->exec('PRAGMA user_version='.$version);
}
public function getLastId()
{
return $this->lastInsertId();
}
public function escapeIdentifier($value)
{
return '"'.$value.'"';
}
public function operatorLikeCaseSensitive()
{
return 'LIKE';
}
public function operatorLikeNotCaseSensitive()
{
return 'LIKE';
}
}

View File

@ -376,7 +376,19 @@ class Table
break;
case 'like':
$sql = sprintf('%s LIKE ?', $this->db->escapeIdentifier($column));
$sql = sprintf(
'%s %s ?',
$this->db->escapeIdentifier($column),
$this->db->getConnection()->operatorLikeCaseSensitive()
);
break;
case 'ilike':
$sql = sprintf(
'%s %s ?',
$this->db->escapeIdentifier($column),
$this->db->getConnection()->operatorLikeNotCaseSensitive()
);
break;
case 'eq':

View File

@ -151,6 +151,12 @@ Response\xml('<xml ... >');
Response\binary($my_file_content);
```
### Send a raw response (no content-type)
```php
Response\raw($content);
```
### Force browser download
```php

View File

@ -90,6 +90,14 @@ function js($data, $status_code = 200)
}
function raw($data, $status_code = 200)
{
status($status_code);
echo $data;
exit;
}
function binary($data, $status_code = 200)
{
status($status_code);