Noizu Entity Scaffolding provides a mechanism to define extended elixir structs with metadata for specifying access control, flagging sensitive data, specifying json formatting, specifying text/geo/vector indexing, and per entity caching settings.
It provides a streamlined standardized mechanism to configure ORM mapping between ecto, mnesia, redis and other persistence layers while reducing the amount of boilerplate code needed while providing streamlined cache, security and indexing controls. Including support for multiple layers of cache/persistence.
It automatically hooks your entities up to support noizu_labs_context and noizu_labs_erp protocols.
- Overview
- Tasks
- Persistence
- Indexing
- Caching
- Entity
- Overview
- ERP
- Field Types
- Cache
- Index
- Annotation
- Access Control
- Sensitive Data
- Transient Data
- JSON Formatting
- Cache
- Index
- Repo
details pending
You can use the helpers to construct entities and related ecto classes.
mix nz.gen.entity my_entity store=ecto sref=my-entity field=biz:integer
Generation is not perfect and some manual editing of ecto and entity may be required.
details pending
details pending
details pending
details pending
details pending
Behind the scenes a Noizu.Entity is just a defstruct with meta data added. Below is simple declaration and the effective defstruct it generates.
defmodule MyApp.Entity.Bar do
@vsn 1.0
use Noizu.Entity
def_entity do
identifier :integer
field :name
field :title, "Hello"
field :description
end
end
The above will generate a struct as below plus meta fields accessible by Noizu.Entity behavior defined methods.
defmodule MyApp.Entity.Bar do
defstruct [
identifier: nil,
name: nil,
title: "Hello",
description: nil,
# Generated Fields
vsn: 1.0,
meta: nil,
__transient__: nil
]
end
You may add json formatting annotation to Noizu.Entities to define how an entity should be displayed for different json formats (:admin, :client,...)
@json true
@json :include
@json false
@json :omit
@json template: :omit
@json as: :apple, omit: false
@json for: [:breif, :apple], set: [as: :alias, omit: false]
details_pending
You may add annotation to control required permissions to access/return an entity field, (:admin, :user, {:permission, name}, {:custom, {m,f,a})
@restrict :user
@restrict {m,f,a} # [entity, field, context] ++ a
@restrict :admin
@restrict {:group, group}
details_pending
details_pending
details_pending
Transient fields (fields that should not be persisted to persistence layers/cache) can be annotated or placed in transient blocks.
defmodule MyApp.Entity.Bar do
@vsn 1.0
use Noizu.Entity
def_entity do
identifier :integer
field :name
@transient true
field :transient_field
field :peristed_field
transient do
field :transient_field_2
field :transient_field_3
end
field :peristed_field2
end
end
Flags with sensitive information can be marked by using pii blocks or via @pii
annotation.
The resulting struct is unchanged but meta data tracks pii status and is used to alter inspect and logging output.
defmodule MyApp.Entity.Bar do
@vsn 1.0
use Noizu.Entity
def_entity do
identifier :integer
field :name
@pii :sensitive
field :passport
pii() do
field :pii_sensitive_field
field :pii_sensitive_field2
end
pii(:low) do
field :pii_low_field
field :pii_low_field2
end
end
end