|
@@ -66,7 +66,8 @@ class SqlWrapper(object):
|
66
|
66
|
self.w_conn = None
|
67
|
67
|
|
68
|
68
|
|
69
|
|
- self.meta = None
|
|
69
|
+ self.meta = None #TODO : use it to load all db schema in 1 request and don't load it each table instanciation
|
|
70
|
+ self.meta_crea = None
|
70
|
71
|
pass
|
71
|
72
|
|
72
|
73
|
@property
|
|
@@ -270,20 +271,32 @@ class SqlWrapper(object):
|
270
|
271
|
self.meta_crea = None
|
271
|
272
|
pass
|
272
|
273
|
|
273
|
|
- def createTable(self, name, columns, extra = dict()):
|
|
274
|
+ def createTable(self, name, columns, **kw):
|
274
|
275
|
""" Create a table
|
275
|
276
|
@param name str: The table name
|
276
|
|
- @param columns list: A list of columns schema
|
|
277
|
+ @param columns list: A list of columns description dict
|
277
|
278
|
@param extra dict: Extra arguments for table creation
|
278
|
279
|
@see SqlWrapper::createColumn()
|
279
|
280
|
"""
|
|
281
|
+
|
|
282
|
+ if self.meta_crea == None:
|
|
283
|
+ self.meta_crea = sqla.MetaData()
|
|
284
|
+ crea_now = True
|
|
285
|
+ else:
|
|
286
|
+ crea_now = False
|
|
287
|
+
|
280
|
288
|
if not isinstance(name, str):
|
281
|
289
|
raise TypeError("<class str> excepted for table name, but got "+type(name))
|
282
|
290
|
|
283
|
|
- res = sqla.Table(name, self.meta_crea, **extra)
|
|
291
|
+ res = sqla.Table(name, self.meta_crea, **kw)
|
284
|
292
|
for i,col in enumerate(columns):
|
285
|
293
|
res.append_column(self.createColumn(**col))
|
286
|
294
|
|
|
295
|
+ if crea_now:
|
|
296
|
+ self.meta_crea.create_all(self.w_engine)
|
|
297
|
+
|
|
298
|
+ pass
|
|
299
|
+
|
287
|
300
|
def createColumn(self, **kwargs):
|
288
|
301
|
""" Create a Column
|
289
|
302
|
|