2#this websocket-client module supports both python 2.7 and 3.x- the "websockets" module supports python 3.4+ but relies on asyncio. It might be possible to mix the modules in this driver or it make more sense to create a separate python 3.4+ database driver.
8paramstyle = None #not applicable
10class Error(exceptions.StandardError):
13class Warning(exceptions.StandardError):
16class InterfaceError(Error):
19class DatabaseError(Error):
22class InternalError(DatabaseError):
25class OperationalError(DatabaseError):
28class ProgrammingError(DatabaseError):
31class IntegrityError(DatabaseError):
34class DataError(DatabaseError):
37class NotSupportedError(DatabaseError):
40class ProjectM36Connection(object):
41 def __init__(self, proto, host, port, path, dbname):
42 assert proto in ('ws', 'wss'), "proto must be one of 'ws' or 'wss'"
53 port = ':{}'.format(self.port)
57 path = '/{}'.format(self.path)
60 self.conn = ws.create_connection('{}://{}{}{}'.format(self.proto,
64 self.conn.send('connectdb:{}'.format(self.dbname))
65 result = self.conn.recv()
68 result = self.conn.recv()
74 if self.conn is None: #already closed
75 raise ProgrammingError('attempt to close connection which was not open')
80 self.executeTutorialD(':commit')
83 self.executeTutorialD(':rollback')
90 return self.conn.send(t)
93 return self.conn.recv()
95class ProjectM36JSONEncoder(json.JSONEncoder):
96 def default(self, obj):
97 if isinstance(obj, RelationalExpr):
100 super(ProjectM36JSONEncoder, self).default(obj)
102class ProjectM36JSONDecoder(json.JSONDecoder):
105 super(ProjectM36JSONDecoder, self).decode(s)
108 def __init__(self, conn):
113 def description(self):
120 #def callproc(self): #not applicable
125 def executeTutorialD(self, tutoriald):
128 def execute(self, relationalExpression):
129 relExprJson = json.dumps(relationalExpression, cls=ProjectM36JSONEncoder)
130 self._conn._send('evalrelexpr:{}'.format(relExprJson))
131 result = self._conn._recv()
132 rel = json.loads(result, cls=ProjectM36JSONDecoder)
135 def executemany(self, op, params):
136 raise NotImplementedError()
147 #def nextset(self): #not applicable
151 return self._arraysize
154 def set_arraysize(self, size):
155 self._arraysize = size
157 def setinputsizes(self, sizes):
160 def setoutputsize(self, size, column):
163def connect(proto, host, port, path, dbname):
164 conn = ProjectM36Connection(proto, host, port, path, dbname)
168class RelationalExpr(object):
170 return {'tag':self.__class__.__name__,
171 'contents':self.json_contents()}
173class RelationVariable(RelationalExpr):
174 def __init__(self, rvname):
177 def json_contents(self):
178 return [self.name, []]
180class Equals(RelationalExpr):
181 def __init__(self, exprA, exprB):
185(Maybe [AttributeExprBase a]) [TupleExprBase a] |
186 --- | Create and reference a relation from attributes and a tuple set.
187 MakeStaticRelation Attributes RelationTupleSet |
188 --- | Reference an existing relation in Haskell-space.
189 ExistingRelation Relation |
190 --MakeFunctionalRelation (creates a relation from a tuple-generating function, potentially infinite)
191 --in Tutorial D, relational variables pick up the type of the first relation assigned to them
192 --relational variables should also be able to be explicitly-typed like in Haskell
193 --- | Reference a relation variable by its name.
194 RelationVariable RelVarName a |
195 --- | Create a projection over attribute names. (Note that the 'AttributeNames' structure allows for the names to be inverted.)
196 Project AttributeNames (RelationalExprBase a) |
197 --- | Create a union of two relational expressions. The expressions should have identical attributes.
198 Union (RelationalExprBase a) (RelationalExprBase a) |
199 --- | Create a join of two relational expressions. The join occurs on attributes which are identical. If the expressions have no overlapping attributes, the join becomes a cross-product of both tuple sets.
200 Join (RelationalExprBase a) (RelationalExprBase a) |
201 --- | Rename an attribute (first argument) to another (second argument).
202 Rename AttributeName AttributeName (RelationalExprBase a) |
203 --- | Return a relation containing all tuples of the first argument which do not appear in the second argument (minus).
204 Difference (RelationalExprBase a) (RelationalExprBase a) |
205 --- | Create a sub-relation composed of the first argument's attributes which will become an attribute of the result expression. The unreferenced attributes are not altered in the result but duplicate tuples in the projection of the expression minus the attribute names are compressed into one. For more information, <https://github.com/agentm/project-m36/blob/master/docs/introduction_to_the_relational_algebra.markdown#group read the relational algebra tutorial.>
206 Group AttributeNames AttributeName (RelationalExprBase a) |
207 --- | Create an expression to unwrap a sub-relation contained within at an attribute's name. Note that this is not always an inverse of a group operation.
208 Ungroup AttributeName (RelationalExprBase a) |
209 --- | Filter the tuples of the relational expression to only retain the tuples which evaluate against the restriction predicate to true.
210 Restrict (RestrictionPredicateExprBase a) (RelationalExprBase a) |
211 --- | Returns the true relation iff
212 Equals (RelationalExprBase a) (RelationalExprBase a) |
213 NotEquals (RelationalExprBase a) (RelationalExprBase a) |
214 Extend (ExtendTupleExprBase a) (RelationalExprBase a)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list