-
Notifications
You must be signed in to change notification settings - Fork 15
Schemas
(use 'clj-orient.core)
You can use create-class!
to create new classes names by keywords and oclass
to look up OClass
object by their name. Class names can be simple keywords or namespaced. If they are namespaced, they will be saved as "namespace_name"
strings in the database.
Examples of class names: :user
, :data/user
, my.data/user
.
derive!
allows you to create sub-classes in the schema to do polymorphic queries.
After doing any sort of change to the schema, you must use the save-schema!
function to make sure the changes in the code are reflected in the DB.
Properties
create-prop!
allows you to create properties that can be configured and even modified later with update-prop!
, e.g.: (create-prop! :user :name :string {:index :fulltext})
prop-info
will return you a hash-map with information about the desired property.
In the clj-orient.schema
namespace is the defoclass
macro, which allows you to easily define your schemas. e.g.:
(defoclass data/foo)
(defoclass data/bar data/foo ; data/bar is derived from data/foo.
[^:mandatory ^:unique id :long]
[name :string {:regex #"(\w+)+"}]
[age :short {:min 0, :max 1000}]
[foo [:link core/baz] {:nullable false}])
You're going to need to invoke the no-args function install-oclasses!
with an open connection to the database in order to register your defined schema.