Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

FQL.Schema.defForIdentifier()

Returns the definition for a user-defined collection or user-defined function (UDF) using the same rules as top-level identifier lookups.

Signature

FQL.Schema.defForIdentifier(identifier: String) => Any

Description

FQL.Schema.defForIdentifier() returns the definition for a user-defined collection or UDF using the same rules as top-level identifier lookups.

The lookup returns the first matching resource using the following precedence:

  1. A user-defined collection where .name == <IDENTIFIER>

  2. A user-defined collection where .alias == <IDENTIFIER>

  3. A UDF where .name == <IDENTIFIER>

  4. A UDF where .alias == <IDENTIFIER>

The document is an FQL definition for the resource’s FSL schema. See:

The method does not retrieve definitions for system collections or other resources.

Parameters

Parameter Type Required Description

identifier

String

Yes

Identifier for a user-defined collection or UDF.

Return value

Type Description

Any

Definition for the resource.

Examples

Get a user-defined collection’s definition

// Gets the FQL definition for the `Product` collection.
FQL.Schema.defForIdentifier('Product')
{
  name: "Product",
  coll: Collection,
  ts: Time("2099-10-22T21:56:30.975Z"),
  history_days: 0,
  indexes: {
    byCategory: {
      terms: [
        {
          field: ".category",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    },
    sortedByCategory: {
      values: [
        {
          field: ".category",
          order: "asc",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    },
    byName: {
      terms: [
        {
          field: ".name",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    },
    sortedByPriceLowToHigh: {
      values: [
        {
          field: ".price",
          order: "asc",
          mva: false
        },
        {
          field: ".name",
          order: "asc",
          mva: false
        },
        {
          field: ".description",
          order: "asc",
          mva: false
        },
        {
          field: ".stock",
          order: "asc",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    }
  },
  constraints: [
    {
      unique: [
        {
          field: ".name",
          mva: false
        }
      ],
      status: "active"
    },
    {
      check: {
        name: "stockIsValid",
        body: "(product) => product.stock >= 0"
      }
    },
    {
      check: {
        name: "priceIsValid",
        body: "(product) => product.price > 0"
      }
    }
  ],
  fields: {
    name: {
      signature: "String"
    },
    description: {
      signature: "String"
    },
    price: {
      signature: "Int"
    },
    category: {
      signature: "Ref<Category>"
    },
    stock: {
      signature: "Int"
    }
  }
}

Get a UDF’s definition

// Gets the FQL definition for the `validateOrderStatusTransition()` UDF.
FQL.Schema.defForIdentifier('validateOrderStatusTransition')
{
  name: "validateOrderStatusTransition",
  coll: Function,
  ts: Time("2024-10-28T15:11:25.460Z"),
  body: <<-END
    (oldStatus, newStatus) => {
      if (oldStatus == "cart" && newStatus != "processing") {
        abort("Invalid status transition.")
      } else if (oldStatus == "processing" && newStatus != "shipped") {
        abort("Invalid status transition.")
      } else if (oldStatus == "shipped" && newStatus != "delivered") {
        abort("Invalid status transition.")
      }
    }
  END
}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!