Git Product home page Git Product logo

db's Introduction

database

Simple cross-platform library based in the ActiveRecord from Ruby, an wrapper around SQL.

Building

Linux

git clone https://github.com/Moonslate/database.git
mkdir build
cd build
cmake ..
make

Basic Usage

User user;
user.name = "Dummy";
user.password = "Some Password";
user.age = 21;
user.save();

The code above executes

INSERT INTO users(name,password,age) VALUES ('Dummy','Some Password',21) RETURNING id;

The same can be archivied by

User user = User::create({
    { "name", "Dummy" },
    { "password", "Some Password" }
    { "age", 21 }
}); 

Creating a new record and a table

database new-model user --migrate

new-model generates the following code

include/models/user.hpp

#include <core.hpp>
#include <database.hpp>

class User : public uva::database::basic_active_record
{    
    uva_database_declare(User);
};

src/models/user.cpp

#include <user.hpp>

uva_database_define(User);

The optional --migrate option generates the following migration

src\migrations\20230129161842_add_users_migration.cpp

#include <core.hpp>
#include <database.hpp>

#include <user.hpp>

class AddUsersMigration : public uva::database::basic_migration
{
uva_declare_migration(AddUsersMigration);
protected:
    virtual void change() override 
    { 
        add_table("users",
        {
            { "id",         "INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" },
            { "updated_at", "INTEGER NOT NULL DEFAULT (STRFTIME('%s'))" },
            { "created_at", "INTEGER NOT NULL DEFAULT (STRFTIME('%s'))" },
            { "removed",    "INTEGER NOT NULL DEFAULT 0" },
        });
    }
};

uva_define_migration(AddUsersMigration);

Columns are defined inside the map in second parameter of add_table. Those columns are accessed by User::operator[](std::string), they'll only be available with the User::operator. when exposing the column inside the class:

uva_database_expose_column(password);

Supported database engines

  • SQLite3

Todo For Next (First) Release

  • Before save, update ๐Ÿ‘Œ
  • Create database tool ๐Ÿ‘Œ
  • Move multiple_value_holder to uva::core (and rename to var) ๐Ÿ‘Œ
  • Create database_exception
  • Strongly typed var ๐Ÿ‘Œ
  • Complete Todo List of uva::string
  • Complete Todo List of uva::string
  • Complete Todo List of uva::cspec
  • Have 100% of tests coverage

Priority (For future releases)

  • ๐Ÿž - Copy constructor of base class not works

Contributing

Just make a PR! :)

db's People

Contributors

andrey-moura avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.