|
| 1 | +from dl_formula_ref.categories.native import CATEGORY_NATIVE |
| 2 | +from dl_formula_ref.i18n.registry import FormulaRefTranslatable as Translatable |
| 3 | +from dl_formula_ref.localization import get_gettext |
| 4 | +from dl_formula_ref.registry.base import FunctionDocRegistryItem |
| 5 | +from dl_formula_ref.registry.example import SimpleExample |
| 6 | +from dl_formula_ref.registry.note import Note |
| 7 | + |
| 8 | + |
| 9 | +_ = get_gettext() |
| 10 | + |
| 11 | + |
| 12 | +FUNCTION_DB_CALL_INT = FunctionDocRegistryItem( |
| 13 | + name="db_call_int", |
| 14 | + category=CATEGORY_NATIVE, |
| 15 | + description=_( |
| 16 | + "Calls a native database function by name and returns an integer result.\n" |
| 17 | + "\n" |
| 18 | + "The first argument {arg:0} must be a constant string with the name of the " |
| 19 | + "database function to call. All subsequent arguments are passed to the " |
| 20 | + "native function and can be of any type.\n" |
| 21 | + "\n" |
| 22 | + "The function name must contain only alphanumeric characters and underscores." |
| 23 | + ), |
| 24 | + notes=[ |
| 25 | + Note( |
| 26 | + Translatable( |
| 27 | + "This function allows you to call database-specific functions that are not available " |
| 28 | + "as standard functions in DataLens. The availability and behavior of native functions " |
| 29 | + "depends on your database type and version." |
| 30 | + ) |
| 31 | + ), |
| 32 | + ], |
| 33 | + examples=[ |
| 34 | + SimpleExample('DB_CALL_INT("sign", -5) = -1'), |
| 35 | + SimpleExample('DB_CALL_INT("sign", 5) = 1'), |
| 36 | + SimpleExample('DB_CALL_INT("positionCaseInsensitive", "Hello", "l") = 3'), |
| 37 | + ], |
| 38 | +) |
| 39 | + |
| 40 | +FUNCTION_DB_CALL_FLOAT = FunctionDocRegistryItem( |
| 41 | + name="db_call_float", |
| 42 | + category=CATEGORY_NATIVE, |
| 43 | + description=_( |
| 44 | + "Calls a native database function by name and returns a float result.\n" |
| 45 | + "\n" |
| 46 | + "The first argument {arg:0} must be a constant string with the name of the " |
| 47 | + "database function to call. All subsequent arguments are passed to the " |
| 48 | + "native function and can be of any type.\n" |
| 49 | + "\n" |
| 50 | + "The function name must contain only alphanumeric characters and underscores." |
| 51 | + ), |
| 52 | + notes=[ |
| 53 | + Note( |
| 54 | + Translatable( |
| 55 | + "This function allows you to call database-specific functions that are not available " |
| 56 | + "as standard functions in DataLens. The availability and behavior of native functions " |
| 57 | + "depends on your database type and version." |
| 58 | + ) |
| 59 | + ), |
| 60 | + ], |
| 61 | + examples=[ |
| 62 | + SimpleExample('DB_CALL_FLOAT("sign", -5.0) = -1.0'), |
| 63 | + SimpleExample('DB_CALL_FLOAT("sign", 5.0) = 1.0'), |
| 64 | + SimpleExample('DB_CALL_FLOAT("log10", 100.0) = 2.0'), |
| 65 | + ], |
| 66 | +) |
| 67 | + |
| 68 | +FUNCTION_DB_CALL_STRING = FunctionDocRegistryItem( |
| 69 | + name="db_call_string", |
| 70 | + category=CATEGORY_NATIVE, |
| 71 | + description=_( |
| 72 | + "Calls a native database function by name and returns a string result.\n" |
| 73 | + "\n" |
| 74 | + "The first argument {arg:0} must be a constant string with the name of the " |
| 75 | + "database function to call. All subsequent arguments are passed to the " |
| 76 | + "native function and can be of any type.\n" |
| 77 | + "\n" |
| 78 | + "The function name must contain only alphanumeric characters and underscores." |
| 79 | + ), |
| 80 | + notes=[ |
| 81 | + Note( |
| 82 | + Translatable( |
| 83 | + "This function allows you to call database-specific functions that are not available " |
| 84 | + "as standard functions in DataLens. The availability and behavior of native functions " |
| 85 | + "depends on your database type and version." |
| 86 | + ) |
| 87 | + ), |
| 88 | + ], |
| 89 | + examples=[ |
| 90 | + SimpleExample('DB_CALL_STRING("reverse", "hello") = "olleh"'), |
| 91 | + ], |
| 92 | +) |
| 93 | + |
| 94 | +FUNCTION_DB_CALL_BOOL = FunctionDocRegistryItem( |
| 95 | + name="db_call_bool", |
| 96 | + category=CATEGORY_NATIVE, |
| 97 | + description=_( |
| 98 | + "Calls a native database function by name and returns a boolean result.\n" |
| 99 | + "\n" |
| 100 | + "The first argument {arg:0} must be a constant string with the name of the " |
| 101 | + "database function to call. All subsequent arguments are passed to the " |
| 102 | + "native function and can be of any type.\n" |
| 103 | + "\n" |
| 104 | + "The function name must contain only alphanumeric characters and underscores." |
| 105 | + ), |
| 106 | + notes=[ |
| 107 | + Note( |
| 108 | + Translatable( |
| 109 | + "This function allows you to call database-specific functions that are not available " |
| 110 | + "as standard functions in DataLens. The availability and behavior of native functions " |
| 111 | + "depends on your database type and version." |
| 112 | + ) |
| 113 | + ), |
| 114 | + ], |
| 115 | + examples=[ |
| 116 | + SimpleExample('DB_CALL_BOOL("isFinite", 5) = TRUE'), |
| 117 | + SimpleExample('DB_CALL_BOOL("isInfinite", 5) = FALSE'), |
| 118 | + ], |
| 119 | +) |
| 120 | + |
| 121 | +FUNCTION_DB_CALL_ARRAY_INT = FunctionDocRegistryItem( |
| 122 | + name="db_call_array_int", |
| 123 | + category=CATEGORY_NATIVE, |
| 124 | + description=_( |
| 125 | + "Calls a native database function by name and returns an array of integers.\n" |
| 126 | + "\n" |
| 127 | + "The first argument {arg:0} must be a constant string with the name of the " |
| 128 | + "database function to call. All subsequent arguments are passed to the " |
| 129 | + "native function and can be of any type.\n" |
| 130 | + "\n" |
| 131 | + "The function name must contain only alphanumeric characters and underscores." |
| 132 | + ), |
| 133 | + notes=[ |
| 134 | + Note( |
| 135 | + Translatable( |
| 136 | + "This function allows you to call database-specific functions that are not available " |
| 137 | + "as standard functions in DataLens. The availability and behavior of native functions " |
| 138 | + "depends on your database type and version." |
| 139 | + ) |
| 140 | + ), |
| 141 | + ], |
| 142 | + examples=[ |
| 143 | + SimpleExample('DB_CALL_ARRAY_INT("range", 5) = ARRAY(0, 1, 2, 3, 4)'), |
| 144 | + ], |
| 145 | +) |
| 146 | + |
| 147 | +FUNCTION_DB_CALL_ARRAY_FLOAT = FunctionDocRegistryItem( |
| 148 | + name="db_call_array_float", |
| 149 | + category=CATEGORY_NATIVE, |
| 150 | + description=_( |
| 151 | + "Calls a native database function by name and returns an array of floats.\n" |
| 152 | + "\n" |
| 153 | + "The first argument {arg:0} must be a constant string with the name of the " |
| 154 | + "database function to call. All subsequent arguments are passed to the " |
| 155 | + "native function and can be of any type.\n" |
| 156 | + "\n" |
| 157 | + "The function name must contain only alphanumeric characters and underscores." |
| 158 | + ), |
| 159 | + notes=[ |
| 160 | + Note( |
| 161 | + Translatable( |
| 162 | + "This function allows you to call database-specific functions that are not available " |
| 163 | + "as standard functions in DataLens. The availability and behavior of native functions " |
| 164 | + "depends on your database type and version." |
| 165 | + ) |
| 166 | + ), |
| 167 | + ], |
| 168 | + examples=[ |
| 169 | + SimpleExample('DB_CALL_ARRAY_FLOAT("arrayConcat", ARRAY(1.0, 2.0), ARRAY(3.0)) = ARRAY(1.0, 2.0, 3.0)'), |
| 170 | + ], |
| 171 | +) |
| 172 | + |
| 173 | +FUNCTION_DB_CALL_ARRAY_STRING = FunctionDocRegistryItem( |
| 174 | + name="db_call_array_string", |
| 175 | + category=CATEGORY_NATIVE, |
| 176 | + description=_( |
| 177 | + "Calls a native database function by name and returns an array of strings.\n" |
| 178 | + "\n" |
| 179 | + "The first argument {arg:0} must be a constant string with the name of the " |
| 180 | + "database function to call. All subsequent arguments are passed to the " |
| 181 | + "native function and can be of any type.\n" |
| 182 | + "\n" |
| 183 | + "The function name must contain only alphanumeric characters and underscores." |
| 184 | + ), |
| 185 | + notes=[ |
| 186 | + Note( |
| 187 | + Translatable( |
| 188 | + "This function allows you to call database-specific functions that are not available " |
| 189 | + "as standard functions in DataLens. The availability and behavior of native functions " |
| 190 | + "depends on your database type and version." |
| 191 | + ) |
| 192 | + ), |
| 193 | + ], |
| 194 | + examples=[ |
| 195 | + SimpleExample('DB_CALL_ARRAY_STRING("splitByChar", ",", "a,b,c") = ARRAY("a", "b", "c")'), |
| 196 | + ], |
| 197 | +) |
| 198 | + |
| 199 | +FUNCTIONS_NATIVE = [ |
| 200 | + FUNCTION_DB_CALL_INT, |
| 201 | + FUNCTION_DB_CALL_FLOAT, |
| 202 | + FUNCTION_DB_CALL_STRING, |
| 203 | + FUNCTION_DB_CALL_BOOL, |
| 204 | + FUNCTION_DB_CALL_ARRAY_INT, |
| 205 | + FUNCTION_DB_CALL_ARRAY_FLOAT, |
| 206 | + FUNCTION_DB_CALL_ARRAY_STRING, |
| 207 | +] |
0 commit comments