Skip to content

Commit

Permalink
Merge v1.7.8 - DBSQLMemoryAdapter: limit support
Browse files Browse the repository at this point in the history
v1.7.8

 - `DBSQLMemoryAdapter`:
   - `_selectEntries`: add support for `limit`.
  • Loading branch information
gmpassos authored Jun 28, 2024
2 parents 2b755f7 + b61bf52 commit 52c0d64
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.7.8

- `DBSQLMemoryAdapter`:
- `_selectEntries`: add support for `limit`.

## 1.7.7

- `EntityHandler`:
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.7';
static const String VERSION = '1.7.8';

static bool _boot = false;

Expand Down
19 changes: 12 additions & 7 deletions lib/src/bones_api_entity_db_memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:map_history/map_history.dart';
import 'package:reflection_factory/reflection_factory.dart';
import 'package:statistics/statistics.dart';

import 'bones_api_condition_encoder.dart';
import 'bones_api_condition.dart';
import 'bones_api_condition_encoder.dart';
import 'bones_api_entity.dart';
import 'bones_api_entity_annotation.dart';
import 'bones_api_entity_db_sql.dart';
Expand Down Expand Up @@ -738,31 +738,36 @@ class DBSQLMemoryAdapter extends DBSQLAdapter<DBSQLMemoryAdapterContext>

final condition = sql.condition;

List<Map<String, dynamic>> sel;
Iterable<Map<String, dynamic>> itr;

if (condition == null) {
sel = map.values.toList();
itr = map.values;
} else if (tableScheme == null ||
(tableScheme.fieldsReferencedTablesLength == 0 &&
tableScheme.tableRelationshipReferenceLength == 0) ||
condition.isIDCondition) {
sel = map.values.where((e) {
itr = map.values.where((e) {
return condition.matchesEntityMap(e,
positionalParameters: sql.positionalParameters,
namedParameters: sql.namedParameters ?? sql.parametersByPlaceholder,
entityHandler: entityHandler);
}).toList();
});
} else {
sel = map.values.where((obj) {
itr = map.values.where((obj) {
obj = _resolveEntityMap(obj, entityHandler, tableScheme);

return condition.matchesEntityMap(obj,
positionalParameters: sql.positionalParameters,
namedParameters: sql.namedParameters ?? sql.parametersByPlaceholder,
entityHandler: entityHandler);
}).toList();
});
}

final limit = sql.limit;

var sel =
limit != null && limit >= 0 ? itr.take(limit).toList() : itr.toList();

return sel;
}

Expand Down
10 changes: 8 additions & 2 deletions lib/src/bones_api_entity_db_sql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class SQL implements SQLWrapper {

final Set<String>? returnColumns;

final int? limit;

final Map<String, String>? returnColumnsAliases;

final String? mainTable;
Expand Down Expand Up @@ -128,6 +130,7 @@ class SQL implements SQLWrapper {
this.idFieldName,
this.returnColumns,
this.returnColumnsAliases,
this.limit,
required this.mainTable,
this.relationship,
this.tablesAliases,
Expand Down Expand Up @@ -1937,7 +1940,7 @@ abstract class DBSQLAdapter<C extends Object> extends DBRelationalAdapter<C>
parameters: parameters,
positionalParameters: positionalParameters,
namedParameters: namedParameters,
sqlBuilder: (String from, EncodingContext context) {
limit: limit, sqlBuilder: (String from, EncodingContext context) {
var tableAlias = context.resolveEntityAlias(table);
var q = dialect.elementQuote;
var limitStr = limit != null && limit > 0 ? ' LIMIT $limit' : '';
Expand All @@ -1956,7 +1959,7 @@ abstract class DBSQLAdapter<C extends Object> extends DBRelationalAdapter<C>
parameters: parameters,
positionalParameters: positionalParameters,
namedParameters: namedParameters,
sqlBuilder: (String from, EncodingContext context) {
limit: limit, sqlBuilder: (String from, EncodingContext context) {
var tableAlias = context.resolveEntityAlias(table);
var tableFieldID = context.tableFieldID ?? 'id';
var q = dialect.elementQuote;
Expand All @@ -1972,6 +1975,7 @@ abstract class DBSQLAdapter<C extends Object> extends DBRelationalAdapter<C>
{Object? parameters,
List? positionalParameters,
Map<String, Object?>? namedParameters,
int? limit,
required String Function(String from, EncodingContext context)
sqlBuilder}) {
if (matcher is! Condition) {
Expand Down Expand Up @@ -2019,6 +2023,7 @@ abstract class DBSQLAdapter<C extends Object> extends DBRelationalAdapter<C>
entityName: encodedSQL.entityName,
mainTable: table,
tablesAliases: encodedSQL.tableAliases,
limit: limit,
);
} else {
var join = StringBuffer();
Expand Down Expand Up @@ -2170,6 +2175,7 @@ abstract class DBSQLAdapter<C extends Object> extends DBRelationalAdapter<C>
entityName: encodedSQL.entityName,
mainTable: table,
tablesAliases: encodedSQL.tableAliases,
limit: limit,
);
}
});
Expand Down
2 changes: 1 addition & 1 deletion 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.7
version: 1.7.8
homepage: https://github.com/Colossus-Services/bones_api

environment:
Expand Down

0 comments on commit 52c0d64

Please sign in to comment.