Пример #1
0
from free4my import DbContext,session_maker
from free4my.dynamic import DynamicBase,Column,FkColumn,Lt,Lte,Gt,Gte,NotEq,Index

ctx=DbContext(host="221.237.177.83",user="******",password="******",database="test_db")

class Auther(DynamicBase):
    name=Column(unicode,max_length=20)
    password=Column(unicode,max_length=46)
    age=Column(int)
    regist_date=Column(datetime.datetime)
    class Meta:
        table_name = "auther"
        by_regist = Index('regist_date',table_name="reg_time_idx_auther")
        by_age = Index('age',table_name="age_idx_auther")

Session=session_maker(ctx)

session=Session()

Auther.objects.sync_table()


#au1=Auther.objects.create(name=u"alexabder",password=u"123456",age=14,regist_date=datetime.datetime.now())

#au2=Auther.objects.create(name=u"susan",password=u"abc",age=20,regist_date=datetime.datetime.now())

#session.commit()

for user in Auther.objects.by_regist.all().order('-regist_date'):
    print user.name
for user in Auther.objects.by_regist.all().order('-regist_date'):
Пример #2
0
from logging import log,INFO,ERROR,DEBUG,WARNING


DATABASE = 'blog'
DEBUG = True
HOST = '127.0.0.1'
SECRET_KEY = '1r4$df(8'
USERNAME = '******'
PASSWORD = '******'
PAGE_SIZE=20

app = Flask(__name__)
app.config.from_object(__name__)

db_ctx=free4my.DbContext(host=HOST,user=USERNAME,password=PASSWORD,database=DATABASE)
Session=free4my.session_maker(db_ctx)

def touni(data, enc='utf8'):
    if isinstance(data, unicode):return data
    return data.decode(enc)

def tob(data, enc='utf8'):
    if isinstance(data, unicode):return data.encode(enc)
    return data

def _to_date_str(key):
    time_s=str(key)
    time_tuple=(time_s[:4],time_s[4:6],time_s[6:9])
    return "-".join(time_tuple)

def hash_passwd(raw_password):