Awesome
<h1><img src="https://github.com/silverqx/TinyORM/blob/main/resources/icons/logo-optim.svg" width="34" height="34" alt="TinyORM Logo" align="center"> TinyORM</h1>TinyORM is a modern ORM library that makes interacting with a database extremely simple.
The code is written in the modern c++20 way and is heavily tested with 3378 unit and functional tests. Almost all the query builder methods are unit tested. The TinyORM's query builder code and the code which is responsible for obtaining relationships, is tested by functional tests against all supported databases. The code coverage is good enough to guarantee API and behavior compatibility.
Donations ๐ช
Bitcoin addressย ย 1NiF2cTvYxUj8FTZJnGn1ycN4yisWfo1vJ<br/> PayPalย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย https://paypal.me/silverzachara
Documentation
The whole library is documented as markdown documents:
- Prologue
- Dependencies
- Supported Compilers
- Database
- TinyORM
- TinyDrivers
- Building
- Stability
- Features Summary
- Donations
Features Summary
Summary List
The following list summarizes the main features of the TinyDrivers
and TinyMySql
libraries. ๐
- can be used instead of the
QtSql
module- can be <ins>swapped</ins> at compile time ๐คฏ
- has 1:1 API as the
QtSql
module ๐ฎ - swapping is controlled by the
qmake
andCMake
build system options - was designed to drop the
QtSql
dependency while maintaining backward compatibility and without the need for any code changes after the swap
- currently, only the
MySQL
database driver is supported and finished ๐ - both, normal and prepared statements are supported
- TLS/SSL connections using
MYSQL_OPT_SSL_MODE
(verify_ca, verify_identity) ๐ฅ - setting many other MySQL connection options (see
mysqldriver_p.cpp
) - building and linking against the
MariaDB Connector/C
๐บ - transactions
- re-using the current
SqlQuery
instance to re-execute the same or another SQL query - detaching from the result set (related to freeing/releasing memory)
- query size, number of affected rows, last inserted ID, testing
isNull()
, ... TinyDrivers
library supports both build systemsqmake
and alsoCMake
- all 3378 unit tests passed ๐ฎ
- strictly using smart pointers (no
new
keyword in the wholeTinyDrivers
code base ๐) - clear code ๐ค
The following list quickly summarizes all the TinyORM
features.
- simple database connections management ๐งฌ
- database manager that helps with the database connections management
Orm::DB
facade class for nicer and shorter syntax- MySQL, MariaDB, SQLite, and PostgreSQL support for all features ๐
- multi-threading support ๐
- SSL connections support ๐
- impressive query builder ๐ง
- allows passing sub-queries and raw expressions practically everywhere, to column names, values, and to every SQL clause as select, where, joins, group by, having, order by ๐ฅ
- a logical grouping that offers to wrap logical groups in parenthesis
- chunked results for lower memory footprint โจ
- raw methods for all SQL clauses
- all join types (left, right, cross, inner) and also join where clause support ๐ซค
- aggregate methods min, max, sum, increment, decrement, ...
- whereExists and exists methods for an existence queries
- transactions and pessimistic locking ๐
- of course, insert, update, and delete SQL clauses support
- correct QDateTime time zone using the
qt_timezone
connection configuration option ๐ (returned QDateTime instances will have the correct time zone, and also works for an ORM)- this feature allows you to set up the database server time zone to the UTC and all returned QDateTime instances will have the correct UTC time zone
- clever ORM with all relation types support ๐
- one-to-one, one-to-many, and many-to-many relation types (also inverse relationships) ๐งจ
- eager and lazy loading with custom select and constraints ๐
- fluent
ModelsCollection
that expose a variety of map / reduce operations that may be chained using an intuitive interface โจ - all query builder methods are proxied from the model instances and also from the relation instances back to the query builder ๐คฏ (everything that can be called on the query builder can also be called on the model and relation instances)
- clean active record pattern
- advanced features like timestamps, touching parent timestamps, soft deleting, default models, default model attributes, and attributes casting ๐ค
- querying relationships existence/absence using the has, whereHas, and hasNested methods (using dot notation for selecting nested relationships users.posts.comments)
- serializing models and collection of models including all nested relations to JSON and converting to vectors and maps ๐ชก
- supports controlling a custom date format during serialization
- supports hiding and appending attributes
- supports defining Accessors (transform attribute value when it is accessed; eg. building value from multiple attributes)
- compiled database migrations and seeders ๐บ
- create, update, drop, and rename database tables
- create, update, drop, and rename table columns
- extensive schema builder that allows creating of all possible column types
- terser syntax for creating foreign keys and foreign key constraints
- supports creating and dropping column indexes (primary, unique, fulltext, spatial)
- the
tom
console application with tab completion for all shells (pwsh, bash, zsh) ๐ฅณ- tab completion is as accurate as possible
- completes commands, long and short parameters, argument values
- even connection names can be completed
- migrate, fresh, refresh, rollback, and reset migrate operations
- install and uninstall migration repository (table that tracks migrations and batches; table name can be customized)
- seed and wipe database operations
- scaffolding of models, migrations, and seeders
- impressive models scaffolding, every feature that is supported by models can be generated using the
tom make:model
cli command
- tab completion is as accurate as possible
- others ๐
- a huge amount of code is unit tested, currently 3378 unit tests ๐คฏ
- C++20 only, with all the latest features used like concepts/constraints, ranges, smart pointers (no
new
keyword in the whole code base ๐), folding expressions - qmake and CMake build systems support
- CMake FetchContent module support ๐ค
- LTO support (backed up by CI)
- vcpkg support (official tinyorm vcpkg port)
- official port doesn't allow to have alternative implementations so it doesn't contain TinyDrivers
- unofficial tinyorm vcpkg port with TinyDrivers support (currently MySQL only)
- it's really fast, you can run 1000 complex queries in 500ms (heavily DB dependent, the PostgreSQL is by far the fastest) โ
- extensive documentation ๐
- ...
:::info
See the TinyDrivers
Features summary.
:::
Showcase Images
Tom console application
Passed all unit tests ๐ฅณ
TinyOrmPlayground
The TinyOrmPlayground project is my personal project where I have tested all the TinyORM database queries in the early development phases, currently, it executes ~1600 database queries across the whole TinyORM framework. Every query has a nice title header, is logged to the console, and is counted and measured (elapsed time). Every query also runs on all Supported Databases.
The TinyOrmPlayground project can be compiled in a single-threaded or multi-threaded mode. In the multi-threaded mode, every database connection runs in its own thread. The connection summary is logged at the end of every database connection and the application summary is logged before an exit. Whole TinyOrmPlayground application is configurable through the src/configuration.hpp class.