Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query builder and driver #3

Closed
wants to merge 9 commits into from
Closed

Conversation

malikbenkirane
Copy link
Contributor

@malikbenkirane malikbenkirane commented May 31, 2023

For further details please read the details from the commit messages.

I will squash and merge to keep a detailed documentation of the changes.

This proof of concept (poc) only includes

SELECT * FROM @table [WHERE @condition] [ORDER BY ASC|DESC]
@condition := @condition AND @condition
            | @filed IS @var
            | @var IS @field
@condition := @condition OR @condition
            | @filed IS @var
            | @var IS @field

The query builder is not optimized it is using too many parentheses without trying to simplify composition of AND operators and composition of OR operators but we could say that it is satisfying for now.

Another caveat is the data-structure used for recursive OR and recursive AND that could be optimized to use of slices.

In the context of this poc, the query driver supports

  • select operations from queries based on the query builder described above
  • select and update operation that does SelectOn and then selectDriver.Update on the first selected document if any otherwise it returns ErrNoDoc
  • (TODO missing doc string)

tag v0.2.2


EDIT

tag version v0.2.0 -> v0.2.1 (d9a1927)
tag version v0.2.1 -> v0.2.2 (20a99ce)

Malik Benkirane added 7 commits May 29, 2023 19:57
I tried my best at keeping the nomenclature from the SELECT statement.

This proof of concept (poc) only includes
```
SELECT * FROM @table [WHERE @condition] [ORDER BY @field ASC|DESC]
@condition := @condition AND @condition
            | @field IS @var
            | @var IS @field
```
but I tried to easily enable the completion with any binary
operator. Also, I guess it would be easy to add unary operators.

To get an idea of what is currently missing check out SurrealDB
official documentation:
- [SELECT statement](
https://surrealdb.com/docs/surrealql/statements/select )
- [Surreal operators](
https://surrealdb.com/docs/surrealql/operators )
- [Record ranges](
https://surrealdb.com/docs/surrealql/datamodel/ids
)

Finally I supposed that we don't need to take care of the types at
this layer of the library because as far as I know, surrealdb.go
library already has the `Var` abstraction I introduced hereby.
add layer on top of whereClause to be able to retrieve valued vars

This solution introduce some complexity that might affect the
performance of the query builder and retrieving the var.

Therefore we should not consider this solution as a final solution
but rather an example of how to isolate concerns with interfaces with
Go. There must be some work to be done if we want to optimize both
the builder and the getter of the query.
top level abstraction for the exported Select struct
Add utilities to read the results of select statement SurrealQL query
as well as the utilities to execute a select query.

There are no integration tests. I only added a very basic unit test.
Mostly to test the behavior of surrealdb.Unmarshal.
@malikbenkirane malikbenkirane self-assigned this Jun 1, 2023
Add NewConditionOr and new NewConditionAnd, both accept unlimited
conditions with at least one condition.
@malikbenkirane malikbenkirane requested a review from t4ke0 June 3, 2023 16:36
@malikbenkirane
Copy link
Contributor Author

d9a1927 address #4

but as mentioned above

the data-structure used for recursive OR and recursive AND that could be optimized to use of slices

@malikbenkirane malikbenkirane added the enhancement New feature or request label Jun 3, 2023
surrealDriver support Update(what, data)

Add DocID interface for documents with Id. Note that we might want to
refactor this but remember we want to stay backward compatible.
@malikbenkirane
Copy link
Contributor Author

malikbenkirane commented Jun 8, 2023

release v0.2.3-rc.backquote(_\d\d*)* will break a lot of your code but I am facing concerning issues with encoding and decoding id with uuid and the marshaler used at all encoding and decoding steps.

see git tag -l for exact tags

scope: NewDefaultDoc

@malikbenkirane
Copy link
Contributor Author

pushed to canonical, please let's focus on this branch now, specially I want to feature #16

see also https://github.com/topics/code-generator?l=go

@t4ke0

@malikbenkirane
Copy link
Contributor Author

malikbenkirane commented Jun 14, 2023

closed in favor of #17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants