Database #140
Replies: 4 comments 2 replies
-
As times goes by, I realized that I can just add/remove/rename a table and its columns as I like. Starting from SQLite v3.25.0 the feature is available via Why SQLite? I decided to use SQLite for some reasons:
|
Beta Was this translation helpful? Give feedback.
-
kalau kita buat tombol like dislike itu, masuk ke penggunaan database ya kang? |
Beta Was this translation helpful? Give feedback.
-
There are many third-party alternative features that allow me to form a beautiful SQL query like this: $page = Base::table('page')->where('id', '=', 24)->first(); Or like this: $page = $base->table('page')->where('id', '=', 24)->first(); But after I did a reflection back on my decision when releasing version 2.2.0 in the past is that this feature might trap me in a situation like when there is still a class SQLite is not that complicated and I might be able to create a database extension that provides simply a static function to query the database: $base = new SQLite3('.\lot\base\table.db');
function base(string $query, array $lot = []) {
$base = $GLOBALS['base'];
$q = $base->prepare($query);
if (array_is_list($lot)) {
foreach ($lot as $k => $v) {
// Positional numbering starts at `1`
$q->bindValue($k + 1, is_array($v) ? json_encode($v) : $v);
}
} else {
foreach ($lot as $k => $v) {
$q->bindValue(':' . $k, is_array($v) ? json_encode($v) : $v);
}
}
$rows = $q->execute();
while ($row = $rows->fetchArray(SQLITE3_ASSOC)) {
yield $row;
}
} Usage would be something like this: $pages = new Pages(y(base('SELECT * FROM "page" WHERE "route" LIKE ? ORDER BY "time" DESC LIMIT 20 OFFSET ?', ['/article/%', 0]))); // First 20 pages chunk $page = new Page(null, base('SELECT * FROM "page" WHERE "route" = ?', ['/article/lorem-ipsum'])->current() ?? []); // Single page Table would look like this: CREATE TABLE "page" (
"content" TEXT,
"description" TEXT,
"id" INTEGER PRIMARY KEY,
"link" TEXT,
"route" TEXT,
"time" TEXT,
"title" TEXT,
"type" TEXT
)
|
Beta Was this translation helpful? Give feedback.
-
apakah nanti extension ini memungkinkan menyimpan tags, category, fitur pencarian secara global ya kang? penyimpanannya gak berdasarkan folder-folder-an lagi ya kang. karena mecha versi yang sekarang masih terbatas di lingkup folder page nya aja |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In the future, if page’s data have become standard and familiar, I want to develop Mecha further by providing an optional database feature. Considering that page’s data are very dynamic, I want a database system that supports dynamic column features like this one.
This kind of feature allows me to add custom fields as I like, while still being able to have default columns whose the length will not change. I will use the standard column names for sorting and filtering purposes.
Beta Was this translation helpful? Give feedback.
All reactions