From 110c11dbb2ca00c5dda0853c131ed1672a734154 Mon Sep 17 00:00:00 2001 From: Joby Elliott Date: Sat, 29 Aug 2020 15:54:37 -0600 Subject: [PATCH] updated and simplified examples --- examples/example_factory.php | 37 ++++++++++++----------- examples/example_use.php | 50 +++++++++++++++++++++++++++++++ examples/mariadb.php | 52 -------------------------------- examples/mysql.php | 52 -------------------------------- examples/sqlite.php | 58 ------------------------------------ 5 files changed, 70 insertions(+), 179 deletions(-) create mode 100644 examples/example_use.php delete mode 100644 examples/mariadb.php delete mode 100644 examples/mysql.php delete mode 100644 examples/sqlite.php diff --git a/examples/example_factory.php b/examples/example_factory.php index 5f1801b..f1d119d 100644 --- a/examples/example_factory.php +++ b/examples/example_factory.php @@ -2,30 +2,33 @@ use Destructr\Factory; -class ExampleFactory extends Factory { +class ExampleFactory extends Factory +{ /** - * Example factory with a different schema, to index on random_data, but not - * by dso_type. - * - * Also uses a different column name for dso.id + * Example factory with a different schema, to index on random_data for faster searching */ protected $schema = [ 'dso.id' => [ - 'name'=>'dso_id_other_name', - 'type'=>'VARCHAR(16)', + 'name' => 'dso_id', //column name to be used + 'type' => 'VARCHAR(16)', //column type + 'index' => 'BTREE', //whether/how to index + 'unique' => true, //whether column should be unique + 'primary' => true, //whether column should be the primary key + ], + 'dso.type' => [ + 'name' => 'dso_type', + 'type' => 'VARCHAR(30)', 'index' => 'BTREE', - 'unique' => true, - 'primary' => true ], 'dso.deleted' => [ - 'name'=>'dso_deleted', - 'type'=>'INT', - 'index'=>'BTREE' + 'name' => 'dso_deleted', + 'type' => 'BIGINT', + 'index' => 'BTREE', ], 'random_data' => [ - 'name'=>'random_data', - 'type'=>'VARCHAR(100)', - 'index'=>'BTREE' - ] + 'name' => 'random_data', + 'type' => 'VARCHAR(64)', + 'index' => 'BTREE', + ], ]; -} \ No newline at end of file +} diff --git a/examples/example_use.php b/examples/example_use.php new file mode 100644 index 0000000..cb4ee91 --- /dev/null +++ b/examples/example_use.php @@ -0,0 +1,50 @@ +prepareEnvironment(); +$factory->updateEnvironment(); + +/* +Inserting a record + */ +$obj = $factory->create( + [ + 'dso.type'=>'foobar', + 'random_data' => md5(rand()) + ] +); +$obj->insert(); + +/* +Search by random data field, which is indexed due to the +ExampleFactory class' $schema property. + */ +$search = $factory->search(); +$search->where('${random_data} LIKE :q'); +$result = $search->execute(['q'=>'ab%']); +foreach($result as $r) { + var_dump($r->get()); +} diff --git a/examples/mariadb.php b/examples/mariadb.php deleted file mode 100644 index 3d88d6c..0000000 --- a/examples/mariadb.php +++ /dev/null @@ -1,52 +0,0 @@ -prepareEnvironment(); -$factory->updateEnvironment(); - -/* -The following can be uncommented to insert dummy records -into the given table. -*/ -// for($i = 0; $i < 10; $i++) { -// $obj = $factory->create( -// [ -// 'dso.type'=>'foobar', -// 'random_data' => md5(rand()) -// ] -// ); -// $obj->insert(); -// } - -/* -Search by random data field -*/ -$search = $factory->search(); -$search->where('${random_data} = :q'); -$result = $search->execute(['q'=>'rw7nivub9bhhh3t4']); - -/* -Search by dso.id, which is much faster because it's indexed -*/ -// $search = $factory->search(); -// $search->where('${dso.id} = :q'); -// $result = $search->execute(['q'=>'rw7nivub9bhhh3t4']); diff --git a/examples/mysql.php b/examples/mysql.php deleted file mode 100644 index 73d09b2..0000000 --- a/examples/mysql.php +++ /dev/null @@ -1,52 +0,0 @@ -prepareEnvironment(); -$factory->updateEnvironment(); - -/* -The following can be uncommented to insert dummy records -into the given table. -*/ -// for($i = 0; $i < 100; $i++) { -// $obj = $factory->create( -// [ -// 'dso.type'=>'foobar', -// 'random_data' => md5(rand()) -// ] -// ); -// $obj->insert(); -// } - -/* -Search by random data field -*/ -// $search = $factory->search(); -// $search->where('${random_data} = :q'); -// $result = $search->execute(['q'=>'rw7nivub9bhhh3t4']); - -/* -Search by dso.id, which is much faster because it's indexed -*/ -// $search = $factory->search(); -// $search->where('${dso.id} = :q'); -// $result = $search->execute(['q'=>'rw7nivub9bhhh3t4']); diff --git a/examples/sqlite.php b/examples/sqlite.php deleted file mode 100644 index b2a9f65..0000000 --- a/examples/sqlite.php +++ /dev/null @@ -1,58 +0,0 @@ -prepareEnvironment(); -$factory->updateEnvironment(); - -/* -The following can be uncommented to insert dummy records -into the given table. - */ -// ini_set('max_execution_time','0'); -// for($i = 0; $i < 10; $i++) { -// $obj = $factory->create( -// [ -// 'dso.type'=>'foobar', -// 'random_data' => md5(rand()) -// ] -// ); -// $obj->insert(); -// } - -/* -Search by random data field - */ -$search = $factory->search(); -$search->where('${random_data} LIKE :q'); -$result = $search->execute(['q'=>'%ab%']); -foreach($result as $r) { - var_dump($r->get()); - $r['random_data_2'] = md5(rand()); - $r->update(); -} - -/* -Search by dso.id, which is much faster because it's indexed - */ -// $search = $factory->search(); -// $search->where('${dso.id} = :q'); -// $result = $search->execute(['q'=>'rw7nivub9bhhh3t4']);