dbParameters static method

void dbParameters({
  1. @required required String param,
  2. @required required dynamic value,
  3. dynamic update = false,
})

This static method updates the database parameters based on the provided arguments.

The param argument is a required string that specifies the database parameter to be updated. It should be one of the following: 'name', 'tables', or 'version'.

The value argument is a dynamic object that specifies the new value for the database parameter.

The update argument is an optional boolean that defaults to false. If set to true and the param argument is 'tables', the value will be added to the existing list of tables.

If the param argument is 'name' and the value argument is a string, the database name will be updated.

If the param argument is 'tables' and the value argument is a list, the list of tables will be updated. If the value argument is a type and the update argument is true, the value will be added to the list of tables.

If the param argument is 'version' and the value argument is an integer, the database version will be updated.

Implementation

static void dbParameters(
    {@required required String param,
    @required required dynamic value,
    update = false}) {
  switch (param.toLowerCase()) {
    case 'name':
      if ('${value.runtimeType}'.toLowerCase().contains('string')) {
        DbParameters.dbName = value;
        PrintHandler.warningLogger.i(
            'sqflite_simple_dao_backend: The value for the database name is now $value. 💫');
      } else {
        PrintHandler.warningLogger.e(
            'sqflite_simple_dao_backend: Unfortunately, the value is ${value.runtimeType} and it should be String, skipping... 😭');
      }
      break;
    case 'tables':
      if ('${value.runtimeType}'.toLowerCase().contains('list')) {
        DbParameters.tables = value;
        PrintHandler.warningLogger.i(
            'sqflite_simple_dao_backend: The value for the tables list just updated with ${DbParameters.tables.length} elements.✨');
      } else if ('${value.runtimeType}'.toLowerCase().contains('type') &&
          update) {
        DbParameters.tables.add(value);
        PrintHandler.warningLogger.i(
            'sqflite_simple_dao_backend: You already insert ${value.toString()} to the tables list.😋');
      } else {
        PrintHandler.warningLogger.e(
            'sqflite_simple_dao_backend: Unfortunately, the value is ${value.runtimeType} and it should be List<Type>, skipping... 😭');
        PrintHandler.warningLogger.w(
            'sqflite_simple_dao_backend: In case you want to update the list, just set update = true. 😉');
      }
    case 'version':
      if ('${value.runtimeType}'.toLowerCase().contains('int')) {
        DbParameters.dbVersion = value;
        PrintHandler.warningLogger.i(
            'sqflite_simple_dao_backend: The value for the database version is now $value. 💫');
      } else {
        PrintHandler.warningLogger.e(
            'sqflite_simple_dao_backend: Unfortunately, the value is ${value.runtimeType} and it should be int, skipping... 😭');
      }
  }
}