mirror of
https://github.com/getml/sqlgen.git
synced 2026-02-17 14:18:39 -06:00
Use shared_ptrs for the connection
This commit is contained in:
@@ -18,14 +18,12 @@
|
||||
namespace sqlgen::sqlite {
|
||||
|
||||
class Connection : public sqlgen::Connection {
|
||||
using ConnPtr = std::unique_ptr<sqlite3, decltype(&sqlite3_close)>;
|
||||
using StmtPtr = std::unique_ptr<sqlite3_stmt, decltype(&sqlite3_finalize)>;
|
||||
using ConnPtr = Ref<sqlite3>;
|
||||
using StmtPtr = std::shared_ptr<sqlite3_stmt>;
|
||||
|
||||
public:
|
||||
Connection(const std::string& _fname)
|
||||
: stmt_(StmtPtr(nullptr, &sqlite3_finalize)), conn_(make_conn(_fname)) {}
|
||||
|
||||
Connection(const Connection& _other) = delete;
|
||||
: stmt_(nullptr), conn_(make_conn(_fname)) {}
|
||||
|
||||
static rfl::Result<Ref<sqlgen::Connection>> make(
|
||||
const std::string& _fname) noexcept;
|
||||
@@ -36,8 +34,6 @@ class Connection : public sqlgen::Connection {
|
||||
|
||||
Result<Nothing> execute(const std::string& _sql) noexcept final;
|
||||
|
||||
Connection& operator=(const Connection& _other) = delete;
|
||||
|
||||
Result<Ref<IteratorBase>> read(const dynamic::SelectFrom& _query) final {
|
||||
return error("TODO");
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ typename Connection::ConnPtr Connection::make_conn(const std::string& _fname) {
|
||||
throw std::runtime_error("Can't open database: " +
|
||||
std::string(sqlite3_errmsg(conn)));
|
||||
}
|
||||
return ConnPtr(conn, &sqlite3_close);
|
||||
return ConnPtr::make(std::shared_ptr<sqlite3>(conn, &sqlite3_close)).value();
|
||||
}
|
||||
|
||||
std::string Connection::properties_to_sql(
|
||||
|
||||
Reference in New Issue
Block a user