oxilite-cli 0.10.0

oxilite command line: load, query, and a SPARQL HTTP endpoint compatible with `oxigraph serve`
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
//! The store behind the CLI: bundled SQLite, a dlopen'ed library, Turso, or D1 through the
//! sidecar.

use crate::Location;
use oxilite::dylib::DylibBackend;
use oxilite::io::{RdfFormat, RdfParser};
use oxilite::model::{GraphName, NamedNode, NamedOrBlankNode, Term};
use oxilite::schema::{RegisteredGraph, Registration, SchemaRole, ShapeIndex};
use oxilite::sparql::{QueryOptions, Reasoning, SparqlParser};
use oxilite::store::Store;
use oxilite::turso::TursoBackend;
use oxilite::version::{Change, CommitInfo, CommitRecord, LevelChange, VersionStatus, Versioning};
use oxilite::AsyncStore;
use oxilite_core::encoding::graph_id;
use oxilite_core::{AsyncBackend, Capabilities, QueryOutput, Request, Response, StoreOptions};
use std::sync::Mutex;

type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

/// D1 through the local sidecar (`testsuite/d1-sidecar/server.mjs`), which runs requests on a
/// Miniflare D1 database exactly like the `@oxilite/d1` driver.
pub struct SidecarD1 {
    url: String,
    caps: Capabilities,
}

impl AsyncBackend for SidecarD1 {
    async fn execute(&self, request: &Request) -> oxilite_core::Result<Response> {
        let body = serde_json::to_value(request).map_err(oxilite_core::Error::backend)?;
        match ureq::post(&format!("{}/execute", self.url)).send_json(body) {
            Ok(r) => r.into_json().map_err(oxilite_core::Error::backend),
            Err(ureq::Error::Status(_, r)) => {
                let v: serde_json::Value = r.into_json().unwrap_or_default();
                Err(oxilite_core::Error::backend(
                    v["error"].as_str().unwrap_or("D1 error"),
                ))
            }
            Err(e) => Err(oxilite_core::Error::backend(e)),
        }
    }

    fn capabilities(&self) -> &Capabilities {
        &self.caps
    }
}

/// How queries match: the reasoning regime, materialized inferences and schema graphs.
/// Flattened into `query`, `explain` and `serve`, and kept per session by the shell.
#[derive(clap::Args, Clone, Debug, PartialEq, Eq)]
pub struct QueryFlags {
    /// Query-time entailment: `none` (default), `rdfs` or `owl-ql`.
    #[arg(long, value_name = "MODE", default_value = "none", value_parser = parse_reasoning)]
    pub reasoning: Reasoning,
    /// Also match the inferences stored by `oxilite materialize`.
    #[arg(long)]
    pub inferred: bool,
    /// Hide the triples of registered schema graphs (ontologies, shapes) from the query.
    #[arg(long = "no-schema-graphs", action = clap::ArgAction::SetFalse)]
    pub schema_graphs: bool,
}

impl Default for QueryFlags {
    fn default() -> Self {
        Self {
            reasoning: Reasoning::None,
            inferred: false,
            schema_graphs: true,
        }
    }
}

impl QueryFlags {
    fn apply(&self, options: &mut QueryOptions) {
        options.reasoning = self.reasoning;
        options.include_inferred = self.inferred;
        options.include_schema_graphs = self.schema_graphs;
    }
}

/// A reasoning regime by name: `none`, `rdfs` or `owl-ql` (`owlql`).
pub fn parse_reasoning(s: &str) -> std::result::Result<Reasoning, String> {
    match s.to_ascii_lowercase().as_str() {
        "none" => Ok(Reasoning::None),
        "rdfs" => Ok(Reasoning::Rdfs),
        "owl-ql" | "owlql" => Ok(Reasoning::OwlQl),
        _ => Err(format!("unknown reasoning {s}: one of none, rdfs, owl-ql")),
    }
}

/// The name `parse_reasoning` reads back.
pub fn reasoning_name(r: Reasoning) -> &'static str {
    match r {
        Reasoning::None => "none",
        Reasoning::Rdfs => "rdfs",
        Reasoning::OwlQl => "owl-ql",
    }
}

/// A graph argument: `DEFAULT`, `<iri>` or a bare IRI.
pub fn parse_graph(s: &str) -> Result<GraphName> {
    if s.eq_ignore_ascii_case("default") {
        return Ok(GraphName::DefaultGraph);
    }
    let iri = s
        .strip_prefix('<')
        .and_then(|t| t.strip_suffix('>'))
        .unwrap_or(s);
    Ok(NamedNode::new(iri)?.into())
}

pub enum Db {
    Native(Store),
    Library(Store<DylibBackend>),
    Turso(Store<TursoBackend>),
    D1(Box<Mutex<AsyncStore<SidecarD1>>>),
}

macro_rules! sync_store {
    ($self:expr, $s:ident => $e:expr, $d1:ident => $f:expr) => {
        match $self {
            Db::Native($s) => $e,
            Db::Library($s) => $e,
            Db::Turso($s) => $e,
            Db::D1(m) => {
                let $d1 = m.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
                futures::executor::block_on($f)
            }
        }
    };
}

/// A vector index operation: on the blocking stores (it fails on those without vector
/// functions); D1 has none.
macro_rules! vector_store {
    ($self:expr, $s:ident => $e:expr) => {
        match $self {
            Db::Native($s) => $e,
            Db::Library($s) => $e,
            Db::Turso($s) => $e,
            Db::D1(_) => Err(oxilite::Error::unsupported(
                "vector indexes need a Turso store (--turso); D1 has no vector functions",
            )),
        }
    };
}

fn graph_ids(iris: &[String]) -> Result<Option<Vec<i64>>> {
    if iris.is_empty() {
        return Ok(None);
    }
    iris.iter()
        .map(|i| {
            Ok(graph_id(
                GraphName::from(NamedNode::new(i.as_str())?).as_ref(),
            ))
        })
        .collect::<Result<Vec<_>>>()
        .map(Some)
}

impl Db {
    pub fn open(l: &Location) -> Result<Self> {
        let options = StoreOptions {
            graph_index: !l.no_graph_index,
            text_index: l.text_index,
            versioning: match &l.versioning {
                Some(v) => v.parse()?,
                None => Versioning::Off,
            },
            as_of_index: l.as_of_index,
            stamp_index: l.stamp_index,
            // A blank store opened by the command line starts with the system graphs.
            system_graphs: !l.no_system_graphs,
        };
        let db = Self::open_with(l, &options)?;
        if l.author.is_some() || l.message.is_some() {
            db.set_commit_info(CommitInfo {
                author: l.author.clone(),
                message: l.message.clone(),
            });
        }
        Ok(db)
    }

    fn open_with(l: &Location, options: &StoreOptions) -> Result<Self> {
        let options = options.clone();
        if let Some(url) = &l.d1_sidecar {
            let backend = SidecarD1 {
                url: url.trim_end_matches('/').to_string(),
                caps: Capabilities::d1(),
            };
            let store =
                futures::executor::block_on(AsyncStore::open_with_options(backend, &options))?;
            return Ok(Self::D1(Box::new(Mutex::new(store))));
        }
        let path = l.location.clone().unwrap_or_else(|| ":memory:".into());
        if l.turso {
            if l.library.is_some() {
                return Err("--turso and --library cannot be combined".into());
            }
            let backend = if path == ":memory:" {
                TursoBackend::memory()?
            } else {
                TursoBackend::open(&path)?
            };
            return Ok(Self::Turso(Store::with_backend_and_options(
                backend, &options,
            )?));
        }
        Ok(match &l.library {
            Some(lib) => Self::Library(Store::with_backend_and_options(
                DylibBackend::open(lib, &path)?,
                &options,
            )?),
            None => Self::Native(Store::open_with_options(&path, options)?),
        })
    }

    pub fn query(
        &self,
        query: &str,
        default_graphs: &[String],
        named_graphs: &[String],
    ) -> Result<QueryOutput> {
        self.query_at(
            query,
            default_graphs,
            named_graphs,
            None,
            &QueryFlags::default(),
        )
    }

    /// Runs a query with `flags`, optionally on a past version of the store.
    pub fn query_at(
        &self,
        query: &str,
        default_graphs: &[String],
        named_graphs: &[String],
        as_of: Option<&str>,
        flags: &QueryFlags,
    ) -> Result<QueryOutput> {
        let q = SparqlParser::new().parse_query(query)?;
        let mut options = QueryOptions {
            default_graph: graph_ids(default_graphs)?,
            named_graphs: graph_ids(named_graphs)?,
            as_of: as_of.map(str::to_owned),
            ..QueryOptions::default()
        };
        flags.apply(&mut options);
        Ok(sync_store!(self, s => s.query_output(q, &options), s => s.query_output(q, &options))?)
    }

    /// The SQL a query compiles to with `flags` (on D1, only with the default options).
    pub fn explain_at(
        &self,
        query: &str,
        as_of: Option<&str>,
        flags: &QueryFlags,
    ) -> Result<String> {
        let mut options = QueryOptions {
            as_of: as_of.map(str::to_owned),
            ..QueryOptions::default()
        };
        flags.apply(&mut options);
        Ok(match self {
            Db::Native(s) => s.explain_opt(query, &options)?,
            Db::Library(s) => s.explain_opt(query, &options)?,
            Db::Turso(s) => s.explain_opt(query, &options)?,
            Db::D1(_) if as_of.is_some() => {
                return Err("explain --as-of is not available on D1; run the query instead".into())
            }
            Db::D1(_) if *flags != QueryFlags::default() => {
                return Err(
                    "explain with query options is not available on D1; run the query instead"
                        .into(),
                )
            }
            Db::D1(m) => m
                .lock()
                .unwrap_or_else(std::sync::PoisonError::into_inner)
                .explain(query)?,
        })
    }

    /// Runs a Datalog program, optionally on a past version of the store.
    pub fn datalog_at(
        &self,
        program: &str,
        as_of: Option<&str>,
    ) -> Result<oxilite::datalog::DatalogResult> {
        let options = oxilite::datalog::Options {
            as_of: as_of.map(str::to_owned),
            ..Default::default()
        };
        Ok(
            sync_store!(self, s => s.datalog_with(program, &options), s => s.datalog_with(program, &options))?,
        )
    }

    // ------------------------------------------------------------------------- versioning

    /// Author and message recorded on the commits of later writes.
    pub fn set_commit_info(&self, info: CommitInfo) {
        match self {
            Db::Native(s) => s.set_commit_info(info),
            Db::Library(s) => s.set_commit_info(info),
            Db::Turso(s) => s.set_commit_info(info),
            Db::D1(m) => m
                .lock()
                .unwrap_or_else(std::sync::PoisonError::into_inner)
                .set_commit_info(info),
        }
    }

    pub fn versioning(&self) -> Result<VersionStatus> {
        Ok(sync_store!(self, s => s.versioning(), s => s.versioning())?)
    }

    pub fn set_versioning(&self, level: Versioning, change: LevelChange) -> Result<VersionStatus> {
        Ok(
            sync_store!(self, s => s.set_versioning(level, change), s => s.set_versioning(level, change))?,
        )
    }

    pub fn history(&self, limit: usize) -> Result<Vec<CommitRecord>> {
        Ok(sync_store!(self, s => s.history(limit), s => s.history(limit))?)
    }

    pub fn resolve_version(&self, version: &str) -> Result<i64> {
        Ok(sync_store!(self, s => s.resolve_version(version), s => s.resolve_version(version))?)
    }

    pub fn changes(&self, after: i64, until: Option<i64>) -> Result<Vec<Change>> {
        Ok(sync_store!(self, s => s.changes(after, until), s => s.changes(after, until))?)
    }

    pub fn diff(&self, from: &str, to: &str) -> Result<Vec<Change>> {
        Ok(sync_store!(self, s => s.diff(from, to), s => s.diff(from, to))?)
    }

    pub fn purge(
        &self,
        pattern: (
            Option<NamedOrBlankNode>,
            Option<NamedNode>,
            Option<Term>,
            Option<GraphName>,
        ),
        reason: Option<&str>,
    ) -> Result<()> {
        let (s_, p, o, g) = pattern;
        let (s_, p, o, g) = (
            s_.as_ref().map(NamedOrBlankNode::as_ref),
            p.as_ref().map(NamedNode::as_ref),
            o.as_ref().map(Term::as_ref),
            g.as_ref().map(GraphName::as_ref),
        );
        Ok(sync_store!(self, s => s.purge(s_, p, o, g, reason), s => s.purge(s_, p, o, g, reason))?)
    }

    /// Runs a Synalog program and returns one predicate's rows.
    pub fn synalog(
        &self,
        program: &str,
        predicate: &str,
        options: &oxilite::synalog::Options,
    ) -> Result<oxilite::synalog::SynalogResult> {
        Ok(sync_store!(
            self,
            s => s.synalog_with(program, predicate, options),
            s => s.synalog_with(program, predicate, options)
        )?)
    }

    /// The SQL a Synalog predicate compiles to on this store.
    pub fn synalog_sql(&self, program: &str, predicate: &str) -> Result<String> {
        Ok(match self {
            Db::Native(s) => s.synalog_sql(program, predicate)?,
            Db::Library(s) => s.synalog_sql(program, predicate)?,
            Db::Turso(s) => s.synalog_sql(program, predicate)?,
            Db::D1(m) => m
                .lock()
                .unwrap_or_else(std::sync::PoisonError::into_inner)
                .synalog_sql(program, predicate)?,
        })
    }

    /// Runs a Datalog program and returns its solutions.
    pub fn datalog(&self, program: &str) -> Result<oxilite::datalog::DatalogResult> {
        Ok(match self {
            Db::Native(s) => s.datalog(program)?,
            Db::Library(s) => s.datalog(program)?,
            Db::Turso(s) => s.datalog(program)?,
            Db::D1(m) => futures::executor::block_on(
                m.lock()
                    .unwrap_or_else(std::sync::PoisonError::into_inner)
                    .datalog(program),
            )?,
        })
    }

    /// Describes how a Datalog program runs: strata, strategies and SQL.
    pub fn explain_datalog(&self, program: &str) -> Result<String> {
        Ok(match self {
            Db::Native(s) => s.explain_datalog(program)?,
            Db::Library(s) => s.explain_datalog(program)?,
            Db::Turso(s) => s.explain_datalog(program)?,
            Db::D1(m) => futures::executor::block_on(
                m.lock()
                    .unwrap_or_else(std::sync::PoisonError::into_inner)
                    .explain_datalog(program),
            )?,
        })
    }

    /// Stores what a Datalog program derives, as inferences.
    /// Runs N3 rules without writing (every backend, D1 included).
    // @tg: implements:: [[openspec:n3-rules#Command line]] {since: "2026-11-03"}
    pub fn n3_reason(
        &self,
        rules: &str,
        options: &oxilite::n3::Options,
    ) -> Result<oxilite::n3::N3Result> {
        Ok(
            sync_store!(self, s => s.n3_reason_with(rules, options), d1 => d1.n3_reason_with(rules, options))?,
        )
    }

    /// Stores what N3 rules conclude as inferences of `options.producer`.
    pub fn n3_materialize(
        &self,
        rules: &str,
        options: &oxilite::n3::Options,
    ) -> Result<oxilite::n3::MaterializeStats> {
        Ok(
            sync_store!(self, s => s.n3_materialize_with(rules, options), d1 => d1.n3_materialize_with(rules, options))?,
        )
    }

    pub fn datalog_materialize(&self, program: &str) -> Result<oxilite::datalog::MaterializeStats> {
        Ok(match self {
            Db::Native(s) => s.datalog_materialize(program)?,
            Db::Library(s) => s.datalog_materialize(program)?,
            Db::Turso(s) => s.datalog_materialize(program)?,
            Db::D1(m) => futures::executor::block_on(
                m.lock()
                    .unwrap_or_else(std::sync::PoisonError::into_inner)
                    .datalog_materialize(program),
            )?,
        })
    }

    pub fn update(&self, update: &str, _using: &[String]) -> Result<()> {
        let u = SparqlParser::new().parse_update(update)?;
        Ok(sync_store!(self, s => s.update(u), s => s.update(u))?)
    }

    pub fn load(
        &self,
        format: RdfFormat,
        data: &[u8],
        graph: Option<&str>,
        bulk: bool,
    ) -> Result<()> {
        let mut parser = RdfParser::from_format(format);
        if let Some(g) = graph {
            parser = parser.with_default_graph(NamedNode::new(g)?);
        }
        match self {
            Db::Native(s) if bulk => {
                let mut loader = s.bulk_loader();
                loader.load_from_slice(parser, data)?;
                loader.commit()?;
            }
            Db::Library(s) if bulk => {
                let mut loader = s.bulk_loader();
                loader.load_from_slice(parser, data)?;
                loader.commit()?;
            }
            Db::Turso(s) if bulk => {
                let mut loader = s.bulk_loader();
                loader.load_from_slice(parser, data)?;
                loader.commit()?;
            }
            Db::Native(s) => s.load_from_slice(parser, data)?,
            Db::Library(s) => s.load_from_slice(parser, data)?,
            Db::Turso(s) => s.load_from_slice(parser, data)?,
            Db::D1(m) => {
                let s = m.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
                futures::executor::block_on(s.bulk_load(parser, data))?;
            }
        }
        Ok(())
    }

    // --------------------------------------------------------------------- vector indexes

    pub fn vector_indexes(&self) -> Result<Vec<oxilite::vector::VectorIndexInfo>> {
        Ok(vector_store!(self, s => s.vector_indexes())?)
    }

    pub fn create_vector_index(&self, index: &oxilite::vector::VectorIndex) -> Result<()> {
        Ok(vector_store!(self, s => s.create_vector_index(index))?)
    }

    pub fn drop_vector_index(&self, name: &str) -> Result<bool> {
        Ok(vector_store!(self, s => s.drop_vector_index(name))?)
    }

    pub fn vector_search(
        &self,
        name: &str,
        query: &oxilite::vector::QueryVector,
        k: u64,
    ) -> Result<Vec<oxilite::vector::VectorHit>> {
        Ok(vector_store!(self, s => s.vector_search(name, query, k))?)
    }

    /// Does the backend have vector functions?
    pub fn supports_vectors(&self) -> bool {
        matches!(self, Db::Turso(_))
    }

    /// The host functions registered on the store.
    pub fn functions(&self) -> Vec<oxilite::functions::HostFunction> {
        match self {
            Db::Native(s) => s.functions(),
            Db::Library(s) => s.functions(),
            Db::Turso(s) => s.functions(),
            Db::D1(_) => Vec::new(),
        }
    }

    pub fn optimize(&self) -> Result<()> {
        Ok(sync_store!(self, s => s.optimize(), s => s.optimize())?)
    }

    // -------------------------------------------------------------------- schema registry

    pub fn register_schema_graph(
        &self,
        graph: &GraphName,
        role: SchemaRole,
        registration: &Registration,
    ) -> Result<()> {
        Ok(sync_store!(self,
            s => s.register_schema_graph(graph, role, registration),
            s => s.register_schema_graph(graph, role, registration))?)
    }

    pub fn schema_graphs(&self) -> Result<Vec<RegisteredGraph>> {
        Ok(sync_store!(self, s => s.schema_graphs(), s => s.schema_graphs())?)
    }

    pub fn set_schema_graph_targets(
        &self,
        graph: &GraphName,
        applies_to: &[GraphName],
    ) -> Result<bool> {
        Ok(sync_store!(self,
            s => s.set_schema_graph_targets(graph, applies_to),
            s => s.set_schema_graph_targets(graph, applies_to))?)
    }

    pub fn registry_problems(&self) -> Result<Vec<String>> {
        Ok(sync_store!(self, s => s.registry_problems(), s => s.registry_problems())?)
    }

    pub fn set_schema_graph_active(&self, graph: &GraphName, active: bool) -> Result<bool> {
        Ok(sync_store!(self,
            s => s.set_schema_graph_active(graph, active),
            s => s.set_schema_graph_active(graph, active))?)
    }

    pub fn unregister_schema_graph(&self, graph: &GraphName) -> Result<bool> {
        Ok(sync_store!(self,
            s => s.unregister_schema_graph(graph),
            s => s.unregister_schema_graph(graph))?)
    }

    pub fn drop_schema_graph(&self, graph: &GraphName) -> Result<u64> {
        Ok(sync_store!(self, s => s.drop_schema_graph(graph), s => s.drop_schema_graph(graph))?)
    }

    /// Installs or refreshes the system graphs; `false` when they were already current.
    pub fn install_system_graphs(&self) -> Result<bool> {
        Ok(sync_store!(self, s => s.install_system_graphs(), s => s.install_system_graphs())?)
    }

    pub fn shape_index(&self) -> Result<ShapeIndex> {
        Ok(sync_store!(self, s => s.shape_index(), s => s.shape_index())?)
    }

    /// Computes the OWL 2 RL closure into the inference table; returns the inferred triples.
    pub fn materialize(&self) -> Result<u64> {
        Ok(sync_store!(self, s => s.materialize(), s => s.materialize())?)
    }

    pub fn clear_inferences(&self) -> Result<()> {
        Ok(sync_store!(self, s => s.clear_inferences(), s => s.clear_inferences())?)
    }
}

/// ELPI runs: blocking stores only, since host calls are synchronous.
#[cfg(feature = "elpi")]
macro_rules! elpi_store {
    ($self:expr, $s:ident => $e:expr) => {
        match $self {
            Db::Native($s) => $e,
            Db::Library($s) => $e,
            Db::Turso($s) => $e,
            Db::D1(_) => Err(oxilite::elpi::ElpiError::Unsupported(
                "ELPI programs need a blocking store; they do not run on D1".into(),
            )),
        }
    };
}

#[cfg(feature = "elpi")]
impl Db {
    pub fn elpi_query(
        &self,
        program: &str,
        goal: &str,
        options: &oxilite::elpi::Options,
    ) -> Result<oxilite::elpi::QueryResult> {
        Ok(elpi_store!(self, s => s.elpi_query_with(program, goal, options))?)
    }

    pub fn elpi_check(
        &self,
        program: &str,
        options: &oxilite::elpi::Options,
    ) -> Result<Vec<oxilite::elpi::Violation>> {
        Ok(elpi_store!(self, s => s.elpi_check_with(program, options))?)
    }

    pub fn elpi_materialize(
        &self,
        program: &str,
        options: &oxilite::elpi::Options,
    ) -> Result<oxilite::elpi::MaterializeStats> {
        Ok(elpi_store!(self, s => s.elpi_materialize_with(program, options))?)
    }
}