Skip to content

Welcome to Formal

Formal is all about data storages.

You'll find packages to:

  • connect to them
  • high abstractions to simplify storing
  • tools to manage the lifecycle of storages

They use declarative code to provide a memory safe approach to data manipulation.

  • formal/access-layer


    Use objects to progamatically build your queries instead of concatening strings.

    $pdo = PDO::of(Url::of('mysql://user:pwd@127.0.0.1:3306/db'));
    
    $_ = $pdo(
        Select::from(
            Table\Name::of('users'),
        ),
    )
        ->map(User::fromRow(...))
        ->foreach(doSomething(...));
    
  • formal/orm


    Manipulate your Domain objects and let the ORM store them (SQL, Elasticsearch or Filesystem).

    $_ = $manager
        ->repository(User::class)
        ->matching(Property::of(
            'email',
            Sign::endsWith,
            '@your-company.com',
        ))
        ->foreach(
            sendResetPasswordEmail(...),
        );
    
  • formal/migrations


    Incrementally run SQL queries to update your database. Or run commands when you deploy.

    $dsn = Url::of('mysql://user:pwd@127.0.0.1:3306/db');
    
    $migrations
        ->storeVersionsInDatabase($dsn)
        ->sql()
        ->files(
            Path::of('migrations/folder/'),
        )
        ->migrate($dsn);