Scheme constructor

Scheme({
  1. int revision = schemeInitialRevision,
  2. DatabaseUpgrader? upgrader,
  3. String kindPath = standardKindPath,
  4. VirtualColumns virtualColumns = const [],
  5. PartialIndexes partialIndexes = const [],
  6. SearchIndexes searchIndexes = const [],
})

Creates a description of a scheme using the given parameters.

The description consists of revision, kindPath, virtualColumns, partialIndexes, and searchIndexes. By default, revision is schemeInitialRevision and kindPath is standardKindPath.

Implementation

Scheme({
  this.revision = schemeInitialRevision,
  this.upgrader,
  this.kindPath = standardKindPath,
  this.virtualColumns = const [],
  this.partialIndexes = const [],
  this.searchIndexes = const [],
}) {
  checkState(
    kindPath != unsetKindPath || searchIndexes.isEmpty,
    message: "Scheme: search indexes are not supported in no-kinds mode",
  );
  if (virtualColumns.map((var e) => e.lcName) case var vc
      when HashSet<String>.from(vc).length != vc.length)
    throw StateError("Scheme.new: coinciding virtual column names ($vc)");
  if (partialIndexes.map((var e) => e.lcName) case var pi
      when HashSet<String>.from(pi).length != pi.length)
    throw StateError("Scheme.new: coinciding partial index names ($pi)");
  if (searchIndexes.map((var e) => e.lcName) case var si
      when HashSet<String>.from(si).length != si.length)
    throw StateError("Scheme.new: coinciding search index names ($si)");
  var tnames = HashSet<String>.from([tableMapping, tableScheme, columnKind]);
  var nmsg = "Scheme.new: index or table name collision ";
  for (var npi in partialIndexes.map((var e) => e.lcName)) {
    if (tnames.contains(npi)) ////
      throw StateError(nmsg + "($npi)");
    tnames.add(npi);
  }
  for (var nsi in searchIndexes.map((var e) sync* {
    yield e.lcName;
    yield e.lcName + "_data";
    yield e.lcName + "_idx";
    yield e.lcName + "_config";
    yield e.lcName + "_docsize";
    yield e.lcName + "_content";
  }).flattened) {
    if (tnames.contains(nsi)) ////
      throw StateError(nmsg + "($nsi)");
    tnames.add(nsi);
  }
  var cnames = HashSet<String>.from([
    ...virtualColumns.map((var e) => e.lcName),
    columnKind,
    columnKeyId,
    columnValue,
  ]);
  for (var pi in partialIndexes)
    for (var cpi in pi.columns)
      if (!cnames.contains(cpi.lcName))
        throw StateError(
          "Scheme.new: partial index `${pi.name}` "
          "refers to nonexistent column `${cpi.name}`",
        );
  if (kindPath == unsetKindPath)
    for (var vc in virtualColumns)
      if (vc.kinds.isNotEmpty)
        throw StateError(
          "Scheme.new: virtual column `${vc.name}` has "
          "non-empty list of kinds in no-kinds mode",
        );
}