Concepts

Your data belongs to you

With Saltcorn you create a well designed database as you build your application.  If you outgrow Saltcorn, you can take the database with you and use it with another system. Your data belongs to you, and it is easy to move it. 

Relational database model

Saltcorn uses the relational data model that you may know from SQL databases like MySQL and PostgreSQL (which Saltcorn uses). If you already know this model, you can skip this section. 

Learn the basics

In the rest of this section, you will learn the basic concepts of the relational model. I use the example of creating a blog.

Alternatively you may also refer to to Wikipedia pages for relational database and relational model.

Types

The type is the smallest unit of data storage. It describes a specific variety of data used to build your database. Some examples of types are

  • strings (a list of characters that can make up a name, a word, or a whole blog post)
  • integers (the whole numbers)
  • floating-point numbers (number with a decimal point)
  • dates (a moment in time, including both the day and the time of the day).

Types are at the abstract level of talking about all strings or integers etc. Concrete objects such as "Adam Smith", or a particular number (15 or 3.14 or -5.5), or 15th August 2020 are not types but are values. Every value has a type.

Types are defined in Saltcorn in plug-ins. Even the most elementary types such as strings or integers are defined in the base plug-in.

Fields

A field gives a type more context. It gives a type a label so you know what it represents. A field might be a string with the label "Full name" and the value "Joshua Bell".

We might show it like this:

Full name: Joshua Bell

The field can also restrict values that it can take. For instance, you might specify that a field Age is an integer (a whole number) which is never negative.

Number of posts written: 53

Row

A row is a collection of fields describing an object, perhaps a physical object. If we are interested in people, we might decide that a person described by their name, age and height. In this case we would use the 3 fields Name (string), Age (integer), and Followers (floatingpoint number), to describe a single person.

Full name
Number of posts written   
Followers (k)
Joshua Bell   
531.65


Tables

A table is a collection of rows that all have the same fields. 

Here is a table of authors for a blog site like Medium.com 

Full name
BioNumber of posts written 
Followers (k)
Twitter
Joshua BellJoshua is from the UK and likes tigers531.65
Janine JansenJanine is from France and likes violins265.6@JJansen
Nigel KennedyNigel is from the USA and likes cooking482.86@Nige
Viktoria MullovaVictoria is from Russia and like trees341.12@VM1985


Some of the rows in the table may have missing values. Here, for example, we do not know Joshua Bell's Twitter name.
When designing a table you need decide which fields can be missing and which are required.
You may decide that some fields must have unique value. The Twitter name, for example, must be unique. But the Full name might not be unique. 

Fields and tables are created in Saltcorn by users with administrative privileges through the Saltcorn user interface. First you create a table and then create the fields in that table by choosing their type and giving them an name. You can always add more fields to a table later. 

Keys

Sometimes, when we have two different tables, a special field in one of the tables can be used to relate the two tables. 

Here we have a table of blog posts. The Full name column in the table of authors above is used as the key to fill in the author column. 

Title

Author

ContentDateTags
Tiger King: The real storyJoshua Bell
Chase ball of string eat plants, meow, and throw up because I ate plants going to catch the red dot today going to catch the red dot today. I could pee on this if I had the energy. Chew iPad power cord steal the warm chair right after you get up for purr for no reason leave hair everywhere, decide to want nothing to do with my owner today.
15 August 2020Tiger, energy, chair
Tiger, Tiger, burning brightJoshua Bell
Donskoy balinese cheetah. Kitten egyptian mau so turkish angora grimalkin. Tom lion. Munchkin manx russian blue abyssinian for tabby cornish rex. Munchkin. Malkin tiger, ragdoll savannah and tomcat yet bengal bengal. Tiger puma puma so bengal. Panther russian blue for tomcat. Balinese tom and egyptian mau. Jaguar maine coon devonshire rex. Norwegian forest. 
12 September 2020Kitten, puma, forest
Cooking with cheeseNigel Kennedy
Cheese on toast airedale the big cheese. Danish fontina cheesy grin airedale danish fontina taleggio the big cheese macaroni cheese port-salut. Edam fromage lancashire feta caerphilly everyone loves chalk and cheese brie. Red leicester parmesan cheese and biscuits cheesy feet blue castello cheesecake fromage frais smelly cheese.
11 October 2020Cheese, chalk, brie
The pine forests of KarakanVictoria Mullova
Dingy I'm tellin' you rhubaahb Bangah Jo-Jeezly got in a gaum Powrtland stove up dooryahd from away, paypuh bowee batrees owt Have a good one. hahd tellin' not knowin', p'dayduhs scrod You is sum wicked suhmart over t'. Lobstah buggin' bogan railed 'em gettin' ugly bluebries ayuhpawt Jo-Jeezly, front dooryahd huck naw got in a gaum bluebries.
9 November 2020tree, lobster, owl



Fieldviews

A field view is a particular way of showing to the user the contents of a single field. For instance, for the Date type, which represents a point in time including both day and time of the day, this can be shown to the user as an absolute time (27 August 2018 14:46), as a relative time (one year and nine months ago) and if edited can be picked with a calendar date picking widget or entered manually.

Views

Views is a way for users to display data from a table. This can be from one or more rows. You can think of this as a screen or a user interface.

New views in Saltcorn are created and defined by the admin user. Apply a view template (see below) to a table and fill in the options for that view template.

Relational databases also have a concept of views, but this is not related to the view in Saltcorn.

View templates

A view template is a template for creating a new view by applying it to a table. The view template will also define what further information is needed in order to create the full view.

View = View templates applied to table with specified options

View templates are defined in plug-ins. Some basic view templates are defined in the base plug-in, and more view templates can be added by activating new plug-ins.

There are two different kinds of view templates, basic and composed.

  • Basic view templates do not rely on other other views. They are specified in their own right by applying a view template to a table and choosing the options.
  • Composed views need other views to be created first, and then are specified in terms of other views. Composed views are still a template applied to a table with specified options, but the options to be specified include selecting other views. 

Plug-ins may provide both composed and basic view templates.

Basic view templates

The base plug-in provides three different basic view templates:  list editand show.

List view: Display multiple rows from a table in a grid with columns you specify. For example, a view with a list of authors. 

You can also add fields to a list view from related tables, links to other views or aggregations (calculations from related tables). For example, the number of posts written is calculated from the Blog table, and displayed in the list view. 

Edit: Form for creating a new row or editing existing rows. With the right permissions, you can set a view to show the list, and allow an admin or other user to edit right on the page. For example, Joshua Bell can be given rights to add another blog post

DO WE NEED THIS HERE? The edit view template creates forms for creating new or editing existing rows in a table. It has somewhat limited customisability consisting only of choosing the fields in the form, and if fields have been left out of the form, a default value may be specified.

Show:  Show a single row, with flexible layout. So rather than just a row, you could design an author bio view with a big photo, a list of credentials, a biography, and contact details. 

You can also add fields to a show view from related tables, links to other views or aggregations (calculations over related tables). For example, you could add cards showing all the posts an author has written to the author bio view. 


Composed view templates

ListShowList: Combine an optional list view on the left with displays on the right of a single selected row, with views of related rows from different tables underneath. You could make an author bio view with a big photo, a list of credentials, a biography, contact details from one table. Then add a list of their blog posts and statistics.

Feed: Show multiple rows by displaying a chosen view for each row, stacked or in columns. 

Filter: Elements that limit the rows shown in other views on the same page. Filter views do not show any rows on their own.


  • feed: a feed view is a view of multiple rows shown one after another. The display of each row in the feed is determined by the chosen underlying view.
  • list-show-list: the list-show-list view is composed of multiple related views. In the full version, on the left hand side of the screen is shown a list from which a single row can be chosen. On the right hand side of the screen is shown at the top a view of that row and below that views of rows that are related to the chosen row, of the same or of different tables. However the list on the left hand side is optional in which case only the view of the primary row and the related tables below are shown.
  • kanban board: a kanban board is provided by the kanban plug-in. What is shown in each card is determined by selecting an underlying view.

Pages

Pages can be built with a drag-and-drop page builder. Pages are not tied to specific tables, but they can include views that display content from the database. You can use tables to decorate views with static content, and to combine multiple views. These views can share a state, for instance a subset of the data, and this can be used to build clickable dashboards.

Plugins

Plug-ins extend Saltcorn with new functionality that you cannot create yourself through the user interface. They are written in the JavaScript programming language and when activated can add to a Saltcorn application:

  • Types
  • Fieldviews
  • View templates

Packs

Packs are collections of defined tables and views, along with the plug-ins needed to support them. You can use them to quickly get started with an application by adding bundles of functionality and then modifying it.

Whereas plugins extend Saltcorn with functionality that you cannot define to the user interface, packs only replicate functionality that you could define yourself. They are only there to save you time and not to extend with new functionality.