Skip to content

Instantly share code, notes, and snippets.

@joseivanlopez
Last active May 7, 2025 10:43
Show Gist options
  • Save joseivanlopez/7199694381713b2e141ce7fb25491185 to your computer and use it in GitHub Desktop.
Save joseivanlopez/7199694381713b2e141ce7fb25491185 to your computer and use it in GitHub Desktop.

Format for search conditions (storage schema)

Property, operator and value

{ property: "size", operator: "greater", value: "1 GiB" }

Problems:

  • property values depends on the device.
  • operator values depends on the property value.
  • value type depends on the property value. For example:
    • property: "name" requires value to be string.
    • property: "partitionNumber" requires value to be a number.
  • The schema would be more complex because it requires conditionals for operator and value depending on the property value.

Property and operator as keys

{ size: { greater: "1 GiB" } }
  • The schema of each device can indicate the accepted keys:
    • Drive: name, size
    • Partition: name, size, number
  • The schema can easily define the operators of each key.
    • Name: equal
    • Size: equal, greater, less, ...
    • PartitionNumber: equal
  • The values accepted by each property-condition is directly defined in the schema without conditionals.

Examples

{ size: "1 GiB" }
{ size: { equal: "1 GiB" } }
{ size: { greater: "1 GiB" } }
{ size: { greaterOrEqual: "1 GiB" } }
{ size: { less: "1 GiB" } }
{ size: { lessOrEqual: "1 GiB" } }
{ size: { between: ["1 GiB", "10 GiB"] } }
{
  drives: [
    {
      search: {
        condition: {
          size: { greater: "10 GiB" },
        },
        max: 1,
        ifNotFound: "error"
      },
      partitions: [
        {
          search: {
            condition: { number: 3 }
            ifNotFound: "create"
          },
          filesystem: {  }
        }
      ]
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment