feat(sqlite): support attached database schema changes
This commit is contained in:
41 files changed
+1219
-129
No files matched your search
@@ -69,6 +69,13 @@ pub struct DuckDbAttachDatabaseSqlOptions {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SqliteAttachDatabaseSqlOptions {
|
||||
pub path: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DropObjectSqlOptions {
|
||||
@@ -303,6 +310,14 @@ pub fn build_duckdb_attach_database_sql(options: DuckDbAttachDatabaseSqlOptions)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn build_sqlite_attach_database_sql(options: SqliteAttachDatabaseSqlOptions) -> String {
|
||||
format!(
|
||||
"ATTACH DATABASE {} AS {};",
|
||||
quote_sql_string(&options.path),
|
||||
quote_table_identifier(Some(DatabaseType::Sqlite), &options.name)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn build_create_user_sql(username: &str, password: &str, tablespace: &str) -> String {
|
||||
format!(
|
||||
"CREATE USER {} IDENTIFIED BY {} DEFAULT TABLESPACE {};",
|
||||
@@ -388,6 +403,7 @@ pub fn build_drop_table_child_object_sql(options: DropTableChildObjectSqlOptions
|
||||
| DatabaseType::Dameng
|
||||
| DatabaseType::OceanbaseOracle
|
||||
| DatabaseType::Iris
|
||||
| DatabaseType::Sqlite
|
||||
)
|
||||
) && options.schema.as_deref().is_some_and(|schema| !schema.is_empty())
|
||||
{
|
||||
@@ -1060,6 +1076,17 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_sqlite_attach_sql() {
|
||||
assert_eq!(
|
||||
build_sqlite_attach_database_sql(SqliteAttachDatabaseSqlOptions {
|
||||
path: "/Users/me/O'Reilly data.sqlite".to_string(),
|
||||
name: "report db".to_string(),
|
||||
}),
|
||||
"ATTACH DATABASE '/Users/me/O''Reilly data.sqlite' AS \"report db\";"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_dameng_create_user_sql_with_escaped_values() {
|
||||
assert_eq!(
|
||||
@@ -1319,6 +1346,17 @@ mod tests {
|
||||
.unwrap(),
|
||||
"DROP INDEX \"public\".\"idx_orders_status\";"
|
||||
);
|
||||
assert_eq!(
|
||||
build_drop_table_child_object_sql(DropTableChildObjectSqlOptions {
|
||||
database_type: Some(DatabaseType::Sqlite),
|
||||
object_type: TableChildObjectType::Index,
|
||||
schema: Some("analytics".to_string()),
|
||||
table_name: "orders".to_string(),
|
||||
name: "idx_orders_status".to_string(),
|
||||
})
|
||||
.unwrap(),
|
||||
"DROP INDEX \"analytics\".\"idx_orders_status\";"
|
||||
);
|
||||
assert_eq!(
|
||||
build_drop_table_child_object_sql(DropTableChildObjectSqlOptions {
|
||||
database_type: Some(DatabaseType::Mysql),
|
||||
|
||||
Reference in new issue
Block a user