Skip to content
Branch: master
Go to file
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
 
 
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Build Status

ActiveRecord - a C++ implementation of the Active Record pattern.

Databases supported:

  • PostgreSQL
  • SQLite

Installation

See the file INSTALL.md.

Quick Start Guide

Here's a Hello World! example, that saves a record to the database, and retrieves it:

#include <active_record/type.h>
#include <active_record/base.h>
#include <active_record/connection.h>
#include <active_record/query.h>
#include <iostream>

class Greeting: public ActiveRecord::Base<Greeting> {
 public:
  AR_CONSTRUCTORS(Greeting)
  static ActiveRecord::Table table(ActiveRecord::Connection* connection) {
    ActiveRecord::Table td(connection, "greetings");
    td.fields() =
      ActiveRecord::fields
        ("salute",   ActiveRecord::Type::text)
        ("thing",    ActiveRecord::Type::text)
        ("language", ActiveRecord::Type::text);
    return td;
  }
};

AR_DECLARE(Greeting)

int main(int argc, const char *argv[]) {
  Connection connection;
  connection.connect(
    ActiveRecord::options
      ("adapter", "sqlite")
      ("database", "greetings.sqlite3")
    );
  Greeting::setup(&connection);
  connection.update_database();
  Greeting greeting(
    ActiveRecord::attributes
      ("salute", "Hello")
      ("thing", "World")
      ("language", "English")
  );
  greeting.save();

  Greeting greeting1(1);
  std::cout << "In " << greeting1["language"] << " you say:" << std::endl;
  std::cout << "'" << greeting1["salute"] << " " << greeting1["thing"] << "!'" << std::endl;

  return 0;
}

Development and Tests

See the file DEVELOPMENT.md.

Other information

  • Usage
    • See the examples directory
  • Documentation
    • See the doc directory

About

A C++ Implementation of the Active Record Pattern

Resources

License

Releases

No releases published
You can’t perform that action at this time.