This method is used to create the user defined macros. :param macro: macro
(macro)
| 135 | |
| 136 | |
| 137 | def 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 | |
| 168 | def update_macro(data, macro): |
no test coverage detected