zoukankan      html  css  js  c++  java
  • sqlsoup


    ################################################

    import sqlsoup
    # SURL = "mysql+pymysql://cic_admin:TaBoq,,1234@192.168.1.170:3306/yct_proxy?charset=utf8&autocommit=true"
    db = sqlsoup.SQLSoup(SURL)
    self.table = db.entity(table_name)

    self.table.filter_by(to_server=to_server, methods=methods,).count():
    self.table.filter_by(registerAppNo=registerAppNo,customer_id=customer_id).update(infodata)
    the_set = self.table.filter_by(pageName=pageName,customer_id=customer_id).one()

    db.delete(the_set)
    db.commit()
    db.rollback()


    #SQLSoup 参考:https://sqlsoup.readthedocs.io/en/latest/
    SQLSoup是一个基于SQLAlchemy对象关系映射器构建的一步式数据库访问工具。
    对数据库的简单操作使用这个,如果复杂的话最好使用SQLAlchemy


    依赖:SQLAlchemy # 确保已经安装了
    安装:pip install sqlsoup

    连接:
    >>> import sqlsoup
    >>> db = sqlsoup.SQLSoup('postgresql://scott:tiger@localhost/test')

    加载对象:
    >>> users = db.users.all()
    也可以像下面一样:
    my_user_table = db.entity("User_Table")

    基本表用法:
    db.users.order_by(db.users.name).all()

    # 从检索结果中取第一个对象
    >>> db.users.filter(db.users.name=='Bhargan Basepair').one()

    db.users.get('Bhargan Basepair')
    db.users.filter_by(name='Bhargan Basepair').one()

    更新对象:
    >>> user.email = 'basepair+nospam@example.edu'
    >>> db.commit()

    >>> book_id = db.books.filter_by(title='Regional Variation in Moss').first().id
    >>> db.loans.insert(book_id=book_id, user_name=user.name)

    >>> loan = db.loans.filter_by(book_id=2, user_name='Bhargan Basepair').one()
    >>> db.delete(loan)
    >>> db.commit()
    # 增
    >>> db.loans.insert(book_id=book_id, user_name=user.name)
    # 删
    >>> db.loans.delete(db.loans.book_id==2)
    # 改
    >>> db.loans.filter_by(db.loans.book_id==2).update({'book_id':1})
    # 查
    db.loans.filter_by(book_id=1).all()

    Joins:
    Relationships:
    Advanced Use:
    Sessions, Transactions and Application Integration
    Mapping arbitrary Selectables
    Raw SQL
    Dynamic table names

    ################################################

  • 相关阅读:
    CodeForces 576E Paingting Edges
    CodeForces 1361D Johnny and James
    agc027_d Modulo Matrix
    agc046_f Forbidden Tournament
    MySQL架构及优化原理
    Ubuntu下无法安装pip
    WSL安装问题----wslregisterdistribution failed with error: 0x8007007b
    基础排序算法总结(一)
    透明代理、匿名代理、混淆代理、高匿代理
    常见“加密”算法之 base64
  • 原文地址:https://www.cnblogs.com/xujinjin18/p/11180831.html
Copyright © 2011-2022 走看看