The SWC-DB C++ Client/API (libswcdb)

The SWC-DB C++ Client API consists of all the required Types and Functions to manage columns, make queries and work with data-types. Applications are required to be built with -I having the swcdb/ on the path and linked with -lswcdb or with the tree of dependencies for a static-linkage.


The SWC-DB Initialization and Configuration Instance

The initialization and configuration is applied with an instance of SWC::Config::Settings. As the Settings instance life-time is required to be through the application runtime, it is strongly suggested to use a continues storage for it or use a managing class SWC::Env::Config of the singleton Settings instance.

  • a User managed continual storage:
    //#include "swcdb/core/config/Settings.h"
    #include "swcdb/db/client/Clients.h"
    
    int main(int argc, char** argv) {
      SWC::Config::Settings::Ptr setting(new SWC::Config::Settings());
      setting->init(argc, argv, nullptr, nullptr);
      // ...
    }
    
  • a SWC::Env::Config managed storage:
    //#include "swcdb/core/config/Settings.h"
    #include "swcdb/db/client/Clients.h"
    
    int main(int argc, char** argv) {
      SWC::Env::Config::init(argc, argv, nullptr, nullptr);
      auto setting = SWC::Env::Config::settings();
      // ...
    }
    

Users can add custom configuration properties with SWC::Config::Settings::init_option_t a static function typedef void SWC::Config::Settings::init_option_t(Settings *). Commonly used in SWC-DB applications as (argc, argv, &init_app_options, &init_post_cmd_args) or without new properties by applying nullptr.

The SWC::Config::Settings instance can be populated with all (dependent on run time requirements) the required configuration properties without using the .cfg files.


The SWC-DB Clients

The SWC::client::Clients instance manages the io-contexts, schemas cache, servers resolutions to role/range and the connections queues for the SWC-DB Manager, Ranger and Broker services. The required life-time of an instance is through the usage of the services. A singleton instance for the purpose is the SWC::Env::Clients::init(const SWC::client::Clients::Ptr&). The Clients constructor has 3 overloaders separated by the combinations of services to initialize Manager+Ranger+Broker, Manager+Ranger or only Broker

#include "swcdb/db/client/Clients.h"

int main(int argc, char** argv) {
  SWC::Env::Config::init(argc, argv, nullptr, nullptr);

  bool with_broker = false; // a Common config in tests and examples

  SWC::Env::Clients::init(
    (with_broker
      ? SWC::client::Clients::make(
          *SWC::Env::Config::settings(),
          SWC::Comm::IoContext::make("Clients", 8),
          nullptr  // std::make_shared<client::BrokerContext>()
        )
      : SWC::client::Clients::make(
          *SWC::Env::Config::settings(),
          SWC::Comm::IoContext::make("Clients", 8),
          nullptr, // std::make_shared<client::ManagerContext>()
          nullptr  // std::make_shared<client::RangerContext>()
        )
    )->init()
  );

  //..
  SWC::client::Clients::Ptr clients = SWC::Env::Clients::get();
  //..

  SWC::Env::Clients::get()->stop();
  return 0;
}

The SWC-DB Clients Instance is required by most of protocols commands' requests classes in the namespaces SWC::Comm::Protocol::{Bkr,Mngr,Rgr}::Req:: and by the pre-defined query handlers in namespace SWC::client::Query::.

The available Request classes by protocol service:

The available Query handlers:


The documentations are continuously in progress!

More information can be found at: