diff options
author | dakkar <dakkar@thenautilus.net> | 2017-12-23 15:21:54 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2017-12-23 15:21:54 +0000 |
commit | cdac5cd0d0eae09b9d2f36ab53907ccefed82fa8 (patch) | |
tree | e48f629b937cad8f2fe26da41474d1f4c7428a6a /lib/Ultramarine/Model/DB.pm6 | |
parent | rough model to extract metadata from music files (diff) | |
download | Ultramarine-cdac5cd0d0eae09b9d2f36ab53907ccefed82fa8.tar.gz Ultramarine-cdac5cd0d0eae09b9d2f36ab53907ccefed82fa8.tar.bz2 Ultramarine-cdac5cd0d0eae09b9d2f36ab53907ccefed82fa8.zip |
minimal db model
Diffstat (limited to 'lib/Ultramarine/Model/DB.pm6')
-rw-r--r-- | lib/Ultramarine/Model/DB.pm6 | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/Ultramarine/Model/DB.pm6 b/lib/Ultramarine/Model/DB.pm6 new file mode 100644 index 0000000..cbc353d --- /dev/null +++ b/lib/Ultramarine/Model/DB.pm6 @@ -0,0 +1,42 @@ +use v6.d.PREVIEW; +use DBI::Async; +use Ultramarine::Model::DBMigration; + +class Ultramarine::Model::DB { + has $.db-driver is required; + has %.db-args is required; + + my @migrations = ( + -> $dbh { + $dbh.query(q:to/END/).finish; + CREATE TABLE songs ( + path TEXT PRIMARY KEY, + title TEXT, + artist TEXT + ); + END + }, + ); + + has $!dbh = do { + my DBI::Async $dbh .= new($!db-driver, |%!db-args); + my Ultramarine::Model::DBMigration $migration .= new(:$dbh,:@migrations); + $migration.ensure-schema; + $dbh; + }; + + method add-song(:$path!,:$title,:$artist) { + $!dbh.query(q:to/END/,$path,$title,$artist); + INSERT INTO songs(path,artist,title) + VALUES (?,?,?) + END + } + + method get-song($path) { + $!dbh.query(q:to/END/,$path).hash; + SELECT * + FROM songs + WHERE path=? + END + } +} |