sqlxgentools/README.md

56 lines
1.4 KiB
Markdown
Raw Normal View History

2024-12-27 23:05:15 +01:00
# [WIP] sqlxgentools
2025-03-15 10:21:53 +01:00
Tools to generate SQL migrations and Rust SQLx repositories code from models structs to use with a SQLite database.
2024-12-27 23:05:15 +01:00
Will be used in [minauthator](https://forge.lefuturiste.fr/mbess/minauthator).
## Project context
### Goals
- Help developers that dont use ORM and use SQLx in a Rust project with a SQLite DB.
- Auto generate boilerplate repositories pattern code
- Auto generate CREATE TABLE base migrations from model struct
- Auto generate Up and Down migrations
- Let developer have flexibility over the model definition
### Non-goals
- Provide a full a ORM interface
2025-03-15 10:21:53 +01:00
## Features
- [x] generate migrations
- [x] from scratch
- [ ] up migration
- [ ] down migration
- [x] generate repositories
- [x] get_all
- [x] get_by_id
- [x] insert
- [x] insert_many
- [ ] generate custom by
- [x] co-exist with custom repository
2025-03-15 10:21:53 +01:00
2024-12-27 23:05:15 +01:00
## Usage
### Generate initial CREATE TABLE sqlite migration
cargo run --bin sqlx-generator -- ./path/to/project generate-create-migrations > migrations/all.sql
2025-10-12 14:02:20 +02:00
sqlx-generator \
-m path/to/models \
gen-repositories \
-o path/to/repositories
sqlx-generator \
-m path/to/models \
gen-migrations \
-o path/to/migrations/all.sql
2024-12-27 23:05:15 +01:00
### Generate repositories code
not implemented yet
cargo run --bin sqlx-generator -- ./path/to/project generate-repositories