19 Commits

Author SHA1 Message Date
c8a23e1360
feat: implement efficient upsert operation for create_or_update
Some checks failed
CI / tests (push) Failing after 3m38s
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-06 11:09:55 +02:00
ca2434da9a
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-06 11:09:54 +02:00
1fdf236159
chore(flake): remove cargo from explicitely installed packages
Cargo is already installed with rustVersion
2025-06-06 11:09:18 +02:00
6fba12da56
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.
2025-06-06 11:09:18 +02:00
11fce7a1e2
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-06 11:09:18 +02:00
2add2fc9c2
docs: add roadmap with prioritized feature development plan 2025-06-06 11:09:18 +02:00
9cb87105bb
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-06 11:09:18 +02:00
91d7651eca
feat: add foreign one_to_one relationships
All checks were successful
CI / tests (push) Successful in 4m20s
2025-03-02 16:12:20 +01:00
4ff2df1a4e
chore: bump to 0.1.1
All checks were successful
CI / tests (push) Successful in 5m18s
0.1.1
2025-02-01 02:03:43 +01:00
f2e59cee7c
fix: correct docs.rs link and switch to GitHub repository
All checks were successful
CI / tests (push) Successful in 7m21s
2025-02-01 01:59:40 +01:00
d82f9fe2f4
docs: update readme
All checks were successful
CI / tests (push) Successful in 6m37s
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
All checks were successful
CI / tests (push) Successful in 4m26s
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