1. Go to this page and download the library: Download preflow/data 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/ */
preflow / data example snippets
$model->fill(array $data): void // hydrate from associative array
$model->toArray(): array // export public properties
$dm->find(Post::class, $id): ?Post
$dm->query(Post::class): QueryBuilder<Post>
$dm->save(Model $model): void // INSERT when ID is empty, UPDATE otherwise
$dm->insert(Model $model): void // explicit INSERT; reads back lastInsertId()
$dm->update(Model $model): void // explicit UPDATE
$dm->delete(Post::class, $id): void // delete by class + ID
$dm->delete($model): void // delete by model instance
$dm->raw(string $sql, array $bindings, string $storage): array // raw SQL query
abstract class Migration
{
abstract public function up(Schema $schema): void;
public function down(Schema $schema): void {}
}
#[Entity(table: 'comments', storage: 'sqlite')]
final class Comment extends Model
{
#[Id]
public int $id = 0;
#[Field]
public string $body = '';
}
$comment = new Comment();
$comment->body = 'Great post!';
$dm->save($comment);
echo $comment->id; // e.g. 42 — populated after insert
$rows = $dm->raw(
'SELECT p.*, COUNT(c.id) AS comment_count FROM posts p LEFT JOIN comments c ON c.post_id = p.id GROUP BY p.id',
[],
'sqlite',
);
use Preflow\Data\{Model, ModelMetadata};
use Preflow\Data\Attributes\{Entity, Id, Field, Timestamps};
#[Entity(table: 'posts', storage: 'sqlite')]
#[Timestamps]
final class Post extends Model
{
#[Id]
public string $id;
#[Field(searchable: true)]
public string $title;
#[Field(searchable: true)]
public string $body;
public string $status = 'draft';
}
use Preflow\Data\Migration\{Migration, Schema};
final class CreatePostsTable extends Migration
{
public function up(Schema $schema): void
{
$schema->create('posts', function (Table $t) {
$t->uuid('id')->primary();
$t->string('title')->index();
$t->text('body');
$t->string('status');
$t->timestamps();
});
}
public function down(Schema $schema): void
{
$schema->drop('posts');
}
}
$dm = new DataManager([
'default' => new JsonFileDriver(basePath: '/storage/data'),
'sqlite' => new SqliteDriver(new \PDO('sqlite:/storage/db.sqlite')),
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.