用户:
lsk666666查看:6 回复:3 评论:6 创建时间:2020-09-08T19:08:11
闲着没事,仿照Java的Mybatis写的。
【下载地址】
"".join(chr(x) for x in list([104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 108, 115, 107, 45, 99, 104, 105, 110, 97, 47, 97, 100, 118, 112, 121, 109, 121, 115, 113, 108]))
【使用方法】
1.下载源代码,并把源代码拷到你的工程文件夹下面。
2.在你的工程文件夹下面新建connection.properties文件,内容是:
db.username=你的数据库用户名
db.password=你的数据库密码
db.host=数据库的ip,在本机可以直接填写此字段为localhost
db.database=数据库名
3.使用时请导入annotations模块的全部内容。
装饰器:
Select:执行一次select操作,参数为sql语句。
Insert:同上,执行insert操作。
Update:同上,执行update操作。
Delete:同上,执行delete操作。
(其实这四个装饰器的代码是一样的,为什么写四个呢?以后应该会有用的。[滑稽])
sql语句中,可以用#{变量名}来表示一个变量,这个变量的值会从被装饰的方法的同名参数中获取。如果找不到,则会报错。
例子:
from annotations import *
"""
数据表:
+----+------+-------+
| id | name | value |
+----+------+-------+
| 1 | test | test |
| 2 | name | value |
+----+------+-------+
"""
@Select("select * from test where id=#{id}")
def select(id):
pass
def main():
id = 1
print(select(1)) #输出:((1, 'test', 'test'),)
if __name__ == "__main__":
main()
--------------------------------分割线--------------------------------------------------------
1.欢迎各位为这个库取名。
2.这个只是第一个版本,有很多bug,也有很多的功能没有实现。这些问题会在以后的更新中解决的。
修正:
tools.py的最后一个方法:
def readAutoInc(dbName):
sql = "select auto_increment from information_schema.`TABLES` where table_name='"+dbName+"'"
return int(execute(sql)[0])点赞0
评论