Schema

Search
Feedback

Schema

You can add new properties (which are called “local attributes” to distinguish them from remote attributes) by entering a property (JSON) name and setting the type.

  • JSON Name: The primary JSON key to reference a property
  • DB Name: Optional name of the database property if different from the JSON key
  • Type: Internal data type
  • Format: You can set a format on Date or Double properties for output formatting. Note that starting with 1.0.RC3, there are more complex attribute types like Function, Counter, Notion, Cypher. The active code for these types has to be entered in the Format column.
  • Not Null: If set, the value must not be null
  • Unique: If set, the value must be unique
  • Default: Default value for this property

You can declare Custom Methods in dynamic schema entities which allows you to specify behaviour / business logic in a functional way.

A “view” in Structr is a set of local and remote properties that is bound to a name and can be accessed via REST. Entity types can have an arbitrary number of views that can contain different properties. You can select a view by appending its name to a REST URL. The default view is selected automatically if you don’t supply a view name in the REST URL.

URLView
/projectsdefault
/projects/c539c26cc20e4e33b66e99a2ac031457default
/projects/appDataappData
/projects/c539c26cc20e4e33b66e99a2ac031457/webAppwebApp
Example

Let’s assume we have defined a “Project” entity with the properties “name”, “members” and “title”, all of which should be included in the default view, so we define the default view like this:




NameAttributes
defaultname, members, title

Please note that in the recent versions of Structr, you have to explicitly declare the properties that the default view should contain.

You can define relations between custom node types by connecting them by an arrow, starting at the dot at the bottom of a schema node and stop at the dot at the bottom of another one, or - if you want to self-relation - of the same node.

When you have successfully established a relation, you should enter relationship type (typically in all-uppercase/underscore notation, see https://gist.github.com/nigelsmall/9366313) and set the cardinality to reflect your data model.

  • Relationship Type: Mandatory identifier to tag relationships with a common semantic
  • Cardinality: Set to 1:*, *:1 or : (default)

For each relation defined between node types, a property will be automatically created for both, source and target node type. The default name will be auto-generated based on the source and target node type and the relationship type.

You can overwrite the default name by entering a new, custom name into the name column.
The Schema Editor allows you to extend the built-in data model or schema with custom data types by either creating new node types one by one, or importing Cypher code, f.e. contained in a GraphGist.

There are buttons to expand and collapse the schema nodes. The details view opens when you click on the edit icon. Please note that since 1.0.RC3, you can also edit schema relationship properties.

You can import a GraphGist to initially load data into Structr and let Structr read and analyze the data model from the GraphGist code to create an initial schema in Structr. To import a GraphGist, copy its raw URL and paste it into the designated form field.
The raw URL is what’s in your browser’s URL field when you see the AsciiDoc source code in the browser’s main area.
Structr takes care for indexing node and relationship properties in the internal Lucene indexes.

Clicking on the Rebuild Index button triggers a maintenance command, running in the background on the server, which rebuilds all these indexes.
If you want so start over with your schema creation, you can use the Clear Schema button to erase all dynamic schema information.

Please note that it won’t delete neither the static, built-in schema definitions, nor data nodes and relationships.
After importing new nodes into Structr, you need to add UUIDs to make them visible for and usable with Structr.

The Add UUIDs button triggers a maintenance command which runs in the background.

This function is available for admin users only.
The Admin Tools dialog provides some handy functions for administration of data stored in Structr like

  • Rebuild index
  • Clear schema
  • Add UUIDs
    In Structr, you can define an application-level schema which holds all information about your data model. At runtime, the schema is represented as Java POJOs as it provides the best performance possible. The primary source of the schema are the built-in classes contained in the different modules structr-core, structr-rest and structr-ui.

To extend the built-in data model or schema, it is possible to create custom data types by adding schema nodes and relationships to the underlying graph database. All graph objects can be modified at runtime, so it is possible to modify the custom schema information at runtime, too. On each modification of the in-graph schema, a process reads all schema nodes and relationships, creates Java source code which is then compiled, and the result is loaded dynamically into the running JVM. There’s no functional or performance difference between the built-in classes and the classes created from the schema graph.

Graph-Browser

Related Articles
About this article
Last change 2016-10-06
Topics Structr 2.0