diff options
author | dakkar <dakkar@thenautilus.net> | 2021-12-31 16:30:23 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2021-12-31 16:30:23 +0000 |
commit | 7a8303eebd7b5419db655408c36b71a11ff02892 (patch) | |
tree | eec34ff138170df5d624c65855ea8d8366e9a30a /lib/App/MediaControl/DB.rakumod | |
parent | kill note (diff) | |
download | media-control-7a8303eebd7b5419db655408c36b71a11ff02892.tar.gz media-control-7a8303eebd7b5419db655408c36b71a11ff02892.tar.bz2 media-control-7a8303eebd7b5419db655408c36b71a11ff02892.zip |
Revert "batch inserts!"
This reverts commit d8623278929c620e22cfb943b5724c66e5f5fb91.
if, inside a batch, we get both a dir and its children, the `WITH`
wouldn't see the parent (it's not there yet), so the children would
have `parent_id` would stay NULL
Diffstat (limited to 'lib/App/MediaControl/DB.rakumod')
-rw-r--r-- | lib/App/MediaControl/DB.rakumod | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/lib/App/MediaControl/DB.rakumod b/lib/App/MediaControl/DB.rakumod index 552ed9c..604d899 100644 --- a/lib/App/MediaControl/DB.rakumod +++ b/lib/App/MediaControl/DB.rakumod @@ -54,28 +54,18 @@ class App::MediaControl::DB { END } } - - subset Entry of Associative where :( - Str:D() :path($)! is copy, - Str:D() :name($)!, - Bool:D() :is-dir($)!, - ); - method add-entries(@entries where { .all ~~ Entry }) { - my $values = 'VALUES ' ~ ('(?, ?, ?)' xx @entries).join(','); - my @binds = @entries.map( - -> (:$path is copy, :$name, :$is-dir) { - $path ~~ s{<!after '/'>$} = '/'; - $path ~~ s{<!before '/'>^} = '/'; - ($path,$name,$is-dir).Slip; - }); + + method add-entry(Str:D() :$path! is copy, Str:D() :$name!, Bool:D() :$is-dir!) { + $path ~~ s{<!after '/'>$} = '/'; + $path ~~ s{<!before '/'>^} = '/'; self!db: { - .query(qq:to/END/, |@binds); + .query(q:to/END/, :$path, :$name, :is_dir($is-dir)); WITH parent(id,path) AS ( SELECT id, path || name || '/' FROM files ), newrow(path,name,is_dir) AS ( - $values + VALUES($path, $name, $is_dir) ) INSERT INTO files(parent_id,path,name,is_dir,seen) SELECT parent.id, newrow.path, newrow.name, newrow.is_dir, true |