Search code examples
google-app-enginepython-2.7google-cloud-datastorebottle

how to connect to google NoSQL database from bottle framework


I am running a bottle webservice in localhost in my system. I have connected it to the MySQL and it is working fine, but when it comes to googleappengine how can i connect to NoSQL.

This is my code:

import bottle
import webapp2
from bottle import route, run, template
import MySQLdb, MySQLdb.cursors
from bottle import route, template, request ,debug
from google.appengine.ext.webapp.util import run_wsgi_app
db = MySQLdb.connect(user="root", passwd="root", db="delhipoc" , host='127.0.0.1')
cur = db.cursor() 
def main():
    debug(True)
    run_wsgi_app(bottle.default_app())   

@route('/hai/<name>')
def show(name):
     print "the name is \n",name
     cur.execute('SELECT * from poc_people')
     print "i am in show \n"
     for row in cur.fetchall() :
        print row[0]
data = row[0]            
print "hai \n",row[0]
return template('<b></br></br></br>Hello{{name}}</br></br></br>{{data}}   </b>!',name=name,data=data)

if __name__ == '__main__':
    main()

In the above way i am able to connect to my local mysql database. But how can i connect it to GAE database


Solution

  • Create a datastore model corresponding to your table and convert all mysql api request to use datastore api. Datastore reference: https://developers.google.com/appengine/docs/python/datastore/ You don't need to explicitly "connect" to gae datastore, you can just issue the query, filter, etc.