Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
committed Jan 8, 2025
1 parent 0090d66 commit 458ebec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
25 changes: 13 additions & 12 deletions lib/json_to_sql_supabase/json_to_sql_supabase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ String generateDataSqlJson({
${key} ${type_data} null ${default_data},
"""
.trim();
script_data += " ${script_data_loop}";
script_data += " ${script_data_loop}";
script_data += "\n";
});
return script_data.replaceAll(RegExp(r"(,|,\n)$", caseSensitive: false), "");
Expand Down Expand Up @@ -119,9 +119,7 @@ ALTER TABLE ${tableName} ADD COLUMN ${key} ${type_data} ${default_data};
script_data += "${script_data_loop}";
script_data += "\n";
});
return script_data
.replaceAll(RegExp(r"(,|,\n)$", caseSensitive: false), "")
.trim();
return script_data.replaceAll(RegExp(r"(,|,\n)$", caseSensitive: false), "").trim();
}

// add column in
Expand All @@ -147,9 +145,11 @@ String jsonToSqlSupabase({
// https://supabase.com/docs/guides/database/tables?database-method=sql
String script = """
-- 1. Create table
CREATE TABLE {table_name} (
id bigint generated by default as identity primary key,
DO \$\$
BEGIN
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = '{table_name}') THEN
CREATE TABLE {table_name} (
"""
.trim();
script += "\n";
Expand All @@ -160,7 +160,11 @@ CREATE TABLE {table_name} (
// script = script.replaceAll(RegExp(r"({table_name})", caseSensitive: false), table_name).trim();

script += """
);
) WITH (OIDS=FALSE);
END IF;
END \$\$;
"""
.trim();
if (isEnableRls) {
Expand All @@ -185,8 +189,5 @@ alter table {table_name} enable row level security;
script += "\n\n";
script += "-- Recommendation";

return (script
.trim()
.replaceAll(RegExp(r"({table_name})", caseSensitive: false), tableName)
.trim());
return (script.trim().replaceAll(RegExp(r"({table_name})", caseSensitive: false), tableName).trim());
}
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ packages:
dependency: "direct main"
description:
name: io_universe
sha256: "1cdda523af01167c552360881be82d0daefb5c6e16fcfc84fcff67b92a8acef4"
sha256: "2cbe86bc482467012bb69ea342c71195caeb8d73ad7165d8f2402890ea66ad05"
url: "https://pub.dev"
source: hosted
version: "0.0.2"
version: "0.0.4"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -530,10 +530,10 @@ packages:
dependency: "direct main"
description:
name: yaml
sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5"
sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce
url: "https://pub.dev"
source: hosted
version: "3.1.2"
version: "3.1.3"
zxing2:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
encrypt: '^5.0.3'
stack_trace: '^1.12.0'
mason_logger: '^0.3.1'
yaml: '^3.1.2'
yaml: '^3.1.3'
archive: '^4.0.2'
qr: '^3.0.2'
zxing2: '^0.2.0'
Expand Down

0 comments on commit 458ebec

Please sign in to comment.