<commit_before>package pman.db;

import tannus.io.*;
import tannus.ds.*;
import tannus.ds.promises.*;

import ida.*;
import ida.backend.idb.IDBCursorWalker in CursorWalker;

import pman.core.*;
import pman.media.*;
import pman.async.*;

import js.Browser.console;
import Slambda.fn;
import tannus.math.TMath.*;
import electron.Tools.defer;
import haxe.extern.EitherType;

using StringTools;
using tannus.ds.StringUtils;
using Lambda;
using tannus.ds.ArrayTools;
using Slambda;

class MediaStore extends TableWrapper {
    /* Constructor Function */
    public function new(dbr : PManDatabase):Void {
        super( dbr );
    }

/* === Instance Methods === */

    /**
      * get an Array of all media item rows
      */
    public function getAllMediaItemRows():ArrayPromise<MediaItemRow> {
        var store = tos('media_items');
        return store.getAll().transform(function(dynlist:Array<Dynamic>):Array<MediaItemRow> {
            return cast dynlist;
        }).array();
    }
    public function getAllMediaItemRows_(done : Cb<Array<MediaItemRow>>):Void {
        getAllMediaItemRows().then(done.yield()).unless(done.raise());
    }

    /**
      * get an array of all media items
      */
    public function getAllMediaItems():ArrayPromise<MediaItem> {
        return getAllMediaItemRows().map(function(row) {
            return mediaItem( row );
        });
    }

    /**
      * request a media_item row by its primary key
      */
    public function getMediaItemRow(id : Int):Promise<Null<MediaItemRow>> {
        var t = db.transaction('media_items');
        var store = t.objectStore('media_items');
        function toMediaItem(dyn : Dynamic):Null<MediaItemRow> {
            return cast dyn;
        }
        var prom = store.get( id ).transform( toMediaItem );
        t.complete.once(function() {
            trace('transaction complete');
        });
        return prom;
    }

    public function getMediaItemRowByUri(uri : String):Promise<Null<MediaItemRow>> {
        return cast select('media_items', {
            uri: uri
        });
    }

    /**
      * obtain a media_item row by its URI when the primary key is not known
      */
    public function getMediaItemRowByUri_(uri : String):Promise<Null<MediaItemRow>> {
        return Promise.create({
            var row:Null<MediaItemRow> = null;
            var store = tos( 'media_items' );

            // iterate over all rows
            function cursorStep(cursor:Cursor, walker:CursorWalker) {
                if (cursor.entry != null) {
                    // we now have the current row to work with
                    var cr:Dynamic = cursor.entry;
                    if (row == null && cr.uri == uri) {
                        row = cast cr;
                    }
                }
                cursor.next();
            }

            var cursorWalker:CursorWalker = store.openCursor( cursorStep );
            cursorWalker.complete.once(function() {
                trace('cursor-iteration complete');
                return row;
            });
            cursorWalker.error.once(function(error) {
                throw error;
            });
        });
    }
    public function getMediaItemByUri(uri : String):Promise<Null<MediaItem>> {
        return getMediaItemRowByUri( uri ).transform(function(row : Null<MediaItemRow>) {
            return (row != null ? mediaItem( row ) : null);
        });
    }

    /**
      * get the id of a media_item row by its uri
      */
    public function getMediaItemIdByUri(uri:String, cb:Cb<Int>):Void {
        getMediaItemRowByUri( uri ).then(function(row:Null<MediaItemRow>) {
            if (row != null)
                return cb(null, row.id);
            else
                return cb();
        }).unless( cb );
    }

    /**
      * check for existance of a row with the given uri
      */
    public function hasRowForUri(uri:String, callback:Bool->Void):Void {
        getMediaItemRowByUri( uri ).then(function(row) {
            callback(row != null);
        });
    }

    /**
      * push updated [row] object onto the table
      */
    public inline function putMediaItemRow(row : MediaItemRow):Promise<Null<MediaItemRow>> {
        return put('media_items', row);
    }

    /**
      * put a media_info row onto the table
      */
    public function putMediaInfoRow(row : MediaInfoRow):Promise<MediaInfoRow> {
        return put('media_info', row);
    }
    public function putMediaInfoRow_(row:MediaInfoRow, done:Null<Dynamic>->Void):Void {
        var prom = putMediaInfoRow( row );
        prom.then(function(nrow){
            done( null );
        });
        prom.unless(function(error){
            done( error );
        });
    }

    /**
      * retrieve the media_info row associated with the given id
      */
    public function getMediaInfoRow(id : Int):Promise<MediaInfoRow> {
        return Promise.create({
            var store = tos( 'media_info' );
            @forward store.get( id ).transform.fn(cast _);
        });
    }
<commit_msg>added 'getMediaInfoRow_' method to pman.db.MediaStore<commit_after>package pman.db;

import tannus.io.*;
import tannus.ds.*;
import tannus.ds.promises.*;

import ida.*;
import ida.backend.idb.IDBCursorWalker in CursorWalker;

import pman.core.*;
import pman.media.*;
import pman.async.*;

import js.Browser.console;
import Slambda.fn;
import tannus.math.TMath.*;
import electron.Tools.defer;
import haxe.extern.EitherType;

using StringTools;
using tannus.ds.StringUtils;
using Lambda;
using tannus.ds.ArrayTools;
using Slambda;

class MediaStore extends TableWrapper {
    /* Constructor Function */
    public function new(dbr : PManDatabase):Void {
        super( dbr );
    }

/* === Instance Methods === */

    /**
      * get an Array of all media item rows
      */
    public function getAllMediaItemRows():ArrayPromise<MediaItemRow> {
        var store = tos('media_items');
        return store.getAll().transform(function(dynlist:Array<Dynamic>):Array<MediaItemRow> {
            return cast dynlist;
        }).array();
    }
    public function getAllMediaItemRows_(done : Cb<Array<MediaItemRow>>):Void {
        getAllMediaItemRows().then(done.yield()).unless(done.raise());
    }

    /**
      * get an array of all media items
      */
    public function getAllMediaItems():ArrayPromise<MediaItem> {
        return getAllMediaItemRows().map(function(row) {
            return mediaItem( row );
        });
    }

    /**
      * request a media_item row by its primary key
      */
    public function getMediaItemRow(id : Int):Promise<Null<MediaItemRow>> {
        var t = db.transaction('media_items');
        var store = t.objectStore('media_items');
        function toMediaItem(dyn : Dynamic):Null<MediaItemRow> {
            return cast dyn;
        }
        var prom = store.get( id ).transform( toMediaItem );
        t.complete.once(function() {
            trace('transaction complete');
        });
        return prom;
    }

    public function getMediaItemRowByUri(uri : String):Promise<Null<MediaItemRow>> {
        return cast select('media_items', {
            uri: uri
        });
    }

    /**
      * obtain a media_item row by its URI when the primary key is not known
      */
    public function getMediaItemRowByUri_(uri : String):Promise<Null<MediaItemRow>> {
        return Promise.create({
            var row:Null<MediaItemRow> = null;
            var store = tos( 'media_items' );

            // iterate over all rows
            function cursorStep(cursor:Cursor, walker:CursorWalker) {
                if (cursor.entry != null) {
                    // we now have the current row to work with
                    var cr:Dynamic = cursor.entry;
                    if (row == null && cr.uri == uri) {
                        row = cast cr;
                    }
                }
                cursor.next();
            }

            var cursorWalker:CursorWalker = store.openCursor( cursorStep );
            cursorWalker.complete.once(function() {
                trace('cursor-iteration complete');
                return row;
            });
            cursorWalker.error.once(function(error) {
                throw error;
            });
        });
    }
    public function getMediaItemByUri(uri : String):Promise<Null<MediaItem>> {
        return getMediaItemRowByUri( uri ).transform(function(row : Null<MediaItemRow>) {
            return (row != null ? mediaItem( row ) : null);
        });
    }

    /**
      * get the id of a media_item row by its uri
      */
    public function getMediaItemIdByUri(uri:String, cb:Cb<Int>):Void {
        getMediaItemRowByUri( uri ).then(function(row:Null<MediaItemRow>) {
            if (row != null)
                return cb(null, row.id);
            else
                return cb();
        }).unless( cb );
    }

    /**
      * check for existance of a row with the given uri
      */
    public function hasRowForUri(uri:String, callback:Bool->Void):Void {
        getMediaItemRowByUri( uri ).then(function(row) {
            callback(row != null);
        });
    }

    /**
      * push updated [row] object onto the table
      */
    public inline function putMediaItemRow(row : MediaItemRow):Promise<Null<MediaItemRow>> {
        return put('media_items', row);
    }

    /**
      * put a media_info row onto the table
      */
    public function putMediaInfoRow(row : MediaInfoRow):Promise<MediaInfoRow> {
        return put('media_info', row);
    }
    public function putMediaInfoRow_(row:MediaInfoRow, done:Null<Dynamic>->Void):Void {
        var prom = putMediaInfoRow( row );
        prom.then(function(nrow){
            done( null );
        });
        prom.unless(function(error){
            done( error );
        });
    }

    /**
      * retrieve the media_info row associated with the given id
      */
    public function getMediaInfoRow(id : Int):Promise<MediaInfoRow> {
        return Promise.create({
            var store = tos( 'media_info' );
            @forward store.get( id ).transform.fn(cast _);
        });
    }
    public function getMediaInfoRow_(id:Int, done:Cb<MediaInfoRow>):Void {
        getMediaInfoRow( id ).then(done.yield()).unless(done.raise());
    }

{'fraction_non_alphanumeric': 0.11707935270033144, 'fraction_numerical': 0.0, 'mean_word_length': 2.120133819951338, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1520878', 'n_tokens_mistral': 2922, 'n_tokens_neox': 2852, 'n_words': 683}