Open Moosieus opened 3 days ago
Thank you @Moosieus!
Our general approach with queries is to stay closer to the database as possible, this makes it really straight-forward to go from ParadeDB docs to Ecto queries and vice-versa. So I would prefer to translate the SQL query above to:
require ParadeDB
query =
from(
p in Post,
where: ParadeDB.boolean(p.id,
must: [
ParadeDB.disjunction_max(
disjuncts: [
ParadeDB.parse(^i_think_therefore_i_param),
ParadeDB.phrase(field: 'body', phrases: ['is', 'awesome'], slop: ^slop),
ParadeDB.phrase(field: 'body', phrases: ['are', 'awesome'], slop: ^slop)
]
),
ParadeDB.range(field: "likes", range: int4range(9000, NULL, '[)'))
]
)
)
The only thing getting in the way of us supporting the above today is that we don't support keyword lists in Ecto queries. But if we did, we could compile them into the equivalent PostgreSQL, and you should be able to provide all of the functions above on top of fragments. WDYT?
Here's my thoughts:
FROM
and WHERE
clauses:
SELECT * FROM table_search_idx.search(query => paradedb.all());
SELECT * FROM table WHERE id @@@ paradedb.all();
'field' => value
syntax is non-standard, so I wouldn't map keyword lists to that. I can probably work around that need-be.|> search()
and |> or_search()
calls into top-level paradedb.boolean(query => ...)
expressions. I'll have to ask the ParadeDB team how the new syntax intends to be handled:
SELECT * FROM table WHERE
table.id @@@ paradedb.parse('search_a') AND
table.id @@@ paradedb.parse('search_b');
where/3
.I've asked the ParadeDB team about the above. If that works out, I can start exploring a solution on top of fragments, and see what blockers I run into (if any).
Got my answer on the where clauses. ParadeDB wil ultimately combine them transparently. That simplifies things for the fork I've been working on, and the tentative approach with fragments. I'm thinking to try both and see how the DX compares.
Proposal: Rich Extensibility for Ecto
There's an increasingly significant market share of Postgres extensions that are radically changing the way people interact with Postgres. These extensions can provide lucrative and key-enabling features without requiring applications to host and synchronize external data stores. At least two extensions in this category include:
These extensions embed their calling conventions within SQL and even compose quite well within its relational model. It's desirable to extend Ecto to incorporate these calling conventions, so developers can use these extensions with the amazing composition, caching, mapping, and other ammenities Ecto currently provides.
The following SQL query is a deliberately limit-testing example from ParadeDB:
A user may want to compose the above SQL query in Ecto like so:
Ecto's existing fragment API can cover simple variations of these queries ad-hoc, but it doesn't provide the desired level of extensibility demonstrated above. Additionally, users may wish to augment Ecto's other modules like
Ecto.Schema
to provide additional information.One example includes mapping a ParadeDB search index for a given schema/table, like so:
Discussion
I'd like to start a discussion on what a possible extension API for Ecto could look like. It'd ideally allow users to extend Ecto in order to support extensions like the one above, obviating the need to fork Ecto or Ecto SQL to do so.
The primary goals are to: