Functions API
Database functions
File to manage the data base, connect, get a cursor on this connection.
connect(user, password, host, port, database)
Connect to a database.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/db.py
def connect(
user: str,
password: str,
host: str,
port: str,
database: str,
) -> Connection:
"""
Connect to a database.
Args:
user: User used to log in to the database.
password: Password of the user.
host: Host used for the connection.
port: Port used for the connection.
database: Database to which we want to connect.
Returns:
A connection to a database if all is working.
Raises:
PSQLConnectionError: If we have an error connecting to the database.
"""
try: # pragma: no cover
connection = psycopg.connect(
user=user,
password=password,
host=host,
port=port,
dbname=database,
)
return connection
except (Exception, Error) as err: # pragma: no cover
raise PSQLConnectionError(f"Error while connecting to posgeSQL {err}") from err
get_cursor(connection)
Get a cursor on the given connection.
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/db.py
def get_cursor(connection: Connection) -> Cursor:
"""
Get a cursor on the given connection.
Args:
connection: A connection to a database on which we want to execute commands.
Returns:
A cursor on the given connection to a data base to execute commands.
"""
cursor = connection.cursor(row_factory=psycopg.rows.namedtuple_row)
return cursor
Aggregate functions
Aggregate functions used in py-linq-sql.
get_aggregate(mdpa, sqle=None)
Get all built aggregate.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/aggregate_functions.py
def get_aggregate(
mdpa: MagicDotPathAggregate | Tuple[MagicDotPathAggregate],
sqle: SQLEnumerableData | None = None,
) -> str:
"""
Get all built aggregate.
Args:
mdpa: MagicDotPathAggregate or tuple of MagicDotPathAggregate to build.
sqle: SQLEnumerableData with connection, flags, list of commands and a table.
Returns:
All aggregate with paths as str.
Raises:
TypeError: If mdpa id not a MagicDotPathAggregate
or indirect raise by `get_one_aggregate`.
psycopg.Error: Indirect raise by `get_one_aggregate`.
TableError: Indirect raise by `get_one_aggregate`.
"""
result = []
match mdpa:
case MagicDotPathAggregate():
result.append(get_one_aggregate(mdpa, mdpa.cast_type, sqle))
case tuple():
for idx, element in enumerate(mdpa):
if not isinstance(element, MagicDotPathAggregate):
raise TypeError(
"get_aggregate_path take only MagicDotPathAggregate "
"or tuple of MagicDotPathAggregate.",
)
result.append(get_one_aggregate(element, element.cast_type, sqle))
if not idx == len(mdpa) - 1:
result.append(",")
case _:
raise TypeError(
"get_aggregate_path take only MagicDotPathAggregate "
"or tuple of MagicDotPathAggregate.",
)
return " ".join(result)
get_one_aggregate(mdpa, cast_type, sqle)
Get one built aggregate.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/aggregate_functions.py
def get_one_aggregate(
mdpa: MagicDotPathAggregate,
cast_type: type,
sqle: SQLEnumerableData | None,
) -> str:
"""
Get one built aggregate.
Args:
mdpa: MagicDotPathAggregate to build.
cast_type: Type in which we want to cast the path(s). Its optional.
sqle: SQLEnumerableData with connection, flags, list of commands and a table.
Returns:
An aggregate with path as str.
Raises:
psycopg.Error: Indirect raise by `get_path` or `get_one_concat_aggregate`.
TableError: Indirect raise by `get_path` or `get_one_concat_aggregate`.
TypeError: Indirect raise by `get_path` or `get_one_concat_aggregate`.
"""
if mdpa.operand == AggregateType.CONCAT:
return get_one_concat_aggregate(mdpa, sqle)
if cast_type == str:
result = [f"{mdpa.operand}({get_path(mdpa.mdp, sqle)[0]})"]
else:
result = [f"{mdpa.operand}(CAST({get_path(mdpa.mdp, sqle)[0]} AS"]
casted_type = get_good_type(cast_type)
if not casted_type:
raise TypeError(
f"Group_by take only int, float, decimal or date type, not {cast_type}",
)
result.append(casted_type)
return " ".join(result)
get_one_concat_aggregate(mdpa, sqle)
Get one built concat aggregate.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/aggregate_functions.py
def get_one_concat_aggregate(
mdpa: MagicDotPathAggregate,
sqle: SQLEnumerableData | None,
) -> str:
"""
Get one built concat aggregate.
Args:
mdpa: MagicDotPathAggregate to build.
sqle: SQLEnumerableData with connection, flags, list of commands and a table.
Returns:
A concat aggregate with path as str.
Raises:
psycopg.Error: Indirect raise by `get_path`.
TableError: Indirect raise by `get_path`.
TypeError: Indirect raise by `get_path`.
"""
return f"{mdpa.operand}({get_path(mdpa.mdp, sqle, True)[0]}, '{mdpa.separator}')"
Join functions
Join functions used in py-linq-sql.
join_get_intersect(join_type, outer_key_paths, inner_key_paths)
Get the correct WHERE subcommand depending on the type of join.
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/join_functions.py
def join_get_intersect(
join_type: JoinType,
outer_key_paths: List[str],
inner_key_paths: List[str],
) -> str | None:
"""
Get the correct WHERE subcommand depending on the type of join.
Args:
join_type: type of join.
outer_key_paths: paths of the values to be compared of the outer SQLEnumerable.
inner_key_paths: paths of the values to be compared og the inner SQLEnumerable.
Return:
A WHERE subcommand with the correct syntax for join or None
if we make join with intersection.
"""
result = []
match join_type:
case JoinType.LEFT_MINUS_INTERSECT | JoinType.RIGHT_MINUS_INTERSECT:
result.append("WHERE")
result.append(
" AND ".join(
[f"{path_inner_k} IS NULL" for path_inner_k in inner_key_paths],
),
)
return " ".join(result)
case JoinType.FULL_MINUS_INTERSECT:
result.append("WHERE")
result.append(
" AND ".join(
[
f"{path_outer_k} IS NULL OR {path_inner_k} IS NULL"
for (path_outer_k, path_inner_k) in zip(
outer_key_paths,
inner_key_paths,
)
],
),
)
return " ".join(result)
case _:
return None
join_get_paths(outer, inner, inner_key, outer_key, result_function)
Get all paths for join.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/join_functions.py
def join_get_paths(
outer: SQLEnumerableData,
inner: SQLEnumerableData,
inner_key: LambdaMagicDotPath,
outer_key: LambdaMagicDotPath,
result_function: Callable[
[BaseMagicDotPath, BaseMagicDotPath],
BaseMagicDotPath | Tuple[BaseMagicDotPath] | Dict[str, BaseMagicDotPath],
]
| None,
) -> DotMap:
"""
Get all paths for join.
Args:
outer: An other SQLEnumerable to make the join.
inner: An SQLEnumerable to make the join.
inner_key: lambda to select the value to be compared of the inner
SQLEnumerable.
outer_key: lambda to select the value to be compared of the outer
SQLEnumerable.
result_function: lambda the select the values to be returned.
Returns:
All paths we will used in the join.
Raises:
psycopg.Error: Indirect raise by `get_path`.
TableError: Indirect raise by `get_path`.
TypeError: Indirect raise by `get_path`.
"""
obj_inner = MagicDotPath(inner.connection, with_table=inner.table)
obj_outer = MagicDotPath(outer.connection, with_table=outer.table)
paths = DotMap(
select_paths=None,
outer_key_paths=get_path(outer_key(obj_outer)),
inner_key_paths=get_path(inner_key(obj_inner)),
)
if result_function:
paths.select_paths = get_path(result_function(obj_inner, obj_outer))
return paths
Path functions
Path functions used in py-linq-sql.
get_path(magic_dp, sqle=None, force=False)
Get path from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/path_functions.py
def get_path(
magic_dp: BaseMagicDotPath | Tuple[BaseMagicDotPath] | Dict[str, BaseMagicDotPath],
sqle: SQLEnumerableData | None = None,
force: bool = False,
) -> List[str]:
"""
Get path from a MagicDotPath.
Args:
magic_dp: A MagicDotPath objects contains a bases with element of the future
path.
sqle: SQLEnumerableData with connection, flags, list of commands and a table.
force: True if we want to force the json path in text, False otherwise.
By default: False.
Returns:
List a path transform by jsonb_path.
Raises:
TypeError: If magic_dp is not a subclass of BaseMagicDotPath.
psycopg.Error: Indirect raise by `_get_path_base_mdp`.
TableError: Indirect raise by `_get_path_base_mdp`.
"""
paths: List[str] = []
match magic_dp:
case BaseMagicDotPath():
_get_path_base_mdp(magic_dp, sqle, force, paths)
case tuple():
for element in magic_dp:
_get_path_base_mdp(element, sqle, force, paths)
case dict():
for element in magic_dp.values():
_get_path_base_mdp(element, sqle, force, paths)
case _:
raise TypeError(
"`get_path()` take only BaseMagicDotPath or tuple of BaseMagicDotPath.",
)
return paths
get_paths(fquery, sqle, as_str=False)
Get jsonb paths to build commands.
The format of paths give by the function: person->'address'->'zip_code'
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/path_functions.py
def get_paths(
fquery: LambdaMagicDotPath,
sqle: SQLEnumerableData,
as_str: bool = False,
) -> List[str]:
"""
Get jsonb paths to build commands.
The format of paths give by the function: person->'address'->'zip_code'
Args:
fquery: Lambda function to get the path(s)
sqle: SQLEnumerableData with connection, flags, list of commands and a table.
as_str: False if we want basic paths, True if we want force the paths on string.
Returns:
List of paths.
Raises:
psycopg.Error: Indirect raise by `get_path`.
TableError: Indirect raise by `get_path`.
TypeError: Indirect raise by `get_path`.
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
or `BaseMagicDotPath._get_generic_operator`.
"""
return get_path(fquery(MagicDotPath(sqle.connection)), sqle, as_str)
get_update_path(path)
Get the correct format of path for UPDATE.
We need a path like: {0, 1, 2, 3}
.
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/path_functions.py
def get_update_path(path: str) -> str:
"""
Get the correct format of path for UPDATE.
We need a path like: `{0, 1, 2, 3}`.
Args:
path: The path to get in the correct format for UPDATE.
Returns:
The path in the correct format for UPDATE.
"""
tmp = re.split(r">|-|'", path)
# Delete the first, is the column
tmp = tmp[1:]
# Join all not None str in tmp with the function filter()
# (https://docs.python.org/3/library/functions.html#filter)
result = ",".join(filter(None, tmp))
return "{" + result + "}"
Predicate functions
Predicate functions used in py-linq-sql.
get_one_predicate_as_str(sqle, mdpo)
Get one predicate as string with the correct cast type and the correct prefix.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/predicate_functions.py
def get_one_predicate_as_str(
sqle: SQLEnumerableData,
mdpo: BaseMagicDotPath,
) -> str:
"""
Get one predicate as string with the correct cast type and the correct prefix.
Args:
sqle: SQLEnumerable with connection, flags, list of commands and a table.
mdpo: BasemagicDotPath to build the predicate.
Returns:
A predicate as a string with the correct cast type and prefix.
Raises:
psycopg.Error: Indirect raise by `get_path`.
TableError: Indirect raise by `get_path`.
TypeError: Indirect raise by `get_path`.
"""
return get_path(mdpo, sqle)[0]
get_predicates_as_str(result, fquery, sqle)
Get all predicates as string with the correct cast type and the correct prefix.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/predicate_functions.py
def get_predicates_as_str(
result: List[str],
fquery: LambdaMagicDotPath,
sqle: SQLEnumerableData,
) -> None:
"""
Get all predicates as string with the correct cast type and the correct prefix.
Args:
result: List contains the request.
fquery: Lambda function to get paths.
sqle: SQLEnumerableData with connection, flags, list of commands and a table.
Returns:
Predicates as a string with the correct cast type and prefix.
Raises:
TypeError: If the type of mdp_w_path isn't BaseMagicDotPath
or tuple of BaseMagicDotPath,
or indirect raise by `get_one_predicate_as_str`.
psycopg.Error: Indirect raise by `get_one_predicate_as_str`.
TableError: Indirect raise by `get_one_predicate_as_str`.
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
or `BaseMagicDotPath._get_generic_operator`.
"""
mdp_w_path = fquery(MagicDotPath(sqle.connection))
match mdp_w_path:
case BaseMagicDotPath():
result.append(get_one_predicate_as_str(sqle, mdp_w_path))
case tuple():
result.append(
" AND ".join(
[get_one_predicate_as_str(sqle, mdp) for mdp in mdp_w_path],
),
)
case _:
raise TypeError(
"Only BaseMagicDotPath or tuple of BaseMagicDotPath are accepted.",
)
MagicDotPath mathematical functions
All mathematics functions for MagicDotPath.
cbrt(mdp)
Cube root function for a MagicDotPath.
From psql docs: Cube root.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def cbrt(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Cube root function for a MagicDotPath.
From psql docs: Cube root.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the cube root.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.CBRT,
)
ceil(mdp)
Ceil function for a MagicDotPath.
From psql docs: Nearest integer greater than or equal to argument.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def ceil(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Ceil function for a MagicDotPath.
From psql docs: Nearest integer greater than or equal to argument.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the ceil.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.CEIL,
)
degrees(mdp)
Degrees function for a MagicDotPath.
From psql docs: Converts radians to degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def degrees(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Degrees function for a MagicDotPath.
From psql docs: Converts radians to degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the degrees.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.DEGREES,
)
exp(mdp)
Exp function for a MagicDotPath.
From psql docs: Exponential (e raised to the given power).
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def exp(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Exp function for a MagicDotPath.
From psql docs: Exponential (e raised to the given power).
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the exp.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.EXP,
)
factorial(mdp)
Factorial function for a MagicDotPath.
From psql docs: Factorial.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def factorial(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Factorial function for a MagicDotPath.
From psql docs: Factorial.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the factorial.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.FACTORIAL,
)
floor(mdp)
Floor function for a MagicDotPath.
From psql docs: Nearest integer less than or equal to argument.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def floor(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Floor function for a MagicDotPath.
From psql docs: Nearest integer less than or equal to argument.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the floor.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.FLOOR,
)
gcd(mdp, other)
Gcd function for a MagicDotPath.
From psql docs: Greatest common divisor (the largest positive number that divides both inputs with no remainder); returns 0 if both inputs are zero; available for integer, bigint, and numeric.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def gcd(mdp: BaseMagicDotPath, other: _NUMBER_TYPE) -> MagicDotPathWithOp:
"""
Gcd function for a MagicDotPath.
From psql docs: Greatest common divisor (the largest positive number
that divides both inputs with no remainder); returns 0 if both inputs are zero;
available for integer, bigint, and numeric.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the gcd.
other: An other element for the comparison.
Returns:
MagicDotPathWithOp with 2 operand and on the correct operator.
Raises:
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
"""
return mdp._get_number_operator( # pylint: disable=protected-access
other,
MathFunctType.GCD,
)
greatest(mdp, other)
Greatest function for a MagicDotPath.
This is equivalent to the max
function in python.
From psql docs: The GREATEST function select the largest value from a list of any number of expressions. The expressions must all be convertible to a common data type, which will be the type of the result
See: https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def greatest(
mdp: BaseMagicDotPath, other: _NUMBER_TYPE | BaseMagicDotPath
) -> MagicDotPathWithOp:
"""
Greatest function for a MagicDotPath.
This is equivalent to the `max` function in python.
From psql docs: The GREATEST function select the largest value from a list of any
number of expressions. The expressions must all be convertible to a common data
type, which will be the type of the result
See:
https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
Args:
mdp: MagicDotPath on which we apply the greatest.
other: An other element for
the comparison.
Returns:
MagicDotPathWithOp with 2 operand and on the correct operator.
Raises:
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
"""
return mdp._get_number_operator( # pylint: disable=protected-access
other,
MathFunctType.GREATEST,
)
lcm(mdp, other)
Lcm function for a MagicDotPath.
From psql docs: Least common multiple (the smallest strictly positive number that is an integral multiple of both inputs); returns 0 if either input is zero; available for integer, bigint, and numeric.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def lcm(mdp: BaseMagicDotPath, other: _NUMBER_TYPE) -> MagicDotPathWithOp:
"""
Lcm function for a MagicDotPath.
From psql docs: Least common multiple (the smallest strictly positive number
that is an integral multiple of both inputs); returns 0 if either input is zero;
available for integer, bigint, and numeric.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the lcm.
other: An other element for the comparison.
Returns:
MagicDotPathWithOp with 2 operand and on the correct operator.
Raises:
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
"""
return mdp._get_number_operator( # pylint: disable=protected-access
other,
MathFunctType.LCM,
)
least(mdp, other)
Greatest function for a MagicDotPath.
This is equivalent to the min
function in python.
From psql docs: The LEAST function select the smallest value from a list of any number of expressions. The expressions must all be convertible to a common data type, which will be the type of the result
See: https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def least(
mdp: BaseMagicDotPath, other: _NUMBER_TYPE | BaseMagicDotPath
) -> MagicDotPathWithOp:
"""
Greatest function for a MagicDotPath.
This is equivalent to the `min` function in python.
From psql docs: The LEAST function select the smallest value from a list of any
number of expressions. The expressions must all be convertible to a common data
type, which will be the type of the result
See:
https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
Args:
mdp: MagicDotPath on which we apply the least.
other: An other element for
the comparison.
Returns:
MagicDotPathWithOp with 2 operand and on the correct operator.
Raises:
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
"""
return mdp._get_number_operator( # pylint: disable=protected-access
other,
MathFunctType.LEAST,
)
ln(mdp)
Ln function for a MagicDotPath.
From psql docs: Natural logarithm.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def ln(
mdp: BaseMagicDotPath,
) -> MagicDotPathWithOp:
"""
Ln function for a MagicDotPath.
From psql docs: Natural logarithm.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the ln.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.LN,
)
log(mdp, other)
Log function for a MagicDotPath.
From psql docs: Logarithm of x to base b.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def log(mdp: BaseMagicDotPath, other: _NUMBER_TYPE) -> MagicDotPathWithOp:
"""
Log function for a MagicDotPath.
From psql docs: Logarithm of x to base b.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the log.
other: Base for the logarithm.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
Raises:
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
"""
return mdp._get_number_operator( # pylint: disable=protected-access
other,
MathFunctType.LOG,
)
log10(mdp)
Log10 function for a MagicDotPath.
From psql docs: Base 10 logarithm.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def log10(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Log10 function for a MagicDotPath.
From psql docs: Base 10 logarithm.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the log10.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.LOG10,
)
min_scale(mdp)
Min scale function for a MagicDotPath.
From psql docs: Minimum scale (number of fractional decimal digits) needed to represent the supplied value precisely.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def min_scale(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Min scale function for a MagicDotPath.
From psql docs: Minimum scale (number of fractional decimal digits) needed
to represent the supplied value precisely.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the min scale.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.MIN_SCALE,
)
radians(mdp)
Radiant function for a MagicDotPath.
From psql docs: Converts degrees to radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def radians(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Radiant function for a MagicDotPath.
From psql docs: Converts degrees to radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the radiant.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.RADIANS,
)
round(mdp, other=None)
Round function for a MagicDotPath.
From psql docs:
- round(mdp): Rounds to nearest integer. For numeric, ties are broken by rounding away from zero. For double precision, the tie-breaking behavior is platform dependent, but “round to nearest even” is the most common rule.
- round(mdp, other): Rounds v to s decimal places. Ties are broken by rounding away from zero.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def round( # noqa: A001
mdp: BaseMagicDotPath,
other: _NUMBER_TYPE | None = None,
) -> MagicDotPathWithOp:
"""
Round function for a MagicDotPath.
From psql docs:
- round(mdp): Rounds to nearest integer. For numeric,
ties are broken by rounding away from zero.
For double precision, the tie-breaking behavior is platform dependent,
but “round to nearest even” is the most common rule.
- round(mdp, other): Rounds v to s decimal places.
Ties are broken by rounding away from zero.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the round.
other: Number of decimal we want to keep.
Returns:
MagicDotPathWithOp with 2 operand and on the correct operator.
Raises:
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
"""
if not other:
other = 0
return mdp._get_number_operator( # pylint: disable=protected-access
other,
MathFunctType.ROUND,
)
scale(mdp)
Scale function for a MagicDotPath.
From psql docs: Scale of the argument (the number of decimal digits in the fractional part).
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def scale(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Scale function for a MagicDotPath.
From psql docs: Scale of the argument
(the number of decimal digits in the fractional part).
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the scale.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.SCALE,
)
sign(mdp)
Sign function for a MagicDotPath.
From psql docs: Sign of the argument (-1, 0, or +1).
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def sign(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Sign function for a MagicDotPath.
From psql docs: Sign of the argument (-1, 0, or +1).
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the sign.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.SIGN,
)
sqrt(mdp)
Squart root function for a MagicDotPath.
From psql docs: Square root.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def sqrt(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Squart root function for a MagicDotPath.
From psql docs: Square root.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the squart root.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.SQRT,
)
trim_scale(mdp)
Trim Scale function for a MagicDotPath.
From psql docs: Reduces the value's scale (number of fractional decimal digits) by removing trailing zeroes.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def trim_scale(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Trim Scale function for a MagicDotPath.
From psql docs: Reduces the value's scale (number of fractional decimal digits)
by removing trailing zeroes.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the trim scale.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
MathFunctType.TRIM_SCALE,
)
trunc(mdp, other=None)
Trunc function for a MagicDotPath.
From psql docs:
- trunc(mdp): Truncates to integer (towards zero).
- trunc(mdp, other): Truncates v to s decimal places.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_maths_functions.py
def trunc(
mdp: BaseMagicDotPath,
other: _NUMBER_TYPE | None = None,
) -> MagicDotPathWithOp:
"""
Trunc function for a MagicDotPath.
From psql docs:
- trunc(mdp): Truncates to integer (towards zero).
- trunc(mdp, other): Truncates v to s decimal places.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the trunc.
other: Number of decimal we want to keep.
Returns:
MagicDotPathWithOp with 2 operand and on the correct operator.
Raises:
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
"""
if not other:
other = 0
return mdp._get_number_operator( # pylint: disable=protected-access
other,
MathFunctType.TRUNC,
)
MagicDotPath trigonometric functions
All trigonometric functions for MagicDotPath.
acos(mdp)
Acos function for a MagicDotPath.
From psql docs: Inverse cosine, result in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def acos(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Acos function for a MagicDotPath.
From psql docs: Inverse cosine, result in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the acos.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.ACOS,
)
acosd(mdp)
Acosd function for a MagicDotPath.
From psql docs: Inverse cosine, result in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def acosd(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Acosd function for a MagicDotPath.
From psql docs: Inverse cosine, result in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the acosd.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.ACOSD,
)
asin(mdp)
Asin function for a MagicDotPath.
From psql docs: Inverse sine, result in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def asin(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Asin function for a MagicDotPath.
From psql docs: Inverse sine, result in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the asin.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.ASIN,
)
asind(mdp)
Asind function for a MagicDotPath.
From psql docs: Inverse sine, result in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def asind(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Asind function for a MagicDotPath.
From psql docs: Inverse sine, result in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the asind.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.ASIND,
)
atan(mdp)
Atan function for a MagicDotPath.
From psql docs: Inverse tangent, result in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def atan(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Atan function for a MagicDotPath.
From psql docs: Inverse tangent, result in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the atan.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.ATAN,
)
atan2(mdp, other)
Atan2 function for a MagicDotPath.
From psql docs: Inverse tangent of y/x, result in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def atan2(mdp: BaseMagicDotPath, other: _NUMBER_TYPE) -> MagicDotPathWithOp:
"""
Atan2 function for a MagicDotPath.
From psql docs: Inverse tangent of y/x, result in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath representing x.
other: number representing y.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
Raises:
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
"""
return mdp._get_number_operator( # pylint: disable=protected-access
other,
TrigoFunctType.ATAN2,
)
atan2d(mdp, other)
Atan2d function for a MagicDotPath.
From psql docs: Inverse tangent of y/x, result in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def atan2d(mdp: BaseMagicDotPath, other: _NUMBER_TYPE) -> MagicDotPathWithOp:
"""
Atan2d function for a MagicDotPath.
From psql docs: Inverse tangent of y/x, result in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath representing x.
other: number representing y.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
Raises:
TypeOperatorError: Indirect raise by `BaseMagicDotPath._get_number_operator`
"""
return mdp._get_number_operator( # pylint: disable=protected-access
other,
TrigoFunctType.ATAN2D,
)
atand(mdp)
Atand function for a MagicDotPath.
From psql docs: Inverse tangent, result in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def atand(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Atand function for a MagicDotPath.
From psql docs: Inverse tangent, result in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the atand.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.ATAND,
)
cos(mdp)
Cos function for a MagicDotPath.
From psql docs: Cosine, argument in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def cos(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Cos function for a MagicDotPath.
From psql docs: Cosine, argument in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the cos.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.COS,
)
cosd(mdp)
Cosd function for a MagicDotPath.
From psql docs: Cosine, argument in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def cosd(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Cosd function for a MagicDotPath.
From psql docs: Cosine, argument in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the cosd.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.COSD,
)
cot(mdp)
Cot function for a MagicDotPath.
From psql docs: Cotangent, argument in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def cot(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Cot function for a MagicDotPath.
From psql docs: Cotangent, argument in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the cot.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.COT,
)
cotd(mdp)
Cotd function for a MagicDotPath.
From psql docs: Cotangent, argument in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def cotd(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Cotd function for a MagicDotPath.
From psql docs: Cotangent, argument in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the cotd.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.COTD,
)
sin(mdp)
Sin function for a MagicDotPath.
From psql docs: Sine, argument in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def sin(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Sin function for a MagicDotPath.
From psql docs: Sine, argument in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the sin.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.SIN,
)
sind(mdp)
Sind function for a MagicDotPath.
From psql docs: Sine, argument in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def sind(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Sind function for a MagicDotPath.
From psql docs: Sine, argument in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the sind.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.SIND,
)
tan(mdp)
Tand function for a MagicDotPath.
From psql docs: Tangent, argument in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def tan(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Tand function for a MagicDotPath.
From psql docs: Tangent, argument in radians.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the tan.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.TAN,
)
tand(mdp)
Tand function for a MagicDotPath.
From psql docs: Tangent, argument in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_trigo_functions.py
def tand(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Tand function for a MagicDotPath.
From psql docs: Tangent, argument in degrees.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the tand.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
TrigoFunctType.TAND,
)
MagicDotPath hyperbolic functions
All trigonometric functions for MagicDotPath.
acosh(mdp)
Acosh function for a MagicDotPath.
From psql docs: Inverse hyperbolic cosine.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_hyperb_functions.py
def acosh(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Acosh function for a MagicDotPath.
From psql docs: Inverse hyperbolic cosine.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the acosh.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
HyperBFuncType.ACOSH,
)
asinh(mdp)
Asinh function for a MagicDotPath.
From psql docs: Inverse hyperbolic sine.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_hyperb_functions.py
def asinh(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Asinh function for a MagicDotPath.
From psql docs: Inverse hyperbolic sine.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the asinh.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
HyperBFuncType.ASINH,
)
atanh(mdp)
Atanh function for a MagicDotPath.
From psql docs: Inverse hyperbolic tangent.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_hyperb_functions.py
def atanh(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Atanh function for a MagicDotPath.
From psql docs: Inverse hyperbolic tangent.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the atanh.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
HyperBFuncType.ATANH,
)
cosh(mdp)
Cosh function for a MagicDotPath.
From psql docs: Hyperbolic cosine.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_hyperb_functions.py
def cosh(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Cosh function for a MagicDotPath.
From psql docs: Hyperbolic cosine.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the cosh.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
HyperBFuncType.COSH,
)
sinh(mdp)
Sinh function for a MagicDotPath.
From psql docs: Hyperbolic sine.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_hyperb_functions.py
def sinh(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Sinh function for a MagicDotPath.
From psql docs: Hyperbolic sine.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the sinh.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
HyperBFuncType.SINH,
)
tanh(mdp)
Tanh function for a MagicDotPath.
From psql docs: Hyperbolic tangent.
See: https://www.postgresql.org/docs/current/functions-math.html
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/magic_dp_hyperb_functions.py
def tanh(mdp: BaseMagicDotPath) -> MagicDotPathWithOp:
"""
Tanh function for a MagicDotPath.
From psql docs: Hyperbolic tangent.
See: https://www.postgresql.org/docs/current/functions-math.html
Args:
mdp: MagicDotPath on which we apply the tanh.
Returns:
MagicDotPathWithOp with one operand and on the correct operator.
"""
return mdp._get_one_operand_operator( # pylint: disable=protected-access
HyperBFuncType.TANH,
)
Operators and functions for MagicDotPath
OperatorsType, functionsType aand the functions that use them.
col_name_hyper(name_op, operator)
Get the corresponding column name for an hyperbolic functions from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Examples:
>>> col_name_hyper(DotMap(op1="mass"), HyperBFuncType.COSH)
'cosh_mass'
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def col_name_hyper(name_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding column name for an hyperbolic functions from a MagicDotPath.
Args:
name_op: name of the operand(s).
operator: Operator Type.
Returns:
A column name with the correct format.
Raises:
TypeOperatorError: If type of operator is not `HyperBFuncType`.
Examples:
>>> col_name_hyper(DotMap(op1="mass"), HyperBFuncType.COSH)
'cosh_mass'
"""
if not isinstance(operator, HyperBFuncType):
raise TypeOperatorError([HyperBFuncType], type(operator))
return f"{operator.name}_{name_op.op1}"
col_name_math(name_op, operator)
Get the corresponding column name for a mathematical functions from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Examples:
>>> col_name_math(DotMap(op1="mass"), MathFunctType.CEIL)
'ceil_mass'
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def col_name_math(name_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding column name for a mathematical functions from a MagicDotPath.
Args:
name_op: name of the operand(s).
operator: Operator Type.
Returns:
A column name with the correct format.
Raises:
TypeOperatorError: If type of operator is not `MathFunctType`.
Examples:
>>> col_name_math(DotMap(op1="mass"), MathFunctType.CEIL)
'ceil_mass'
"""
if not isinstance(operator, MathFunctType):
raise TypeOperatorError([MathFunctType], type(operator))
if operator in [
MathFunctType.GCD,
MathFunctType.LCM,
MathFunctType.LOG,
MathFunctType.ROUND,
MathFunctType.TRUNC,
MathFunctType.GREATEST,
MathFunctType.LEAST,
]:
return f"{operator.name}_{name_op.op1}_{name_op.op2}"
return f"{operator.name}_{name_op.op1}"
col_name_ope(name_op, operator)
Get the corresponding column name for an operator from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Examples:
>>> col_name_ope(DotMap(op1="mass", op2="power"), OperatorType.POW)
'mass_pow_power'
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def col_name_ope(name_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding column name for an operator from a MagicDotPath.
Args:
name_op: name of the operand(s).
operator: Operator Type.
Returns:
A column name with the correct format.
Raises:
TypeOperatorError: If type of operator is not `OperatorType.`.
Examples:
>>> col_name_ope(DotMap(op1="mass", op2="power"), OperatorType.POW)
'mass_pow_power'
"""
if not isinstance(operator, OperatorType):
raise TypeOperatorError([OperatorType], type(operator))
if operator in [
OperatorType.ABS,
OperatorType.NEG,
OperatorType.POS,
OperatorType.INVERT,
]:
return f"{operator.name}_{name_op.op1}"
return f"{name_op.op1}_{operator.name}_{name_op.op2}"
col_name_str(name_op, operator)
Get the corresponding column name for a str functions from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Examples:
>>> col_name_str(DotMap(op1="star_name"), StrFunctType.LOWER)
>>> 'lower_star_name'
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def col_name_str(name_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding column name for a str functions from a MagicDotPath.
Args:
name_op: name of the operand(s).
operator: Operator Type.
Returns:
A column name with correct format.
Raises:
TypeOperatorErrir: If type of operator is not `StrFunctType`.
Examples:
>>> col_name_str(DotMap(op1="star_name"), StrFunctType.LOWER)
>>> 'lower_star_name'
"""
if not isinstance(operator, StrFunctType):
raise TypeOperatorError([StrFunctType], type(operator))
return f"{operator.name}_{name_op.op1}"
col_name_trigo(name_op, operator)
Get the corresponding column name for a trigonometric functions from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Examples:
>>> col_name_trigo(DotMap(op1="mass"), TrigoFunctType.ASIND)
>>> "asind_mass"
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def col_name_trigo(name_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding column name for a trigonometric functions from a MagicDotPath.
Args:
name_op: name of the operand(s).
operator: Operator Type.
Returns:
A column name with the correct format.
Raises:
TypeOperatorError: If type of operator is not `TrigoFunctType`.
Examples:
>>> col_name_trigo(DotMap(op1="mass"), TrigoFunctType.ASIND)
>>> "asind_mass"
"""
if not isinstance(operator, TrigoFunctType):
raise TypeOperatorError([TrigoFunctType], type(operator))
if operator in [TrigoFunctType.ATAN2, TrigoFunctType.ATAN2D]:
return f"{operator.name}_{name_op.op1}_{name_op.op2}"
return f"{operator.name}_{name_op.op1}"
json_path_hyper(path_op, operator)
Get the corresponding jsonb path for an hyperbolic function from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def json_path_hyper(path_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding jsonb path for an hyperbolic function from a MagicDotPath.
Args:
path_op: path of the operand(s).
operator: Operator Type.
Returns:
A path with the correct jsonb syntax.
Raises:
TypeOperatorError: If type of operator is not `HyperBFuncType`.
"""
if not isinstance(operator, HyperBFuncType):
raise TypeOperatorError([HyperBFuncType], type(operator))
return f"{operator.psql}(CAST({path_op.op1} AS decimal))"
json_path_math(path_op, operator)
Get the corresponding jsonb path for a mathematical function from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def json_path_math(path_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding jsonb path for a mathematical function from a MagicDotPath.
Args:
path_op: path of the operand(s).
operator: Operator Type.
Returns:
A path with the correct jsonb syntax.
Raises:
TypeOperatorError: If type of operator is not `MathFunctType`.
"""
if not isinstance(operator, MathFunctType):
raise TypeOperatorError([MathFunctType], type(operator))
if operator in [MathFunctType.FACTORIAL]:
return f"{operator.psql}(CAST({path_op.op1} AS integer))"
if operator in [
MathFunctType.SQRT,
MathFunctType.CBRT,
]:
return f"{operator.psql} CAST({path_op.op1} AS decimal)"
if operator in [MathFunctType.GCD, MathFunctType.LCM]:
operand_1 = f"CAST({path_op.op1} AS integer)"
operand_2 = f"CAST({path_op.op2} AS integer)"
return f"{operator.psql}({operand_1}, {operand_2})"
if operator in [MathFunctType.TRUNC, MathFunctType.ROUND]:
return f"{operator.psql}(CAST({path_op.op1} AS decimal), {path_op.op2})"
if operator in [MathFunctType.LOG]:
return f"{operator.psql}({path_op.op2}, CAST({path_op.op1} AS decimal))"
if operator in [MathFunctType.GREATEST, MathFunctType.LEAST]:
operand_1 = f"CAST({path_op.op1} AS decimal)"
operand_2 = f"CAST({path_op.op2} AS decimal)"
return f"{operator.psql}({operand_1}, {operand_2})"
return f"{operator.psql}(CAST({path_op.op1} AS decimal))"
json_path_ope(path_op, operator)
Get the corresponding jsonb path for an operator from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def json_path_ope(path_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding jsonb path for an operator from a MagicDotPath.
Args:
path_op: path of the operand(s).
operator: Operator Type.
Returns:
A path with the correct jsonb syntax.
Raises:
TypeOperatorError: If type of operator is not `OperatorType`.
"""
if not isinstance(operator, OperatorType):
raise TypeOperatorError([OperatorType], type(operator))
if operator in [OperatorType.AND, OperatorType.OR, OperatorType.IN]:
return f"{path_op.op1} {operator.psql} {path_op.op2}"
if operator in [OperatorType.INVERT]:
return f"{operator.psql} {path_op.op1}"
return f"{operator.psql} CAST({path_op.op1} AS decimal)"
json_path_str(path_op, operator)
Get the corresponding jsonb path for a str function from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def json_path_str(path_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding jsonb path for a str function from a MagicDotPath.
Args:
path_op: path of the operand(s).
operator: Operator Type.
Returns:
A path with the correct jsonb syntax.
Raises:
TypeOperatorError: If type of operator is not `StrFunctType`.
"""
if not isinstance(operator, StrFunctType):
raise TypeOperatorError([StrFunctType], type(operator))
return f"{operator.psql}(CAST({path_op.op1} AS TEXT))"
json_path_trigo(path_op, operator)
Get the corresponding jsonb path for a trigonometric function from a MagicDotPath.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/classes/op_and_func_of_mdp.py
def json_path_trigo(path_op: DotMap, operator: _OPERATORTYPE) -> str:
"""
Get the corresponding jsonb path for a trigonometric function from a MagicDotPath.
Args:
path_op: path of the operand(s).
operator: Operator Type.
Returns:
A path with the correct jsonb syntax.
Raises:
TypeOperatorError: If type of operator is not `TrigoFunctType`.
"""
if not isinstance(operator, TrigoFunctType):
raise TypeOperatorError([TrigoFunctType], type(operator))
if operator in [TrigoFunctType.ATAN2, TrigoFunctType.ATAN2D]:
return f"{operator.psql}(CAST({path_op.op1} AS decimal), {path_op.op2})"
return f"{operator.psql}(CAST({path_op.op1} AS decimal))"
Other functions
Functions used in py-linq-sql.
get_columns_name(mdps)
Get all column name.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/other_functions.py
def get_columns_name(
mdps: MagicDotPath
| List[MagicDotPath]
| Tuple[MagicDotPath]
| Dict[str, MagicDotPath],
) -> List[str]:
"""
Get all column name.
Args:
mdps: MagicDotPath for which we want the column name.
Returns:
All of paths and columns.
Raises:
TypeOperatorError: Indirect raise by `MagicDotPathWithOp.col_name`.
"""
result = []
match mdps:
case BaseMagicDotPath():
col_name = mdps.col_name()
result.append(
f"_{_short_columns_default_name(col_name)}"
if len(col_name) > 58
else f"{col_name}",
)
case tuple() | list():
for element in mdps:
col_name = element.col_name()
result.append(
f"_{_short_columns_default_name(col_name)}"
if len(col_name) > 58
else f"{col_name}",
)
case dict():
for key in mdps:
result.append(_col_name_validator(key))
return _fix_same_column_name(result)
get_good_type(cast_type)
Get the good type as str from a cast_type.
Parameters: |
|
---|
Returns: |
|
---|
Source code in py_linq_sql/utils/functions/other_functions.py
def get_good_type(cast_type: type) -> str | None:
"""
Get the good type as str from a cast_type.
Args:
cast_type: Type in which we want to cast the path.
Returns:
SQL type with '))' to cast in sql command. None if we give the wrong type.
"""
if cast_type in (int, float, Decimal):
return "decimal))"
if cast_type == date:
return "date))"
return None
get_json(data)
Get a json from data.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/other_functions.py
def get_json(data: Dict[Any, Any]) -> str:
"""
Get a json from data.
Args:
data: data we want to have in json.
Returns:
A json contains data.
Raises:
ValueError: Indirect raise by `json.dumps`.
"""
return json.dumps(data)
pretty_print(record)
Print a record in a pretty table with rich.
Parameters: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/other_functions.py
def pretty_print(record: Enumerable) -> None:
"""
Print a record in a pretty table with rich.
Args:
record: Record to display.
Raises:
rich.errors.ConsoleError: Indirect raise by `rich.table`
rich.console.CaptureError: Indirect raise by `rich.console`
"""
if record is None:
Console().print("Record is None.")
else:
rec_in_list = record.to_list()
if not rec_in_list:
Console().print("Empty Enumerable.")
else:
table = Table(title="Record", show_lines=True)
for name in rec_in_list[0]._fields:
table.add_column(name, justify="center", no_wrap=True)
for element in rec_in_list:
table.add_row(*map(str, element))
Console().print(table)
count = len(rec_in_list)
row_repr = f"({count} rows)" if count > 1 else f"({count} row)"
Console().print(row_repr)
safe(connection, name)
Secure a column or a table for a request.
Parameters: |
|
---|
Returns: |
|
---|
Exceptions: |
|
---|
Source code in py_linq_sql/utils/functions/other_functions.py
def safe(connection: Connection, name: str) -> str:
"""
Secure a column or a table for a request.
Args:
name: Name of the column or table we want to secure.
Returns:
Name but verified by psycopg.sql.Identifier.
Raises:
psycopg.Error: Indirect raise by `sql.Identifier` or `as_string`.
"""
return sql.Identifier(name).as_string(connection)