1. Go to this page and download the library: Download corneltek/lazyrecord library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
corneltek / lazyrecord example snippets
namespace YourApp\Model;
use LazyRecord\Schema;
class UserSchema extends Schema
{
public function schema()
{
$this->column('account')
->varchar(16);
$this->column('password')
->varchar(40)
->filter('sha1');
}
}
$config = new LazyRecord\ConfigLoader;
$config->load( __DIR__ . '/db/config/database.yml');
$config->init();
$user = new YourApp\Model\User;
$ret = $user->create(array('account' => 'guest', 'password' => '123123' ));
if ($ret->error ) {
echo $ret->message; // get the error message
if ($ret->exception) {
echo $ret->exception; // get the exception object
}
echo $ret; // __toString() is supported
}
$record = new MyApp\Model\User( 1 ); // select * from users where id = 1;
$record->name; // get "users.name" and inflate it.
$record->get('name');
$record->getValue('name');
foreach( $record as $column => $rawValue ) {
}
$author = new Author;
$ret = $author->create(array(
'name' => 'Foo'
));
if ( $ret->success ) {
echo 'created';
}
namespace LazyRecord\Schema\Mixin;
use LazyRecord\Schema\MixinDeclareSchema;
class MetadataMixinSchema extends MixinDeclareSchema
{
public function schema()
{
// ... define your schema here
}
public function fooMethod($record, $arg1, $arg2, $arg3, $arg4)
{
// ...
return ...;
}
}
$record = new FooModal;
$result = $record->fooMethod(1,2,3,4);
namespace User;
class UserSchema extends LazyRecord\Schema {
public function schema() {
// ...
}
public function bootstrap($model) {
// do something you want
}
}
use LazyRecord\Schema;
class UserSchema extends Schema {
public function schema() {
$this->writeTo('master');
$this->readFrom('slave');
}
}
use LazyRecord\Schema;
class UserSchema extends Schema {
public function schema() {
$this->using('master');
}
}
namespace User;
class Seed {
public static function seed() {
}
}
class AddUserColumn_1347451491 extends \LazyRecord\Migration\Migration {
public function upgrade() {
$this->importSchema(new TestApp\AuthorSchema);
$this->importSchema(new TestApp\AddressSchema);
// To upgrade with new schema:
$this->importSchema(new TestApp\AuthorBookSchema);
// To create index:
$this->createIndex($table,$indexName,$columnNames);
// To drop index:
$this->dropIndex($table,$indexName);
// To add a foreign key:
$this->addForeignKey($table,$columnName,$referenceTable,$referenceColumn = null)
// To drop table:
$this->dropTable('authors');
}
public function downgrade() {
$this->dropTable('authors');
$this->dropTable('addresses');
}
}
use LazyRecord\CollectionFilter\CollectionFilter;
$posts = new PostCollection;
$filter = new CollectionFilter($posts);
$filter->defineEqual('status', [ 'published', 'draft' ]); // valid values are 'published', 'draft'
$filter->defineContains('content');
$filter->defineRange('created_on', CollectionFilter::String );
$filter->defineInSet('created_by', CollectionFilter::Integer );
$collection = $filter->apply([
'status' => 'published', // get published posts
'content' => ['foo', 'bar'], // posts contains 'foo' and 'bar'
'created_on' => [ '2011-01-01', '2011-12-30' ], // posts between '2011-01-01' and '2011-12-30'
'created_by' => [1,2,3,4], // created by member 1, 2, 3, 4
]);
$collection = $filter->applyFromRequest('_filter_prefix_');
// use '_filter_' as the parameter prefix by default.
$collection = $filter->applyFromRequest();