{"size": 1803, "ext": "js", "max_stars_repo_path": "src/Database.js", "max_stars_repo_name": "yasavbrain/yasav", "max_stars_repo_stars_event_min_datetime": "2017-10-31T10:11:04.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-20T15:25:49.000Z", "max_issues_repo_path": "src/Database.js", "max_issues_repo_name": "yasavbrain/yasav", "max_issues_repo_issues_event_min_datetime": "2018-01-17T08:26:39.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-31T22:22:05.000Z", "max_forks_repo_path": "src/Database.js", "max_forks_repo_name": "yasavbrain/yasav", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 25.7571428571, "max_line_length": 61, "alphanum_fraction": 0.6616749861}
import { SQLite } from 'expo';

// db needs to be a singleton in all the project
export default db = SQLite.openDatabase('yasav.db');

// we need to separate all the requests;
export const CREATE_DB_TABLES_REQUESTS = [
  `CREATE TABLE IF NOT EXISTS activity (
    id INTEGER PRIMARY KEY NOT NULL,
    title TEXT,
    description TEXT,
    type INT,
    activity_date DATE,
    visible BOOLEAN,
    content_source TEXT,
    interlocutor_id INT,
    FOREIGN KEY (interlocutor_id) REFERENCES interlocutor(id)
  );`,
  `CREATE TABLE IF NOT EXISTS interlocutor (
    id INTEGER PRIMARY KEY NOT NULL,
    name TEXT,
    link_to_me TEXT,
    type INT,
    characteristics TEXT
  );`,
  `CREATE TABLE IF NOT EXISTS todo (
    id INTEGER PRIMARY KEY NOT NULL,
    title TEXT,
    due_date DATETIME,
    priority INT,
    status INT,
    activity_id INT,
    FOREIGN KEY (activity_id) REFERENCES activity(id)
  );`,
  `CREATE TABLE IF NOT EXISTS tag (
    id INTEGER PRIMARY KEY NOT NULL,
    name TEXT,
    slug TEXT
  );`,
  `CREATE TABLE IF NOT EXISTS activity_tag (
    id INTEGER PRIMARY KEY NOT NULL,
    activity_id INT,
    tag_id INT,
    FOREIGN KEY (activity_id) REFERENCES activity(id),
    FOREIGN KEY (tag_id) REFERENCES tag(id)
  );`,
  `CREATE TABLE IF NOT EXISTS activity_link (
    id INTEGER PRIMARY KEY NOT NULL,
    weight INT,
    comment TEXT,
    activity_one_id INT,
    activity_two_id INT,
    FOREIGN KEY (activity_one_id) REFERENCES activity(id),
    FOREIGN KEY (activity_two_id) REFERENCES activity(id)
  );`
];

export function executeSql(request, params=null) {
  return new Promise((resolve, reject) => {
    db.transaction(tx => {
      tx.executeSql(
        request,
        params,
        (tx, res) => resolve(res),
        (tx, err) => reject(err),
      );
    })
  })
};
