schema_sentinel.metadata_manager.model.procedure API documentation

# schema_sentinel.metadata_manager.model.procedure

View Source

     1import json
     2
     3import sqlalchemy as db
     4from sqlalchemy import ForeignKey, select
     5
     6from . import CommonBase
     7
     8
     9class Procedure(CommonBase):
    10    __tablename__ = "procedures"
    11    procedure_id = db.Column(db.String, primary_key=True)
    12    argument_signature = db.Column(db.String)
    13    schema_id = db.Column(db.String, ForeignKey("schemas.schema_id"))
    14    procedure_name = db.Column(db.String)
    15    procedure_owner = db.Column(db.String)
    16    data_type = db.Column(db.String)
    17    character_maximum_length = db.Column(db.Integer)
    18    character_octet_length = db.Column(db.Integer)
    19    numeric_precision = db.Column(db.Integer)
    20    numeric_precision_radix = db.Column(db.Integer)
    21    numeric_scale = db.Column(db.Integer)
    22    datetime_presision = db.Column(db.Integer)
    23    procedure_language = db.Column(db.String)
    24    procedure_definition = db.Column(db.String)
    25    comment = db.Column(db.String)
    26    created = db.Column(db.String)
    27    last_altered = db.Column(db.String)
    28
    29    def save(self, session) -> None:
    30        if not session.execute(self.exists()).first():
    31            session.add(self)
    32            session.commit()
    33
    34    def exists(self) -> str:
    35        return select(Procedure).filter_by(procedure_id=self.procedure_id)
    36
    37    def __get_id__(self) -> str:
    38        id = json.loads(self.schema_id)
    39        id["procedure_name"] = self.procedure_name
    40        id["argument_signature"] = self.argument_signature
    41        return json.dumps(id)
    42
    43    def __data_type__(self) -> str:
    44        if self.data_type in ["VARCHAR", "TEXT"]:
    45            data_type = f"{self.data_type}({self.character_maximum_length})"
    46        elif self.data_type == "NUMBER":
    47            data_type = f"{self.data_type}({self.numeric_precision}, {self.numeric_scale})"
    48        elif self.data_type in ["TIMESTAMP_NTZ", "TIMESTAMP_LTZ", "TIMESTAMP_TZ"]:
    49            data_type = f"{self.data_type}({self.datetime_presision})"
    50        else:
    51            data_type = self.data_type
    52        return data_type

class Procedure(schema_sentinel.metadata_manager.model.CommonBase): View Source

    10class Procedure(CommonBase):
    11    __tablename__ = "procedures"
    12    procedure_id = db.Column(db.String, primary_key=True)
    13    argument_signature = db.Column(db.String)
    14    schema_id = db.Column(db.String, ForeignKey("schemas.schema_id"))
    15    procedure_name = db.Column(db.String)
    16    procedure_owner = db.Column(db.String)
    17    data_type = db.Column(db.String)
    18    character_maximum_length = db.Column(db.Integer)
    19    character_octet_length = db.Column(db.Integer)
    20    numeric_precision = db.Column(db.Integer)
    21    numeric_precision_radix = db.Column(db.Integer)
    22    numeric_scale = db.Column(db.Integer)
    23    datetime_presision = db.Column(db.Integer)
    24    procedure_language = db.Column(db.String)
    25    procedure_definition = db.Column(db.String)
    26    comment = db.Column(db.String)
    27    created = db.Column(db.String)
    28    last_altered = db.Column(db.String)
    29
    30    def save(self, session) -> None:
    31        if not session.execute(self.exists()).first():
    32            session.add(self)
    33            session.commit()
    34
    35    def exists(self) -> str:
    36        return select(Procedure).filter_by(procedure_id=self.procedure_id)
    37
    38    def __get_id__(self) -> str:
    39        id = json.loads(self.schema_id)
    40        id["procedure_name"] = self.procedure_name
    41        id["argument_signature"] = self.argument_signature
    42        return json.dumps(id)
    43
    44    def __data_type__(self) -> str:
    45        if self.data_type in ["VARCHAR", "TEXT"]:
    46            data_type = f"{self.data_type}({self.character_maximum_length})"
    47        elif self.data_type == "NUMBER":
    48            data_type = f"{self.data_type}({self.numeric_precision}, {self.numeric_scale})"
    49        elif self.data_type in ["TIMESTAMP_NTZ", "TIMESTAMP_LTZ", "TIMESTAMP_TZ"]:
    50            data_type = f"{self.data_type}({self.datetime_presision})"
    51        else:
    52            data_type = self.data_type
    53        return data_type

The base class of the class hierarchy.

When called, it accepts no arguments and returns a new featureless instance that has no instance attributes and cannot be given any.

Procedure(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in `kwargs`.

Only keys that are present as attributes of the instance's class are allowed. These could be, for example, any mapped columns or relationships.

procedure_id
argument_signature
schema_id
procedure_name
procedure_owner
data_type
character_maximum_length
character_octet_length
numeric_precision
numeric_precision_radix
numeric_scale
datetime_presision
procedure_language
procedure_definition
comment
created
last_altered
def save(self, session) -> None: View Source

    30    def save(self, session) -> None:
    31        if not session.execute(self.exists()).first():
    32            session.add(self)
    33            session.commit()

def exists(self) -> str: View Source

    35    def exists(self) -> str:
    36        return select(Procedure).filter_by(procedure_id=self.procedure_id)