[tracker/wip/carlosg/statement-from-resource: 1/2] libtracker-sparql: Add method to create statement from a resource file
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/statement-from-resource: 1/2] libtracker-sparql: Add method to create statement from a resource file
- Date: Sun, 25 Jul 2021 12:20:33 +0000 (UTC)
commit 6bea39bc3371c7d909d0ca5ed8f93badee68af4d
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Jul 25 11:56:05 2021 +0200
libtracker-sparql: Add method to create statement from a resource file
This TrackerSparqlConnection method creates a TrackerSparqlStatement from
a query located in a resource path. This could allow a better code/model
separation where all Tracker resources are separately editable in the
source tree (e.g. distinct per-query .rq files, with syntax highlighting,
etc), and still directly available at runtime without further disk reads.
There's other nice side effects of this, like having queries nicely
indented in logging output (instead of the usual string concatenation in
code that makes queries alright to see in the source code, but a mess when
logged), or avoiding hard to follow code changes (e.g. mass reindenting)
when only query changes are required. Also, queries would be easily
readable with the "gresource list/extract" command line tool without
looking across the source code.
.../libtracker-sparql-sections.txt | 1 +
src/libtracker-sparql/tracker-connection.c | 40 ++++++++++++++++++++++
src/libtracker-sparql/tracker-connection.h | 6 ++++
3 files changed, 47 insertions(+)
---
diff --git a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
index ffbcfb8cf..115cbd76d 100644
--- a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
+++ b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
@@ -115,6 +115,7 @@ tracker_sparql_connection_query
tracker_sparql_connection_query_async
tracker_sparql_connection_query_finish
tracker_sparql_connection_query_statement
+tracker_sparql_connection_query_statement_from_resource
tracker_sparql_connection_update
tracker_sparql_connection_update_async
tracker_sparql_connection_update_finish
diff --git a/src/libtracker-sparql/tracker-connection.c b/src/libtracker-sparql/tracker-connection.c
index fcb2d2ecd..442c7863e 100644
--- a/src/libtracker-sparql/tracker-connection.c
+++ b/src/libtracker-sparql/tracker-connection.c
@@ -806,3 +806,43 @@ tracker_sparql_connection_create_batch (TrackerSparqlConnection *connection)
return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->create_batch (connection);
}
+
+/**
+ * tracker_sparql_connection_query_statement_from_resource:
+ * @connection: a #TrackerSparqlConnection
+ * @resource_path: the resource path of the file to parse.
+ * @cancellable: a #GCancellable, or %NULL
+ * @error: return location for an error, or %NULL
+ *
+ * Prepares a #TrackerSparqlStatement for the SPARQL query contained as a resource
+ * file at @resource_path. SPARQL Query files typically have the .rq extension.
+ *
+ * Returns: (transfer full) (nullable): a prepared statement
+ *
+ * Since: 3.2
+ **/
+TrackerSparqlStatement *
+tracker_sparql_connection_query_statement_from_resource (TrackerSparqlConnection *connection,
+ const gchar *resource_path,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GBytes *query;
+
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), NULL);
+ g_return_val_if_fail (resource_path && *resource_path, NULL);
+ g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ query = g_resources_lookup_data (resource_path,
+ G_RESOURCE_LOOKUP_FLAGS_NONE,
+ error);
+ if (!query)
+ return NULL;
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->query_statement (connection,
+ g_bytes_get_data (query,
+ NULL),
+ cancellable,
+ error);
+}
diff --git a/src/libtracker-sparql/tracker-connection.h b/src/libtracker-sparql/tracker-connection.h
index e8969860f..0da5657de 100644
--- a/src/libtracker-sparql/tracker-connection.h
+++ b/src/libtracker-sparql/tracker-connection.h
@@ -212,6 +212,12 @@ gboolean tracker_sparql_connection_close_finish (TrackerSparqlConnection *conne
GAsyncResult *res,
GError **error);
+TRACKER_AVAILABLE_IN_3_2
+TrackerSparqlStatement * tracker_sparql_connection_query_statement_from_resource (TrackerSparqlConnection
*connection,
+ const gchar
*resource_path,
+ GCancellable
*cancellable,
+ GError
**error);
+
G_END_DECLS
#endif /* __TRACKER_SPARQL_CONNECTION_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]