`

a naive way to use dictcursor of psycopg2 with twisted adbapi

 
阅读更多

make a new file called fakedb.py

 

and copy some contents from psycopg1.py from psycopg2 package

 

 

class connection(_2connection):

    """psycopg 1.1.x connection."""

 

    def cursor(self):

        """cursor() -> new psycopg 1.1.x compatible cursor object"""

        return _2connection.cursor(self, cursor_factory=psycopg2.extras.DictCursor)

 

    def autocommit(self, on_off=1):

        """autocommit(on_off=1) -> switch autocommit on (1) or off (0)"""

        if on_off > 0:

            self.set_isolation_level(_ext.ISOLATION_LEVEL_AUTOCOMMIT)

        else:

            self.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED)

 

the point is to specify cursor_factory as DictCursor..

 

 

now use this file with adbapi like

 

 

adbapi.ConnectionPool("fakedb", database="test",host='localhost',\

                                  port=9000,user='mathgl')

 

 

 

分享到:
评论

相关推荐

    Learning.Data.Mining.with.Python.1784396052

    This book teaches you to design and develop data mining applications using a variety of datasets, starting with basic classification and affinity analysis. Next, we move on to more complex data types ...

    Data Science from Scratch First Principles with Python

    Data science libraries, frameworks, modules, and toolkits are great for doing data science, but they’re also a good way to dive into the discipline without actually understanding data science....

    Mastering Machine Learning with scikit-learn [2017,第二版]

    By the end of this book, you will master all required concepts of scikit-learn to build efficient models at work to carry out advanced tasks with the practical approach. What you will learn Review ...

    Machine Learning Made Easy with R

    YOUR PERSONAL BLUE PRINT: Through a simple to follow intuitive step by step process, you will learn how to use the most popular machine learning algorithms using R. Once you have mastered the process,...

    Data Science from Scratch- First Principles with Python(O'Reilly,2015)

    Data science libraries, frameworks, modules, and toolkits are great for doing data science, but they’re also a good way to dive into the discipline without actually understanding data science....

    Learning.Boost.Cplusplus.Libraries.1783551216

    This book teaches you to design and develop data mining applications using a variety of datasets, starting with basic classification and affinity analysis. Next, we move on to more complex data types ...

    Mastering Machine Learning with scikit-learn -2017.7.24

    By the end of this book, you will master all required concepts of scikit-learn to build efficient models at work to carry out advanced tasks with the practical approach. What you will learn Review ...

    R.Unleash.Machine.Learning.Techniques

    This Learning Path will take you through the fundamentals of R and demonstrate how to use the language to solve a diverse range of challenges through machine learning. Accessible yet comprehensive, it...

    Naive-Bayes-Classifier-master_naivebayes_

    朴素贝叶斯(Naive Bayes)是一种基于概率论的分类算法,因其简单高效而广泛应用于文本分类、垃圾邮件过滤、情感分析等多个领域。在这个"Naive-Bayes-Classifier-master"项目中,我们将深入探讨朴素贝叶斯的理论基础...

    NaiveBayes分类器介绍

    NaiveBayes分类器是一种基于贝叶斯定理和事件独立性假设的统计分类方法。在机器学习领域,它被广泛用于文本分类、垃圾邮件过滤、情感分析等任务,因其简单高效而备受青睐。 首先,我们需要理解贝叶斯定理的基本概念...

    NIST SP800-120.pdf

    In addition to these older and less secure methods, there are now a number of stronger EAP methods intended for integrated use with standard wireless access protocols, such that the keys generated in ...

    LuaUnicode icu-lua

    Happily UTF-8 is designed so that it is relatively easy to count the number of unicode symbols in a string: simply count the number of octets that are in the ranges 0x00 to 0x7f (inclusive) or 0xC2 to...

    Mastering Machine Learning with scikit-learn 第二版 2017

    Mastering Machine Learning with scikit-learn (2 ed) (True PDF + AWZ3 + codes) Table of Contents Preface 1 Chapter 1: The Fundamentals of Machine Learning 6 Defining machine learning 6 Learning from ...

    Unity 5.x Game AI Programming Cookbook

    Use techniques such as A*and A*mbush to empower your agents with path finding capabilities. Create a representation of the world and make agents navigate it Construct decision-making systems to make ...

    A Corpus Reader and POS-Tagger for MULTEXT-East in NLTK.

    It provides easy-to-use interfaces to over 50 corpora and lexical resources such as WordNet, along with a suite of text processing libraries for tokenization, parsing, classification, stemming, ...

    Naive Bayes Classifier_NavieBayes_naivebayes_

    **朴素贝叶斯分类器(Naive Bayes Classifier)** 朴素贝叶斯分类器是一种基于概率理论的机器学习算法,其核心思想是利用贝叶斯定理进行预测。该算法假设特征之间相互独立,这也是“朴素”一词的由来。尽管在现实...

    Thoughtful.Machine.Learning.with.Python.epub

    With this practical guide, author Matthew Kirk shows you how to integrate and test machine learning algorithms in your code, without the academic subtext. Featuring graphs and highlighted code ...

Global site tag (gtag.js) - Google Analytics