Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goto-bus-stop/odmongo
Work-in-progress mini composable MongoDB ODM.
https://github.com/goto-bus-stop/odmongo
Last synced: 27 days ago
JSON representation
Work-in-progress mini composable MongoDB ODM.
- Host: GitHub
- URL: https://github.com/goto-bus-stop/odmongo
- Owner: goto-bus-stop
- License: other
- Created: 2018-06-08T18:13:36.000Z (over 6 years ago)
- Default Branch: default
- Last Pushed: 2023-11-17T04:25:53.000Z (12 months ago)
- Last Synced: 2024-10-05T16:25:43.020Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 85 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# odmongo
A barebones MongoDB ODM designed for use with modern ES syntax.
It provides a very small wrapper that you can extend in various places to build
yourself a nice DB library.## Usage
In short:
```js
import joi from 'joi'
import { Connection, Model } from 'odmongo'// Set up a connection instance
const connection = new Connection()// Create some Model classes
class User extends Model {
validate () {
return joi.validate(this.fields, User.schema)
}
}
User.schema = joi.object({
username: joi.string().required()
})
User.collection = 'users'// Register models on the connection instance
connection.define({ User })// Connect!
await connection.connect('mongodb://localhost:27017/my_db')// Query existing documents
for await (const user of connection.models.User.find()) {
console.log(user.fields.username)
}// Create new documents
const user = new connection.models.User({
username: 'Me'
})
try {
await user.save()
console.log('saved')
} catch (err) {
console.error('Could not save the new user:', err.message)
}
```## API
See the documentation in [API.md](./API.md).
## License
[Apache-2.0](./LICENSE.md)