Skip to content

Commit

Permalink
πŸ”€ Merge pull request #2 from mychidarko/next
Browse files Browse the repository at this point in the history
Leaf DB rewrite
  • Loading branch information
mychidarko authored Jan 16, 2022
2 parents 75687a7 + aed618d commit 4595d80
Show file tree
Hide file tree
Showing 7 changed files with 1,040 additions and 803 deletions.
23 changes: 19 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
test
Experimental
vendor
composer.lock
# Global
.phpunit*
.composer
composer.lock
package-lock.json
vendor/
test/
tests/
*.tests.php

# OS Generated
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
*.swp

# phpstorm
.idea/*
59 changes: 53 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,41 @@
<p align="center">
<br><br>
<img src="https://leafphp.netlify.app/assets/img/leaf3-logo.png" height="100"/>
<h1 align="center">Leaf Db module</h1>
<h1 align="center">Leaf Db v3</h1>
<br><br>
</p>

# Leaf PHP

[![Latest Stable Version](https://poser.pugx.org/leafs/db/v/stable)](https://packagist.org/packages/leafs/db)
[![Total Downloads](https://poser.pugx.org/leafs/db/downloads)](https://packagist.org/packages/leafs/db)
[![License](https://poser.pugx.org/leafs/db/license)](https://packagist.org/packages/leafs/db)

Leaf PHP db feature packaged as a serve-yourself module.
Leaf DB has gone through yet another re-write. This time, Leaf DB focuses on maintaining a cleaner structure with more usable and grounded code. v3 supports more databases like postgres and sqlite, comes with some performance gains and is far more efficient than v1 and v2. It is also independent of the leaf core which makes it suitable for any project you run.

## What's new?

### DB Support

Leaf DB now supports connections with other databases like postgresql, sqlite, oracle and more.

### Deep syncing with leaf 3

Leaf DB is now detached from leaf, however, as a leaf 3 module, there's additional functionality you can get from using leaf db in a leaf 3 app. Deep syncing config, instances and functional mode all become available to you.

### PDO rewrite

Under the hood, Leaf DB has been rewritten to fully support PDO, both internally and user instantiated PDO instances. This makes leaf db more flexible and more compatible with most systems and applications.

### Performance Improvements

After a series of benchmarks with ApacheBench, apps using leaf db v3 were almost twice as fast as apps using the prior version. These small performance wins can go a long way to improve the overall perfomance of your app drastically.

### Methods

- `create`
- `drop`
- `insert` with multiple fields
- Connections with pgsql, oracle, sqlite and many more db types
- Functional mode

## Installation

Expand All @@ -22,6 +46,29 @@ You can easily install Leaf using [Composer](https://getcomposer.org/).
composer require leafs/db
```

## View Leaf's docs [here](https://leafphp.netlify.app/#/)
## Basic usage

After installing leaf db, you need to connect to your database to use any of the db functions.

```php
$db = new Leaf\Db('127.0.0.1', 'dbName', 'user', 'password');

# or

$db = new Leaf\Db();
$db->connect('127.0.0.1', 'dbName', 'user', 'password');
```

If you're using leaf db in a leaf 3 app, you will have access to the `db` global

```php
db()->connect('127.0.0.1', 'dbName', 'user', 'password');
```

From there, you can use any db method.

```php
$users = db()->select('users')->all();
```

Built with ❀ by [**Mychi Darko**](https://mychi.netlify.app)
You can find leaf db's complete documentation [here](https://leafphp.dev/modules/db/). **The docs are still being updated.**
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
"autoload": {
"psr-4": {
"Leaf\\": "src"
}
},
"files": [
"src/functions.php"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"ext-mysqli": "*",
"leafs/form": "^1.0"
"ext-mysqli": "*"
},
"require-dev": {
"pestphp/pest": "^1.21"
}
}
Loading

0 comments on commit 4595d80

Please sign in to comment.