-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerfORMStorage.php
853 lines (733 loc) · 21.3 KB
/
PerfORMStorage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
<?php
/**
* PerfORM - Object-relational mapping based on David Grudl's dibi
*
* @copyright Copyright (c) 2010 Eduard 'edke' Kracmar
* @license no license set at this point
* @link http://perform.local :-)
* @category PerfORM
* @package PerfORM
*/
/**
* PerfORMStorage
*
* write desc when class ready
*
* @final
* @copyright Copyright (c) 2010 Eduard 'edke' Kracmar
* @package PerfORM
*/
final class PerfORMStorage extends DibiConnection
{
const TABLE_ADD = 1;
const TABLE_DROP = 2;
const FIELD_ADD = 3;
const FIELD_DROP = 4;
const VIEW_ADD = 5;
const VIEW_DROP = 6;
protected $queue= array();
protected $renamedTables= array();
protected $renamedViews= array();
protected $renamedFields= array();
/**
* Constractor creates connection and checks/creates tables stucture
*/
public function __construct()
{
$dibiConfig= dibi::getConnection()->getConfig();
$dbname= isset($dibiConfig['dbname']) ? $dibiConfig['dbname'] : $dibiConfig['database'];
$config= array(
'driver' => 'sqlite',
'profiler' => Environment::getConfig('perform')->storage_profiler,
'database' => realpath(Environment::getConfig('perform')->modelCache) . '/'. $dbname .'-storage.sdb',
);
parent::__construct($config, 'storage');
if ( !$this->getDatabaseInfo()->hasTable('fields'))
{
$this->query('CREATE TABLE [fields] ([id] INTEGER NOT NULL PRIMARY KEY,
[name] VARCHAR(100) NOT NULL, [table] VARCHAR(50) NOT NULL,
[hash] VARCHAR(32) NOT NULL, [type] VARCHAR(50));
CREATE UNIQUE INDEX [fields_idx] on [fields] ( [name], [table]);');
}
if ( !$this->getDatabaseInfo()->hasTable('tables'))
{
$this->query('CREATE TABLE [tables] ( [id] INTEGER NOT NULL PRIMARY KEY,
[name] VARCHAR(100) NOT NULL UNIQUE, [hash] VARCHAR(32) NOT NULL);');
}
if ( !$this->getDatabaseInfo()->hasTable('views'))
{
$this->query('CREATE TABLE [views] ( [id] INTEGER NOT NULL PRIMARY KEY,
[name] VARCHAR(100) NOT NULL UNIQUE, [hash] VARCHAR(32) NOT NULL);');
}
if ( !$this->getDatabaseInfo()->hasTable('indexes'))
{
$this->query('CREATE TABLE [indexes] ([id] INTEGER NOT NULL PRIMARY KEY,
[name] VARCHAR(100) NOT NULL, [table] VARCHAR(50) NOT NULL,
[hash] VARCHAR(32) NOT NULL, [unique] BOOLEAN);
CREATE UNIQUE INDEX [indexes_idx] on [indexes] ( [name], [table]);');
}
}
/**
* Adds column to table
* @param Field $field
*/
public function addFieldToModel($field)
{
$sql= $this->sql('insert into [fields] values( null, %s, %s, %s, %s)',
$field->getName(),
$field->getModel()->getTableName(),
$field->getHash(),
get_class($field));
$this->queue(
PerfORMStorage::FIELD_ADD,
$field->getName().'|'.$field->getModel()->getTableName(),
$sql,
array(
'field' => $field,
)
);
$key= $field->getHash().'|'.$field->getModel()->getTableName();
if ( key_exists($key, $this->renamedFields))
{
$array= $this->renamedFields[$key];
$array->counter++;
$array->to= $field->getName();
}
else
{
$this->renamedFields[$key]= (object) array(
'counter' => 1,
'to' => $field->getName(),
'modelName' => $field->getModel()->getTableName(),
);
}
}
/**
* Adds index to table
* @param Index $index
*/
public function addIndexToModel($index)
{
$this->query('insert into [indexes] values( null, %s, %s, %s, %s)',
$index->getName(),
$index->getModel()->getTableName(),
$index->getHash(),
$index->isUnique());
PerfORMController::getBuilder()->createIndex($index);
}
/**
* Change column's default value
* @param Field $field
*/
public function changeFieldDefaultValue($field)
{
PerfORMController::getBuilder()->changeFieldsDefault($field);
$this->updateFieldSync($field);
}
/**
* Change column from null to not null
* @param Field $field
*/
public function changeFieldToNotNullable($field)
{
$result= PerfORMController::getConnection()->query('select * from %n where %n is null',
$field->getModel()->getTableName(),
$field->getName()
);
$pk= $field->getModel()->getPrimaryKey();
foreach($result as $row )
{
if ( !is_null($value= $field->getDefaultValue()) )
{
}
elseif ( is_callable($field->getDefaultCallback()))
{
$value= call_user_func($field->getDefaultCallback(), $row);
}
else
{
throw new Exception("Unable to set default value for field '".$field->getName()."'");
}
PerfORMController::getConnection()->query('update %n set %n = %'.$field->getType().' where %n = %i',
$field->getModel()->getTableName(),
$field->getName(),
$value,
$pk,
$row->{$pk}
);
}
PerfORMController::getBuilder()->changeFieldsNullable($field);
$this->updateFieldSync($field);
}
/**
* Change column from not null to null
* @param Field $field
*/
public function changeFieldToNullable($field)
{
PerfORMController::getBuilder()->changeFieldsNullable($field);
$this->updateFieldSync($field);
}
/**
* Change column from null to not null
* @param Field $field
*/
public function changeFieldType($field)
{
if ( !$field->getRecastCallback())
{
throw new Exception("Unable to recast value as recast callback was not set for field '".$field->getName()."'");
}
$builder= PerfORMController::getBuilder('fieldretype');
$tmpfield= $field->getName().'_'.md5(time());
$template= $builder->getTemplate('field-add');
$fieldInfo= $builder->getField($field);
$fieldInfo->name= $tmpfield;
$fieldInfo->nullable= true;
$template->field= $fieldInfo;
PerfORMController::getBuilder()->addToBuffer($builder->renderTemplate($template), 'alters');
//PerfORMController::getConnection()->nativeQuery($sql);
$result= PerfORMController::getConnection()->query('select * from %n',
$field->getModel()->getTableName()
);
$pk= $field->getModel()->getPrimaryKey();
foreach($result as $row )
{
if ( is_callable($field->getRecastCallback()))
{
$value= call_user_func($field->getRecastCallback(), $row);
if ( !$field->isNullable() and is_null($value))
{
throw new Exception("Unable to recast null value for field '".$field->getName()."' (id=".$row->{$pk}.") as field is not null");
}
}
else
{
throw new Exception("Unable to recast value for field '".$field->getName()."' (id=".$row->{$pk}.")");
}
$sql= PerfORMController::getConnection()->sql('update %n set %n = %'.$field->getType().' where %n = %i;',
$field->getModel()->getTableName(),
$tmpfield,
$value,
$pk,
$row->{$pk}
);
PerfORMController::getBuilder()->addToBuffer($sql, 'alters');
}
if (!$field->isNullable())
{
$fieldInfo->nullable= false;
$template= $builder->getTemplate('field-change-nullable');
$template->field= $fieldInfo;
$sql= $builder->renderTemplate($template);
PerfORMController::getBuilder()->addToBuffer($sql, 'alters');
//PerfORMController::getConnection()->nativeQuery($sql);
}
PerfORMController::getBuilder()->dropField($field->getName(), $field->getModel());
PerfORMController::getBuilder()->renameField($field, $tmpfield);
$this->updateFieldSync($field);
}
/**
* Drops column from table
* @param string $fieldName
* @param PerfORM $model
* @return string
*/
public function dropFieldFromModel($fieldName, $model)
{
$hash= $this->fetchSingle('select hash from [fields] where [name] = %s and [table] = %s',
$fieldName,
$model->getTableName());
$sql= $this->sql('delete from [fields] where [name] = %s and [table] = %s',
$fieldName,
$model->getTableName());
$this->queue(
PerfORMStorage::FIELD_DROP,
$fieldName.'|'.$model->getTableName(),
$sql,
array(
'fieldName' => $fieldName,
'model' => $model
)
);
$key= $hash.'|'. $model->getTableName();
if ( key_exists($key, $this->renamedFields))
{
$array= $this->renamedFields[$key];
$array->counter++;
$array->from= $fieldName;
}
else
{
$this->renamedFields[$key]= (object) array(
'counter' => 1,
'from' => $fieldName,
'modelName' => $model->getTableName(),
);
}
}
/**
* Drops index from table
* @param string $indexName
* @param PerfORM $model
*/
public function dropIndexFromModel($indexName, $model)
{
$this->query('delete from [indexes] where [name] = %s and [table] = %s',
$indexName,
$model->getTableName());
PerfORMController::getBuilder()->dropIndex($indexName, $model);
$this->updateModelSync($model);
}
/**
* Drops table from database
* @param PerfORM|string $model
* @return void
*/
public function dropTable($model)
{
$modelName= is_object($model) ? $model->getTableName() : $model;
$hash= $this->fetchSingle('select hash from [tables] where [name] = %s ',
$modelName);
$sql= array();
$sql[] = $this->sql('delete from [tables] where [name] = %s;', $modelName );
$sql[] = $this->sql('delete from [fields] where [table] = %s;', $modelName );
$sql[] = $this->sql('delete from [indexes] where [table] = %s;', $modelName );
$this->queue(
PerfORMStorage::TABLE_DROP,
$modelName,
$sql,
array(
'model' => $model)
);
$key= $hash;
if ( key_exists($key, $this->renamedTables))
{
$array= $this->renamedTables[$key];
$array->counter++;
$array->from= $modelName;
}
else
{
$this->renamedTables[$key]= (object) array(
'counter' => 1,
'from' => $modelName,
);
}
}
/**
* Drops view from database
* @param PerfORM|string $model
* @return void
*/
public function dropView($model)
{
$modelName= is_object($model) ? $model->getTableName() : $model;
$hash= $this->fetchSingle('select hash from [views] where [name] = %s ',
$modelName);
$sql= array();
$sql[] = $this->sql('delete from [views] where [name] = %s;', $modelName );
$this->queue(
PerfORMStorage::VIEW_DROP,
$modelName,
$sql,
array(
'model' => $model)
);
$key= $hash;
if ( key_exists($key, $this->renamedViews))
{
$array= $this->renamedViews[$key];
$array->counter++;
$array->from= $modelName;
}
else
{
$this->renamedViews[$key]= (object) array(
'counter' => 1,
'from' => $modelName,
);
}
}
/**
* Checks if column in sync
* @param Field $field
* @return boolean
*/
public function fieldHasSync($field)
{
return $this->fetch('select [id] from [fields] where [name] = %s and [table] = %s and [hash] = %s',
$field->getName(),
$field->getModel()->getTableName(),
$field->getHash()
) === false ? false : true;
}
/**
* Get all fields of model from storage
* @param PerfORM $model
* @return DibiResult
*/
public function getModelFields($model)
{
return $this->query('select [name] from [fields] where [table] = %s', $model->getTableName() );
}
/**
* Get all indexes of model from storage
* @param PerfORM $model
* @return DibiResult
*/
public function getModelIndexes($model)
{
return $this->query('select [name] from [indexes] where [table] = %s', $model->getTableName() );
}
/**
* Get all models from storage
* @return DibiResult
*/
public function getTables()
{
return $this->query('select [name] from [tables]');
}
/**
* Get all views from storage
* @return DibiResult
*/
public function getViews()
{
return $this->query('select [name] from [views]');
}
/**
* Checks if model exists
* @param PerfORM $model
* @return boolean
*/
public function hasModel($model)
{
return $this->fetch('
select [id] from (select [id], [name] from [tables] union select [id], [name] from [views]) where [name] = %s',
$model->getTableName()) === false ? false : true;
}
/**
* Inserts tables' name and hash into storage
* @param PerfORM $model
*/
public function insertTable($model)
{
$modelName= is_object($model) ? $model->getTableName() : $model;
$sql=array();
$sql[] = $this->sql('insert into [tables] values (null, %s, %s);', $model->getTableName(), $model->getHash() );
foreach($model->getFields() as $field )
{
$sql[] = $this->sql('insert into [fields] values (null, %s, %s, %s, %s);',
strtolower($field->getName()),
$model->getTableName(),
$field->getHash(),
get_class($field));
}
$this->queue(
PerfORMStorage::TABLE_ADD,
$modelName,
$sql,
array(
'model' => $model)
);
$key= $model->getHash();
if ( key_exists($key, $this->renamedTables))
{
$array= $this->renamedTables[$key];
$array->counter++;
$array->to= $modelName;
}
else
{
$this->renamedTables[$key]= (object) array(
'counter' => 1,
'to' => $modelName,
);
}
}
/**
* Inserts view's name and hash into storage
* @param PerfORM $model
*/
public function insertView($model)
{
$modelName= is_object($model) ? $model->getTableName() : $model;
$sql=array();
$sql[] = $this->sql('insert into [views] values (null, %s, %s);', $model->getTableName(), $model->getHash() );
$this->queue(
PerfORMStorage::VIEW_ADD,
$modelName,
$sql,
array(
'model' => $model)
);
$key= $model->getHash();
if ( key_exists($key, $this->renamedViews))
{
$array= $this->renamedViews[$key];
$array->counter++;
$array->to= $modelName;
}
else
{
$this->renamedViews[$key]= (object) array(
'counter' => 1,
'to' => $modelName,
);
}
}
/**
* Checks if field belongs to it's model
* @param Field $field
* @return boolean
*/
public function fieldBelongsToItsModel($field)
{
return $this->fetch('select [id] from [fields] where [table] = %s and [name] = %s',
$field->getModel()->getTableName(),
$field->getName()
) === false ? false : true;
}
/**
* Checks if model in sync
* @param PerfORM $model
* @return boolean
*/
public function modelHasSync($model)
{
return $this->fetch('select [id] from [tables] where [name] = %s and [hash] = %s',
$model->getTableName(),
$model->getHash()
) === false ? false : true;
}
/**
* Checks if model in sync
* @param PerfORM $model
* @return boolean
*/
public function modelHasIndex($index)
{
return $this->fetch('select [id] from [indexes] where [name] = %s and [table] = %s and [hash] = %s',
$index->getName(),
$index->getModel()->getTableName(),
$index->getHash()
) === false ? false : true;
}
/**
* Storage processing
* @return string
*/
public function process()
{
# renamed fields, remove adds and drops
foreach( $this->renamedFields as $key => $array)
{
if ( $array->counter == 2 and isset($array->from) and isset($array->to) and isset($array->modelName))
{
$field= $this->queue[PerfORMStorage::FIELD_ADD][$array->to.'|'.$array->modelName]->values['field'];
unset($this->queue[PerfORMStorage::FIELD_ADD][$array->to.'|'.$array->modelName]);
unset($this->queue[PerfORMStorage::FIELD_DROP][$array->from.'|'.$array->modelName]);
$this->query('update [fields] set [name] = %s where [name] = %s and [table] = %s',
$array->to,
$array->from,
$array->modelName);
$this->query('update [tables] set [hash] = %s where [name] = %s',
$field->getModel()->getHash(),
$array->modelName);
PerfORMController::getBuilder()->renameField($field, $array->from);
}
}
# renamed tables, remove adds and drops
foreach( $this->renamedTables as $key => $array)
{
if ( $array->counter == 2 and isset($array->from) and isset($array->to))
{
$model= $this->queue[PerfORMStorage::TABLE_ADD][$array->to]->values['model'];
unset($this->queue[PerfORMStorage::TABLE_ADD][$array->to]);
unset($this->queue[PerfORMStorage::TABLE_DROP][$array->from]);
$this->query('update [tables] set [name] = %s where [name] = %s',
$array->to,
$array->from);
$this->query('update [fields] set [table] = %s where [table] = %s',
$array->to,
$array->from);
PerfORMController::getBuilder()->renameTable($model, $array->from);
$this->query('delete from [indexes] where [table] = %s', $array->from);
foreach($model->getIndexes() as $index)
{
$this->query('insert into [indexes] values( null, %s, %s, %s, %s)',
$index->getName(),
$index->getModel()->getTableName(),
$index->getHash(),
$index->isUnique());
PerfORMController::getBuilder()->renameIndex($index, $array->from);
}
}
}
# renamed views, remove adds and drops
foreach( $this->renamedViews as $key => $array)
{
if ( $array->counter == 2 and isset($array->from) and isset($array->to))
{
$model= $this->queue[PerfORMStorage::VIEW_ADD][$array->to]->values['model'];
unset($this->queue[PerfORMStorage::VIEW_ADD][$array->to]);
unset($this->queue[PerfORMStorage::VIEW_DROP][$array->from]);
$this->query('update [views] set [name] = %s where [name] = %s',
$array->to,
$array->from);
$this->query('update [views] set [table] = %s where [table] = %s',
$array->to,
$array->from);
PerfORMController::getBuilder()->renameView($model, $array->from);
}
}
foreach( $this->queue as $operation => $actions)
{
foreach($actions as $key => $action)
{
//list($field, $table)= explode('|', $key);
switch($operation)
{
case PerfORMStorage::FIELD_ADD:
$field= $action->values['field'];
$builder= PerfORMController::getBuilder('fieldadd');
$template= $builder->getTemplate('field-add');
$fieldInfo= $builder->getField($field);
$fieldInfo->nullable= true;
$template->field= $fieldInfo;
PerfORMController::getBuilder()->addToBuffer( $builder->renderTemplate($template), 'alters' );
//PerfORMController::getConnection()->nativeQuery($sql);
$result= PerfORMController::getConnection()->query('select * from %n',
$field->getModel()->getTableName()
);
$pk= $field->getModel()->getPrimaryKey();
foreach($result as $row )
{
if ( !is_null($default= $field->getDefault($row)))
{
PerfORMController::getBuilder()->addToBuffer(
PerfORMController::getConnection()->sql('update %n set %n = %'.$field->getType().' where %n = %i;',
$field->getModel()->getTableName(),
$field->getName(),
$default,
$pk,
$row->{$pk}
), 'alters');
}
elseif ( !$field->isNullable())
{
throw new Exception("Unable to find default value for field '".$field->getName()."' (id=".$row->{$pk}.")");
}
}
if (!$field->isNullable())
{
$fieldInfo->nullable= false;
$template= $builder->getTemplate('field-change-nullable');
$template->field= $fieldInfo;
PerfORMController::getBuilder()->addToBuffer( $builder->renderTemplate($template), 'alters' );
//PerfORMController::getConnection()->nativeQuery($sql);
}
//PerfORMController::getBuilder()->addField();
$this->updateModelSync($action->values['field']->getModel());
break;
case PerfORMStorage::FIELD_DROP:
PerfORMController::getBuilder()->dropField($action->values['fieldName'], $action->values['model']);
$this->updateModelSync($action->values['model']);
break;
case PerfORMStorage::TABLE_ADD:
PerfORMController::getBuilder()->createTable($action->values['model']);
foreach($action->values['model']->getIndexes() as $index)
{
$this->addIndexToModel($index);
}
break;
case PerfORMStorage::TABLE_DROP:
PerfORMController::getBuilder()->dropTable($action->values['model']);
break;
case PerfORMStorage::VIEW_ADD:
PerfORMController::getBuilder()->createView($action->values['model']);
break;
case PerfORMStorage::VIEW_DROP:
PerfORMController::getBuilder()->dropView($action->values['model']);
break;
}
if ( is_array($action->sql))
{
array_walk($action->sql, array($this, 'query'));
}
else
{
$this->query($action->sql);
}
}
}
return PerfORMController::getBuilder()->getSql();
}
/**
* Adds item to queue
* @param integer $operation
* @param string $sql
* @param array $values
*/
protected function queue($operation, $key, $sql, $values)
{
$this->queue[$operation][$key]= (object) array(
'sql' => $sql,
'values' => $values,
);
}
/**
* Cleans storage info
*/
public function trash()
{
$this->query('delete from [tables]');
$this->query('delete from [fields]');
$this->query('delete from [indexes]');
}
/**
* Run sqls from queue
*/
public function set()
{
foreach( $this->queue as $operation => $actions)
{
foreach($actions as $key => $action)
{
if ( is_array($action->sql))
{
array_walk($action->sql, array($this, 'query'));
}
else
{
$this->query($action->sql);
}
}
}
}
/**
* Update field in storage, sets hashes for field and it's model
* @param Field $field
*/
public function updateFieldSync($field)
{
$this->query('update [fields] set [hash] = %s where [name] = %s and [table] = %s',
$field->getHash(),
$field->getName(),
$field->getModel()->GetTableName()
);
$this->updateModelSync($field->getModel());
}
/**
* Update model in storage, sets hashes for it's model
* @param PerfORM $model
*/
public function updateModelSync($model)
{
$this->query('update [tables] set [hash] = %s where [name] = %s',
$model->getHash(),
$model->getTableName()
);
}
}