File: connection-example.js

package info (click to toggle)
tracker 3.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,096 kB
  • sloc: ansic: 57,908; javascript: 15,606; python: 6,272; cs: 242; perl: 106; sh: 98; xml: 29; makefile: 20
file content (32 lines) | stat: -rwxr-xr-x 731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/gjs

const { GLib, Gio, Tracker } = imports.gi

try {
    let connection = Tracker.SparqlConnection.bus_new(
        'org.freedesktop.Tracker3.Miner.Files',
        null, null);

    let stmt = connection.query_statement (
        'SELECT DISTINCT nie:url(?u) WHERE { ' +
        '  ?u a nfo:FileDataObject ; ' +
        '     nfo:fileName ~name ' +
        '}', null);

    stmt.bind_string('name', ARGV[0]);

    let cursor = stmt.execute(null);
    let i = 0;

    while (cursor.next(null)) {
        i++;
        print(`Result ${i}: ${cursor.get_string(0)[0]}`);
    }

    print(`A total of ${i} results were found`);

    cursor.close();
    connection.close();
} catch (e) {
    printerr(`Error: ${e.message}`)
}