Project

General

Profile

« Previous | Next » 

Revision 3442

sql_gen.py: Added FunctionDef

View differences:

lib/sql_gen.py
384 384

  
385 385
class InternalFunction(CustomCode): pass
386 386

  
387
#### Calls
388

  
387 389
class NamedArg(NamedCol):
388 390
    def __init__(self, name, value):
389 391
        NamedCol.__init__(self, name, value)
......
426 428
        assert name == None or name == check_name
427 429
    return func_call.args[0]
428 430

  
431
#### Definitions
432

  
433
class FunctionDef(Code):
434
    def __init__(self, function, return_type, body, lang='sql'):
435
        self.function = function
436
        self.return_type = return_type
437
        self.body = body
438
        self.lang = lang
439
    
440
    def to_str(self, db):
441
        str_ = '''\
442
CREATE FUNCTION '''+self.function.to_str(db)+'''()
443
RETURNS SETOF '''+self.return_type+'''
444
LANGUAGE '''+self.lang+'''
445
AS $$
446
'''+self.body+'''
447
$$;
448
'''
449
        return str_
450

  
429 451
##### Casts
430 452

  
431 453
class Cast(FunctionCall):

Also available in: Unified diff