pyLodStorage 0.0.78__tar.gz → 0.0.80__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {pylodstorage-0.0.78/pylodstorage.egg-info → pylodstorage-0.0.80}/PKG-INFO +1 -1
  2. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/entity.py +34 -10
  3. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/jsonable.py +15 -4
  4. {pylodstorage-0.0.78 → pylodstorage-0.0.80/pylodstorage.egg-info}/PKG-INFO +1 -1
  5. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/setup.py +1 -1
  6. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/LICENSE +0 -0
  7. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/README.md +0 -0
  8. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/__init__.py +0 -0
  9. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/csv.py +0 -0
  10. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/jsonpicklemixin.py +0 -0
  11. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/lod.py +0 -0
  12. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/mwTable.py +0 -0
  13. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/plot.py +0 -0
  14. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/query.py +0 -0
  15. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/sample.py +0 -0
  16. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/schema.py +0 -0
  17. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/sparql.py +0 -0
  18. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/sql.py +0 -0
  19. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/storageconfig.py +0 -0
  20. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/tabulateCounter.py +0 -0
  21. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/uml.py +0 -0
  22. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/yamlablemixin.py +0 -0
  23. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/pylodstorage.egg-info/SOURCES.txt +0 -0
  24. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/pylodstorage.egg-info/dependency_links.txt +0 -0
  25. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/pylodstorage.egg-info/requires.txt +0 -0
  26. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/pylodstorage.egg-info/top_level.txt +0 -0
  27. {pylodstorage-0.0.78 → pylodstorage-0.0.80}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.0.78
3
+ Version: 0.0.80
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -5,6 +5,7 @@ Created on 2020-08-19
5
5
  '''
6
6
  from lodstorage.yamlablemixin import YamlAbleMixin
7
7
  from lodstorage.jsonpicklemixin import JsonPickleMixin
8
+ from lodstorage.jsonable import JSONAble
8
9
  from lodstorage.storageconfig import StorageConfig, StoreMode
9
10
  from lodstorage.sparql import SPARQL
10
11
  from lodstorage.sql import SQLDB
@@ -102,7 +103,7 @@ class EntityManager(YamlAbleMixin, JsonPickleMixin,JSONAbleList):
102
103
  cacheFile=self.getCacheFile(mode=mode)
103
104
  if os.path.isfile(cacheFile):
104
105
  os.remove(cacheFile)
105
-
106
+
106
107
  def getSQLDB(self,cacheFile):
107
108
  '''
108
109
  get the SQL database for the given cacheFile
@@ -114,6 +115,23 @@ class EntityManager(YamlAbleMixin, JsonPickleMixin,JSONAbleList):
114
115
  sqldb=self.sqldb=SQLDB(cacheFile,debug=config.debug,errorDebug=config.errorDebug)
115
116
  return sqldb
116
117
 
118
+ def initSQLDB(self,sqldb,listOfDicts=None,withCreate:bool=True,withDrop:bool=True,sampleRecordCount=-1):
119
+ '''
120
+ initialize my sql DB
121
+
122
+ Args:
123
+ listOfDicts(list): the list of dicts to analyze for type information
124
+ withDrop(boolean): true if the existing Table should be dropped
125
+ withCreate(boolean): true if the create Table command should be executed - false if only the entityInfo should be returned
126
+ sampleRecordCount(int): the number of records to analyze for type information
127
+ Return:
128
+ EntityInfo: the entity information such as CREATE Table command
129
+ '''
130
+ if listOfDicts is None:
131
+ listOfDicts=JSONAble.getJsonTypeSamplesForClass(self.clazz)
132
+ entityInfo=sqldb.createTable(listOfDicts, self.tableName, primaryKey=self.primaryKey,withCreate=withCreate,withDrop=withDrop,sampleRecordCount=sampleRecordCount)
133
+ return entityInfo
134
+
117
135
  def setNone(self,record,fields):
118
136
  '''
119
137
  make sure the given fields in the given record are set to none
@@ -167,14 +185,14 @@ GROUP by ?source
167
185
  raise Exception("unsupported mode %s" % self.mode)
168
186
  return result
169
187
 
170
- def fromCache(self,force:bool=False,getListOfDicts=None,withDrop=True,sampleRecordCount=-1):
188
+ def fromCache(self,force:bool=False,getListOfDicts=None,append=False,sampleRecordCount=-1):
171
189
  '''
172
190
  get my entries from the cache or from the callback provided
173
191
 
174
192
  Args:
175
193
  force(bool): force ignoring the cache
176
194
  getListOfDicts(callable): a function to call for getting the data
177
- withDrop(bool): True if the table should be (re) created
195
+ append(bool): True if records should be appended
178
196
  sampleRecordCount(int): the number of records to analyze for type information
179
197
 
180
198
  Returns:
@@ -191,7 +209,7 @@ GROUP by ?source
191
209
  listOfDicts=getListOfDicts()
192
210
  duration=time.time()-startTime
193
211
  self.showProgress(f"got {len(listOfDicts)} {self.entityPluralName} in {duration:5.1f} s")
194
- self.cacheFile=self.storeLoD(listOfDicts,withDrop=withDrop,sampleRecordCount=sampleRecordCount)
212
+ self.cacheFile=self.storeLoD(listOfDicts,append=append,sampleRecordCount=sampleRecordCount)
195
213
  self.setListFromLoD(listOfDicts)
196
214
  else:
197
215
  # fromStore also sets self.cacheFile
@@ -270,14 +288,14 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
270
288
  lod.append(entity.__dict__)
271
289
  return lod
272
290
 
273
- def store(self,limit=10000000,batchSize=250,withDrop=True,fixNone=True,sampleRecordCount=-1)->str:
291
+ def store(self,limit=10000000,batchSize=250,append=False,fixNone=True,sampleRecordCount=-1)->str:
274
292
  '''
275
293
  store my list of dicts
276
294
 
277
295
  Args:
278
296
  limit(int): maximum number of records to store per batch
279
297
  batchSize(int): size of batch for storing
280
- withDrop(bool): True if the table should be (re) created
298
+ append(bool): True if records should be appended
281
299
  fixNone(bool): if True make sure the dicts are filled with None references for each record
282
300
  sampleRecordCount(int): the number of records to analyze for type information
283
301
 
@@ -285,9 +303,9 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
285
303
  str: The cachefile being used
286
304
  '''
287
305
  lod=self.getLoD()
288
- return self.storeLoD(lod,limit=limit,batchSize=batchSize,withDrop=withDrop,fixNone=fixNone,sampleRecordCount=sampleRecordCount)
306
+ return self.storeLoD(lod,limit=limit,batchSize=batchSize,append=append,fixNone=fixNone,sampleRecordCount=sampleRecordCount)
289
307
 
290
- def storeLoD(self,listOfDicts,limit=10000000,batchSize=250,cacheFile=None,withDrop=True,fixNone=True,sampleRecordCount=1)->str:
308
+ def storeLoD(self,listOfDicts,limit=10000000,batchSize=250,cacheFile=None,append=False,fixNone=True,sampleRecordCount=1)->str:
291
309
  '''
292
310
  store my entities
293
311
 
@@ -296,7 +314,7 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
296
314
  limit(int): maximum number of records to store
297
315
  batchSize(int): size of batch for storing
298
316
  cacheFile(string): the name of the storage e.g path to JSON or sqlite3 file
299
- withDrop(bool): True if the table should be (re) created
317
+ append(bool): True if records should be appended
300
318
  fixNone(bool): if True make sure the dicts are filled with None references for each record
301
319
  sampleRecordCount(int): the number of records to analyze for type information
302
320
 
@@ -331,7 +349,13 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
331
349
  cacheFile=self.getCacheFile(config=self.config,mode=self.config.mode)
332
350
  sqldb=self.getSQLDB(cacheFile)
333
351
  self.showProgress ("storing %d %s for %s to %s:%s" % (len(listOfDicts),self.entityPluralName,self.name,config.mode,cacheFile))
334
- entityInfo=sqldb.createTable(listOfDicts, self.tableName, primaryKey=self.primaryKey,withDrop=withDrop,sampleRecordCount=sampleRecordCount)
352
+ if append:
353
+ withDrop=False
354
+ withCreate=False
355
+ else:
356
+ withDrop=True
357
+ withCreate=True
358
+ entityInfo=self.initSQLDB(sqldb,listOfDicts,withCreate=withCreate,withDrop=withDrop,sampleRecordCount=sampleRecordCount)
335
359
  self.sqldb.store(listOfDicts, entityInfo,executeMany=self.executeMany,fixNone=fixNone)
336
360
  self.showProgress ("store for %s done after %5.1f secs" % (self.name,time.time()-startTime))
337
361
  else:
@@ -122,10 +122,21 @@ class JSONAble(object):
122
122
  cls=self.__class__
123
123
  if isinstance(self, JSONAbleList) and not hasattr(cls, 'getSamples'):
124
124
  cls=self.clazz
125
- if hasattr(cls, 'getSamples'):
126
- getSamples=getattr(cls,'getSamples');
127
- if callable(getSamples):
128
- return getSamples()
125
+ return JSONAble.getJsonTypeSamplesForClass(cls)
126
+ return None
127
+
128
+ @staticmethod
129
+ def getJsonTypeSamplesForClass(cls):
130
+ '''
131
+ return the type samples for the given class
132
+
133
+ Return:
134
+ list: a list of dict that specify the types by example
135
+ '''
136
+ if hasattr(cls, 'getSamples'):
137
+ getSamples=getattr(cls,'getSamples');
138
+ if callable(getSamples):
139
+ return getSamples()
129
140
  return None
130
141
 
131
142
  @staticmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.0.78
3
+ Version: 0.0.80
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -11,7 +11,7 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
11
11
 
12
12
  setup(
13
13
  name='pylodstorage',
14
- version='0.0.78',
14
+ version='0.0.80',
15
15
 
16
16
  packages=['lodstorage',],
17
17
  author='Wolfgang Fahl',
File without changes
File without changes
File without changes