@@ -19,9 +19,13 @@ def __init__(self, array, space):
19
19
self .parts .append ((array [5 + 1 + i * 2 ], array [5 + 2 + i * 2 ]))
20
20
self .space = space
21
21
self .space .indexes [self .iid ] = self
22
+ if self .name :
23
+ self .space .indexes [self .name ] = self
22
24
23
25
def flush (self ):
24
26
del self .space .indexes [self .iid ]
27
+ if self .name :
28
+ del self .space .indexes [self .name ]
25
29
26
30
class SchemaSpace (object ):
27
31
def __init__ (self , array , schema ):
@@ -31,44 +35,24 @@ def __init__(self, array, schema):
31
35
self .indexes = {}
32
36
self .schema = schema
33
37
self .schema [self .sid ] = self
38
+ if self .name :
39
+ self .schema [self .name ] = self
34
40
35
41
def flush (self ):
36
42
del self .schema [self .sid ]
43
+ if self .name :
44
+ del self .schema [self .name ]
37
45
38
46
class Schema (object ):
39
47
def __init__ (self , con ):
40
48
self .schema = {}
41
49
self .con = con
42
50
43
- def find_local_space (self , space ):
44
- if isinstance (space , basestring ):
45
- for _ , val in self .schema .iteritems ():
46
- if val .name == space :
47
- return val
48
- return None
51
+ def get_space (self , space ):
49
52
try :
50
53
return self .schema [space ]
51
54
except KeyError :
52
- return None
53
-
54
- def find_local_index (self , space , index ):
55
- space = self .find_local_space (space )
56
- if space is None :
57
- return None
58
- if isinstance (index , basestring ):
59
- for _ , val in space .indexes .iteritems ():
60
- if val .name == index :
61
- return val
62
- return None
63
- try :
64
- return space .indexes [index ]
65
- except KeyError :
66
- return None
67
-
68
- def get_space (self , space ):
69
- _space = self .find_local_space (space )
70
- if _space is not None :
71
- return _space
55
+ pass
72
56
_index = (const .INDEX_SPACE_NAME if isinstance (space , basestring ) else const .INDEX_SPACE_PRIMARY )
73
57
74
58
array = self .con .select (const .SPACE_SPACE , space , index = _index )
@@ -82,21 +66,22 @@ def get_space(self, space):
82
66
return SchemaSpace (array , self .schema )
83
67
84
68
def get_index (self , space , index ):
85
- _index = self .find_local_index (space , index )
86
- if _index is not None :
87
- return _index
88
- space = self .get_space (space )
69
+ _space = self .get_space (space )
70
+ try :
71
+ return _space .indexes [index ]
72
+ except KeyError :
73
+ pass
89
74
_index = (const .INDEX_INDEX_NAME if isinstance (index , basestring ) else const .INDEX_INDEX_PRIMARY )
90
75
91
- array = self .con .select (const .SPACE_INDEX , [space .sid , index ], index = _index )
76
+ array = self .con .select (const .SPACE_INDEX , [_space .sid , index ], index = _index )
92
77
if len (array ) > 1 :
93
78
raise SchemaError ('Some strange output from server: \n ' + array )
94
79
elif len (array ) == 0 or not len (array [0 ]):
95
80
temp_name = ('name' if isinstance (index , basestring ) else 'id' )
96
81
raise SchemaError ('There\' s no index with {2} \' {0}\' '
97
- 'in space \' {1}\' ' .format (index , space .name , temp_name ))
82
+ 'in space \' {1}\' ' .format (index , _space .name , temp_name ))
98
83
array = array [0 ]
99
- return SchemaIndex (array , space )
84
+ return SchemaIndex (array , _space )
100
85
101
86
def flush (self ):
102
87
self .schema .clear ()
0 commit comments