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

One-off query support #198

Merged
merged 1 commit into from
Sep 15, 2023
Merged

One-off query support #198

merged 1 commit into from
Sep 15, 2023

Conversation

kazimuth
Copy link
Contributor

@kazimuth kazimuth commented Aug 16, 2023

Description of Changes

Support one-off queries without establishing a subscription. Took me a while to figure out all the routing. This is (NO LONGER) TOTALLY UNTESTED.

The SQL engine seems to support returning multiple tables so I've routed that through to the client, but I have no idea what queries would actually use that -- @mamcx ?

Also, I don't know how to validate that a query only SELECTs and doesn't do anything else.

@jdetter

@mamcx
Copy link
Contributor

mamcx commented Aug 16, 2023

About what queries we support, is all that specified in https://github.com/clockworklabs/SpacetimeDB/tree/master/crates/sqltest when running the validation suite. In concrete https://github.com/clockworklabs/SpacetimeDB/tree/master/crates/sqltest/test/basic are examples of valid queries.

@mamcx
Copy link
Contributor

mamcx commented Aug 17, 2023

Also, I don't know how to validate that a query only SELECTs and doesn't do anything else.

Check

pub fn compile_query(relational_db: &RelationalDB, tx: &MutTxId, input: &str) -> Result<Query, DBError> {

@kazimuth
Copy link
Contributor Author

@mamcx thanks. Question: I noticed https://github.com/clockworklabs/SpacetimeDB/blob/master/crates/core/src/sql/execute.rs#L86 returns a Vec of Memtables. When will this Vec contain more than one entry?

@mamcx
Copy link
Contributor

mamcx commented Aug 17, 2023

When will this Vec contain more than one entry?

For example in

SELECT * FROM table1;SELECT * FROM table2

You can run SQL queries with the cli:

spacetime sql quickstart --interactive

@kazimuth
Copy link
Contributor Author

kazimuth commented Aug 29, 2023

This is ready for review @cloutiertyler. Ended up quite short, but I ran into a number of bugs in the process (mainly of my own creation), which ate up a lot of time.

crates/core/src/client/message_handlers.rs Outdated Show resolved Hide resolved
crates/core/src/host/wasm_common/module_host_actor.rs Outdated Show resolved Hide resolved
crates/core/src/host/module_host.rs Outdated Show resolved Hide resolved
@kulakowski
Copy link
Contributor

And the commit message should probably not say it is ENTIRELY UNTESTED when it lands :)

@kazimuth
Copy link
Contributor Author

kazimuth commented Sep 5, 2023

Rebased and squashed, comments addressed. This should be ready for merge

Copy link
Contributor

@cloutiertyler cloutiertyler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good to me. I also like the with_read_only fn.

Copy link
Collaborator

@jdetter jdetter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was finally able to get this working after some futzing with Unity. I opened this PR to eventually add support for this to our UnitySDK: https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/pull/2/files

I've attributed @kazimuth to the commit in the PR. Also @kazimuth would you be willing to write some documentation for this on the website? Maybe it should be part of the API reference. In the future I will work this into the Unity tutorial so that there's better visibility on this.

Thank you James, this is awesome 👍

@kazimuth kazimuth merged commit 1bfe4c5 into master Sep 15, 2023
5 checks passed
@kazimuth kazimuth deleted the oneoff branch September 15, 2023 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants