Skip to content

Commit

Permalink
Merge v1.7.23
Browse files Browse the repository at this point in the history
 - `SQL`:
   - Added `copy`, `isSharedDummy`, and `ensureNotSharedDummy`.
   - Fix `generateInsertRelationshipSQLs`: use `ensureNotSharedDummy`.

 - meta: ^1.16.0
  • Loading branch information
gmpassos authored Sep 23, 2024
2 parents b0af3b9 + da76cbd commit 7d8af6c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.7.23

- `SQL`:
- Added `copy`, `isSharedDummy`, and `ensureNotSharedDummy`.
- Fix `generateInsertRelationshipSQLs`: use `ensureNotSharedDummy`.

- meta: ^1.16.0

## 1.7.22

- `APIModuleProxyHttpCaller`:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bones_api_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef APILogger = void Function(APIRoot apiRoot, String type, String? message,
/// Bones API Library class.
class BonesAPI {
// ignore: constant_identifier_names
static const String VERSION = '1.7.22';
static const String VERSION = '1.7.23';

static bool _boot = false;

Expand Down
43 changes: 40 additions & 3 deletions lib/src/bones_api_entity_db_sql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,37 @@ class SQL implements SQLWrapper {
_parametersValuesByPosition = parametersValuesByPosition,
placeholderRegexp = placeholderRegexp ?? _defaultPlaceholderRegexp;

bool get isDummy => this == dummy;
SQL copy() => SQL(
sql,
positionalParameters?.toList(),
namedParameters?.map((k, v) => MapEntry(k, v)),
parametersByPlaceholder.map((k, v) => MapEntry(k, v)),
sqlCondition: sqlCondition,
sqlPositional: _sqlPositional,
parametersKeysByPosition: _parametersKeysByPosition?.toList(),
parametersValuesByPosition: _parametersValuesByPosition?.toList(),
condition: condition,
entityName: entityName,
idFieldName: idFieldName,
returnColumns: returnColumns?.toSet(),
returnColumnsAliases:
returnColumnsAliases?.map((k, v) => MapEntry(k, v)),
limit: limit,
mainTable: mainTable,
relationship: relationship,
tablesAliases: tablesAliases?.map((k, v) => MapEntry(k, v)),
placeholderRegexp: placeholderRegexp,
);

/// Ensures that this is not the [dummy] instance.
/// Returns a [copy] if necessary.
SQL ensureNotSharedDummy() => identical(this, dummy) ? copy() : this;

/// Returns `true` if this is the [dummy] instance.
/// See [ensureNotSharedDummy].
bool get isSharedDummy => identical(this, dummy);

bool get isDummy => identical(this, dummy) || sql == 'dummy';

bool get isFullyDummy => isDummy && !hasPreOrPosSQL;

Expand Down Expand Up @@ -1567,7 +1597,12 @@ abstract class DBSQLAdapter<C extends Object> extends DBRelationalAdapter<C>
var constrainSQL = _generateConstrainRelationshipSQL(
tableScheme, table, field, id, otherTableName, otherIds);

sqls.last.posSQL = [constrainSQL];
var lastIdx = sqls.lastIndex;

var sqlsLast = sqls[lastIdx].ensureNotSharedDummy();
sqls[lastIdx] = sqlsLast;

sqlsLast.posSQL = [constrainSQL];

return sqls;
});
Expand Down Expand Up @@ -1696,7 +1731,7 @@ abstract class DBSQLAdapter<C extends Object> extends DBRelationalAdapter<C>
sql, op.transaction, connection);

if (sql.hasPosSQL) {
sql.posSQL!.map((e) {
return sql.posSQL!.map((e) {
_logTransactionOperationSQL('insertRelationship[POS]', op, e);
return doDeleteSQL(
entityName, e.mainTable!, e, op.transaction, connection);
Expand Down Expand Up @@ -2270,6 +2305,8 @@ abstract class DBSQLAdapter<C extends Object> extends DBRelationalAdapter<C>
var posSql2 =
SQL('DROP TABLE $q$tmpTable$q', [], {}, {}, mainTable: tmpTable);

deleteSQL = deleteSQL.ensureNotSharedDummy();

deleteSQL.preSQL = [preSql];
deleteSQL.posSQL = [posSql1, posSql2];
deleteSQL.posSQLReturnIndex = 0;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bones_api
description: Bones_API - A powerful API backend framework for Dart. It comes with a built-in HTTP Server, route handler, entity handler, SQL translator, and DB adapters.
version: 1.7.22
version: 1.7.23
homepage: https://github.com/Colossus-Services/bones_api

environment:
Expand Down Expand Up @@ -32,7 +32,7 @@ dependencies:
shelf_gzip: ^4.1.0
shelf_static: ^1.1.3
args: ^2.5.0
meta: ^1.15.0
meta: ^1.16.0
petitparser: ^6.0.2
hotreloader: ^4.2.0
logging: ^1.2.0
Expand Down

0 comments on commit 7d8af6c

Please sign in to comment.