https://github.com/emirror-de/naphtha
Universal database connection layer for your application in Rust. Implements the most common functions insert, update and remove for database connections. Change the database without having to adjust your code. Specific models can be stored in different databases. Query models by property. Migrations in pure Rust and available during runtime.
https://github.com/emirror-de/naphtha
database database-connector database-migrations models rust-lang
Last synced: about 1 year ago
JSON representation
Universal database connection layer for your application in Rust. Implements the most common functions insert, update and remove for database connections. Change the database without having to adjust your code. Specific models can be stored in different databases. Query models by property. Migrations in pure Rust and available during runtime.
- Host: GitHub
- URL: https://github.com/emirror-de/naphtha
- Owner: emirror-de
- License: other
- Created: 2021-04-14T12:24:48.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2022-09-12T15:15:36.000Z (almost 4 years ago)
- Last Synced: 2025-04-23T23:48:12.794Z (about 1 year ago)
- Topics: database, database-connector, database-migrations, models, rust-lang
- Language: Rust
- Homepage:
- Size: 115 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# naphtha
*Universal database connection layer*
[](COPYRIGHT.md)
[](https://crates.io/crates/naphtha) [](https://docs.rs/naphtha) **naphtha**
[](https://crates.io/crates/naphtha-proc-macro) **naphtha-proc-macro**
Please checkout the [documentation page](https://docs.rs/naphtha) for more information (also see examples folder in [naphtha](./naphtha/examples))
## About
This crate is to simplify the creation and usage of models that require a database connection. If applied correct, changing the database type is only a feature flag away.
The models can also be compiled and used without database connection support for better usage on server and client side.
## Roadmap
- [x] Connect to database using a wrapper, defining the base for interchangeable Databases
- [x] Implement support for `diesel::SQLiteConnection`
- [x] Create traits to enable database interaction before and after the execution of the `insert`, `update` or `remove` transactions
- [x] Implement `query_by_{property}` for querying models from the database using an exact match of the given property
- [x] Thread safe sharing of the database connection
- [x] Integrate `barrel` crate for writing migrations in Rust, available at runtime
- [x] Implement support for `diesel::MySqlConnection`
- [x] Implement support for `diesel::PgConnection`
- [ ] Connection pooling?
- [ ] More databases?
## Troubleshooting
It is very easy to get a whole bunch of `trait bound not satisfied` error messages when your model is not configured correctly. Make sure that your `schema` module and the containing `table!` definition is in line with your `model` definition and that it uses the correct types defined by [barrel](https://docs.rs/barrel).
## Contributing
Unless explicitly stated, any contribution intentionally submitted
for inclusion in this project, as defined in the Apache-2.0 license, shall be
dual licensed as below, without any additional terms or conditions.
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
https://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or
https://opensource.org/licenses/MIT)
at your option.