Skip to content

Commit 2144ab7

Browse files
authored
feat: Add temporary option to CreateTableBuilder (#398)
1 parent 8140b55 commit 2144ab7

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

core/src/sql/arrow_sql_gen/statement.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct CreateTableBuilder {
3737
schema: SchemaRef,
3838
table_name: String,
3939
primary_keys: Vec<String>,
40+
temporary: bool,
4041
}
4142

4243
impl CreateTableBuilder {
@@ -46,6 +47,7 @@ impl CreateTableBuilder {
4647
schema,
4748
table_name: table_name.to_string(),
4849
primary_keys: Vec::new(),
50+
temporary: false,
4951
}
5052
}
5153

@@ -58,6 +60,13 @@ impl CreateTableBuilder {
5860
self
5961
}
6062

63+
#[must_use]
64+
/// Set whether the table is temporary or not.
65+
pub fn temporary(mut self, temporary: bool) -> Self {
66+
self.temporary = temporary;
67+
self
68+
}
69+
6170
#[must_use]
6271
#[cfg(feature = "postgres")]
6372
pub fn build_postgres(self) -> Vec<String> {
@@ -145,6 +154,10 @@ impl CreateTableBuilder {
145154
create_stmt.primary_key(&mut index);
146155
}
147156

157+
if self.temporary {
158+
create_stmt.temporary();
159+
}
160+
148161
create_stmt.to_string(query_builder)
149162
}
150163
}
@@ -1550,6 +1563,20 @@ mod tests {
15501563
assert_eq!(sql, "CREATE TABLE IF NOT EXISTS \"users\" ( \"id\" integer NOT NULL, \"id2\" integer NOT NULL, \"name\" text NOT NULL, \"age\" integer, PRIMARY KEY (\"id\", \"id2\") )");
15511564
}
15521565

1566+
#[test]
1567+
fn test_temporary_table_creation() {
1568+
let schema = Schema::new(vec![
1569+
Field::new("id", DataType::Int32, false),
1570+
Field::new("name", DataType::Utf8, false),
1571+
]);
1572+
let sql = CreateTableBuilder::new(SchemaRef::new(schema), "users")
1573+
.primary_keys(vec!["id"])
1574+
.temporary(true)
1575+
.build_sqlite();
1576+
1577+
assert_eq!(sql, "CREATE TEMPORARY TABLE IF NOT EXISTS \"users\" ( \"id\" integer NOT NULL, \"name\" text NOT NULL, PRIMARY KEY (\"id\") )");
1578+
}
1579+
15531580
#[test]
15541581
fn test_table_insertion_with_list() {
15551582
let schema1 = Schema::new(vec![Field::new(

0 commit comments

Comments
 (0)