Skip to content
This repository was archived by the owner on Oct 21, 2020. It is now read-only.
This repository was archived by the owner on Oct 21, 2020. It is now read-only.

Raw Query Spec for SQL connectors #383

@mavilein

Description

@mavilein

This spec decribes the feature Raw Query for SQL connectors. This features allows clients to send a query string to the query engine which is sent as is to the underlying database. The result of the query is returned as JSON to the client.

Protocol

The query engine exposes a top level mutation called executeRaw. It is a mutation instead of a query because it may potentially write to the database. The mutation takes one parameter called query which is of type String. The return type depends on the provided query.

Read Queries

If the query begins with the SELECT keyword the returned result set is converted to JSON. The JSON is an array containing one object for each entry in the result set. The keys of the object are the column names of the result set. The values for each key are the respective values for the entry in the result set.

Example:
SQL Query:

Select id,title as my_title from Post;

Response JSON:

{
    "data": [
        {
            "id": 1,
            "my_title": "Hello World"
        },
        {
            "id": 2,
            "my_title": "My 2nd Post"
        }
    ]
}

Write Queries

If the query does not begin with the SELECT keyword the result is expected to modify rows. In this case the number of modified rows is returned.

Example:
SQL Query

Update Post
Set title = "Hello World!!!!"
Where id = 1; 

Response JSON:

{
    "data": 1
}

Error Handling

In case of errors the underlying error is returned as is. For this purpose we introduce a new dedicated error code for raw queries in the query engine:

#[user_facing(
    code = "P2010",
    message = "Raw query failed. Code: `${code}`. Message: `${message}`"
)]
pub struct RawQueryFailed {
    /// The error code returned by the underlying database.
    pub code: String,

    /// The error message returned by the underlying database.
    pub message: String,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions