Hi All,
I heard about web2py following this question:
http://stackoverflow.com/questions/5899483/generate-rest-based-service-from-database-schema
My goal is to create a RESTful web service from a DB, such that when the DB
is modified, no code changes would be needed.
Questions:
1. When creating the DB schema to be extracted, should I add an 'id' field?
If I do, the resulted 'legacy_db_web2py_code' string contains an 'ID' field
in 'define_table'. However, the documentation says such field is already
created implicitly. If I don't, I need another PK to create relations with
foreign keys.
2. I've found an example here:
http://www.web2pyslices.com/slice/show/1534/restful-services-with-curl-andor-python
but PUT and DELETE won't work (GET and POST do work). any suggestions?
3.I've written a small scitpt (attached) which wraps
'extract_mysql_models'. Feedback would be welcomed.
Thanks in advance
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
from extract_mysql_models_no_auth import mysql;
def convert (dbname, username, pwd, path):
legacy_db_web2py_code = mysql(dbname,username,pwd);
print("Conversion OK\n");
#print(legacy_db_web2py_code);
with open(path, 'w') as db_model_code_file:
db_model_code_file.write("from gluon import Field, DAL\n\n")
db_model_code_file.write("def add_mysql_model_to_DAL ():\n");
lines = legacy_db_web2py_code.splitlines();
legacy_db_web2py_code = "\n".join(" " + l for l in lines);
db_model_code_file.write(legacy_db_web2py_code);
db_model_code_file.write("\n\n return legacy_db\n");
print("Result written to "+path+"\n");
# replace with your data
if __name__ == '__main__':
dbname = 'mydb';
username ='myuser';
pwd = 'mypass';
path = '../applications/myapp/modules/mysql_db_DAL.py'
convert (dbname, username, pwd, path);