Skip to content

Commit ec09e65

Browse files
authored
Refresh README and contribution guide (#21)
1 parent d5a4e0b commit ec09e65

2 files changed

Lines changed: 78 additions & 89 deletions

File tree

CONTRIBUTING.md

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
# Contributing
1+
# Contributing to Model ORM
22

3-
Thanks for contributing to `model-orm-php`.
3+
Thanks for contributing to `model-orm-php`. The project aims to stay small, practical, and dependable across supported databases, so focused changes and clear validation matter.
44

5-
## Ground rules
5+
## Principles
66

7-
- Be respectful and constructive in issues, pull requests, and review discussion.
8-
- Keep changes focused. Small, well-scoped pull requests are easier to review and safer to merge.
9-
- Preserve backward compatibility where practical, or clearly call out breaking changes.
7+
- Keep changes focused and easy to review.
8+
- Preserve backward compatibility where practical, or call out breaking behavior clearly.
9+
- Favor direct, readable PDO-centered code over extra abstraction.
10+
- Update tests and docs when public behavior changes.
1011

11-
## Development setup
12+
## Local setup
1213

1314
Requirements:
1415

1516
- PHP `8.3+`
1617
- `ext-pdo`
17-
- A PDO driver for the database you want to test against, typically `pdo_mysql` or `pdo_pgsql`
18+
- A PDO driver for the database you want to test against, usually `pdo_mysql` or `pdo_pgsql`
1819
- Composer
1920

2021
Install dependencies:
@@ -23,12 +24,17 @@ Install dependencies:
2324
composer install
2425
```
2526

26-
Optional local databases:
27+
Start optional local databases:
2728

2829
```bash
2930
docker-compose up -d
3031
```
3132

33+
Default local ports:
34+
35+
- MySQL/MariaDB on `127.0.0.1:3306`
36+
- PostgreSQL on `127.0.0.1:5432`
37+
3238
## Running checks
3339

3440
Run the test suite:
@@ -37,64 +43,68 @@ Run the test suite:
3743
vendor/bin/phpunit -c phpunit.xml.dist
3844
```
3945

40-
Override the database connection with environment variables when needed:
46+
Run static analysis:
4147

4248
```bash
43-
MODEL_ORM_TEST_DSN=mysql:host=127.0.0.1;port=3306
44-
MODEL_ORM_TEST_USER=root
45-
MODEL_ORM_TEST_PASS=
49+
vendor/bin/phpstan analyse -c phpstan.neon
4650
```
4751

48-
Or for PostgreSQL:
52+
Run the formatter:
4953

5054
```bash
51-
MODEL_ORM_TEST_DSN=pgsql:host=127.0.0.1;port=5432;dbname=categorytest
52-
MODEL_ORM_TEST_USER=postgres
53-
MODEL_ORM_TEST_PASS=postgres
55+
vendor/bin/php-cs-fixer fix
5456
```
5557

56-
Run static analysis:
58+
Check formatting without changing files:
5759

5860
```bash
59-
vendor/bin/phpstan analyse -c phpstan.neon
61+
vendor/bin/php-cs-fixer fix --dry-run --diff
6062
```
6163

62-
Run formatting:
64+
## Database configuration for tests
65+
66+
Override the test connection with environment variables when needed.
67+
68+
MySQL or MariaDB:
6369

6470
```bash
65-
vendor/bin/php-cs-fixer fix
71+
MODEL_ORM_TEST_DSN=mysql:host=127.0.0.1;port=3306
72+
MODEL_ORM_TEST_USER=root
73+
MODEL_ORM_TEST_PASS=
6674
```
6775

68-
Check formatting only:
76+
PostgreSQL:
6977

7078
```bash
71-
vendor/bin/php-cs-fixer fix --dry-run --diff
79+
MODEL_ORM_TEST_DSN=pgsql:host=127.0.0.1;port=5432;dbname=categorytest
80+
MODEL_ORM_TEST_USER=postgres
81+
MODEL_ORM_TEST_PASS=postgres
7282
```
7383

7484
## Coding expectations
7585

7686
- Follow the existing project style: 4-space indentation, `StudlyCaps` class names, and `camelCase` methods.
77-
- Keep the library framework-agnostic and PDO-centered.
78-
- Add or update tests for behavior changes, especially around cross-database behavior.
79-
- Prefer clear, direct code over clever abstractions.
87+
- Keep the library framework-agnostic.
88+
- Add or adjust tests for behavior changes, especially cross-database behavior.
89+
- Prefer small, well-scoped pull requests over mixed changes.
8090

8191
## Pull requests
8292

8393
Before opening a pull request:
8494

85-
- Make sure tests pass locally for the database you changed or relied on.
95+
- Run PHPUnit for the database setup you changed or relied on.
8696
- Run PHPStan and the formatting check.
87-
- Update documentation when the public behavior or setup changes.
97+
- Update documentation when API behavior, setup, or migration guidance changes.
8898

8999
When opening a pull request:
90100

91-
- Explain the user-visible problem and the change you made.
92-
- Note database-specific assumptions or compatibility impacts.
101+
- Describe the problem and the change in user-facing terms.
102+
- Note any database-specific assumptions or compatibility impacts.
93103
- Include the commands you ran to validate the change.
94104

95105
## Contribution terms
96106

97-
By submitting code, documentation, or any other contribution to this repository, you represent that:
107+
By submitting code, documentation, or other contributions to this repository, you represent that:
98108

99109
- You have the right to submit the contribution.
100110
- The contribution is your own original work, or you have sufficient rights to provide it under the project license.

README.md

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
Model ORM
2-
=========
1+
Model ORM for PHP
2+
=================
33

44
[![CI](https://github.com/davebarnwell/model-orm-php/actions/workflows/ci.yml/badge.svg)](https://github.com/davebarnwell/model-orm-php/actions/workflows/ci.yml)
55
[![PHP 8.3+](https://img.shields.io/badge/PHP-8.3%2B-777BB4?logo=php&logoColor=white)](https://www.php.net/)
66

7-
`Freshsauce\Model\Model` is a lightweight ORM-style base class for PHP applications that want database-backed models without committing to a large framework. Point it at a table, extend the base class, and you get CRUD operations, dynamic finders, counters, and raw query access with very little setup.
7+
`Freshsauce\Model\Model` gives you the sweet spot between raw PDO and a full framework ORM: fast setup, familiar model-style workflows, and complete freedom to drop to SQL whenever you want.
88

9-
It is designed for projects that value straightforward PHP, direct PDO access, and a small abstraction layer that stays out of the way.
9+
If you want database-backed PHP models without pulling in a heavyweight stack, this library is built for that job.
1010

11-
## Why use it?
11+
## Why teams pick it
1212

13-
- Minimal setup: define a model class and table name, then start reading and writing rows.
14-
- PDO-first: use the ORM helpers when they help and drop down to raw SQL when they do not.
15-
- Familiar model flow: create, hydrate, validate, save, update, count, find, and delete.
16-
- Dynamic finders: call methods such as `findByName()`, `findOneByName()`, `countByName()`, and more.
17-
- Multi-database support: tested against MySQL/MariaDB, PostgreSQL, and SQLite.
13+
- Lightweight by design: point a model at a table and start reading and writing records.
14+
- PDO-first: keep the convenience methods, keep full access to SQL, keep control.
15+
- Framework-agnostic: use it in custom apps, legacy codebases, small services, or greenfield projects.
16+
- Productive defaults: CRUD helpers, dynamic finders, counters, hydration, and timestamp handling are ready out of the box.
17+
- Portable across databases: exercised against MySQL/MariaDB, PostgreSQL, and SQLite.
1818

19-
## Installation
20-
21-
Install from Composer:
19+
## Install in minutes
2220

2321
```bash
2422
composer require freshsauce/model
@@ -30,11 +28,9 @@ Requirements:
3028
- `ext-pdo`
3129
- A PDO driver such as `pdo_mysql` or `pdo_pgsql`
3230

33-
Looking for fuller, example-led usage? See [EXAMPLE.md](EXAMPLE.md).
34-
3531
## Quick start
3632

37-
Create a table. This quick-start example uses PostgreSQL syntax:
33+
Create a table. This example uses PostgreSQL syntax:
3834

3935
```sql
4036
CREATE TABLE categories (
@@ -45,7 +41,7 @@ CREATE TABLE categories (
4541
);
4642
```
4743

48-
If you are using MySQL or MariaDB, use `INT AUTO_INCREMENT PRIMARY KEY` for the `id` column instead.
44+
If you are using MySQL or MariaDB, use `INT AUTO_INCREMENT PRIMARY KEY` for `id` instead.
4945

5046
Connect and define a model:
5147

@@ -64,7 +60,7 @@ class Category extends Freshsauce\Model\Model
6460
}
6561
```
6662

67-
Create and save a record:
63+
Create, read, update, and delete records:
6864

6965
```php
7066
$category = new Category([
@@ -73,35 +69,19 @@ $category = new Category([
7369

7470
$category->save();
7571

76-
echo $category->id;
77-
```
78-
79-
Read it back:
80-
81-
```php
8272
$loaded = Category::getById($category->id);
83-
```
84-
85-
Update it:
86-
87-
```php
8873
$loaded->name = 'Science Fiction';
8974
$loaded->save();
90-
```
91-
92-
Delete it:
93-
94-
```php
9575
$loaded->delete();
9676
```
9777

98-
For more end-to-end snippets, see [EXAMPLE.md](EXAMPLE.md).
78+
That is the core promise of the library: minimal ceremony, direct results.
9979

10080
## What you get
10181

102-
### CRUD helpers
82+
### Full record lifecycle helpers
10383

104-
The base model gives you the common record lifecycle methods:
84+
The base model gives you the methods most applications reach for first:
10585

10686
- `save()`
10787
- `insert()`
@@ -114,11 +94,11 @@ The base model gives you the common record lifecycle methods:
11494
- `last()`
11595
- `count()`
11696

117-
Timestamp columns named `created_at` and `updated_at` are populated automatically on insert and update when present.
97+
If your table includes `created_at` and `updated_at`, they are populated automatically on insert and update.
11898

11999
### Dynamic finders and counters
120100

121-
You can query using camelCase dynamic method names:
101+
Build expressive queries straight from method names:
122102

123103
```php
124104
Category::findByName('Science Fiction');
@@ -128,21 +108,19 @@ Category::lastByName(['Sci-Fi', 'Fantasy']);
128108
Category::countByName('Science Fiction');
129109
```
130110

131-
Legacy snake_case dynamic methods remain available during the transition, but they are deprecated and emit `E_USER_DEPRECATED` notices.
111+
Legacy snake_case dynamic methods still work during the transition, but they are deprecated and emit `E_USER_DEPRECATED` notices.
132112

133-
### Custom where clauses
113+
### Flexible SQL when convenience methods stop helping
134114

135-
When you need more control, fetch one or many records with SQL fragments:
115+
Use targeted where clauses:
136116

137117
```php
138118
$one = Category::fetchOneWhere('id = ? OR name = ?', [1, 'Science Fiction']);
139119

140120
$many = Category::fetchAllWhere('name IN (?, ?)', ['Sci-Fi', 'Fantasy']);
141121
```
142122

143-
### Raw statements when needed
144-
145-
If a query does not fit the model helpers, execute SQL directly through PDO:
123+
Or run raw SQL directly through PDO:
146124

147125
```php
148126
$statement = Freshsauce\Model\Model::execute(
@@ -153,9 +131,9 @@ $statement = Freshsauce\Model\Model::execute(
153131
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
154132
```
155133

156-
## Validation hooks
134+
### Validation hooks
157135

158-
Override `validate()` in your model to enforce business rules before inserts and updates:
136+
Override `validate()` in your model when writes need application rules:
159137

160138
```php
161139
class Category extends Freshsauce\Model\Model
@@ -169,11 +147,11 @@ class Category extends Freshsauce\Model\Model
169147
}
170148
```
171149

172-
Throw an exception from `validate()` to block invalid writes.
150+
Throw an exception from `validate()` to block invalid inserts or updates.
173151

174-
## Database notes
152+
## Database support
175153

176-
MySQL/MariaDB example connection:
154+
MySQL or MariaDB:
177155

178156
```php
179157
Freshsauce\Model\Model::connectDb(
@@ -183,7 +161,7 @@ Freshsauce\Model\Model::connectDb(
183161
);
184162
```
185163

186-
PostgreSQL example connection:
164+
PostgreSQL:
187165

188166
```php
189167
Freshsauce\Model\Model::connectDb(
@@ -193,18 +171,19 @@ Freshsauce\Model\Model::connectDb(
193171
);
194172
```
195173

196-
SQLite is supported in the library and covered by the automated test suite alongside MySQL/MariaDB and PostgreSQL.
174+
SQLite is supported in the library and covered by the automated test suite.
197175

198-
## Quality
176+
## Built for real projects
199177

200-
The repository ships with:
178+
The repository includes:
201179

202-
- PHPUnit coverage for the core model behavior
180+
- PHPUnit coverage for core model behavior
203181
- PHPStan static analysis
204182
- PHP-CS-Fixer formatting checks
205-
- GitHub Actions CI for pull requests and pushes
183+
- GitHub Actions CI for pushes and pull requests
206184
- Automatic `vYY.MM.DD.n` CalVer tags and GitHub releases for merged PRs to `main`
207185

208-
## Contributing
186+
## Learn more
209187

210-
Development setup, testing commands, pull request expectations, and contribution terms are documented in [CONTRIBUTING.md](CONTRIBUTING.md).
188+
- Want fuller usage examples? See [EXAMPLE.md](EXAMPLE.md).
189+
- Want to contribute? See [CONTRIBUTING.md](CONTRIBUTING.md).

0 commit comments

Comments
 (0)