@new


Description:

public static SparqlConnection @new (SparqlConnectionFlags flags, File? store, File? ontology, Cancellable? cancellable = null) throws Error

Creates or opens a process-local database.

This method should only be used for databases owned by the current process. To connect to databases managed by other processes, use [ ctor@SparqlConnection.bus_new].

The store argument determines where in the local filesystem the database will be stored. If store is null, the database will be created in memory. Traditionally, store describes a directory where a file named `meta.db` contains the data. Starting with version 3.10, if the basename of store contains a `.` extension separator, it will be considered as the database file itself.

If defined, the ontology argument must point to a location containing suitable `.ontology` files in Turtle format. These define the structure of the triple store. You can learn more about [ontologies](ontologies.html), or you can use the stock Nepomuk ontologies by calling [func@sparql_get_ontology_nepomuk].

If opening an existing database, it is possible to pass null as the ontology location, the ontology will be introspected from the database. Passing a null ontology will raise an error if the database does not exist.

If a database is opened without the `READONLY` [flags@SparqlConnectionFlags] flag enabled, and the given ontology holds differences with the current data layout, migration to the new structure will be attempted. This operation may raise an error. In particular, not all migrations are possible without causing data loss and Tracker will refuse to delete data during a migration. The database is always left in a consistent state, either prior or posterior to migration.

Operations on a [class@SparqlConnection] resulting on a `CORRUPT` [error@SparqlError] will have the event recorded persistently through a `.$DB_BASENAME.corrupted` file alongside the database file. If the database is opened without the `READONLY` [flags@SparqlConnectionFlags ] flag enabled and the file is found, this constructor will attempt to repair the database. In that situation, this constructor will either return a valid [class@SparqlConnection] if the database was repaired successfully, or raise a `CORRUPT` [error@SparqlError] error if the database remains corrupted.

It is considered a developer error to ship ontologies that contain format errors, or that fail at migrations.

It is encouraged to use `resource:///` URI locations for ontology wherever possible, so the triple store structure is tied to the executable binary, and in order to minimize disk seeks during `TrackerSparqlConnection` initialization.

Parameters:

flags

Connection flags to define the SPARQL connection behavior

store

The database location as a [iface@Gio.File], or null

ontology

The directory that contains the database schemas as a [iface@Gio.File], or null

cancellable

Optional [type@Gio.Cancellable]

Returns:

a new `TrackerSparqlConnection`.