sea_schema/sqlite/
probe.rs1use sea_query::{Condition, Expr, Query, SelectStatement, SimpleExpr};
2
3use super::query::{SqliteMaster, SqliteSchema};
4use super::Sqlite;
5use crate::probe::{Has, Schema, SchemaProbe};
6
7impl SchemaProbe for Sqlite {
8 fn get_current_schema() -> SimpleExpr {
9 unimplemented!()
10 }
11
12 fn query_tables(&self) -> SelectStatement {
13 Query::select()
14 .expr_as(Expr::col(SqliteSchema::Name), Schema::TableName)
15 .from(SqliteMaster)
16 .cond_where(
17 Condition::all()
18 .add(Expr::col(SqliteSchema::Type).eq("table"))
19 .add(Expr::col(SqliteSchema::Name).ne("sqlite_sequence")),
20 )
21 .take()
22 }
23
24 fn has_column<T, C>(&self, table: T, column: C) -> SelectStatement
25 where
26 T: AsRef<str>,
27 C: AsRef<str>,
28 {
29 Query::select()
30 .expr(Expr::cust_with_values(
31 "COUNT(*) > 0 AS \"has_column\" FROM pragma_table_info(?)",
32 [table.as_ref()],
33 ))
34 .and_where(Expr::col(SqliteSchema::Name).eq(column.as_ref()))
35 .take()
36 }
37
38 fn has_index<T, C>(&self, table: T, index: C) -> SelectStatement
39 where
40 T: AsRef<str>,
41 C: AsRef<str>,
42 {
43 Query::select()
44 .expr_as(Expr::cust("COUNT(*) > 0"), Has::Index)
45 .from(SqliteMaster)
46 .cond_where(
47 Condition::all()
48 .add(Expr::col(SqliteSchema::Type).eq("index"))
49 .add(Expr::col(SqliteSchema::TblName).eq(table.as_ref()))
50 .add(Expr::col(SqliteSchema::Name).eq(index.as_ref())),
51 )
52 .take()
53 }
54}