Repository: SeaQL/sea-query (language: rust)

Issue:
`TRUNCATE` equivalent in SQLite
SQLite doesn't support `TRUNCATE`. We have to either panic or construct a `DELETE` statement instead.

- Demo: https://dbfiddle.uk/R3QFo6ej

https://github.com/SeaQL/sea-query/blob/03d2a1de32056d126a2e8bfd3c035e9b8cff77e9/src/table/truncate.rs#L7-L28

Ref `TRUNCATE` on all supported DBs:
- https://dbfiddle.uk/gwqzgGGZ
- https://dbfiddle.uk/5QXwOEab
- https://dbfiddle.uk/EI2fujSd
- https://dbfiddle.uk/R3QFo6ej


Discussion / hints:
I would like solve this issue. But what should be the prefered method: `panic!` or `DELETE`?
I am new to this codebase so I don't know what is the better trade-off here: "it should only do what I say" or "automatic cross-compatibility".
I think because SeaQuery is a query builder. IMO, we better "only do what I say".

@tyt2y3 please advice!
In SeaQuery sea the desired behaviour should be error (for now it's panic)

Fix patch:
diff --git a/README.md b/README.md
index aa08dd087..860f03153 100644
--- a/README.md
+++ b/README.md
@@ -651,10 +651,7 @@ assert_eq!(
     table.to_string(PostgresQueryBuilder),
     r#"TRUNCATE TABLE "font""#
 );
-assert_eq!(
-    table.to_string(SqliteQueryBuilder),
-    r#"TRUNCATE TABLE "font""#
-);
+// Sqlite does not support the TRUNCATE statement
 ```
 
 ### Foreign Key Create
diff --git a/src/backend/sqlite/table.rs b/src/backend/sqlite/table.rs
index 04615a8a3..9791c38b3 100644
--- a/src/backend/sqlite/table.rs
+++ b/src/backend/sqlite/table.rs
@@ -100,6 +100,14 @@ impl TableBuilder for SqliteQueryBuilder {
         // SQLite does not support table drop options
     }
 
+    fn prepare_table_truncate_statement(
+        &self,
+        _truncate: &TableTruncateStatement,
+        _sql: &mut dyn SqlWriter,
+    ) {
+        panic!("Sqlite doesn't support TRUNCATE statement")
+    }
+
     fn prepare_table_alter_statement(&self, alter: &TableAlterStatement, sql: &mut dyn SqlWriter) {
         if alter.options.is_empty() {
             panic!("No alter option found")
diff --git a/src/lib.rs b/src/lib.rs
index e052b0f91..941d29a87 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -683,10 +683,7 @@
 //!     table.to_string(PostgresQueryBuilder),
 //!     r#"TRUNCATE TABLE "font""#
 //! );
-//! assert_eq!(
-//!     table.to_string(SqliteQueryBuilder),
-//!     r#"TRUNCATE TABLE "font""#
-//! );
+//! // Sqlite does not support the TRUNCATE statement
 //! ```
 //!
 //! ### Foreign Key Create
diff --git a/src/table/truncate.rs b/src/table/truncate.rs
index 5863b401f..7db0fc920 100644
--- a/src/table/truncate.rs
+++ b/src/table/truncate.rs
@@ -17,10 +17,7 @@ use crate::{backend::SchemaBuilder, types::*, SchemaStatementBuilder};
 ///     table.to_string(PostgresQueryBuilder),
 ///     r#"TRUNCATE TABLE "font""#
 /// );
-/// assert_eq!(
-///     table.to_string(SqliteQueryBuilder),
-///     r#"TRUNCATE TABLE "font""#
-/// );
+/// // Sqlite does not support the TRUNCATE statement
 /// ```
 #[derive(Default, Debug, Clone)]
 pub struct TableTruncateStatement {


Test patch:
diff --git a/tests/sqlite/table.rs b/tests/sqlite/table.rs
index 9765e0467..01eaee3b2 100644
--- a/tests/sqlite/table.rs
+++ b/tests/sqlite/table.rs
@@ -329,6 +329,7 @@ fn drop_1() {
 }
 
 #[test]
+#[should_panic(expected = "Sqlite doesn't support TRUNCATE statement")]
 fn truncate_1() {
     assert_eq!(
         Table::truncate()