Jaguar-dart / jaguar_orm

Source-generated ORM with relations (one-to-one, one-to-many, many-to-many), preloading, cascading, polymorphic relations, etc
https://jaguar-dart.github.io
BSD 3-Clause "New" or "Revised" License
217 stars 52 forks source link

Feature request - support Optional data type #126

Open JamesMcIntosh opened 5 years ago

JamesMcIntosh commented 5 years ago

When creating the model it would be great to have nullable columns handled with the Optional so nullability becomes explicit and null checks can be removed from the code.

import 'package:optional/optional.dart';

class NullableClass extends Equatable {
  @Column(isNullable: true)
  Optional<String> nullableValue;

  NullableClass({this.nullableValue}) : super([nullableValue]);

}

Current behaviour is an Exception which is logged in the generate .jorm.dart files, see issue #127

JamesMcIntosh commented 5 years ago

Another area which Optional could be introduced is in the generated bean's find

Future<Optional<?>> find(int id)

Future<?> get(int id)
tejainece commented 5 years ago

Will look into this.

jaumard commented 4 years ago

dart will (soon?) have nullable field so it will be better to wait for it and use it once it's there instead of playing around and add an Optional class that will complexify the core code