1. Go to this page and download the library: Download marcojetson/freckle 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/ */
foreach ($connection->generate() as $mapping) {
file_put_contents($mapping->entityClass() . '.php', (string)$mapping);
}
$postMapper = $connection->mapper(Post::class);
// create entity and insert
$post1 = $postMapper->entity([
'title' => 'Hello World',
'body' => 'My very first post',
]);
$postMapper->insert($entity);
// ...or do it in a single step
$post2 = $postMapper->create([
'title' => 'Lorem Ipsum',
'body' => 'My second post',
]);
$post2->setTitle('Lorem ipsum dolor');
$postMapper->update($post2);
$postMapper->delete($post2);
$query = $postMapper->find(['title like' => '% post']);
// queries are lazy, keep attaching parts till ready
$query->not('id', 1)->gte('score', 10);
foreach ($query as $post) {
echo $post->getName(), PHP_EOL;
}
// or retrieve a single result
$postMapper->find(['id' => 1])->first();
class JsonExists extends Operator
{
public function __invoke(Query $query, $column, $value = null)
{
return 'jsonb_exists(' . $column . ', ' . $query->parameter($value) . ')';
}
}
Freckle\Operator::add('json_exists', JsonExists::class);
$postMapper->find([
'properties json_exists' => 'author',
]);
// or use it as a method
$postMapper->find()->json_exists('properties', 'author');