1 unstable release

0.1.0 Jun 20, 2019

#10 in #automaat

MIT/Apache

31KB
430 lines

Automaat Processor: SQL Query

🚧 Work In Progress 🚧


lib.rs:

An Automaat processor to run SQL queries.

This processor allows you to run SQL queries and return the output of the query as a JSON object.

The returned JSON object contains the returned column names as keys, and the row values as the JSON value.

Right now, the processor only supports Postgres connections, and only supports SELECT statements. Not all SQL types are supported, but the most common ones are, and new ones can be added if there is a need for them.

Combining this processor with the "JSON Editor" processor allows you to transform the returned data before presenting it to the user.

Example

Query the database for multiple records with multiple columns of different types.

#
#
#
#
use automaat_core::{Context, Processor};
use automaat_processor_sql_query::SqlQuery;
use url::Url;
use serde_json::{from_str, json, Value};

let context = Context::new()?;
let database_url = Url::parse("postgres://postgres@127.0.0.1")?;

let processor = SqlQuery {
    statement: "SELECT id, name FROM users LIMIT 2".to_owned(),
    url: database_url,
};

let output = processor.run(&context)?.expect("Some");
let expect = json!([{ "id" :1, "name": "Bart" }, { "id": 2, "name": "Lisa" }]);

assert_eq!(from_str::<Value>(&output)?, expect);
#

Package Features

  • juniper – creates a set of objects to be used in GraphQL-based requests/responses.

Dependencies

~13–26MB
~469K SLoC