Yii Gii with MongoDB - mongodb

Could anyone please tell me how MongoDB can be used with YII?
How can we create controller and model functions using Gii if the database used is MongoDB?

I've used YiiMongoDBSuite (YMDS), which has some very rough support for Gii. You can generate starter classes, but given that MongoDB does not have a fixed schema you will need to edit the model to make them useful. There is an odd kludge that lets you generate MongoDB models from a SQL table, but this seems more effort than it's worth.
YMDS' EMongoDocument class extends the standard Yii CModel class, so this is a useful base if you want to build apps with CRUDS.
The unfortunate caveat is that YMDS is no longer maintained by the original author, and there are a few community forks to chose between.

The way of creating controllers is same as usual but you have to use an extension to talk to mongoDB from Yii ,
You need to use direct Mongo suite of yii . It is an extension which has a collection of components for the mongoDB .

Related

CRUD operation Grails

I need to read data from existing database is it possible using
compile "org.grails.plugins:db-reverse-engineer:4.0.0"?
My operations are: user should read data from existing table, create new record, create new coulmn, edit coulmn name, edit records.
View format will be in grid like xml grid.
Which technology is the best for these operations in grails, I have plan to work on javascript using jaxrs, is it good to do?
DB Reverse Engineering Plugin (org.grails.plugins:db-reverse-engineer:4.0.0) allows you to generate domain classes using existing DB. After you generate them - just use GORM to perform CRUD operations. You can read about GORM here
You can implement REST api in Grails using standart ways, check this answer to get high level understanding. If you need jaxrs- there is a plugin for that.

Telosys : How can i get database table records in template?

I am using Telosys tools for code generation. It's very nice tool and help me a lot.
But there is one problem, that is, it provides database schema information and i can access in templates (templates are formerly velocity templates), which is good, but how can i get selected entity's data from database? There is no way i can find, by which i can get that selected table data.
Please provide solution if any, or provide alternate way to do it.
Thanking You!
Telosys Tools is designed to retrieve the model from the database,
not the data stored in the tables.
But it allows to create your own specific tooling classes usable
in the templates, so it's possible to create a specific Java Class to retrieve the data from the database.
There's an example of this kind of specific class in the "database-doc" bundle
https://github.com/telosys-tools/database-doc-bundle-TT210 ( in classes folder )
To simplify the loading the simplest way is to create the class in the "default package" (no java package)
NB:
The problem is that the jar containing the JDBC driver
is not accessible by the generator class-loader, so you will have to use a specific class-loader and to connect directly with the JDBC driver.
Here is an example : https://gist.github.com/l-gu/ed0c8726807e5e8dd83a
Don't use it as is (the connection is never closed) but it can be easily adapted.

Generating table class for postgres

I have a postgres database and I want to generate the entity class of a table. I need this in order to connect to the database without using something like :
NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM TABLE1", conn);
How can I obtain the class?
Can you provide some detailed steps? I can't seem to find this anywhere.
Thanks in advance!
Entity classes are usually hand-written, or are generated from a schema then hand-tweaked. In the Java world many tools like NetBeans and Eclipse can help, but things seem much less mature in the C#/.NET world if you're not using Microsoft databases and Microsoft query tools.
This answer refers to a few useful tools, and a quick search also found the NHibernate entity generator, which seems to be part of a tool with support for Entity Framework and LINQ too.
Depends on a language but yes - you can do something like this in Java or Python using Object Relational tools such as SQLAlchemy, Hybernate, iBatis, etc.
They can generate schema for you, can populate data based on the definitions of objects.

mongodb: how to express "schema"?

Once many teams work with the same mongodb database there needs to be some way to express what each document may contain. Otherwise the document will end be having "email", "mail", "email_addr" fields added by each team. What's the best way to represent this for the purpose of communication across teams?
Obviously, the best way is what the team is most comfortable with. It can be UML, whiteboard drawings, XML mappings, model code files, maybe even haiku poems :)
I personally prefer using an ODM (mongoid). It encourages you to specify all fields in the model class. Then you just need one glance at it to understand the schema.
What you can do is create your Objects first in a set of commons that all team members import into their projects. If you change schema design, you update Commons project and all team members import latest.
It's more about process and project management and less about technology given Mongo's schema-less design. One thing we find helpful is design your Tests first and lately, SoapUI and LoadUI have been excellent tools. Once you define your tests, it can stub the returns for you and produces HTML documentation you can distribute to team.
Check out: http://www.soapui.org/REST-Testing/working-with-rest-services.html
When you create collection, just add to it some first "reference" object that would have all the fields/sub-objects that object of this collection can possibly have and use it as "schema". You can even write validator that would check that new objects conform to this reference object.

TG2.1: Proper location to store a database session instance?

I am using a custom database (MongoDB) with TG 2.1 and i am wondering where the proper place to store the PyMongo connection/database instances would be?
Eg, at the moment they are getting created inside of my inherited instance of AppConfig. Is there a standard location to store this? Would shoving the variables into the project.model.__init__ be the best location, given that under SQLAlchemy, the database seems to commonly be retrieved via:
from project.model import DBSession, metadata
Anyway, just curious what the best practice is.
As of TurboGears 2.1.3, MongoDB support is integrated via the Ming ORM. I would look at a quickstarted project using the --ming option to get best practices if you want to do some customization: http://turbogears.org/2.1/docs/main/Ming.html