MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / create_macro

Function create_macro

web/pgadmin/tools/sqleditor/utils/macros.py:137–165  ·  view source on GitHub ↗

This method is used to create the user defined macros. :param macro: macro

(macro)

Source from the content-addressed store, hash-verified

135
136
137def create_macro(macro):
138 """
139 This method is used to create the user defined macros.
140 :param macro: macro
141 """
142
143 required_args = [
144 'name',
145 'sql'
146 ]
147 for arg in required_args:
148 if arg not in macro:
149 return False, gettext(
150 "Could not find the required parameter ({}).").format(arg)
151
152 try:
153 new_macro = UserMacros(
154 uid=current_user.id,
155 mid=macro['mid'] if macro.get('mid') else None,
156 name=macro['name'],
157 sql=macro['sql']
158 )
159 db.session.add(new_macro)
160 db.session.commit()
161 except Exception as e:
162 db.session.rollback()
163 return False, str(e)
164
165 return True, None
166
167
168def update_macro(data, macro):

Callers 1

set_macrosFunction · 0.85

Calls 4

UserMacrosClass · 0.90
gettextFunction · 0.85
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected