1
/* This file will include set of functions
2
* to store, retrieve and modify data from database.
5
.import QtQuick.LocalStorage 2.0 as SQL
8
/* For internal usage in module.
10
function openStdDataBase() {
11
return SQL.LocalStorage.openDatabaseSync("RSS Reader", "1.0", "Feed DB", 10000)
14
function ensureTableExists(transaction) {
15
transaction.executeSql('CREATE TABLE IF NOT EXISTS UserFeeds(link STRING PRIMARY KEY, displayName STRING, siteLink STRING, description STRING)')
17
/* Internal module usage end. */
19
/* This variable will store result of any operation with database.
23
/* Load all feed from database.
24
* Mb later we will need some criteria, such as tag, date and so on!
26
function loadFeeds() {
27
var db = openStdDataBase()
29
db.transaction(function(tx) {
31
dbResult = tx.executeSql("SELECT * FROM UserFeeds")
32
console.log("SELECTED: ", dbResult.rows.length)
37
/* Add feed to database.
38
* Now only 3 fields, later - more (date, tag and etc.)
40
function addFeed(link, displayName, siteLink, description) {
41
displayName = displayName || ""
42
siteLink = siteLink || ""
43
description = description || ""
45
var db = openStdDataBase()
47
db.transaction(function (tx) {
49
dbResult = tx.executeSql('INSERT INTO UserFeeds VALUES(?, ?, ?, ?)', [link , displayName, siteLink, description])
50
console.log("INSERT ID", dbResult.insertId)
55
function updateWithInfo(link, displayName, siteLink, description) {
56
var db = openStdDataBase()
58
db.transaction(function (tx) {
60
dbResult = tx.executeSql('UPDATE UserFeeds SET displayName=?, siteLink=?, description=? WHERE link=?', [displayName, siteLink, description, link])
61
console.log("UPDATE, AFFECTED ROWS", dbResult.rowsAffected)
66
function deleteFeed(link) {
67
var db = openStdDataBase()
69
db.transaction(function (tx) {
71
dbResult = tx.executeSql('DELETE FROM UserFeeds WHERE link = ?', [link])
72
console.log("DELETE, AFFECTED ROWS", dbResult.rowsAffected)
77
/* Only for debug purposes.
79
function dropTable() {
80
var db = openStdDataBase()
82
db.transaction(function(tx) {
83
tx.executeSql("DROP TABLE IF EXISTS UserFeeds")
84
console.log("DATABASE DELETED")