Skip to content

Commit 929fbdf

Browse files
feat: add first-class database integration, update Bootstrapper/provider order, fix schema resolution and improve container stability
1 parent 274b56b commit 929fbdf

File tree

4 files changed

+135
-14
lines changed

4 files changed

+135
-14
lines changed

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,46 @@
22

33
All notable changes to **codemonster-ru/annabel** will be documented in this file.
44

5+
## [1.11.0] – 2025-12-09
6+
7+
### Added
8+
9+
- **First-class database integration** with the `codemonster-ru/database` package:
10+
11+
- Added `DatabaseServiceProvider` with proper container bindings for:
12+
- `DatabaseManager`
13+
- automatic connection resolution
14+
- runtime grammar selection (MySQL, SQLite, extensible structure)
15+
- Added container binding for the Schema builder (`Schema`), enabling use of:
16+
- `schema()->create()`
17+
- `schema()->table()`
18+
- `schema()->drop()`
19+
- Automatic loading of DB configuration via `config('database')`.
20+
21+
- **Support for global helpers from codemonster-ru/support**, including:
22+
- `db()` — returns the current database connection
23+
- `schema()` — returns schema builder for the selected connection
24+
- `transaction()` — executes code inside a DB transaction
25+
26+
### Changed
27+
28+
- `Bootstrapper` updated to load the new `DatabaseServiceProvider`
29+
before view and session providers for correct dependency ordering.
30+
- Standardized provider boot order for proper initialization of config,
31+
database, view, session, and router layers.
32+
33+
### Fixed
34+
35+
- Eliminated errors caused by instantiating schema grammars directly from Annabel.
36+
- Corrected container resolution of database-related classes when running without Annabel (standalone mode).
37+
- Improved stability of the application container when resolving database singletons.
38+
39+
### Improvements
40+
41+
- Cleaner dependency injection for all DB components.
42+
- Better separation between Annabel core and database layer (no hard dependency on MySqlGrammar inside the framework).
43+
- Improved developer experience for Xen and other Annabel-based modules using database operations.
44+
545
## [1.10.0] - 2025-11-16
646

747
### Added

README.md

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,76 @@ return $app;
3737
router()->get('/', fn() => view('home', ['title' => 'Welcome to Annabel']));
3838
```
3939

40+
## 🗄 Database Integration
41+
42+
Annabel ships with first‑class integration for
43+
[`codemonster-ru/database`](https://github.com/codemonster-ru/database).
44+
45+
### 1. Create `config/database.php`
46+
47+
```php
48+
return [
49+
'default' => 'mysql',
50+
51+
'connections' => [
52+
'mysql' => [
53+
'driver' => 'mysql',
54+
'host' => '127.0.0.1',
55+
'port' => 3306,
56+
'database' => env('DB_NAME'),
57+
'username' => env('DB_USER'),
58+
'password' => env('DB_PASS'),
59+
'charset' => 'utf8mb4',
60+
],
61+
62+
'sqlite' => [
63+
'driver' => 'sqlite',
64+
'database' => base_path('database/database.sqlite'),
65+
],
66+
],
67+
];
68+
```
69+
70+
### 2. Usage
71+
72+
```php
73+
// Query builder
74+
$users = db()->table('users')->where('active', 1)->get();
75+
76+
// Schema builder
77+
schema()->create('posts', function ($table) {
78+
$table->id();
79+
$table->string('title');
80+
});
81+
82+
// Transactions
83+
transaction(function () {
84+
db()->table('logs')->insert(['type' => 'created']);
85+
});
86+
```
87+
4088
## 🧩 Helpers
4189

42-
| Function | Description |
43-
| ----------------------- | ------------------------------------ |
44-
| `app()` | Access the application container |
45-
| `base_path()` | Resolve base project paths |
46-
| `config()` | Get or set configuration values |
47-
| `dump()` / `dd()` | Debugging utilities |
48-
| `env()` | Read environment variables |
49-
| `request()` | Get current HTTP request |
50-
| `response()`/ `json()` | Create HTTP response |
51-
| `router()` / `route()` | Access router instance |
52-
| `session()`/ `render()` | Read, write, or access session store |
53-
| `view()` | Render or return view instance |
90+
| Function | Description |
91+
| ----------------------- | ---------------------------------- |
92+
| `app()` | Access the application container |
93+
| `base_path()` | Resolve base project paths |
94+
| `config()` | Get or set configuration values |
95+
| `env()` | Read environment variables |
96+
| `dump()` / `dd()` | Debugging utilities |
97+
| `request()` | Get current HTTP request |
98+
| `response()` / `json()` | Create HTTP response |
99+
| `router()` / `route()` | Access router instance |
100+
| `view()` | Render or return view instance |
101+
| `session()` | Access session store |
102+
| `db()` | Get the active database connection |
103+
| `schema()` | Get the schema builder |
104+
| `transaction()` | Execute a DB transaction |
105+
106+
All helpers are autoloaded automatically.
54107

55108
## 🧪 Testing
56109

57-
You can run tests with the command:
58-
59110
```bash
60111
composer test
61112
```

src/Bootstrap/Bootstrapper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function registerProviders(): void
5050
{
5151
$defaultProviders = [
5252
\Codemonster\Annabel\Providers\CoreServiceProvider::class,
53+
\Codemonster\Annabel\Providers\DatabaseServiceProvider::class,
5354
\Codemonster\Annabel\Providers\ViewServiceProvider::class,
5455
\Codemonster\Annabel\Providers\SessionServiceProvider::class,
5556
];
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Codemonster\Annabel\Providers;
4+
5+
use Codemonster\Annabel\Contracts\ServiceProviderInterface;
6+
use Codemonster\Database\DatabaseManager;
7+
8+
class DatabaseServiceProvider implements ServiceProviderInterface
9+
{
10+
public function __construct(protected $app) {}
11+
12+
public function register(): void
13+
{
14+
// Register DatabaseManager as singleton
15+
$this->app->singleton(DatabaseManager::class, function () {
16+
$config = config('database') ?? [
17+
'default' => 'mysql',
18+
'connections' => [],
19+
];
20+
21+
return new DatabaseManager($config);
22+
});
23+
}
24+
25+
public function boot(): void
26+
{
27+
// optional: nothing to boot
28+
}
29+
}

0 commit comments

Comments
 (0)