mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
init database constructor
This commit is contained in:
parent
7ac9260ba7
commit
2053ab01de
5 changed files with 71 additions and 5 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
/vendor/
|
/vendor/
|
||||||
/composer.lock
|
/composer.lock
|
||||||
/db.sqlite
|
/database.sqlite
|
||||||
|
|
@ -7,10 +7,11 @@ At this moment project under development!
|
||||||
* [x] Custom DNS resolver with memory cache, oriented to alt networks like [Yggdrasil](https://github.com/yggdrasil-network/yggdrasil-go)
|
* [x] Custom DNS resolver with memory cache, oriented to alt networks like [Yggdrasil](https://github.com/yggdrasil-network/yggdrasil-go)
|
||||||
* [x] Flexible settings in `config.json`, then UI
|
* [x] Flexible settings in `config.json`, then UI
|
||||||
* [x] Native GTK environment, no custom colors until you change it in `css`
|
* [x] Native GTK environment, no custom colors until you change it in `css`
|
||||||
* [x] Page tabs
|
* [x] Multi-tabs
|
||||||
* [ ] Local pages history snaps to make it accessible even offline
|
* [ ] Navigation history
|
||||||
* [ ] Bookmarks
|
* [ ] Bookmarks
|
||||||
* [ ] Certificate features
|
* [ ] Certificate features
|
||||||
|
* [ ] Local snaps to make resources accessible even offline
|
||||||
* [ ] `Gemfeed` reader
|
* [ ] `Gemfeed` reader
|
||||||
* [ ] Search engine integrations, probably [Yo!](https://github.com/YGGverse/Yo/tree/gemini) Search by default
|
* [ ] Search engine integrations, probably [Yo!](https://github.com/YGGverse/Yo/tree/gemini) Search by default
|
||||||
* [ ] Machine translations (e.g. [Lingva](https://github.com/thedaviddelta/lingva-translate) API)
|
* [ ] Machine translations (e.g. [Lingva](https://github.com/thedaviddelta/lingva-translate) API)
|
||||||
|
|
|
||||||
10
config.json
10
config.json
|
|
@ -2,6 +2,12 @@
|
||||||
"app":
|
"app":
|
||||||
{
|
{
|
||||||
"theme":"Default",
|
"theme":"Default",
|
||||||
|
"database":
|
||||||
|
{
|
||||||
|
"name":"database.sqlite",
|
||||||
|
"username":null,
|
||||||
|
"password":null
|
||||||
|
},
|
||||||
"header":
|
"header":
|
||||||
{
|
{
|
||||||
"enabled":true,
|
"enabled":true,
|
||||||
|
|
@ -123,6 +129,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"history":
|
||||||
|
{
|
||||||
|
"enabled":true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace Yggverse\Yoda\Entity;
|
||||||
|
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
|
public \Yggverse\Yoda\Model\Database $database;
|
||||||
|
|
||||||
public \GtkWindow $window;
|
public \GtkWindow $window;
|
||||||
public \GtkHeaderBar $header;
|
public \GtkHeaderBar $header;
|
||||||
public \GtkNotebook $tabs;
|
public \GtkNotebook $tabs;
|
||||||
|
|
@ -17,6 +19,13 @@ class App
|
||||||
// Init config
|
// Init config
|
||||||
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app; // @TODO
|
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app; // @TODO
|
||||||
|
|
||||||
|
// Init database
|
||||||
|
$this->database = new \Yggverse\Yoda\Model\Database(
|
||||||
|
$this->config->database->name,
|
||||||
|
$this->config->database->username,
|
||||||
|
$this->config->database->password
|
||||||
|
);
|
||||||
|
|
||||||
// Init theme
|
// Init theme
|
||||||
$css = new \GtkCssProvider();
|
$css = new \GtkCssProvider();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,52 @@ namespace Yggverse\Yoda\Model;
|
||||||
|
|
||||||
class Database
|
class Database
|
||||||
{
|
{
|
||||||
public function __construct()
|
public \PDO $database;
|
||||||
{}
|
|
||||||
|
public function __construct(
|
||||||
|
string $database,
|
||||||
|
?string $username = null,
|
||||||
|
?string $password = null
|
||||||
|
) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$this->database = new \PDO(
|
||||||
|
sprintf(
|
||||||
|
'sqlite:%s',
|
||||||
|
$database
|
||||||
|
),
|
||||||
|
$username,
|
||||||
|
$password
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->database->setAttribute(
|
||||||
|
\PDO::ATTR_ERRMODE,
|
||||||
|
\PDO::ERRMODE_EXCEPTION
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->database->setAttribute(
|
||||||
|
\PDO::ATTR_DEFAULT_FETCH_MODE,
|
||||||
|
\PDO::FETCH_OBJ
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->database->query('
|
||||||
|
CREATE TABLE IF NOT EXISTS "history"
|
||||||
|
(
|
||||||
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
"time" INTEGER NOT NULL,
|
||||||
|
"address" VARCHAR(1024) NOT NULL
|
||||||
|
)
|
||||||
|
');
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (\PDOException $exception)
|
||||||
|
{
|
||||||
|
exit(
|
||||||
|
print_r(
|
||||||
|
$exception->getMessage(),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue