diff --git a/packages/wasm_packages/sql_parser/typesql/lib/src/sql_executor.dart b/packages/wasm_packages/sql_parser/typesql/lib/src/sql_executor.dart index 2e0be8b..a18f267 100644 --- a/packages/wasm_packages/sql_parser/typesql/lib/src/sql_executor.dart +++ b/packages/wasm_packages/sql_parser/typesql/lib/src/sql_executor.dart @@ -329,10 +329,20 @@ class SqlTypedController insertMany(List> models) => SqlExec.insertMany(type, models).run(executor.executor); - Future> insertManyReturning(List> models) => - SqlExec.insertMany(type, models) + Future> insertManyReturning(List> models) async { + if (models.isEmpty) { + return []; + } else if (models.length == 1) { + return SqlExec.insertMany(type, models, useDefault: false) .addReturning(type) .run(executor.executor); + } else { + final result = await executor.executor.transaction(() { + return Future.wait(models.map(insertReturning)); + }); + return result!; + } + } Future updateReturning(SqlUniqueKeyModel key, U model) => SqlExec.update(key, model) diff --git a/packages/wasm_packages/sql_parser/typesql_generator/example/typesql_generator_example.dart b/packages/wasm_packages/sql_parser/typesql_generator/example/typesql_generator_example.dart index 86493f2..99ac1bb 100644 --- a/packages/wasm_packages/sql_parser/typesql_generator/example/typesql_generator_example.dart +++ b/packages/wasm_packages/sql_parser/typesql_generator/example/typesql_generator_example.dart @@ -135,7 +135,7 @@ class SqliteExecutor extends SqlExecutor { Future transaction(Future Function() transact) async { bool started = false; try { - db.execute('START TRANSACTION'); + db.execute('BEGIN TRANSACTION'); started = true; final result = await transact(); db.execute('COMMIT'); diff --git a/packages/wasm_packages/sql_parser/typesql_generator/lib/src/dart_generator.dart b/packages/wasm_packages/sql_parser/typesql_generator/lib/src/dart_generator.dart index e0825e1..278aa7f 100644 --- a/packages/wasm_packages/sql_parser/typesql_generator/lib/src/dart_generator.dart +++ b/packages/wasm_packages/sql_parser/typesql_generator/lib/src/dart_generator.dart @@ -33,6 +33,11 @@ class GenModel { tableName: tableName ?? this.tableName, ); } + + @override + String toString() { + return 'GenModel(useOptional: $useOptional, interfaces: $interfaces, allNullable: $allNullable, tableName: $tableName)'; + } } void addModelClass( @@ -225,8 +230,7 @@ String? addModelClassInsert( GenModel model = const GenModel(), }) { final name = '${className}Insert'; - final didGenerate = - t.fields.any((e) => e.defaultValue != null && !e.nullable); + final didGenerate = t.fields.any((e) => e.defaultValue != null || e.optional); if (didGenerate) { addModelClass( buf,