| 148 | * surface a clean "already exists" error instead of the raw SQL text. |
| 149 | */ |
| 150 | export function isUniqueViolation(e: any): boolean { |
| 151 | if (e?.code === "23505") return true; |
| 152 | const code = String(e?.code ?? ""); |
| 153 | if ( |
| 154 | code === "SQLITE_CONSTRAINT_PRIMARYKEY" || |
| 155 | code === "SQLITE_CONSTRAINT_UNIQUE" |
| 156 | ) { |
| 157 | return true; |
| 158 | } |
| 159 | const msg = String(e?.message ?? "").toLowerCase(); |
| 160 | return ( |
| 161 | msg.includes("unique constraint") || |
| 162 | msg.includes("primary key constraint") || |
| 163 | msg.includes("duplicate key") |
| 164 | ); |
| 165 | } |
| 166 | |
| 167 | // --------------------------------------------------------------------------- |
| 168 | // Dialect detection |