As for document oriented databases, Repository can be used to store and retrieve Json object. Serialization from/to Json is used to translate from/to nit instances.
See MongoRepository
for a concrete implementation example.
popcorn :: JsonRepository :: defaultinit
popcorn $ JsonRepository :: SELF
Type of this instance, automatically specialized in every classpopcorn $ JsonRepository :: deserialize
Deserialize astring
to an instance.
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
popcorn :: JsonRepository :: defaultinit
popcorn :: Repository :: defaultinit
core :: Object :: defaultinit
popcorn :: Repository :: deserialize
Deserialize astring
to an instance.
popcorn :: Repository :: find_by_id
Find an instance by it'sid
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).popcorn :: Repository :: remove_all
Remove all the instances matching onquery
popcorn :: Repository :: remove_by_id
Remove the instance withid
github :: BranchRepo
github :: CommitRepo
# A Repository for JsonObjects.
#
# As for document oriented databases, Repository can be used to store and retrieve
# Json object.
# Serialization from/to Json is used to translate from/to nit instances.
#
# See `MongoRepository` for a concrete implementation example.
abstract class JsonRepository[E: Serializable]
super Repository[E]
redef fun serialize(item) do
if item == null then return null
var stream = new StringWriter
var serializer = new RepoSerializer(stream)
serializer.serialize item
stream.close
return stream.to_s
end
redef fun deserialize(string) do
if string == null then return null
var deserializer = new JsonDeserializer(string)
return deserializer.deserialize.as(E)
end
end
lib/popcorn/pop_repos.nit:220,1--244,3