PHPackages                             marcojetson/freckle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. marcojetson/freckle

ActiveLibrary[Database &amp; ORM](/categories/database)

marcojetson/freckle
===================

A minimalistic ORM built on top of Doctrine DBAL and heavily inspired by Spot2

v1.0(9y ago)119BSD-3PHPPHP &gt;=5.6.0

Since Jun 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/marcojetson/freckle)[ Packagist](https://packagist.org/packages/marcojetson/freckle)[ Docs](https://github.com/marcojetson/freckle)[ RSS](/packages/marcojetson-freckle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Freckle
=======

[](#freckle)

Freckle is an Object-Relational-Mapper built on top of Doctrine DBAL.

Freckle is inspired by [Spot2](https://github.com/vlucas/spot2).

[![Build Status](https://camo.githubusercontent.com/ca0e2c09cf99603bcaa236e4996e2986f1e5fba52f63600ab360b5cde801e6c6/68747470733a2f2f7472617669732d63692e6f72672f6d6172636f6a6574736f6e2f667265636b6c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/marcojetson/freckle)[![Code Climate](https://camo.githubusercontent.com/5ef06d7fae1f9107c275b84d67dc8c727480c5e23e271ea4ab86cc7beef1e31a/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d6172636f6a6574736f6e2f667265636b6c652f6261646765732f6770612e737667)](https://codeclimate.com/github/marcojetson/freckle)

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Entities](#entities)
    - [Definition](#entities-definition)
    - [Generation](#entities-generation)
- [Data manipulation](#data-manipulation)
    - [Insert](#insert)
    - [Update](#update)
    - [Delete](#delete)
    - [Retrieval](#retrieval)
        - [Where operators](#where-operators)
- [Relations](#relations)
    - [Definition](#relations-definition)

Installation
------------

[](#installation)

Install with Composer

```
composer require marcojetson/freckle
```

Configuration
-------------

[](#configuration)

You can get a connection through the `Freckle\Manager` class.

```
$connection = Freckle\Manager::getConnection([
  'driver' => 'pdo_sqlite',
]);
```

Entities
--------

[](#entities)

Entities must extend `Freckle\Entity` and implement the `definition` method.

```
/**
 * @method int getId()
 *
 * @method string getTitle()
 * @method setTitle(string $title)
 *
 * @method string getBody()
 * @method setBody(string $body)
 */
class Post extends Freckle\Entity
{
  public static function definition()
  {
  	return [
      'table' => 'post',
      'fields' => [
        'id' => ['integer', 'sequence' => true, 'primary' => true],
        'title' => 'string',
        'body' => 'string',
      ],
	];
  }
}
```

### Definition

[](#definition)

Defining an entity requires a table name and its fields. Fields are defined by an array with mandatory positional parameters and optional named parameters.

```
[
    string $type,
    mixed default=null, // default value, callables supported!
    bool primary=false,
    bool require=false,
    bool|string sequence=false, // specify sequence name if required by database
]
```

### Generation

[](#generation)

Freckle is able to generate entities for you. Use `Freckle\Connection::import()` to automatically generate mappings for your tables.

```
foreach ($connection->generate() as $mapping) {
    file_put_contents($mapping->entityClass() . '.php', (string)$mapping);
}
```

Data manipulation
-----------------

[](#data-manipulation)

Interact with your entities using a mapper. You can get a mapper using the previously created connection.

```
$postMapper = $connection->mapper(Post::class);
```

### Insert

[](#insert)

```
// 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',
]);
```

### Update

[](#update)

```
$post2->setTitle('Lorem ipsum dolor');
$postMapper->update($post2);
```

Not sure if new entity or not? Then use `Freckle\Mapper::save()`.

### Delete

[](#delete)

```
$postMapper->delete($post2);
```

### Retrieval

[](#retrieval)

Use `Freckle\Mapper::find()` to initialize a query

```
$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();
```

#### Where operators

[](#where-operators)

Where operators can be appended to field when using `Freckle\Query::where()` or being executed as query methods.

- eq, equals, =
- not, !=
- gt, greaterThan, &gt;
- gte, greaterThanOrEquals, &gt;=
- lt, lessThan, &lt;
- lte, lessThanOrEquals, &lt;=
- like

##### Custom operators

[](#custom-operators)

Add your own operators extending `Freckle\Operator`.

```
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');
```

Relations
---------

[](#relations)

Related entity retrieval is supported.

```
/**
 * @method int getId()
 *
 * @method string getBody()
 * @method setBody(string $body)
 *
 * @method int getPostId()
 * @method setPostId(int $postId)
 *
 * @method Post getPost()
 */
class Comment extends Freckle\Entity
{
  public static function definition()
  {
  	return [
      'table' => 'comment',
      'fields' => [
        'id' => ['integer', 'sequence' => true, 'primary' => true],
        'body' => 'string',
        'post_id' => 'integer',
      ],
      'relations' => [
        'post' => ['one', Post::class, ['id' => 'this.id']],
        },
      ],
	];
  }
}
```

### Definition

[](#definition-1)

In the same fashion of fields, defining a relation consist in an array with mandatory positional parameters and optional named parameters.

```
[
    string $type,
    string $entityClass,
    array $conditions,
    string through=null, // "table.column" for many-to-many relations
    string field='id', // related entity primary column
]
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3608d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fea021b095644a08ddb0d040b2048832304b2360844ba59b8145d6aee70bbf22?d=identicon)[marcojetson](/maintainers/marcojetson)

---

Top Contributors

[![marcojetson](https://avatars.githubusercontent.com/u/408194?v=4)](https://github.com/marcojetson "marcojetson (28 commits)")

---

Tags

databaseormdata mapper

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marcojetson-freckle/health.svg)

```
[![Health](https://phpackages.com/badges/marcojetson-freckle/health.svg)](https://phpackages.com/packages/marcojetson-freckle)
```

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M35](/packages/scienta-doctrine-json-functions)[laravel-doctrine/migrations

Doctrine Migrations for Laravel

782.8M16](/packages/laravel-doctrine-migrations)[laravel-doctrine/fluent

A fluent PHP mapping driver for Doctrine2.

43430.3k13](/packages/laravel-doctrine-fluent)[laravel-doctrine/acl

ACL for Laravel and Doctrine

44445.3k7](/packages/laravel-doctrine-acl)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[hiqdev/yii2-data-mapper

Data Mapper for Yii2

1516.9k1](/packages/hiqdev-yii2-data-mapper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
