SSPkrolik / nimongo

Pure Nim lang MongoDB driver
http://sspkrolik.github.io/nimongo
MIT License
101 stars 20 forks source link

feedback: planning on creating a MongoORM #44

Closed JohnAD closed 5 years ago

JohnAD commented 6 years ago

I'd like to write a mongoORM nimble package similar to python's MongoEngine library. MongoORM would, ideally, depend on nimongo for the underlying access to MongoDB. mongoORM's purpose is to overlay client-side type checking and validation on collections.

Essentially, the package module would use nim's support for compile-time macros, generics, and templates to create a domain-specific language (DSL). Essentially allowing something like:

# Create new Mongo client via nimongo
var m = newMongo().slaveOk(true).allowPartial(false)

# define a document using DSL

document Page(m):
  name string
  posts seq[int]:
    nil_allowed = true
  contact email:
    required = true

# now I'll use it

var mydoc = Page().new()
mydoc.name = "joe"
mydoc.posts = [3, 9, nil, 2]
mydoc.contact = "test@example.com"
mydoc.save()
# an invalid field, such as invalid email address generates a MongoORMError

But, before I go writing this beast, I wanted to make sure: