schemaColumn method

  1. @mustCallSuper
SchemaColumn? schemaColumn(
  1. Sqlite column, {
  2. required SharedChecker<Model> checker,
})

Implementation

@mustCallSuper
SchemaColumn? schemaColumn(Sqlite column, {required SharedChecker checker}) {
  if (column.columnType != null) {
    return SchemaColumn(
      column.name!,
      column.columnType!,
      nullable: column.nullable,
      unique: column.unique,
    );
  }

  if (checker.isDartCoreType) {
    return SchemaColumn(
      column.name!,
      Migration.fromDartPrimitive(checker.asPrimitive),
      nullable: column.nullable,
      unique: column.unique,
    );
  } else if (checker.isEnum) {
    return SchemaColumn(
      column.name!,
      Column.integer,
      nullable: column.nullable,
      unique: column.unique,
    );
  } else if (checker.isSibling) {
    return SchemaColumn(
      InsertForeignKey.foreignKeyColumnName(
        SharedChecker.withoutNullability(checker.unFuturedType),
        column.name,
      ),
      Column.integer,
      isForeignKey: true,
      foreignTableName: SharedChecker.withoutNullability(checker.unFuturedType),
      nullable: column.nullable,
      onDeleteCascade: column.onDeleteCascade,
      onDeleteSetDefault: column.onDeleteSetDefault,
    );
  } else if (checker.isMap || checker.isIterable) {
    // Iterables and Maps are stored as JSON
    return SchemaColumn(
      column.name!,
      Column.varchar,
      nullable: column.nullable,
      unique: column.unique,
    );
  } else if (checker.toJsonMethod != null) {
    return SchemaColumn(
      column.name!,
      Column.varchar,
      nullable: column.nullable,
      unique: column.unique,
    );
  }

  return null;
}