Added rudimentary SQLite support.
This commit is contained in:
parent
8da0ad07f0
commit
76548146c0
|
@ -34,7 +34,7 @@ link_directories(${LIBXDG_BASEDIR_LIBRARY_DIRS})
|
||||||
link_directories(${SQLITE3_LIBRARY_DIRS})
|
link_directories(${SQLITE3_LIBRARY_DIRS})
|
||||||
|
|
||||||
set(COMMON_LIBRARIES
|
set(COMMON_LIBRARIES
|
||||||
${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp)
|
${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs)
|
||||||
|
|
||||||
# Write version in header
|
# Write version in header
|
||||||
configure_file(
|
configure_file(
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
This program is not usable at the moment. Most of the described functions are
|
This program is not usable at the moment. Most of the described functions are
|
||||||
not yet available.
|
not yet available.
|
||||||
|
|
||||||
*remwharead* saves URLs of things you read in a database along with the current
|
*remwharead* saves URLs of things you read in a database along with an URL to
|
||||||
date and time, title, description, the full text of the page and optional tags.
|
the archived version, the current date and time, title, description, the full
|
||||||
|
text of the page and optional tags.
|
||||||
|
|
||||||
== Usage
|
== Usage
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
:doctype: manpage
|
:doctype: manpage
|
||||||
:Author: tastytea
|
:Author: tastytea
|
||||||
:Email: tastytea@tastytea.de
|
:Email: tastytea@tastytea.de
|
||||||
:Date: 2019-05-12
|
:Date: 2019-05-14
|
||||||
:Revision: 0.0.0
|
:Revision: 0.0.0
|
||||||
:man source: remwharead
|
:man source: remwharead
|
||||||
:man manual: General Commands Manual
|
:man manual: General Commands Manual
|
||||||
|
@ -19,8 +19,9 @@ remwharead - Remember what you read, and when
|
||||||
|
|
||||||
== DESCRIPTION
|
== DESCRIPTION
|
||||||
|
|
||||||
*remwharead* saves URLs of things you read in a database along with the current
|
*remwharead* saves URLs of things you read in a database along with an URL to
|
||||||
date and time, title, description, the full text of the page and optional tags.
|
the archived version, the current date and time, title, description, the full
|
||||||
|
text of the page and optional tags.
|
||||||
|
|
||||||
== OPTIONS
|
== OPTIONS
|
||||||
|
|
||||||
|
|
|
@ -32,5 +32,11 @@ int main(const int argc, const char *argv[])
|
||||||
return opts.status_code;
|
return opts.status_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Database db;
|
||||||
|
db ? cout << "success." : cout << "failure.";
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
db.store("a", "b", "c", "d", "e", "f", "g");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
78
src/sqlite.cpp
Normal file
78
src/sqlite.cpp
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/* This file is part of remwharead.
|
||||||
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
#include <basedir.h>
|
||||||
|
#include <sqlite/execute.hpp>
|
||||||
|
#include <sqlite/query.hpp>
|
||||||
|
#include "sqlite.hpp"
|
||||||
|
|
||||||
|
using std::cerr;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
|
Database::Database()
|
||||||
|
: _connected(false)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
xdgHandle xdg;
|
||||||
|
xdgInitHandle(&xdg);
|
||||||
|
_dbpath = xdgDataHome(&xdg) / fs::path("remwharead");
|
||||||
|
xdgWipeHandle(&xdg);
|
||||||
|
|
||||||
|
if (!fs::exists(_dbpath))
|
||||||
|
{
|
||||||
|
fs::create_directories(_dbpath);
|
||||||
|
}
|
||||||
|
_dbpath /= "database.sqlite";
|
||||||
|
|
||||||
|
_con = std::make_unique<sqlite::connection>(_dbpath);
|
||||||
|
sqlite::execute(*_con, "CREATE TABLE IF NOT EXISTS remwharead("
|
||||||
|
"uri TEXT, archive_uri TEXT, datetime TEXT, tags TEXT, "
|
||||||
|
"title TEXT, description TEXT, fulltext TEXT);", true);
|
||||||
|
|
||||||
|
_connected = true;
|
||||||
|
}
|
||||||
|
catch (std::exception &e)
|
||||||
|
{
|
||||||
|
cerr << "Error: " << e.what() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Database::operator bool() const
|
||||||
|
{
|
||||||
|
return _connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Database::store(const string &uri, const string &archive_uri,
|
||||||
|
const string &datetime, const string &tags,
|
||||||
|
const string &title, const string &description,
|
||||||
|
const string &fulltext)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sqlite::execute ins(*_con, "INSERT INTO remwharead "
|
||||||
|
"VALUES(?, ?, ?, ?, ?, ?, ?);");
|
||||||
|
ins % uri % archive_uri % datetime % tags
|
||||||
|
% title % description % fulltext;
|
||||||
|
ins();
|
||||||
|
}
|
||||||
|
catch (std::exception &e)
|
||||||
|
{
|
||||||
|
cerr << "Error: " << e.what() << endl;
|
||||||
|
}
|
||||||
|
}
|
44
src/sqlite.hpp
Normal file
44
src/sqlite.hpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/* This file is part of remwharead.
|
||||||
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef REMWHAREAD_SQLITE_HPP
|
||||||
|
#define REMWHAREAD_SQLITE_HPP
|
||||||
|
|
||||||
|
#include <experimental/filesystem>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <sqlite/connection.hpp>
|
||||||
|
|
||||||
|
namespace fs = std::experimental::filesystem;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
class Database
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Database();
|
||||||
|
operator bool() const;
|
||||||
|
|
||||||
|
void store(const string &uri, const string &archive_uri,
|
||||||
|
const string &datetime, const string &tags, const string &title,
|
||||||
|
const string &description, const string &fulltext);
|
||||||
|
|
||||||
|
private:
|
||||||
|
fs::path _dbpath;
|
||||||
|
std::unique_ptr<sqlite::connection> _con;
|
||||||
|
bool _connected;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // REMWHAREAD_SQLITE_HPP
|
Loading…
Reference in New Issue
Block a user