Exemplo n.º 1
0
 def _init_db(self, dbname):
     if not os.path.exists(dbname):
         cx = sqlite3.connect(dbname)
         cursor = cx.cursor()
         res = cursor.execute("""
             create table proxy (
                 ip_port varchar primary key,
                 anonymous varchar,
                 proxy_type varchar,
                 location varchar,
                 response_time varchar,
                 last_confirm varchar,
                 last_used float,
                 is_dead boolean
               )
           """)
         print 'create a new proxy database in: %s' % os.path.abspath(dbname)
     Database.set_dbapi(sqlite3)
     Database.config(db=dbname)
Exemplo n.º 2
0
 def __init__(self, db_name):
     Database.set_dbapi(sqlite3)
     Database.config(db=db_name)
Exemplo n.º 3
0
Arquivo: models.py Projeto: hit9/zhiz
        return ''


class Blog(Model):

    name = Field()
    description = Field()
    disqus = Field()


class Post(Model):

    datetime = Field()
    title = Field()
    title_pic = Field()
    body = Field()
    published = Field()

    @property
    def summary(self):
        return markdown.render(self.body[:150])


class Admin(Model):

    passwd = Field()

import pymysql
Database.set_dbapi(pymysql)
Database.config(**app.config['DB_CFG'])
Exemplo n.º 4
0
class Groups(Model):
    id = PrimaryKey()
    uid = Field()    # 用户id
    name = Field()    # 分类名

class Ngroups(Model):
    uid = Field()    # 用户id
    name = Field()    # 分组名
    count = Field()    # 分组好友数量

if __name__ == "__main__":
    import sqlite3
    import os
    from skylark import Database
    Database.set_dbapi(sqlite3)
    Database.set_autocommit(True)
    Database.config(db = os.path.abspath("../../data/data.db"))

    r = Groups.where(Groups.id == "1", Groups.uid == 1).update(name = "bbbdfdfdfb").execute()
    print(r)

    r = Ngroups.select()
    for i in r:
        print(i.data)

    groups = Ngroups.where(Ngroups.uid == 1).select()
    for g in groups:
        print(g)
    print([group.data for group in groups])
Exemplo n.º 5
0
import MySQLdb
from skylark import Database, Model, Field, PrimaryKey, ForeignKey


class User(Model):
    name = Field()
    email = Field()


class Post(Model):
    name = Field()
    post_id = PrimaryKey()
    user_id = ForeignKey(User.id)


Database.set_dbapi(MySQLdb)
Database.config(db='mydb', user='******', passwd='')
Exemplo n.º 6
0
import MySQLdb
from skylark import Database, Model, Field
from django.conf import settings as _options

Database.set_dbapi(MySQLdb)
Database.config(host=_options.DATABASES['default']['HOST'], user=_options.DATABASES['default']['USER'],
                  passwd=_options.DATABASES['default']['PASSWORD'], port=int(_options.DATABASES['default']['PORT']),
                  db=_options.DATABASES['default']['NAME'], charset='utf8')
Exemplo n.º 7
0
import sqlite3
from skylark import Database, Model, Field, PrimaryKey, ForeignKey


class User(Model):
    name = Field()
    email = Field()


class Post(Model):
    name = Field()
    post_id = PrimaryKey()
    user_id = ForeignKey(User.id)


Database.set_dbapi(sqlite3)
Database.config(db='mydb')
Exemplo n.º 8
0
def initdb(path = None):
    Database.set_dbapi(sqlite3)
    Database.set_autocommit(True)
    Database.config(db = path if path else lib.DBPATH, check_same_thread = False)
Exemplo n.º 9
0
    # 表示程式在雲端執行
    download_root_dir = os.environ['OPENSHIFT_DATA_DIR']
    data_dir = os.environ['OPENSHIFT_DATA_DIR']
    template_root_dir = os.environ['OPENSHIFT_REPO_DIR']+"/wsgi/static"
    # template_root_dir = _curdir + "/static"
else:
    # 表示程式在近端執行
    download_root_dir = _curdir + "/local_data/"
    data_dir = _curdir + "/local_data/"
    template_root_dir = _curdir + "/static"
# 資料庫選用
# 內建使用 sqlite3
ormdb = "sqlite"
#ormdb = "mysql"
if ormdb == "sqlite":
    Database.set_dbapi(sqlite3)
    Database.config(db=data_dir+"task.db")
else:
    # 選用 mysql
    # 注意 port 必須為整數, 而非字串
    if 'OPENSHIFT_REPO_DIR' in os.environ.keys():
        Database.set_dbapi(pymysql)
        Database.config(host=os.environ[str('OPENSHIFT_MYSQL_DB_HOST')],  \
            port=int(os.environ['OPENSHIFT_MYSQL_DB_PORT']), db='cadp', \
            user=os.environ['OPENSHIFT_MYSQL_DB_USERNAME'], \
            passwd=os.environ['OPENSHIFT_MYSQL_DB_PASSWORD'], charset='utf8')
    else:
        Database.set_dbapi(pymysql)
        Database.config(host='localhost', port=3306, db='cadp', user='******', passwd='root', charset='utf8')
#@-<<declarations>>
#@+others
Exemplo n.º 10
0
# coding=utf8


import pymysql
from skylark import Database, Model, Field
from messageboard import app


class Message(Model):
    title = Field()
    content = Field()
    create_at = Field()


Database.set_dbapi(pymysql)
Database.config(**app.config['DB_CONN_CFG'])