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.
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.
In the rest of this section, you will learn the basic concepts of the relational model. I use the example of creating a blog.
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
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.
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
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 ||53||1.65|
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||Bio||Number of posts written ||Followers (k)||Twitter|
|Joshua Bell||Joshua is from the UK and likes tigers||53||1.65|
|Janine Jansen||Janine is from France and likes violins||26||5.6||@JJansen|
|Nigel Kennedy||Nigel is from the USA and likes cooking||48||2.86||@Nige|
|Viktoria Mullova||Victoria is from Russia and like trees||34||1.12||@VM1985|
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.
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.
|Tiger King: The real story||Joshua 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 2020||Tiger, energy, chair|
|Tiger, Tiger, burning bright||Joshua 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 2020||Kitten, puma, forest|
|Cooking with cheese||Nigel 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 2020||Cheese, chalk, brie|
|The pine forests of Karakan||Victoria 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 2020||tree, lobster, owl|
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 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.
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.
Plug-ins may provide both composed and basic view templates.
The base plug-in provides three different basic view templates: list edit, and 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.
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.
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.
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.