From 8de9fd30276a273e715c0f3ee4cf227d2927bb36 Mon Sep 17 00:00:00 2001
From: Jeena <spam@jeenaparadies.net>
Date: Wed, 15 Jul 2015 20:04:07 -0700
Subject: adds possibility to use sqlite as a db

---
 lib/config.template.php |  5 +++++
 lib/helpers.php         | 10 +++++++---
 schema/mysql.sql        | 23 +++++++++++++++++++++++
 schema/schema.sql       | 23 -----------------------
 schema/sqlite.sql       | 22 ++++++++++++++++++++++
 5 files changed, 57 insertions(+), 26 deletions(-)
 create mode 100644 schema/mysql.sql
 delete mode 100644 schema/schema.sql
 create mode 100644 schema/sqlite.sql

diff --git a/lib/config.template.php b/lib/config.template.php
index dae8968..ee822bb 100644
--- a/lib/config.template.php
+++ b/lib/config.template.php
@@ -4,11 +4,16 @@ class Config {
   public static $base_url = 'http://quill.dev/';
   public static $gaid = '';
 
+  // MySQL (default)
   public static $dbHost = '127.0.0.1';
   public static $dbName = 'quill';
   public static $dbUsername = 'quill';
   public static $dbPassword = '';
 
+  // Sqlite
+  // public static $dbType = 'sqlite';
+  // public static $dbFilePath = './example.db';
+
   public static $jwtSecret = 'xxx';
 
   public static $fbClientID = '';
diff --git a/lib/helpers.php b/lib/helpers.php
index 4f6b4c1..e7e7771 100644
--- a/lib/helpers.php
+++ b/lib/helpers.php
@@ -1,8 +1,12 @@
 <?php
 
-ORM::configure('mysql:host=' . Config::$dbHost . ';dbname=' . Config::$dbName);
-ORM::configure('username', Config::$dbUsername);
-ORM::configure('password', Config::$dbPassword);
+if(Config::$dbType == 'sqlite') {
+  ORM::configure('sqlite:' . Config::$dbFilePath);
+} else {
+  ORM::configure('mysql:host=' . Config::$dbHost . ';dbname=' . Config::$dbName);
+  ORM::configure('username', Config::$dbUsername);
+  ORM::configure('password', Config::$dbPassword);  
+}
 
 function render($page, $data) {
   global $app;
diff --git a/schema/mysql.sql b/schema/mysql.sql
new file mode 100644
index 0000000..5f33ce6
--- /dev/null
+++ b/schema/mysql.sql
@@ -0,0 +1,23 @@
+CREATE TABLE `users` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `url` varchar(255) DEFAULT NULL,
+  `authorization_endpoint` varchar(255) DEFAULT NULL,
+  `token_endpoint` varchar(255) DEFAULT NULL,
+  `micropub_endpoint` varchar(255) DEFAULT NULL,
+  `micropub_access_token` text,
+  `micropub_scope` varchar(255) DEFAULT NULL,
+  `micropub_response` text,
+  `micropub_success` tinyint(4) DEFAULT '0',
+  `date_created` datetime DEFAULT NULL,
+  `last_login` datetime DEFAULT NULL,
+  `last_micropub_response` text,
+  `last_micropub_response_date` datetime DEFAULT NULL,
+  `location_enabled` tinyint(4) NOT NULL DEFAULT '0',
+  `syndication_targets` text,
+  `facebook_access_token` text,
+  `twitter_access_token` text,
+  `twitter_token_secret` text,
+  `twitter_username` varchar(255) DEFAULT NULL,
+  `instagram_access_token` text,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
diff --git a/schema/schema.sql b/schema/schema.sql
deleted file mode 100644
index 5f33ce6..0000000
--- a/schema/schema.sql
+++ /dev/null
@@ -1,23 +0,0 @@
-CREATE TABLE `users` (
-  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
-  `url` varchar(255) DEFAULT NULL,
-  `authorization_endpoint` varchar(255) DEFAULT NULL,
-  `token_endpoint` varchar(255) DEFAULT NULL,
-  `micropub_endpoint` varchar(255) DEFAULT NULL,
-  `micropub_access_token` text,
-  `micropub_scope` varchar(255) DEFAULT NULL,
-  `micropub_response` text,
-  `micropub_success` tinyint(4) DEFAULT '0',
-  `date_created` datetime DEFAULT NULL,
-  `last_login` datetime DEFAULT NULL,
-  `last_micropub_response` text,
-  `last_micropub_response_date` datetime DEFAULT NULL,
-  `location_enabled` tinyint(4) NOT NULL DEFAULT '0',
-  `syndication_targets` text,
-  `facebook_access_token` text,
-  `twitter_access_token` text,
-  `twitter_token_secret` text,
-  `twitter_username` varchar(255) DEFAULT NULL,
-  `instagram_access_token` text,
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
diff --git a/schema/sqlite.sql b/schema/sqlite.sql
new file mode 100644
index 0000000..ac691e3
--- /dev/null
+++ b/schema/sqlite.sql
@@ -0,0 +1,22 @@
+CREATE TABLE users (
+  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
+  url TEXT,
+  authorization_endpoint TEXT,
+  token_endpoint TEXT,
+  micropub_endpoint TEXT,
+  micropub_access_token TEXT,
+  micropub_scope TEXT,
+  micropub_response TEXT,
+  micropub_success INTEGER default 0,
+  date_created datetime,
+  last_login datetime,
+  last_micropub_response TEXT,
+  last_micropub_response_date datetime,
+  location_enabled INTEGER NOT NULL default 0,
+  syndication_targets TEXT,
+  facebook_access_token TEXT,
+  twitter_access_token TEXT,
+  twitter_token_secret TEXT,
+  twitter_username TEXT,
+  instagram_access_token TEXT
+);
\ No newline at end of file
-- 
cgit v1.2.3