Mongo ODM (Object Document Mapper) with repositories for crystal lang
- Serialize & Deserialize
- Connection Pool
- Thread Safety
Currently, in the container, we are creating several instances
-
Add the dependency to your
shard.yml
:dependencies: glassy-mongodb-odm: github: glassy-framework/glassy-mongo-odm
-
Run
shards install
require "glassy-mongo-odm"
include Glassy::MongoODM::Annotations
@[ODM::Document]
class User
@[ODM::Id]
property id : BSON::ObjectId?
@[ODM::Field(name: "Name")]
property name : String
@[ODM::Field]
property birth_date : Time
@[ODM::Field]
property mother : Mother?
@[ODM::Document]
class Mother
@[ODM::Field]
property name : String?
end
def initialize(@name, @birth_date)
end
end
class UserRepository < Glassy::MongoODM::Repository(User)
end
conn = Glassy::MongoODM::Connection.new("mongodb://mongo", db_name)
repository = UserRepository.new(conn)
user = User.new(name: "My Name", birth_date: Time.local)
repository.save(user)
Always run crystal spec before submiting code
- Fork it (https://github.com/glassy-framework/glassy-mongo-odm/fork)
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create a new Pull Request
- Anderson Danilo - creator and maintainer