Value<T> class
A wrapper around arbitrary data T to indicate presence or absence
explicitly.
Values are commonly used in companions to distringuish between null and
absent values.
For instance, consider a table with a nullable column with a non-nullable
default value:
CREATE TABLE orders (
priority INT DEFAULT 1 -- may be null if there's no assigned priority
);
For inserts in Dart, there are three different scenarios for the `priority`
column:
- It may be set to `null`, overriding the default value
- It may be absent, meaning that the default value should be used
- It may be set to an `int` to override the default value
As you can see, a simple int? does not provide enough information to
distinguish between the three cases. A null value could mean that the
column is absent, or that it should explicitly be set to null.
For this reason, drift introduces the Value wrapper to make the
distinction explicit.
Constructors
- Value(T value)
-
Create a (present) value by wrapping the
valueprovided.const - Value.absent()
-
Create an absent value that will not be written into the database, the
default value or null will be used instead.
const
- Value.absentIfNull(T? value)
-
Create a value that is absent if
valueisnulland present if it's not.const - Value.ofNullable(T? value)
-
Create a value that is absent if
valueisnulland present if it's not.const
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- present → bool
-
Whether this Value wrapper contains a present value that should be
inserted or updated.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T
-
If this value is present, contains the value to update or insert.
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override