tornado-Database (TORNDB package)

Source: Internet
Author: User

1, TORNDB Database Introduction
Prior to the Tornado3.0 version, the Tornado.database module was used to operate the MySQL database, and since the 3.0 release, the module was independently provided as a TORNDB package. Torndb is just a simple package for mysqldb and does not support Python 3.

2, TORNDB installation
Pip Install Torndb

3. Connection Initialization
Class Applicatin (tornado.web.application):
def Init(self):
Handler = [
(r "index/", Indexhandler),
]

        settings = dic(            template_path = os.path.join(os.path.dirname(__file__),"templates"),            static_path = os.path.join(os.path.dirname(__file__),"static")        )        super(Application,self).__init__(handler,**settings)        self.db = torndb.Connection(            host = "127,0,0,1",            database = "ihome",            user = "root",            pwd = "mysql"        )

4. Using the database
1. Execute the statement
1. Execute (query,*patameters,**kwparameters)
1. Query: SQL statement to execute

        2, *patameters: For the parameters specified in the SQL statement data value 3, **kwparameters: For the parameters specified in the SQL statement data assignment Operation 4, return the effect of the last self-increment field value 2, Execu Te_rowcount (query, (patameters,**kwparameters)) 1, query: SQL statement to execute 2, *patameters: Data is passed to the parameter specified in the SQL statement 3, **kwparameters: The assignment of data to the parameters specified in the SQL statement 4, returns the number of rows affected 3, instance: Db.execute ("INSERT into houses (title, Position, Pric E, score, comments) values (%s,%s,%s,%s,%s), "individually decorated cottage", "close to Wen Jin Jie", 280, 5, 128) or Db.execute ("insert INTO Houses (title, position, price, score, comments) values (% (title) s,% (position) s,% (price) s,% (score) s,% (comments) s) ",        Title= "individually decorated cottage", position= "close to Wen Jin Jie", price=280, Score=5, comments=128) 2, query statement 1, get (query, parameters, *kwparameters) 1. Query: SQL statement to execute 2, *patameters: Data value for the parameters specified in the SQL statement 3, **kwparameters: For the parameters specified in the SQL statement data assignment Operation 4, return a single-line knot Or none, if there are multiple lines then the error. The return value is torndb.    The row type is a class Dictionary object that supports both the dictionary's keyword index and the object's zodiac access. 2. Query (query, parameters, *kwparameters) 1, query: SQL statement to execute 2, *pataMeters: Data is passed to the parameters specified in the SQL statement 3, **kwparameters: Assignment of data to the parameters specified in the SQL statement 4, returns the multiline result, torndb. The list of row.

Tornado-Database (TORNDB package)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.