Skip to content

mmjvox/lazy-orm-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

141 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ Warning: Under Active Development
This library is in the early stages of development. The API is unstable and may change significantly without notice until version 1.0.0 is released. Expect bugs, incomplete documentation, and rough edges.

🚧 Not recommended for production use.

C++20 License CMake

LazyOrm-CPP

A lazy ORM for C++ that makes SQL query building simple and elegant.

FeaturesQuick StartInstallationExamplesDocumentation


Features

  • Simple API: Build SQL queries with intuitive operator syntax
  • Multi-Database: Support for MariaDB/MySQL, PostgreSQL, and SQLite
  • CRUD Operations: INSERT, SELECT, UPDATE, DELETE with ease
  • Advanced Filters: WHERE, ORDER BY, GROUP BY, LIMIT, HAVING
  • Bulk Operations: Efficient bulk insert and update
  • Transactions: Built-in transaction support
  • Type-Safe: Strong typing with DbVariant for multiple data types
  • C++20: Modern C++ features and best practices

Quick Start

#include "MariadbLazy.h"
#include <iostream>

int main() {
    LazyOrm::MariadbLazy lazyOrm;
    lazyOrm[LazyOrm::INSERT] = "users";
    lazyOrm["name"] = "John Doe";
    lazyOrm["email"] = "john@example.com";
    lazyOrm["age"] = 30;

    std::cout << lazyOrm.query_with_trim_consecutive_spaces() << std::endl;
    // Output: INSERT INTO users (`age`,`email`,`name`) VALUES ('30','john@example.com','John Doe') ;

    return 0;
}

Installation

Requirements

  • CMake 3.15 or higher
  • C++20 compatible compiler (GCC 9+, Clang 10+, MSVC 19.28+)

Build from Source

git clone https://github.com/your-repo/lazy-orm-cpp.git
cd lazy-orm-cpp
mkdir build && cd build
cmake ..
cmake --build .

Use in Your Project

add_subdirectory(path/to/lazy-orm-cpp)
target_link_libraries(your_app PRIVATE lazyorm)

Examples

SELECT with WHERE

LazyOrm::MariadbLazy lazyOrm;
lazyOrm[LazyOrm::SELECT] = "users";
lazyOrm << "name" << "email" << "age";
lazyOrm[LazyOrm::WHERE] = {{"age", ">=", "18"}};
lazyOrm[LazyOrm::ORDERBY_DESC] = {{"created_at"}};
lazyOrm[LazyOrm::LIMIT] = "0,10";

UPDATE with Conditions

LazyOrm::MariadbLazy lazyOrm;
lazyOrm[LazyOrm::UPDATE] = "users";
lazyOrm["name"] = "John Doe";
lazyOrm["email"] = "newemail@example.com";
lazyOrm[LazyOrm::WHERE] = {{"id", "=", "1"}};

DELETE with Filter

LazyOrm::MariadbLazy lazyOrm;
lazyOrm[LazyOrm::DELETE] = "users";
lazyOrm[LazyOrm::WHERE] = {{"active", false}};

Bulk INSERT

LazyOrm::MariadbLazy lazyOrm;
lazyOrm[LazyOrm::BULK_INSERT] = "users";
lazyOrm.setProperties({
    {{"name", "John"}, {"email", "john@example.com"}, {"age", 30}},
    {{"name", "Jane"}, {"email", "jane@example.com"}, {"age", 25}},
    {{"name", "Bob"}, {"email", "bob@example.com"}, {"age", 35}}
});

Transaction

#include "Transaction.h"

LazyOrm::MariadbLazy q1, q2;
q1[LazyOrm::INSERT] = "users";
q1["name"] = "John";

q2[LazyOrm::INSERT] = "logs";
q2["action"] = "user_created";

LazyOrm::Transaction<LazyOrm::MariadbLazy> transaction({q1, q2});
// Output: START TRANSACTION; INSERT ... ; INSERT ... ; COMMIT;

Complex WHERE

LazyOrm::MariadbLazy lazyOrm;
lazyOrm[LazyOrm::SELECT] = "users";
lazyOrm << "name" << "age";

lazyOrm[LazyOrm::WHERE] = {
    {
        {"name", "like", "John%"},
        {"OR"},
        {"name", "like", "Jane%"}
    },
    {"AND"},
    {"age", "between", "18,65"}
};

Database Support

Database Class Example
MariaDB/MySQL MariadbLazy LazyOrm::MariadbLazy
PostgreSQL PostgreLazy LazyOrm::PostgreLazy
SQLite SqliteLazy LazyOrm::SqliteLazy

Documentation


License

Licensed under the MIT License.


Author

mmjvox - GitHub

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages