fix bug in ddl template fro ddl

This commit is contained in:
yumoqing 2022-11-16 01:30:31 +08:00
parent 992665f9ec
commit f75c6f72f4
3 changed files with 9 additions and 42 deletions

View File

@ -235,13 +235,16 @@ class DBPools:
cur = None
if self.isAsyncDriver(dbname):
if dbdesc['driver'] == 'sqlite3':
conn = await driver.connect(dbdesc['kwargs']['dbname'])
else:
conn = await driver.connect(**dbdesc['kwargs'])
conn = await driver.connect(dbdesc['kwargs']['dbname'])
else:
conn = await driver.connect(**dbdesc['kwargs'])
cur = await conn.cursor()
return True,conn,cur
else:
conn = driver.connect(**dbdesc.kwargs)
if dbdesc['driver'] == 'sqlite3':
conn = driver.connect(dbdesc['kwargs']['dbname'])
else:
conn = driver.connect(**dbdesc['kwargs'])
cur = conn.cursor()
return False,conn,cur

View File

@ -1,4 +1,4 @@
sqlite_ddl_tmpl = """{% macro typeStr(type,len,dec) %}
sqlite3_ddl_tmpl = """{% macro typeStr(type,len,dec) %}
{%- if type in ['str', 'char', 'date', 'time', 'datetime', 'timestamp'] -%}
TEXT
{%- elif type in ['long', 'int', 'short', 'longlong' ] -%}
@ -23,7 +23,7 @@ drop table if exists {{summary[0].name}};
CREATE TABLE {{summary[0].name}}
(
{% for field in fields %}
`{{field.name}}` {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}} {%if field.title -%} -- {{field.title}}{%- endif %}{%- if not loop.last -%},{%- endif -%}
`{{field.name}}` {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}}{%- if not loop.last -%},{%- endif -%} {%if field.title -%} -- {{field.title}}{%- endif %}
{% endfor %}
{% if summary[0].primary and len(summary[0].primary)>0 %}
{{primary()}}

View File

@ -1,36 +0,0 @@
import sys
import os
import asyncio
from sqlor.dbpools import DBPools
async def exesqls(sqllines):
sqls = txt.split(';')
async with DBpools.sqlorContext('db') as sor:
for sql in sqls:
await sor.sqlExe(sql, {})
async def main():
with codecs.open(sys.argv[2],'r', 'utf-8') as f:
txt = f.read()
await exesql(txt)
dbs = {
"db":{
"driver":"sqlite3",
"kwargs":{
"dbname":sys.argv[1]
}
}
}
if __name__ == '__main__':
if len(sys.argv) < 3:
print(f'Usage:{sys.argv[0]} sqlite3_db_file sqlfile')
sys.exit(1)
DBPools(dbs)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())