Query Engines
Logica is native to the SQL ecosystem; it is designed to compile to SQL and run on data that customers already have in their databases. As of January 2025, Logica runs on DuckDB, Google BigQuery, SQLite, and PostgreSQL. In this guide, we will be using SQLite, a highly efficient, free database that is omnipresent and part of the Python standard library.
To specify that you would like to run your Logica program in SQLite, include the line @Engine("sqlite");
in your program. For example, you could write the following into file socrates.l
:
@Engine("sqlite");
Human("Socrates");
Mortal(x) :- Human(x);
Now you can find out who is mortal with the command:
$ logica socrates.l run Mortal
and it will run with the built-in SQLite engine. The output would look like
+----------+
| col0 |
+----------+
| Socrates |
+----------+
The line @Engine("sqlite");
that you have added looks like a fact, and it is. The predicate here is @Engine
. Special predicates that start with @Engine
are called imperatives (more can be found here). These predicates are used to command the Logica engine on what to do.
Obviously, you can use other query engines to run the queries such as DuckDB and BigQuery.