class
CouchDB::Document
- CouchDB::Document
- Reference
- Object
Overview
An open-schema CouchDB document with typed _id, _rev, and _deleted fields.
Document uses JSON::Serializable for round-trip JSON encoding and
JSON::Serializable::Unmapped to preserve any extra fields in json_unmapped.
Subclass it to add strongly-typed application fields:
class Note < CouchDB::Document
property title : String = ""
property body : String = ""
end
Subclass properties are serialized as top-level JSON keys alongside _id and _rev.
Unknown fields are transparently preserved through json_unmapped and survive
replication without loss.
Included Modules
- JSON::Serializable
- JSON::Serializable::Unmapped
Defined in:
couchdb/document.crConstructors
- .new(pull : JSON::PullParser)
-
.new
Creates a new empty document.
- .new(*, __pull_for_json_serializable pull : JSON::PullParser)
Instance Method Summary
-
#[](key : String) : JSON::Any
Reads a field by JSON key.
-
#[]=(key : String, value : JSON::Any)
Writes a field by JSON key.
-
#[]?(key : String) : JSON::Any | Nil
Reads a field by JSON key, returning
nilif the key is absent. - #deleted : Bool | Nil
- #deleted=(deleted : Bool | Nil)
-
#deleted? : Bool
Returns
truewhen#deletedis explicitly set totrue. - #id : String
- #id=(id : String)
-
#next_rev : String
Computes the next revision string
"N-<md5>"without mutatingself. - #rev : String | Nil
- #rev=(rev : String | Nil)
-
#rev_num : Int32
Returns the integer generation counter from the current
#rev(e.g.
Constructor Detail
Instance Method Detail
Reads a field by JSON key.
Routes "_id", "_rev", and "_deleted" to their typed properties;
all other keys are read from json_unmapped. Raises KeyError if the
key is absent (use #[]? for a nil-safe variant).
Writes a field by JSON key.
Routes "_id", "_rev", and "_deleted" to their typed properties;
all other keys are stored in json_unmapped.
Reads a field by JSON key, returning nil if the key is absent.
Routes "_id", "_rev", and "_deleted" to their typed properties;
all other keys are read from json_unmapped.
Computes the next revision string "N-<md5>" without mutating self.
The hash is computed over the document JSON with _rev removed, matching
the CouchDB wire format. Delegates to DocumentHelper.next_rev.