PHPackages                             napp/dbalcore - 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. napp/dbalcore

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

napp/dbalcore
=============

DBAL core for projects

2.0.0(5y ago)04.0k1MITPHPPHP ^7.1|^8.0

Since Mar 5Pushed 5y ago2 watchersCompare

[ Source](https://github.com/Napp/dbalcore)[ Packagist](https://packagist.org/packages/napp/dbalcore)[ RSS](/packages/napp-dbalcore/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)Dependencies (6)Versions (14)Used By (0)

Napp DBAL Core
==============

[](#napp-dbal-core)

[![Build Status](https://camo.githubusercontent.com/2646a65d7f40ff635b36a2c5316599fcad17085ed3f44539dbca032af188d2cf/68747470733a2f2f7472617669732d63692e6f72672f4e6170702f6462616c636f72652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Napp/dbalcore)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1a72047553838a2db881bc1cf75c675dc1b0c4eae7ffbd0bac3a1936e4770f65/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e6170702f6462616c636f72652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Napp/dbalcore/?branch=master)[![codecov](https://camo.githubusercontent.com/cefb73510429e26622f38953a6151e087a6165a56723a439718dfdc1c4d7d2a4/68747470733a2f2f636f6465636f762e696f2f67682f4e6170702f6462616c636f72652f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d4869444e6e4358593033)](https://codecov.io/gh/Napp/dbalcore/branch/master)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

This package extends the Laravel Query Builder, has a nice `Base Repository` and has a collection of helpful `Criteria` to build queries.

Repositories
------------

[](#repositories)

The Basereposity has various helpful methods.

### Transactions

[](#transactions)

```
return $this->transaction(function () use ($data) {
    User::update($data);
});
```

Criteria
--------

[](#criteria)

A `Criterion` is a way to build custom query logic in its own class and reuse within your project. Use it together with the BaseRepository to

```
$this->criteriaCollection = new CriteriaCollection();
$this->criteriaCollection
    ->reset()
    ->add(new WithRelationCriterion('contentGroups'))
    ->add(new WithRelatedUserCriterion($request->user()))
    ->add(new WithSearchQueryCriterion('foobar', 'name'));

$forms = $this->formsRepository->getAllMatchingCriteria($this->criteriaCollection);
```

QueryBuilder Usage
------------------

[](#querybuilder-usage)

This package extends the Laravel QueryBuilder by the following methods:

### Replace

[](#replace)

Makes it possible to use the `REPLACE INTO` MySQL grammar in Laravel. Simply do:

```
User::replace($data);
```

### insertOnDuplicateKey

[](#insertonduplicatekey)

Call `insertOnDuplicateKey` or `insertIgnore` from a model with the array of data to insert in its table.

```
$data = [
    ['id' => 1, 'name' => 'name1', 'email' => 'user1@email.com'],
    ['id' => 2, 'name' => 'name2', 'email' => 'user2@email.com'],
];

User::insertOnDuplicateKey($data);

User::insertIgnore($data);
```

#### Customizing the ON DUPLICATE KEY UPDATE clause

[](#customizing-the-on-duplicate-key-update-clause)

##### Update only certain columns

[](#update-only-certain-columns)

If you want to update only certain columns, pass them as the 2nd argument.

```
User::insertOnDuplicateKey([
    'id'    => 1,
    'name'  => 'new name',
    'email' => 'foo@gmail.com',
], ['name']);
// The name will be updated but not the email.
```

##### Update with custom values

[](#update-with-custom-values)

You can customize the value with which the columns will be updated when a row already exists by passing an associative array.

In the following example, if a user with id = 1 doesn't exist, it will be created with name = 'created user'. If it already exists, it will be updated with name = 'updated user'.

```
User::insertOnDuplicateKey([
    'id'    => 1,
    'name'  => 'created user',
], ['name' => 'updated user']);
```

The generated SQL is:

```
INSERT INTO `users` (`id`, `name`) VALUES (1, "created user") ON DUPLICATE KEY UPDATE `name` = "updated user"
```

You may combine key/value pairs and column names in the 2nd argument to specify the columns to update with a custom literal or expression or with the default `VALUES(column)`. For example:

```
User::insertOnDuplicateKey([
    'id'       => 1,
    'name'     => 'created user',
    'email'    => 'new@gmail.com',
    'password' => 'secret',
], ['name' => 'updated user', 'email]);
```

will generate

```
INSERT INTO `users` (`id`, `name`, `email`, `password`)
VALUES (1, "created user", "new@gmail.com", "secret")
ON DUPLICATE KEY UPDATE `name` = "updated user", `email` = VALUES(`email`)
```

### Pivot tables

[](#pivot-tables)

Call `attachOnDuplicateKey` and `attachIgnore` from a `BelongsToMany` relation to run the inserts in its pivot table. You can pass the data in all of the formats accepted by `attach`.

```
$pivotData = [
    1 => ['expires_at' => Carbon::today()],
    2 => ['expires_at' => Carbon::tomorrow()],
];

$user->roles()->attachOnDuplicateKey($pivotData);

$user->roles()->attachIgnore($pivotData);
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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

Every ~121 days

Recently: every ~204 days

Total

9

Last Release

2023d ago

Major Versions

0.5 → 1.02019-07-02

1.0.2 → 2.0.02020-10-29

PHP version history (2 changes)0.1PHP &gt;=7.0

2.0.0PHP ^7.1|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e24155f0d3ab61799ca35477a940edce613075a20d1073f2241905271f29d23?d=identicon)[viezel](/maintainers/viezel)

---

Top Contributors

[![morloderex](https://avatars.githubusercontent.com/u/5677808?v=4)](https://github.com/morloderex "morloderex (2 commits)")[![bluemanos](https://avatars.githubusercontent.com/u/9991002?v=4)](https://github.com/bluemanos "bluemanos (1 commits)")

---

Tags

databasedbalcriterianapp

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/napp-dbalcore/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[czim/laravel-repository

Repository for Laravel (inspired by and indebted to Bosnadev/Repositories)

54110.0k4](/packages/czim-laravel-repository)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)

PHPackages © 2026

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