-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(sqlx): Refactor to use async Sqlx
- Loading branch information
Showing
25 changed files
with
2,654 additions
and
1,118 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
use sqlx::{Error, FromRow, PgConnection}; | ||
|
||
const QUERY: &str = r#" | ||
SELECT | ||
table_catalog, | ||
table_schema, | ||
table_name, | ||
column_name, | ||
ordinal_position, | ||
column_default, | ||
is_nullable, | ||
data_type, | ||
character_maximum_length, | ||
character_octet_length, | ||
numeric_precision, | ||
numeric_precision_radix, | ||
numeric_scale, | ||
datetime_precision, | ||
interval_type, | ||
interval_precision, | ||
character_set_catalog, | ||
character_set_schema, | ||
character_set_name, | ||
collation_catalog, | ||
collation_schema, | ||
collation_name, | ||
domain_catalog, | ||
domain_schema, | ||
domain_name, | ||
udt_catalog, | ||
udt_schema, | ||
udt_name, | ||
scope_catalog, | ||
scope_schema, | ||
scope_name, | ||
maximum_cardinality, | ||
dtd_identifier, | ||
is_self_referencing, | ||
is_identity, | ||
identity_generation, | ||
identity_start, | ||
identity_increment, | ||
identity_maximum, | ||
identity_minimum, | ||
identity_cycle, | ||
is_generated, | ||
generation_expression, | ||
is_updatable | ||
FROM | ||
information_schema.columns | ||
WHERE | ||
table_schema = ANY($1) | ||
ORDER BY | ||
table_catalog, | ||
table_schema, | ||
table_name, | ||
column_name;"#; | ||
|
||
pub async fn columns(connection: &mut PgConnection, schema_names: &[String]) -> Result<Vec<Column>, Error> { | ||
sqlx::query_as(QUERY) | ||
.bind(&schema_names[..]) | ||
.fetch_all(connection).await | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, FromRow)] | ||
pub struct Column { | ||
pub table_catalog: String, | ||
pub table_schema: String, | ||
pub table_name: String, | ||
pub column_name: String, | ||
pub ordinal_position: i32, | ||
pub column_default: Option<String>, | ||
pub is_nullable: String, | ||
pub data_type: String, | ||
pub character_maximum_length: Option<i32>, | ||
pub character_octet_length: Option<i32>, | ||
pub numeric_precision: Option<i32>, | ||
pub numeric_precision_radix: Option<i32>, | ||
pub numeric_scale: Option<i32>, | ||
pub datetime_precision: Option<i32>, | ||
pub interval_type: Option<String>, | ||
pub interval_precision: Option<i32>, | ||
pub character_set_catalog: Option<String>, | ||
pub character_set_schema: Option<String>, | ||
pub character_set_name: Option<String>, | ||
pub collation_catalog: Option<String>, | ||
pub collation_schema: Option<String>, | ||
pub collation_name: Option<String>, | ||
pub domain_catalog: Option<String>, | ||
pub domain_schema: Option<String>, | ||
pub domain_name: Option<String>, | ||
pub udt_catalog: Option<String>, | ||
pub udt_schema: Option<String>, | ||
pub udt_name: Option<String>, | ||
pub scope_catalog: Option<String>, | ||
pub scope_schema: Option<String>, | ||
pub scope_name: Option<String>, | ||
pub maximum_cardinality: Option<i32>, | ||
pub dtd_identifier: Option<String>, | ||
pub is_self_referencing: String, | ||
pub is_identity: String, | ||
pub identity_generation: Option<String>, | ||
pub identity_start: Option<String>, | ||
pub identity_increment: Option<String>, | ||
pub identity_maximum: Option<String>, | ||
pub identity_minimum: Option<String>, | ||
pub identity_cycle: Option<String>, | ||
pub is_generated: String, | ||
pub generation_expression: Option<String>, | ||
pub is_updatable: String, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use sqlx::{Error, FromRow, PgConnection}; | ||
use crate::db::privilege::Privilege; | ||
|
||
const QUERY: &str = r#" | ||
SELECT | ||
grantor, | ||
grantee, | ||
table_catalog, | ||
table_schema, | ||
table_name, | ||
column_name, | ||
privilege_type, | ||
is_grantable | ||
FROM | ||
information_schema.column_privileges | ||
WHERE | ||
table_schema = ANY($1) | ||
ORDER BY | ||
table_catalog, | ||
table_schema, | ||
table_name, | ||
column_name, | ||
grantor, | ||
grantee, | ||
privilege_type;"#; | ||
|
||
pub async fn column_privileges(connection: &mut PgConnection, schema_names: &[String]) -> Result<Vec<ColumnPrivilege>, Error> { | ||
sqlx::query_as(QUERY) | ||
.bind(&schema_names[..]) | ||
.fetch_all(connection).await | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, FromRow)] | ||
pub struct ColumnPrivilege { | ||
pub grantor: String, | ||
pub grantee: String, | ||
pub table_catalog: String, | ||
pub table_schema: String, | ||
pub table_name: String, | ||
pub column_name: String, | ||
pub privilege_type: String, | ||
pub is_grantable: String, | ||
} | ||
|
||
impl Privilege for &ColumnPrivilege { | ||
fn grantor(&self) -> &str { | ||
&self.grantor | ||
} | ||
|
||
fn grantee(&self) -> &str { | ||
&self.grantee | ||
} | ||
|
||
fn privilege_type(&self) -> &str { | ||
&self.privilege_type | ||
} | ||
} |
Oops, something went wrong.