22 Commits

Author SHA1 Message Date
7e7a3ccd29
refactor(macros): split trait implementations into modular files
Move trait implementation code from single monolithic file into separate
modules organised by operation type (create, delete, find, update,
upsert) for better code organisation and maintainability.
2025-06-10 11:44:25 +02:00
a7696270da
docs: rewrite documentation for core traits and library
Completely rewrite and expand documentation for Georm’s core
functionality with detailed explanations, examples, and implementation
details.

Changes:
- Rewrite lib.rs with comprehensive library documentation covering all
  features
- Add extensive Georm trait documentation with method-specific details
- Add detailed Defaultable trait documentation with usage patterns

The documentation now provides complete coverage of:
- All CRUD operations with database behavior details
- Composite key support and generated ID structs
- Defaultable field patterns and companion struct generation
- Relationship modeling (field-level and struct-level)
- Error handling and performance characteristics
- PostgreSQL-specific features and optimizations
2025-06-09 22:41:43 +02:00
19284665e6
feat: implement preliminary composite primary key support
Add support for entities with composite primary keys using multiple
#[georm(id)] fields. Automatically generates {EntityName}Id structs for
type-safe composite key handling.

Features:
- Multi-field primary key detection and ID struct generation
- Full CRUD operations (find, create, update, delete, create_or_update)
- Proper SQL generation with AND clauses for composite keys
- Updated documNtation in README and lib.rs

Note: Relationships not yet supported for composite key entities
2025-06-09 22:41:39 +02:00
190c4d7b1d
feat(examples): add PostgreSQL example with user relationship
Adds an example demonstrating user, comment, and follower relationship
including:
- User management with profiles
- Comments (not really useful, just for showcasing)
- Follower/follozing relationships
- Ineractive CLI interface with CRUD operations
- Database migrations for the example schema
2025-06-09 21:30:35 +02:00
9e56952dc6
feat: implement efficient upsert operation for create_or_update
Replace the existing two-query create_or_update implementation with a
single atomic PostgreSQL upsert using ON CONFLICT clause to eliminate
race conditions and improve performance.

Race condition fix:
The previous implementation had a critical race condition where
multiple concurrent requests could:
1. Both call find() and get None (record doesn't exist)
2. Both call create() and the second one fails with duplicate key
   error
3. Or between find() and create(), another transaction inserts the
   record

This created unreliable behavior in high-concurrency scenarios.

Changes:
- Add generate_upsert_query function in trait_implementation.rs
- Generate SQL with INSERT ... ON CONFLICT ... DO UPDATE SET pattern
- Remove default trait implementation that used separate
  find/create/update calls
- Update derive_trait to include upsert query generation
- Convert create_or_update from default implementation to required
  trait method

The new implementation eliminates race conditions while reducing
database round trips from 2-3 queries down to 1, significantly
improving both reliability and performance.
2025-06-09 21:30:35 +02:00
0c3d5e6262
feat: upgrade to Rust 1.86 and edition 2024
Upgrades rust toolchain from 1.84 to 1.86, switches to Rust edition
2024, and updates dependencies including SQLx to 0.8.6.
2025-06-09 21:26:19 +02:00
8217a28a28
fix(deps): update tokio to 1.45.1 to address RUSTSEC-2025-0023
Updates tokio dependency to address security advisory RUSTSEC-2025-0023.
This ensures the codebase uses a secure version of the tokio runtime.
2025-06-07 15:46:10 +02:00
ab2d80d2f6
chore: migrate development environment from Nix flakes to devenv
Replace Nix flake-based development setup with devenv for better
developer experience and more streamlined environment management.

Changes:
  - Remove flake.nix and flake.lock files
  - Add devenv.nix, devenv.yaml, and devenv.lock configuration
  - Update .envrc to use devenv instead of nix develop
  - Remove Docker development setup (compose.dev.yml, docker/mod.just)
  - Expand .gitignore with comprehensive IDE and OS exclusions
  - Remove Docker-related just commands from justfile
2025-06-07 15:46:10 +02:00
7cdaa27f3b
docs: complete rewrite of README
Replaces the existing README with a comprehensive guide that
significantly improves the developer and user experience. The new README
provides complete documentation for all Georm features and a detailed
development setup guide.

It also includes a roadmap with prioritized feature development plan.
2025-06-07 15:45:25 +02:00
a38b8e873d
feat: add defaultable field support with companion struct generation
Introduces support for `#[georm(defaultable)]` attribute on entity
fields. When fields are marked as defaultable, generates companion
`<Entity>Default` structs where defaultable fields become `Option<T>`,
enabling easier entity creation when some fields have database defaults
or are auto-generated.

Key features:
- Generates `<Entity>Default` structs with optional defaultable fields
- Implements `Defaultable<Id, Entity>` trait with async `create` method
- Validates that `Option<T>` fields cannot be marked as defaultable
- Preserves field visibility in generated companion structs
- Only generates companion struct when defaultable fields are present
2025-06-07 15:42:48 +02:00
aafbfb7964
feat: add foreign one_to_one relationships 2025-06-07 15:42:31 +02:00
4ff2df1a4e
chore: bump to 0.1.1 0.1.1 2025-02-01 02:03:43 +01:00
f2e59cee7c
fix: correct docs.rs link and switch to GitHub repository 2025-02-01 01:59:40 +01:00
d82f9fe2f4
docs: update readme 0.1.0 2025-02-01 01:25:55 +01:00
59eb96b9c8
docs: improve documentation of georm 2025-02-01 01:25:52 +01:00
f7cdcb1563
chore: add CI and issue templates 2025-01-31 23:23:19 +01:00
003af71107
chore: simplify flake.nix and update flake.lock 2025-01-31 23:14:40 +01:00
b70b4b7a81
test: added tests for M2M relationships, it works 2025-01-31 23:14:40 +01:00
86e29fa2dc
test: one-to-many relationships work 2025-01-31 23:14:40 +01:00
bca0619f30
fix: simple ORM for one struct and foreign references work
Currently, all methods declared in the Georm trait are available.

If a struct has an ID pointing towards another entity, the user can
create a get method to get the entity pointed at from the database
too (local one-to-one relationship).

I still need to implement remote one-to-one relationships (one-to-one
relationships when the ID of the remote object is not available
locally).

I still need to also test and debug one-to-many relationships (ID of
the remote entiies not available locally) and many-to-many
relationships (declared in a dedicated table).

For now, IDs in all cases are simple types recognized by SQLx that are
not arrays. Options are only supported when explicitely specified for
one-to-one relationships.
2025-01-31 23:14:39 +01:00
96ac2aa979
chore: migrate source code from old repo to this repo 2025-01-26 15:18:31 +01:00
39f757991a
initial commit 2025-01-26 15:18:31 +01:00