Skip to content

Commit 604b154

Browse files
committed
Remove SqliteConnection#execute_pragma
We prefer to avoid polluting the main diesel crate with code that is only needed for CLI or codegen. Unifying this code will aid with the addition of prepared statement caching. All we really needed was the ability to execute a SqlLiteral node directly.
1 parent 87b5e58 commit 604b154

3 files changed

Lines changed: 13 additions & 17 deletions

File tree

diesel/src/expression/sql_literal.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ impl<ST, DB> QueryFragment<DB> for SqlLiteral<ST> where
3535
}
3636
}
3737

38+
impl<ST> Query for SqlLiteral<ST> {
39+
type SqlType = ST;
40+
}
41+
3842
impl<QS, ST> SelectableExpression<QS> for SqlLiteral<ST> {
3943
}
4044

diesel/src/sqlite/connection/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,6 @@ impl SqliteConnection {
137137
}
138138
query.map(|_| ())
139139
}
140-
141-
#[doc(hidden)]
142-
pub fn execute_pragma<ST, U>(&self, source: &str) -> QueryResult<Vec<U>> where
143-
U: Queryable<ST, Sqlite>,
144-
<SqliteConnection as Connection>::Backend: HasSqlType<ST>,
145-
{
146-
Statement::prepare(&self.raw_connection, source)
147-
.map(StatementIterator::new)
148-
.and_then(Iterator::collect)
149-
}
150140
}
151141

152142
fn error_message(err_code: libc::c_int) -> &'static str {

diesel_codegen/src/schema_inference/sqlite.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use diesel::*;
2+
use diesel::expression::dsl::sql;
23
use diesel::sqlite::{SqliteConnection, Sqlite};
34
use diesel::types::{HasSqlType, FromSqlRow};
45
use syntax::ast;
@@ -22,8 +23,8 @@ table!{
2223
pub fn get_table_data(conn: &SqliteConnection, table_name: &str)
2324
-> QueryResult<Vec<ColumnInformation>>
2425
{
25-
conn.execute_pragma::<pragma_table_info::SqlType, ColumnInformation>(
26-
&format!("PRAGMA TABLE_INFO('{}')", table_name))
26+
let query = format!("PRAGMA TABLE_INFO('{}')", table_name);
27+
sql::<pragma_table_info::SqlType>(&query).load(conn)
2728
}
2829

2930
fn is_text(type_name: &str) -> bool {
@@ -92,9 +93,10 @@ impl<ST> Queryable<ST, Sqlite> for FullTableInfo where
9293
}
9394

9495
pub fn get_primary_keys(conn: &SqliteConnection, table_name: &str) -> QueryResult<Vec<String>> {
95-
conn.execute_pragma::<pragma_table_info::SqlType, FullTableInfo>(
96-
&format!("PRAGMA TABLE_INFO('{}')", table_name))
97-
.map( |i| i.iter()
98-
.filter_map(|i| if i.primary_key { Some(i.name.clone()) } else { None })
99-
.collect())
96+
let query = format!("PRAGMA TABLE_INFO('{}')", table_name);
97+
let results = try!(sql::<pragma_table_info::SqlType>(&query)
98+
.load::<FullTableInfo>(conn));
99+
Ok(results.iter()
100+
.filter_map(|i| if i.primary_key { Some(i.name.clone()) } else { None })
101+
.collect())
100102
}

0 commit comments

Comments
 (0)