Update design

I remembered that I don't like SQL, so managing my own library database
is probably better.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2013-06-19 14:07:36 -04:00 committed by Anna Schumaker
parent b7ee8a0f78
commit 2b145f2dab
1 changed files with 58 additions and 72 deletions

View File

@ -4,28 +4,14 @@
= =
===============================================================================
My main goal for Ocarina 6.x is to stop writing my own solutions to problems
that have already been solved. For example, this means using SQL to store
a library rather than developing my own file format. This should help with
future maintenance because I'll have less code to navigate.
My main goal for Ocarina 6.x is to plan out all of my actions before writing
code. In the past I was adding features as I thought of them before thinking
out how everything works together, and this made Ocarina difficult to maintain
because I had no overall plan. This document aims to fix that.
I will also create unit tests as I add features so bugs can be found faster.
SQLite:
I plan on using SQLite for data storage as much as possible. I had
been using my own custom file formats for storing preferences or
libraries, but this is turning into a hassle as I have more code that
needs to be maintained. Try to use an SQLite prepared statement
whenever possible.
#include <sqlite3.h>
$ pkg-config --cflags --libs sqlite3
Files:
ocarina/
design.txt
@ -38,54 +24,13 @@ Files:
playlist.cpp
ocarina/tests/
$HOME/.ocarina{-debug}/ocarina.db
$HOME/.ocarina{-debug}/
library/global.db
library/{0-X}
Database: (ocarina.db)
Paths -
create table if not exists paths(
id INTEGER PRIMARY KEY AUTOINCREMENT,
dirpath TEXT UNIQUE, /* root path of library */
enabled INTEGER, /* 0 = false, 1 = true */
);
Artist -
create table if not exists artists(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE
);
Album -
create table if not exists albums(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
year SHORT INTEGER,
);
Tracks -
create table if not exists tracks(
id INTEGER PRIMARY KEY AUTOINCREMENT,
FOREIGN KEY(path_id) REFERENCES paths(id),
FOREIGN KEY(artist_id) REFERENCES artists(id),
FOREIGN KEY(album_id) REFERENCES albums(id),
filepath TEXT UNIQUE, /* full path - libary root */
title TEXT,
comment TEXT,
genre TEXT,
lenstr TEXT,
track UNSIGNED INT,
count UNSIGNED INT DEFAULT 0,
last_day UNSIGNED INT DEFAULT 0,
last_month UNSIGNED INT DEFAULT 0,
last_year UNSIGNED INT DEFAULT 0,
length INT,
bitrate INT,
sample INT,
channels INT,
banned INT, /* 0 = false, 1 = true */
);
<Research FTS tables and inverted indexes for filtering>
Tags index -
@ -98,14 +43,59 @@ Database: (ocarina.db)
value INT,
);
Library: (lib/library.cpp)
The purpose of library.cpp is to control access to the library tables
in the SQLite database. This file will set up prepared statements and
wrapper functions to make it really easy for the Ocarina gui to affect
the library.
This file will manage and control access to the library.
Album and artist information tables will be saved to a file in
library/global.db and can be shared across multiple library paths.
Internal:
struct Album {
unsigned int id;
string name;
short year;
};
vector<Album>;
struct Artist {
unsigned int id;
string name;
};
vector<Artist>
struct Track {
unsigned int id;
unsigned int artist_id;
unsigned int album_id;
bool valid;
string filepath;
string title;
string genre;
string length_str;
short track;
short last_year;
short last_month;
short last_day;
unsigned int play_count;
unsigned int length;
};
class Library {
string base_path;
bool enabled;
bool valid;
vector<struct Track>
};
typedef struct trackid_t {
unsigned int library_id;
unsigned int track_id;
};
- API
/* Path management */
@ -164,7 +154,3 @@ Tags:
tag_song(name, songid);
untag_song(name, songid);
set_tag_visible(name, visible);
Archlinux packages:
extra/sqlite