From 7a8303eebd7b5419db655408c36b71a11ff02892 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 31 Dec 2021 16:30:23 +0000 Subject: 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 --- lib/App/MediaControl/DB.rakumod | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'lib/App/MediaControl/DB.rakumod') 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{$} = '/'; - $path ~~ s{^} = '/'; - ($path,$name,$is-dir).Slip; - }); + + method add-entry(Str:D() :$path! is copy, Str:D() :$name!, Bool:D() :$is-dir!) { + $path ~~ s{$} = '/'; + $path ~~ s{^} = '/'; 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 -- cgit v1.2.3