DEV Community

Patrick Stolc
Patrick Stolc

Posted on • Originally published at Medium on

1 3

Feature Release: Field Rules | Busywork

Following the addition of roles and permissions, we’ve just released field rules. Field rules allow you to set up validation rules for fields in your database.

Field Rules

The Busywork platform is database-centric, which means that many of the major feature releases lately have revolved around the database API and view. Our latest release introduces field rules. This allows you to set up validation for individual fields, visually, from within Busywork.

For starters the following rules have been implemented:

Text Rules

  • Maximum length
  • Minimum length
  • Equal To
  • Not Equal To

Number Rules

  • Equal To
  • Not Equal To
  • Greater Than
  • Greater Than or Equal To
  • Less Than
  • Less Than or Equal To

These rules are in addition to the schematic rules already available, such as required , unique and data type.

You can add multiple rules to each field, like in the example above. This allows you to set lower and upper limits to the length of a text field, for instance.

Examples

This example requires you to set up a new database table. The first step is to create the new table, let’s call it Projects. The table should contain the following fields:

In addition to specifying the type for the fields, now add a set of rules to the Lines of Code field. Specifically, add a rule that doesn't allow values less than 0 and greater than 100.000.

Now you can test that the rules validate queries correctly. Make a POST request according to the tables API docs. Pass data that should be valid according to the rules you've set up.

{
    "name": "SaaS Corp",
    "shipped": false,
    "owner": "Busywork",
    "lines of code": 1000
}

This results in a response similar to this:

{
    "id": "5e79d3ef26d01e05bbcc0138",
    "status_code": 201,
    "status_descr": "created"
}

Now we can try to make the query fail by changing lines of code to a value less than 0 or greater than 100.000.

{
    "name": "SaaS Corp",
    "shipped": false,
    "owner": "Busywork",
    "lines of code": 100001
}

This should give you the following response:

{
    "status_code": 400,
    "status_descr": "lines of code must be less than or equal to 100000"
}

Confirming that the insert operation isn’t valid because of the lines of code value we're trying to pass.

What’s next?

The next item on the roadmap will allow you to link storage items, such as images, videos or documents to fields in your database. This will allow you to implement user uploads and reference their files directly in your database.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay