#pragma once #include #include #include class DB; class DBStatement; class DBQueryRow { public: DBQueryRow(DBStatement &); public: template T col(int index, const T & default_value) const; template T col(int index) const; private: DBStatement & parent; }; class DBQueryRowRange { public: DBQueryRowRange(DBStatement & stmt); private: class DBQueryRowIterator { public: DBQueryRowIterator(DBQueryRowRange & parent); public: DBQueryRow & operator * () const; DBQueryRowIterator & operator ++ (); bool operator != (const DBQueryRowIterator &) const; private: bool end = false; DBQueryRowRange & parent; }; public: DBQueryRowIterator begin(); DBQueryRowIterator end(); private: DBStatement & parent; DBQueryRow row; }; class DBStatement { friend class DBQueryRow; friend class DBQueryRowRange; public: DBStatement(const DB &, const std::string & query); public: DBStatement & reset(); DBStatement & bind(const std::string & text); DBStatement & bind(const int & number); public: void execute(); DBQueryRow row(); DBQueryRowRange rows(); private: std::unique_ptr> stmt; int param_index = 1; const DB & parent; }; class DB { friend class DBStatement; public: DB(const std::string & path); DBStatement prepare(const std::string & query) const; private: std::unique_ptr> db = NULL; };