gomondel
Golang MongoDB Model Generator with CRUD
Description
Create ready-to-go models when working with the Official Go Driver for MongoDB including CRUD Operations (Create, Read, Update, Delete).
Installation
go get -u github.com/aliforever/gomondel
Usage
go install
after go get
to install gomondel in bin folder located at %GOPATH%/bin (make sure bin folder is added to path variable).
Note: Run Initialize New Database for Project
To add database connection to your project:
-
cd into your project directory, forexample:
cd %GOPATH%/src/myproject/
, and then run:gomondel --init=your_database_name_here
(This will create a models folder with a db.go file)
-
call
models.InitMongoDB()
in your main file to initialize the database.
Create New Model
To create a new model based on your MongoDB collections, run:
gomondel --model=ModelName
(This will create modelname.go file in models folder)
Note:
gomondel uses Inflect Package to pluralize model names, so forexample if your collection name is users
, you should use User
as model name.
This is to comply to golang naming conventions, your model struct type will be named User.
Contribution
You're free to create issues and pull requests to help complete gomondel!