- Overview
- Installation
- Actions
- Tasks
- Middleware
- Satellites
- Cluster
- Cache
- Chat
- Development Mode
- File System
- Events
- WebSocket
- TCP
- HTTP
- Security
- Validation
- Logging
- Commands
- Testing
Models
- Introduction
- Data Types and Attributes
- Instance and Class Methods
- Validations
- Associations
- Model Configuration
- Queries
Data Types and Attributes
Data Types
The following data types are currently available:
- string
- text
- integer
- float
- date
- time
- datetime
- boolean
- binary
- array
- json
These will map to the underlying database type if available. If a database doesn’t support a type a polyfill will be used. For example when using an array or json type in MySQL the values will be stringified before being saved.
Attribute Properties
These properties are also available on an attribute and can be used to enforce various constraints on the data.
defaultsTo
Will set a default value on an attribute if one is not supplied when the record is created. The supplied value can also be a
function that stellar will run while creating the record.
attributes: { |
autoIncrement
Will create a new auto-incrementing attribute. These should always be of type integer
and will not be supported in all datastores. For example MySQL will not allow more than one auto-incrementing
column per table.
attributes: { |
unique
Ensures no two records will be allowed with the same value. This is a database level constraint so in most cases a unique index will be created in the underlying datastore.
attributes: { |
index
Will create a simple index in the underlying datastore for faster queries if available. This is only for simple indexes and currently doens’t support compound indexes. For these you will need to create them yourself.
There is currently an issue with adding indexes to string fields. Because the ORM performs its queries in a case insensitive manner we are unable to use the index on a string attribute. There are some workarounds being discussed, but nothing is implemented so far. This will be updated in the near future to fully support indexes on strings.
attributes: { |
primaryKey
Will set the primary key of the record. This should be used when autoPK
is set to false.
attributes: { |
enum
A special validation property which will only allow values that match a whitelisted set of values.
attributes: { |
size
If supported in the datastore, can be used to define the size of the attribute. For example, in MySQL size can be used with a string to create a column with data type: varchar(n)
.
attributes: { |
columnName
Override the attribute name before sending to a datastore. This allows you to have a different interface for interacting with your data at the application layer and the data layer. It comes in handy when integrating with legacy databases. You can have a nice API for your data and still allow the data to be saved in legacy columns.
attributes: { |