Caching describe

This commit is contained in:
Julius de Bruijn
2020-07-07 16:56:13 +02:00
committed by Ryan Leckey
parent eba6f3973d
commit 590f97df4a
19 changed files with 323 additions and 50 deletions

View File

@@ -10,7 +10,7 @@ use std::env;
async fn it_describes_simple() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;
let info = conn.describe("SELECT * FROM tweet").await?;
let info = conn.describe_full("SELECT * FROM tweet").await?;
let columns = info.columns();
assert_eq!(columns[0].name(), "id");
@@ -41,13 +41,13 @@ async fn it_describes_variables() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;
// without any context, we resolve to NULL
let info = conn.describe("SELECT ?1").await?;
let info = conn.describe_full("SELECT ?1").await?;
assert_eq!(info.column(0).type_info().name(), "NULL");
assert_eq!(info.nullable(0), None); // unknown
// context can be provided by using CAST(_ as _)
let info = conn.describe("SELECT CAST(?1 AS REAL)").await?;
let info = conn.describe_full("SELECT CAST(?1 AS REAL)").await?;
assert_eq!(info.column(0).type_info().name(), "REAL");
assert_eq!(info.nullable(0), None); // unknown
@@ -60,7 +60,7 @@ async fn it_describes_expression() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;
let d = conn
.describe("SELECT 1 + 10, 5.12 * 2, 'Hello', x'deadbeef'")
.describe_full("SELECT 1 + 10, 5.12 * 2, 'Hello', x'deadbeef'")
.await?;
let columns = d.columns();
@@ -92,7 +92,7 @@ async fn it_describes_expression_from_empty_table() -> anyhow::Result<()> {
.await?;
let d = conn
.describe("SELECT COUNT(*), a + 1, name, 5.12, 'Hello' FROM _temp_empty")
.describe_full("SELECT COUNT(*), a + 1, name, 5.12, 'Hello' FROM _temp_empty")
.await?;
assert_eq!(d.column(0).type_info().name(), "INTEGER");
@@ -121,7 +121,7 @@ async fn it_describes_expression_from_empty_table_with_star() -> anyhow::Result<
.await?;
let d = conn
.describe("SELECT *, 5, 'Hello' FROM _temp_empty")
.describe_full("SELECT *, 5, 'Hello' FROM _temp_empty")
.await?;
assert_eq!(d.column(0).type_info().name(), "TEXT");
@@ -137,13 +137,15 @@ async fn it_describes_insert() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;
let d = conn
.describe("INSERT INTO tweet (id, text) VALUES (2, 'Hello')")
.describe_full("INSERT INTO tweet (id, text) VALUES (2, 'Hello')")
.await?;
assert_eq!(d.columns().len(), 0);
let d = conn
.describe("INSERT INTO tweet (id, text) VALUES (2, 'Hello'); SELECT last_insert_rowid();")
.describe_full(
"INSERT INTO tweet (id, text) VALUES (2, 'Hello'); SELECT last_insert_rowid();",
)
.await?;
assert_eq!(d.columns().len(), 1);
@@ -163,7 +165,7 @@ async fn it_describes_insert_with_read_only() -> anyhow::Result<()> {
let mut conn = options.connect().await?;
let d = conn
.describe("INSERT INTO tweet (id, text) VALUES (2, 'Hello')")
.describe_full("INSERT INTO tweet (id, text) VALUES (2, 'Hello')")
.await?;
assert_eq!(d.columns().len(), 0);
@@ -175,7 +177,10 @@ async fn it_describes_insert_with_read_only() -> anyhow::Result<()> {
async fn it_describes_bad_statement() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;
let err = conn.describe("SELECT 1 FROM not_found").await.unwrap_err();
let err = conn
.describe_full("SELECT 1 FROM not_found")
.await
.unwrap_err();
let err = err
.as_database_error()
.unwrap()