id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
231,000 | sdispater/orator | orator/schema/blueprint.py | Blueprint.morphs | def morphs(self, name, index_name=None):
"""
Add the proper columns for a polymorphic table.
:type name: str
:type index_name: str
"""
self.unsigned_integer("%s_id" % name)
self.string("%s_type" % name)
self.index(["%s_id" % name, "%s_type" % name], index_name) | python | def morphs(self, name, index_name=None):
"""
Add the proper columns for a polymorphic table.
:type name: str
:type index_name: str
"""
self.unsigned_integer("%s_id" % name)
self.string("%s_type" % name)
self.index(["%s_id" % name, "%s_type" % name], index_name) | [
"def",
"morphs",
"(",
"self",
",",
"name",
",",
"index_name",
"=",
"None",
")",
":",
"self",
".",
"unsigned_integer",
"(",
"\"%s_id\"",
"%",
"name",
")",
"self",
".",
"string",
"(",
"\"%s_type\"",
"%",
"name",
")",
"self",
".",
"index",
"(",
"[",
"\"%s_id\"",
"%",
"name",
",",
"\"%s_type\"",
"%",
"name",
"]",
",",
"index_name",
")"
] | Add the proper columns for a polymorphic table.
:type name: str
:type index_name: str | [
"Add",
"the",
"proper",
"columns",
"for",
"a",
"polymorphic",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L634-L644 |
231,001 | sdispater/orator | orator/schema/blueprint.py | Blueprint._drop_index_command | def _drop_index_command(self, command, type, index):
"""
Create a new drop index command on the blueprint.
:param command: The command
:type command: str
:param type: The index type
:type type: str
:param index: The index name
:type index: str
:rtype: Fluent
"""
columns = []
if isinstance(index, list):
columns = index
index = self._create_index_name(type, columns)
return self._index_command(command, columns, index) | python | def _drop_index_command(self, command, type, index):
"""
Create a new drop index command on the blueprint.
:param command: The command
:type command: str
:param type: The index type
:type type: str
:param index: The index name
:type index: str
:rtype: Fluent
"""
columns = []
if isinstance(index, list):
columns = index
index = self._create_index_name(type, columns)
return self._index_command(command, columns, index) | [
"def",
"_drop_index_command",
"(",
"self",
",",
"command",
",",
"type",
",",
"index",
")",
":",
"columns",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"index",
",",
"list",
")",
":",
"columns",
"=",
"index",
"index",
"=",
"self",
".",
"_create_index_name",
"(",
"type",
",",
"columns",
")",
"return",
"self",
".",
"_index_command",
"(",
"command",
",",
"columns",
",",
"index",
")"
] | Create a new drop index command on the blueprint.
:param command: The command
:type command: str
:param type: The index type
:type type: str
:param index: The index name
:type index: str
:rtype: Fluent | [
"Create",
"a",
"new",
"drop",
"index",
"command",
"on",
"the",
"blueprint",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L646-L668 |
231,002 | sdispater/orator | orator/schema/blueprint.py | Blueprint._index_command | def _index_command(self, type, columns, index):
"""
Add a new index command to the blueprint.
:param type: The index type
:type type: str
:param columns: The index columns
:type columns: list or str
:param index: The index name
:type index: str
:rtype: Fluent
"""
if not isinstance(columns, list):
columns = [columns]
if not index:
index = self._create_index_name(type, columns)
return self._add_command(type, index=index, columns=columns) | python | def _index_command(self, type, columns, index):
"""
Add a new index command to the blueprint.
:param type: The index type
:type type: str
:param columns: The index columns
:type columns: list or str
:param index: The index name
:type index: str
:rtype: Fluent
"""
if not isinstance(columns, list):
columns = [columns]
if not index:
index = self._create_index_name(type, columns)
return self._add_command(type, index=index, columns=columns) | [
"def",
"_index_command",
"(",
"self",
",",
"type",
",",
"columns",
",",
"index",
")",
":",
"if",
"not",
"isinstance",
"(",
"columns",
",",
"list",
")",
":",
"columns",
"=",
"[",
"columns",
"]",
"if",
"not",
"index",
":",
"index",
"=",
"self",
".",
"_create_index_name",
"(",
"type",
",",
"columns",
")",
"return",
"self",
".",
"_add_command",
"(",
"type",
",",
"index",
"=",
"index",
",",
"columns",
"=",
"columns",
")"
] | Add a new index command to the blueprint.
:param type: The index type
:type type: str
:param columns: The index columns
:type columns: list or str
:param index: The index name
:type index: str
:rtype: Fluent | [
"Add",
"a",
"new",
"index",
"command",
"to",
"the",
"blueprint",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L670-L691 |
231,003 | sdispater/orator | orator/schema/blueprint.py | Blueprint._remove_column | def _remove_column(self, name):
"""
Removes a column from the blueprint.
:param name: The column name
:type name: str
:rtype: Blueprint
"""
self._columns = filter(lambda c: c.name != name, self._columns)
return self | python | def _remove_column(self, name):
"""
Removes a column from the blueprint.
:param name: The column name
:type name: str
:rtype: Blueprint
"""
self._columns = filter(lambda c: c.name != name, self._columns)
return self | [
"def",
"_remove_column",
"(",
"self",
",",
"name",
")",
":",
"self",
".",
"_columns",
"=",
"filter",
"(",
"lambda",
"c",
":",
"c",
".",
"name",
"!=",
"name",
",",
"self",
".",
"_columns",
")",
"return",
"self"
] | Removes a column from the blueprint.
:param name: The column name
:type name: str
:rtype: Blueprint | [
"Removes",
"a",
"column",
"from",
"the",
"blueprint",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L727-L738 |
231,004 | sdispater/orator | orator/schema/blueprint.py | Blueprint._add_command | def _add_command(self, name, **parameters):
"""
Add a new command to the blueprint.
:param name: The command name
:type name: str
:param parameters: The command parameters
:type parameters: dict
:rtype: Fluent
"""
command = self._create_command(name, **parameters)
self._commands.append(command)
return command | python | def _add_command(self, name, **parameters):
"""
Add a new command to the blueprint.
:param name: The command name
:type name: str
:param parameters: The command parameters
:type parameters: dict
:rtype: Fluent
"""
command = self._create_command(name, **parameters)
self._commands.append(command)
return command | [
"def",
"_add_command",
"(",
"self",
",",
"name",
",",
"*",
"*",
"parameters",
")",
":",
"command",
"=",
"self",
".",
"_create_command",
"(",
"name",
",",
"*",
"*",
"parameters",
")",
"self",
".",
"_commands",
".",
"append",
"(",
"command",
")",
"return",
"command"
] | Add a new command to the blueprint.
:param name: The command name
:type name: str
:param parameters: The command parameters
:type parameters: dict
:rtype: Fluent | [
"Add",
"a",
"new",
"command",
"to",
"the",
"blueprint",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L740-L755 |
231,005 | sdispater/orator | orator/dbal/index.py | Index.get_quoted_columns | def get_quoted_columns(self, platform):
"""
Returns the quoted representation of the column names
the constraint is associated with.
But only if they were defined with one or a column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is returned.
:param platform: The platform to use for quotation.
:type platform: Platform
:rtype: list
"""
columns = []
for column in self._columns.values():
columns.append(column.get_quoted_name(platform))
return columns | python | def get_quoted_columns(self, platform):
"""
Returns the quoted representation of the column names
the constraint is associated with.
But only if they were defined with one or a column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is returned.
:param platform: The platform to use for quotation.
:type platform: Platform
:rtype: list
"""
columns = []
for column in self._columns.values():
columns.append(column.get_quoted_name(platform))
return columns | [
"def",
"get_quoted_columns",
"(",
"self",
",",
"platform",
")",
":",
"columns",
"=",
"[",
"]",
"for",
"column",
"in",
"self",
".",
"_columns",
".",
"values",
"(",
")",
":",
"columns",
".",
"append",
"(",
"column",
".",
"get_quoted_name",
"(",
"platform",
")",
")",
"return",
"columns"
] | Returns the quoted representation of the column names
the constraint is associated with.
But only if they were defined with one or a column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is returned.
:param platform: The platform to use for quotation.
:type platform: Platform
:rtype: list | [
"Returns",
"the",
"quoted",
"representation",
"of",
"the",
"column",
"names",
"the",
"constraint",
"is",
"associated",
"with",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L65-L84 |
231,006 | sdispater/orator | orator/dbal/index.py | Index.spans_columns | def spans_columns(self, column_names):
"""
Checks if this index exactly spans the given column names in the correct order.
:type column_names: list
:rtype: bool
"""
columns = self.get_columns()
number_of_columns = len(columns)
same_columns = True
for i in range(number_of_columns):
column = self._trim_quotes(columns[i].lower())
if i >= len(column_names) or column != self._trim_quotes(
column_names[i].lower()
):
same_columns = False
return same_columns | python | def spans_columns(self, column_names):
"""
Checks if this index exactly spans the given column names in the correct order.
:type column_names: list
:rtype: bool
"""
columns = self.get_columns()
number_of_columns = len(columns)
same_columns = True
for i in range(number_of_columns):
column = self._trim_quotes(columns[i].lower())
if i >= len(column_names) or column != self._trim_quotes(
column_names[i].lower()
):
same_columns = False
return same_columns | [
"def",
"spans_columns",
"(",
"self",
",",
"column_names",
")",
":",
"columns",
"=",
"self",
".",
"get_columns",
"(",
")",
"number_of_columns",
"=",
"len",
"(",
"columns",
")",
"same_columns",
"=",
"True",
"for",
"i",
"in",
"range",
"(",
"number_of_columns",
")",
":",
"column",
"=",
"self",
".",
"_trim_quotes",
"(",
"columns",
"[",
"i",
"]",
".",
"lower",
"(",
")",
")",
"if",
"i",
">=",
"len",
"(",
"column_names",
")",
"or",
"column",
"!=",
"self",
".",
"_trim_quotes",
"(",
"column_names",
"[",
"i",
"]",
".",
"lower",
"(",
")",
")",
":",
"same_columns",
"=",
"False",
"return",
"same_columns"
] | Checks if this index exactly spans the given column names in the correct order.
:type column_names: list
:rtype: bool | [
"Checks",
"if",
"this",
"index",
"exactly",
"spans",
"the",
"given",
"column",
"names",
"in",
"the",
"correct",
"order",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L115-L134 |
231,007 | sdispater/orator | orator/dbal/index.py | Index.is_fullfilled_by | def is_fullfilled_by(self, other):
"""
Checks if the other index already fulfills
all the indexing and constraint needs of the current one.
:param other: The other index
:type other: Index
:rtype: bool
"""
# allow the other index to be equally large only. It being larger is an option
# but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)
if len(other.get_columns()) != len(self.get_columns()):
return False
# Check if columns are the same, and even in the same order
if not self.spans_columns(other.get_columns()):
return False
if not self.same_partial_index(other):
return False
if self.is_simple_index():
# this is a special case: If the current key is neither primary or unique,
# any unique or primary key will always have the same effect
# for the index and there cannot be any constraint overlaps.
# This means a primary or unique index can always fulfill
# the requirements of just an index that has no constraints.
return True
if other.is_primary() != self.is_primary():
return False
if other.is_unique() != self.is_unique():
return False
return True | python | def is_fullfilled_by(self, other):
"""
Checks if the other index already fulfills
all the indexing and constraint needs of the current one.
:param other: The other index
:type other: Index
:rtype: bool
"""
# allow the other index to be equally large only. It being larger is an option
# but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)
if len(other.get_columns()) != len(self.get_columns()):
return False
# Check if columns are the same, and even in the same order
if not self.spans_columns(other.get_columns()):
return False
if not self.same_partial_index(other):
return False
if self.is_simple_index():
# this is a special case: If the current key is neither primary or unique,
# any unique or primary key will always have the same effect
# for the index and there cannot be any constraint overlaps.
# This means a primary or unique index can always fulfill
# the requirements of just an index that has no constraints.
return True
if other.is_primary() != self.is_primary():
return False
if other.is_unique() != self.is_unique():
return False
return True | [
"def",
"is_fullfilled_by",
"(",
"self",
",",
"other",
")",
":",
"# allow the other index to be equally large only. It being larger is an option",
"# but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)",
"if",
"len",
"(",
"other",
".",
"get_columns",
"(",
")",
")",
"!=",
"len",
"(",
"self",
".",
"get_columns",
"(",
")",
")",
":",
"return",
"False",
"# Check if columns are the same, and even in the same order",
"if",
"not",
"self",
".",
"spans_columns",
"(",
"other",
".",
"get_columns",
"(",
")",
")",
":",
"return",
"False",
"if",
"not",
"self",
".",
"same_partial_index",
"(",
"other",
")",
":",
"return",
"False",
"if",
"self",
".",
"is_simple_index",
"(",
")",
":",
"# this is a special case: If the current key is neither primary or unique,",
"# any unique or primary key will always have the same effect",
"# for the index and there cannot be any constraint overlaps.",
"# This means a primary or unique index can always fulfill",
"# the requirements of just an index that has no constraints.",
"return",
"True",
"if",
"other",
".",
"is_primary",
"(",
")",
"!=",
"self",
".",
"is_primary",
"(",
")",
":",
"return",
"False",
"if",
"other",
".",
"is_unique",
"(",
")",
"!=",
"self",
".",
"is_unique",
"(",
")",
":",
"return",
"False",
"return",
"True"
] | Checks if the other index already fulfills
all the indexing and constraint needs of the current one.
:param other: The other index
:type other: Index
:rtype: bool | [
"Checks",
"if",
"the",
"other",
"index",
"already",
"fulfills",
"all",
"the",
"indexing",
"and",
"constraint",
"needs",
"of",
"the",
"current",
"one",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L136-L172 |
231,008 | sdispater/orator | orator/dbal/index.py | Index.same_partial_index | def same_partial_index(self, other):
"""
Return whether the two indexes have the same partial index
:param other: The other index
:type other: Index
:rtype: bool
"""
if (
self.has_option("where")
and other.has_option("where")
and self.get_option("where") == other.get_option("where")
):
return True
if not self.has_option("where") and not other.has_option("where"):
return True
return False | python | def same_partial_index(self, other):
"""
Return whether the two indexes have the same partial index
:param other: The other index
:type other: Index
:rtype: bool
"""
if (
self.has_option("where")
and other.has_option("where")
and self.get_option("where") == other.get_option("where")
):
return True
if not self.has_option("where") and not other.has_option("where"):
return True
return False | [
"def",
"same_partial_index",
"(",
"self",
",",
"other",
")",
":",
"if",
"(",
"self",
".",
"has_option",
"(",
"\"where\"",
")",
"and",
"other",
".",
"has_option",
"(",
"\"where\"",
")",
"and",
"self",
".",
"get_option",
"(",
"\"where\"",
")",
"==",
"other",
".",
"get_option",
"(",
"\"where\"",
")",
")",
":",
"return",
"True",
"if",
"not",
"self",
".",
"has_option",
"(",
"\"where\"",
")",
"and",
"not",
"other",
".",
"has_option",
"(",
"\"where\"",
")",
":",
"return",
"True",
"return",
"False"
] | Return whether the two indexes have the same partial index
:param other: The other index
:type other: Index
:rtype: bool | [
"Return",
"whether",
"the",
"two",
"indexes",
"have",
"the",
"same",
"partial",
"index"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L174-L193 |
231,009 | sdispater/orator | orator/dbal/index.py | Index.overrules | def overrules(self, other):
"""
Detects if the other index is a non-unique, non primary index
that can be overwritten by this one.
:param other: The other index
:type other: Index
:rtype: bool
"""
if other.is_primary():
return False
elif self.is_simple_index() and other.is_unique():
return False
same_columns = self.spans_columns(other.get_columns())
if (
same_columns
and (self.is_primary() or self.is_unique())
and self.same_partial_index(other)
):
return True
return False | python | def overrules(self, other):
"""
Detects if the other index is a non-unique, non primary index
that can be overwritten by this one.
:param other: The other index
:type other: Index
:rtype: bool
"""
if other.is_primary():
return False
elif self.is_simple_index() and other.is_unique():
return False
same_columns = self.spans_columns(other.get_columns())
if (
same_columns
and (self.is_primary() or self.is_unique())
and self.same_partial_index(other)
):
return True
return False | [
"def",
"overrules",
"(",
"self",
",",
"other",
")",
":",
"if",
"other",
".",
"is_primary",
"(",
")",
":",
"return",
"False",
"elif",
"self",
".",
"is_simple_index",
"(",
")",
"and",
"other",
".",
"is_unique",
"(",
")",
":",
"return",
"False",
"same_columns",
"=",
"self",
".",
"spans_columns",
"(",
"other",
".",
"get_columns",
"(",
")",
")",
"if",
"(",
"same_columns",
"and",
"(",
"self",
".",
"is_primary",
"(",
")",
"or",
"self",
".",
"is_unique",
"(",
")",
")",
"and",
"self",
".",
"same_partial_index",
"(",
"other",
")",
")",
":",
"return",
"True",
"return",
"False"
] | Detects if the other index is a non-unique, non primary index
that can be overwritten by this one.
:param other: The other index
:type other: Index
:rtype: bool | [
"Detects",
"if",
"the",
"other",
"index",
"is",
"a",
"non",
"-",
"unique",
"non",
"primary",
"index",
"that",
"can",
"be",
"overwritten",
"by",
"this",
"one",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L195-L218 |
231,010 | sdispater/orator | orator/dbal/index.py | Index.remove_flag | def remove_flag(self, flag):
"""
Removes a flag.
:type flag: str
"""
if self.has_flag(flag):
del self._flags[flag.lower()] | python | def remove_flag(self, flag):
"""
Removes a flag.
:type flag: str
"""
if self.has_flag(flag):
del self._flags[flag.lower()] | [
"def",
"remove_flag",
"(",
"self",
",",
"flag",
")",
":",
"if",
"self",
".",
"has_flag",
"(",
"flag",
")",
":",
"del",
"self",
".",
"_flags",
"[",
"flag",
".",
"lower",
"(",
")",
"]"
] | Removes a flag.
:type flag: str | [
"Removes",
"a",
"flag",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L252-L259 |
231,011 | sdispater/orator | orator/schema/grammars/mysql_grammar.py | MySQLSchemaGrammar._compile_create_encoding | def _compile_create_encoding(self, sql, connection, blueprint):
"""
Append the character set specifications to a command.
:type sql: str
:type connection: orator.connections.Connection
:type blueprint: Blueprint
:rtype: str
"""
charset = blueprint.charset or connection.get_config("charset")
if charset:
sql += " DEFAULT CHARACTER SET %s" % charset
collation = blueprint.collation or connection.get_config("collation")
if collation:
sql += " COLLATE %s" % collation
return sql | python | def _compile_create_encoding(self, sql, connection, blueprint):
"""
Append the character set specifications to a command.
:type sql: str
:type connection: orator.connections.Connection
:type blueprint: Blueprint
:rtype: str
"""
charset = blueprint.charset or connection.get_config("charset")
if charset:
sql += " DEFAULT CHARACTER SET %s" % charset
collation = blueprint.collation or connection.get_config("collation")
if collation:
sql += " COLLATE %s" % collation
return sql | [
"def",
"_compile_create_encoding",
"(",
"self",
",",
"sql",
",",
"connection",
",",
"blueprint",
")",
":",
"charset",
"=",
"blueprint",
".",
"charset",
"or",
"connection",
".",
"get_config",
"(",
"\"charset\"",
")",
"if",
"charset",
":",
"sql",
"+=",
"\" DEFAULT CHARACTER SET %s\"",
"%",
"charset",
"collation",
"=",
"blueprint",
".",
"collation",
"or",
"connection",
".",
"get_config",
"(",
"\"collation\"",
")",
"if",
"collation",
":",
"sql",
"+=",
"\" COLLATE %s\"",
"%",
"collation",
"return",
"sql"
] | Append the character set specifications to a command.
:type sql: str
:type connection: orator.connections.Connection
:type blueprint: Blueprint
:rtype: str | [
"Append",
"the",
"character",
"set",
"specifications",
"to",
"a",
"command",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/mysql_grammar.py#L71-L89 |
231,012 | sdispater/orator | orator/commands/seeds/seed_command.py | SeedCommand._get_path | def _get_path(self, name):
"""
Get the destination class path.
:param name: The name
:type name: str
:rtype: str
"""
path = self.option("path")
if path is None:
path = self._get_seeders_path()
return os.path.join(path, "%s.py" % name) | python | def _get_path(self, name):
"""
Get the destination class path.
:param name: The name
:type name: str
:rtype: str
"""
path = self.option("path")
if path is None:
path = self._get_seeders_path()
return os.path.join(path, "%s.py" % name) | [
"def",
"_get_path",
"(",
"self",
",",
"name",
")",
":",
"path",
"=",
"self",
".",
"option",
"(",
"\"path\"",
")",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"self",
".",
"_get_seeders_path",
"(",
")",
"return",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"\"%s.py\"",
"%",
"name",
")"
] | Get the destination class path.
:param name: The name
:type name: str
:rtype: str | [
"Get",
"the",
"destination",
"class",
"path",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/commands/seeds/seed_command.py#L63-L76 |
231,013 | sdispater/orator | orator/orm/relations/has_one_or_many.py | HasOneOrMany.update | def update(self, _attributes=None, **attributes):
"""
Perform an update on all the related models.
:param attributes: The attributes
:type attributes: dict
:rtype: int
"""
if _attributes is not None:
attributes.update(_attributes)
if self._related.uses_timestamps():
attributes[self.get_related_updated_at()] = self._related.fresh_timestamp()
return self._query.update(attributes) | python | def update(self, _attributes=None, **attributes):
"""
Perform an update on all the related models.
:param attributes: The attributes
:type attributes: dict
:rtype: int
"""
if _attributes is not None:
attributes.update(_attributes)
if self._related.uses_timestamps():
attributes[self.get_related_updated_at()] = self._related.fresh_timestamp()
return self._query.update(attributes) | [
"def",
"update",
"(",
"self",
",",
"_attributes",
"=",
"None",
",",
"*",
"*",
"attributes",
")",
":",
"if",
"_attributes",
"is",
"not",
"None",
":",
"attributes",
".",
"update",
"(",
"_attributes",
")",
"if",
"self",
".",
"_related",
".",
"uses_timestamps",
"(",
")",
":",
"attributes",
"[",
"self",
".",
"get_related_updated_at",
"(",
")",
"]",
"=",
"self",
".",
"_related",
".",
"fresh_timestamp",
"(",
")",
"return",
"self",
".",
"_query",
".",
"update",
"(",
"attributes",
")"
] | Perform an update on all the related models.
:param attributes: The attributes
:type attributes: dict
:rtype: int | [
"Perform",
"an",
"update",
"on",
"all",
"the",
"related",
"models",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/has_one_or_many.py#L297-L312 |
231,014 | sdispater/orator | orator/utils/url.py | URL.get_dialect | def get_dialect(self):
"""Return the SQLAlchemy database dialect class corresponding
to this URL's driver name.
"""
if "+" not in self.drivername:
name = self.drivername
else:
name = self.drivername.replace("+", ".")
cls = registry.load(name)
# check for legacy dialects that
# would return a module with 'dialect' as the
# actual class
if (
hasattr(cls, "dialect")
and isinstance(cls.dialect, type)
and issubclass(cls.dialect, Dialect)
):
return cls.dialect
else:
return cls | python | def get_dialect(self):
"""Return the SQLAlchemy database dialect class corresponding
to this URL's driver name.
"""
if "+" not in self.drivername:
name = self.drivername
else:
name = self.drivername.replace("+", ".")
cls = registry.load(name)
# check for legacy dialects that
# would return a module with 'dialect' as the
# actual class
if (
hasattr(cls, "dialect")
and isinstance(cls.dialect, type)
and issubclass(cls.dialect, Dialect)
):
return cls.dialect
else:
return cls | [
"def",
"get_dialect",
"(",
"self",
")",
":",
"if",
"\"+\"",
"not",
"in",
"self",
".",
"drivername",
":",
"name",
"=",
"self",
".",
"drivername",
"else",
":",
"name",
"=",
"self",
".",
"drivername",
".",
"replace",
"(",
"\"+\"",
",",
"\".\"",
")",
"cls",
"=",
"registry",
".",
"load",
"(",
"name",
")",
"# check for legacy dialects that",
"# would return a module with 'dialect' as the",
"# actual class",
"if",
"(",
"hasattr",
"(",
"cls",
",",
"\"dialect\"",
")",
"and",
"isinstance",
"(",
"cls",
".",
"dialect",
",",
"type",
")",
"and",
"issubclass",
"(",
"cls",
".",
"dialect",
",",
"Dialect",
")",
")",
":",
"return",
"cls",
".",
"dialect",
"else",
":",
"return",
"cls"
] | Return the SQLAlchemy database dialect class corresponding
to this URL's driver name. | [
"Return",
"the",
"SQLAlchemy",
"database",
"dialect",
"class",
"corresponding",
"to",
"this",
"URL",
"s",
"driver",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/utils/url.py#L122-L142 |
231,015 | sdispater/orator | orator/utils/url.py | URL.translate_connect_args | def translate_connect_args(self, names=[], **kw):
"""Translate url attributes into a dictionary of connection arguments.
Returns attributes of this url (`host`, `database`, `username`,
`password`, `port`) as a plain dictionary. The attribute names are
used as the keys by default. Unset or false attributes are omitted
from the final dictionary.
:param \**kw: Optional, alternate key names for url attributes.
:param names: Deprecated. Same purpose as the keyword-based alternate
names, but correlates the name to the original positionally.
"""
translated = {}
attribute_names = ["host", "database", "username", "password", "port"]
for sname in attribute_names:
if names:
name = names.pop(0)
elif sname in kw:
name = kw[sname]
else:
name = sname
if name is not None and getattr(self, sname, False):
translated[name] = getattr(self, sname)
return translated | python | def translate_connect_args(self, names=[], **kw):
"""Translate url attributes into a dictionary of connection arguments.
Returns attributes of this url (`host`, `database`, `username`,
`password`, `port`) as a plain dictionary. The attribute names are
used as the keys by default. Unset or false attributes are omitted
from the final dictionary.
:param \**kw: Optional, alternate key names for url attributes.
:param names: Deprecated. Same purpose as the keyword-based alternate
names, but correlates the name to the original positionally.
"""
translated = {}
attribute_names = ["host", "database", "username", "password", "port"]
for sname in attribute_names:
if names:
name = names.pop(0)
elif sname in kw:
name = kw[sname]
else:
name = sname
if name is not None and getattr(self, sname, False):
translated[name] = getattr(self, sname)
return translated | [
"def",
"translate_connect_args",
"(",
"self",
",",
"names",
"=",
"[",
"]",
",",
"*",
"*",
"kw",
")",
":",
"translated",
"=",
"{",
"}",
"attribute_names",
"=",
"[",
"\"host\"",
",",
"\"database\"",
",",
"\"username\"",
",",
"\"password\"",
",",
"\"port\"",
"]",
"for",
"sname",
"in",
"attribute_names",
":",
"if",
"names",
":",
"name",
"=",
"names",
".",
"pop",
"(",
"0",
")",
"elif",
"sname",
"in",
"kw",
":",
"name",
"=",
"kw",
"[",
"sname",
"]",
"else",
":",
"name",
"=",
"sname",
"if",
"name",
"is",
"not",
"None",
"and",
"getattr",
"(",
"self",
",",
"sname",
",",
"False",
")",
":",
"translated",
"[",
"name",
"]",
"=",
"getattr",
"(",
"self",
",",
"sname",
")",
"return",
"translated"
] | Translate url attributes into a dictionary of connection arguments.
Returns attributes of this url (`host`, `database`, `username`,
`password`, `port`) as a plain dictionary. The attribute names are
used as the keys by default. Unset or false attributes are omitted
from the final dictionary.
:param \**kw: Optional, alternate key names for url attributes.
:param names: Deprecated. Same purpose as the keyword-based alternate
names, but correlates the name to the original positionally. | [
"Translate",
"url",
"attributes",
"into",
"a",
"dictionary",
"of",
"connection",
"arguments",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/utils/url.py#L144-L169 |
231,016 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_check_declaration_sql | def get_check_declaration_sql(self, definition):
"""
Obtains DBMS specific SQL code portion needed to set a CHECK constraint
declaration to be used in statements like CREATE TABLE.
:param definition: The check definition
:type definition: dict
:return: DBMS specific SQL code portion needed to set a CHECK constraint.
:rtype: str
"""
constraints = []
for field, def_ in definition.items():
if isinstance(def_, basestring):
constraints.append("CHECK (%s)" % def_)
else:
if "min" in def_:
constraints.append("CHECK (%s >= %s)" % (field, def_["min"]))
if "max" in def_:
constraints.append("CHECK (%s <= %s)" % (field, def_["max"]))
return ", ".join(constraints) | python | def get_check_declaration_sql(self, definition):
"""
Obtains DBMS specific SQL code portion needed to set a CHECK constraint
declaration to be used in statements like CREATE TABLE.
:param definition: The check definition
:type definition: dict
:return: DBMS specific SQL code portion needed to set a CHECK constraint.
:rtype: str
"""
constraints = []
for field, def_ in definition.items():
if isinstance(def_, basestring):
constraints.append("CHECK (%s)" % def_)
else:
if "min" in def_:
constraints.append("CHECK (%s >= %s)" % (field, def_["min"]))
if "max" in def_:
constraints.append("CHECK (%s <= %s)" % (field, def_["max"]))
return ", ".join(constraints) | [
"def",
"get_check_declaration_sql",
"(",
"self",
",",
"definition",
")",
":",
"constraints",
"=",
"[",
"]",
"for",
"field",
",",
"def_",
"in",
"definition",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"def_",
",",
"basestring",
")",
":",
"constraints",
".",
"append",
"(",
"\"CHECK (%s)\"",
"%",
"def_",
")",
"else",
":",
"if",
"\"min\"",
"in",
"def_",
":",
"constraints",
".",
"append",
"(",
"\"CHECK (%s >= %s)\"",
"%",
"(",
"field",
",",
"def_",
"[",
"\"min\"",
"]",
")",
")",
"if",
"\"max\"",
"in",
"def_",
":",
"constraints",
".",
"append",
"(",
"\"CHECK (%s <= %s)\"",
"%",
"(",
"field",
",",
"def_",
"[",
"\"max\"",
"]",
")",
")",
"return",
"\", \"",
".",
"join",
"(",
"constraints",
")"
] | Obtains DBMS specific SQL code portion needed to set a CHECK constraint
declaration to be used in statements like CREATE TABLE.
:param definition: The check definition
:type definition: dict
:return: DBMS specific SQL code portion needed to set a CHECK constraint.
:rtype: str | [
"Obtains",
"DBMS",
"specific",
"SQL",
"code",
"portion",
"needed",
"to",
"set",
"a",
"CHECK",
"constraint",
"declaration",
"to",
"be",
"used",
"in",
"statements",
"like",
"CREATE",
"TABLE",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L71-L93 |
231,017 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_unique_constraint_declaration_sql | def get_unique_constraint_declaration_sql(self, name, index):
"""
Obtains DBMS specific SQL code portion needed to set a unique
constraint declaration to be used in statements like CREATE TABLE.
:param name: The name of the unique constraint.
:type name: str
:param index: The index definition
:type index: Index
:return: DBMS specific SQL code portion needed to set a constraint.
:rtype: str
"""
columns = index.get_quoted_columns(self)
name = Identifier(name)
if not columns:
raise DBALException('Incomplete definition. "columns" required.')
return "CONSTRAINT %s UNIQUE (%s)%s" % (
name.get_quoted_name(self),
self.get_index_field_declaration_list_sql(columns),
self.get_partial_index_sql(index),
) | python | def get_unique_constraint_declaration_sql(self, name, index):
"""
Obtains DBMS specific SQL code portion needed to set a unique
constraint declaration to be used in statements like CREATE TABLE.
:param name: The name of the unique constraint.
:type name: str
:param index: The index definition
:type index: Index
:return: DBMS specific SQL code portion needed to set a constraint.
:rtype: str
"""
columns = index.get_quoted_columns(self)
name = Identifier(name)
if not columns:
raise DBALException('Incomplete definition. "columns" required.')
return "CONSTRAINT %s UNIQUE (%s)%s" % (
name.get_quoted_name(self),
self.get_index_field_declaration_list_sql(columns),
self.get_partial_index_sql(index),
) | [
"def",
"get_unique_constraint_declaration_sql",
"(",
"self",
",",
"name",
",",
"index",
")",
":",
"columns",
"=",
"index",
".",
"get_quoted_columns",
"(",
"self",
")",
"name",
"=",
"Identifier",
"(",
"name",
")",
"if",
"not",
"columns",
":",
"raise",
"DBALException",
"(",
"'Incomplete definition. \"columns\" required.'",
")",
"return",
"\"CONSTRAINT %s UNIQUE (%s)%s\"",
"%",
"(",
"name",
".",
"get_quoted_name",
"(",
"self",
")",
",",
"self",
".",
"get_index_field_declaration_list_sql",
"(",
"columns",
")",
",",
"self",
".",
"get_partial_index_sql",
"(",
"index",
")",
",",
")"
] | Obtains DBMS specific SQL code portion needed to set a unique
constraint declaration to be used in statements like CREATE TABLE.
:param name: The name of the unique constraint.
:type name: str
:param index: The index definition
:type index: Index
:return: DBMS specific SQL code portion needed to set a constraint.
:rtype: str | [
"Obtains",
"DBMS",
"specific",
"SQL",
"code",
"portion",
"needed",
"to",
"set",
"a",
"unique",
"constraint",
"declaration",
"to",
"be",
"used",
"in",
"statements",
"like",
"CREATE",
"TABLE",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L95-L119 |
231,018 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_foreign_key_declaration_sql | def get_foreign_key_declaration_sql(self, foreign_key):
"""
Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
of a field declaration to be used in statements like CREATE TABLE.
:param foreign_key: The foreign key
:type foreign_key: ForeignKeyConstraint
:rtype: str
"""
sql = self.get_foreign_key_base_declaration_sql(foreign_key)
sql += self.get_advanced_foreign_key_options_sql(foreign_key)
return sql | python | def get_foreign_key_declaration_sql(self, foreign_key):
"""
Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
of a field declaration to be used in statements like CREATE TABLE.
:param foreign_key: The foreign key
:type foreign_key: ForeignKeyConstraint
:rtype: str
"""
sql = self.get_foreign_key_base_declaration_sql(foreign_key)
sql += self.get_advanced_foreign_key_options_sql(foreign_key)
return sql | [
"def",
"get_foreign_key_declaration_sql",
"(",
"self",
",",
"foreign_key",
")",
":",
"sql",
"=",
"self",
".",
"get_foreign_key_base_declaration_sql",
"(",
"foreign_key",
")",
"sql",
"+=",
"self",
".",
"get_advanced_foreign_key_options_sql",
"(",
"foreign_key",
")",
"return",
"sql"
] | Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
of a field declaration to be used in statements like CREATE TABLE.
:param foreign_key: The foreign key
:type foreign_key: ForeignKeyConstraint
:rtype: str | [
"Obtain",
"DBMS",
"specific",
"SQL",
"code",
"portion",
"needed",
"to",
"set",
"the",
"FOREIGN",
"KEY",
"constraint",
"of",
"a",
"field",
"declaration",
"to",
"be",
"used",
"in",
"statements",
"like",
"CREATE",
"TABLE",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L148-L161 |
231,019 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_advanced_foreign_key_options_sql | def get_advanced_foreign_key_options_sql(self, foreign_key):
"""
Returns the FOREIGN KEY query section dealing with non-standard options
as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
:param foreign_key: The foreign key
:type foreign_key: ForeignKeyConstraint
:rtype: str
"""
query = ""
if self.supports_foreign_key_on_update() and foreign_key.has_option(
"on_update"
):
query += " ON UPDATE %s" % self.get_foreign_key_referential_action_sql(
foreign_key.get_option("on_update")
)
if foreign_key.has_option("on_delete"):
query += " ON DELETE %s" % self.get_foreign_key_referential_action_sql(
foreign_key.get_option("on_delete")
)
return query | python | def get_advanced_foreign_key_options_sql(self, foreign_key):
"""
Returns the FOREIGN KEY query section dealing with non-standard options
as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
:param foreign_key: The foreign key
:type foreign_key: ForeignKeyConstraint
:rtype: str
"""
query = ""
if self.supports_foreign_key_on_update() and foreign_key.has_option(
"on_update"
):
query += " ON UPDATE %s" % self.get_foreign_key_referential_action_sql(
foreign_key.get_option("on_update")
)
if foreign_key.has_option("on_delete"):
query += " ON DELETE %s" % self.get_foreign_key_referential_action_sql(
foreign_key.get_option("on_delete")
)
return query | [
"def",
"get_advanced_foreign_key_options_sql",
"(",
"self",
",",
"foreign_key",
")",
":",
"query",
"=",
"\"\"",
"if",
"self",
".",
"supports_foreign_key_on_update",
"(",
")",
"and",
"foreign_key",
".",
"has_option",
"(",
"\"on_update\"",
")",
":",
"query",
"+=",
"\" ON UPDATE %s\"",
"%",
"self",
".",
"get_foreign_key_referential_action_sql",
"(",
"foreign_key",
".",
"get_option",
"(",
"\"on_update\"",
")",
")",
"if",
"foreign_key",
".",
"has_option",
"(",
"\"on_delete\"",
")",
":",
"query",
"+=",
"\" ON DELETE %s\"",
"%",
"self",
".",
"get_foreign_key_referential_action_sql",
"(",
"foreign_key",
".",
"get_option",
"(",
"\"on_delete\"",
")",
")",
"return",
"query"
] | Returns the FOREIGN KEY query section dealing with non-standard options
as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
:param foreign_key: The foreign key
:type foreign_key: ForeignKeyConstraint
:rtype: str | [
"Returns",
"the",
"FOREIGN",
"KEY",
"query",
"section",
"dealing",
"with",
"non",
"-",
"standard",
"options",
"as",
"MATCH",
"INITIALLY",
"DEFERRED",
"ON",
"UPDATE",
"..."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L163-L186 |
231,020 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_foreign_key_referential_action_sql | def get_foreign_key_referential_action_sql(self, action):
"""
Returns the given referential action in uppercase if valid, otherwise throws an exception.
:param action: The action
:type action: str
:rtype: str
"""
action = action.upper()
if action not in [
"CASCADE",
"SET NULL",
"NO ACTION",
"RESTRICT",
"SET DEFAULT",
]:
raise DBALException("Invalid foreign key action: %s" % action)
return action | python | def get_foreign_key_referential_action_sql(self, action):
"""
Returns the given referential action in uppercase if valid, otherwise throws an exception.
:param action: The action
:type action: str
:rtype: str
"""
action = action.upper()
if action not in [
"CASCADE",
"SET NULL",
"NO ACTION",
"RESTRICT",
"SET DEFAULT",
]:
raise DBALException("Invalid foreign key action: %s" % action)
return action | [
"def",
"get_foreign_key_referential_action_sql",
"(",
"self",
",",
"action",
")",
":",
"action",
"=",
"action",
".",
"upper",
"(",
")",
"if",
"action",
"not",
"in",
"[",
"\"CASCADE\"",
",",
"\"SET NULL\"",
",",
"\"NO ACTION\"",
",",
"\"RESTRICT\"",
",",
"\"SET DEFAULT\"",
",",
"]",
":",
"raise",
"DBALException",
"(",
"\"Invalid foreign key action: %s\"",
"%",
"action",
")",
"return",
"action"
] | Returns the given referential action in uppercase if valid, otherwise throws an exception.
:param action: The action
:type action: str
:rtype: str | [
"Returns",
"the",
"given",
"referential",
"action",
"in",
"uppercase",
"if",
"valid",
"otherwise",
"throws",
"an",
"exception",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L188-L207 |
231,021 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_foreign_key_base_declaration_sql | def get_foreign_key_base_declaration_sql(self, foreign_key):
"""
Obtains DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
of a field declaration to be used in statements like CREATE TABLE.
:param foreign_key: The foreign key
:type foreign_key: ForeignKeyConstraint
:rtype: str
"""
sql = ""
if foreign_key.get_name():
sql += "CONSTRAINT %s " % foreign_key.get_quoted_name(self)
sql += "FOREIGN KEY ("
if not foreign_key.get_local_columns():
raise DBALException('Incomplete definition. "local" required.')
if not foreign_key.get_foreign_columns():
raise DBALException('Incomplete definition. "foreign" required.')
if not foreign_key.get_foreign_table_name():
raise DBALException('Incomplete definition. "foreign_table" required.')
sql += "%s) REFERENCES %s (%s)" % (
", ".join(foreign_key.get_quoted_local_columns(self)),
foreign_key.get_quoted_foreign_table_name(self),
", ".join(foreign_key.get_quoted_foreign_columns(self)),
)
return sql | python | def get_foreign_key_base_declaration_sql(self, foreign_key):
"""
Obtains DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
of a field declaration to be used in statements like CREATE TABLE.
:param foreign_key: The foreign key
:type foreign_key: ForeignKeyConstraint
:rtype: str
"""
sql = ""
if foreign_key.get_name():
sql += "CONSTRAINT %s " % foreign_key.get_quoted_name(self)
sql += "FOREIGN KEY ("
if not foreign_key.get_local_columns():
raise DBALException('Incomplete definition. "local" required.')
if not foreign_key.get_foreign_columns():
raise DBALException('Incomplete definition. "foreign" required.')
if not foreign_key.get_foreign_table_name():
raise DBALException('Incomplete definition. "foreign_table" required.')
sql += "%s) REFERENCES %s (%s)" % (
", ".join(foreign_key.get_quoted_local_columns(self)),
foreign_key.get_quoted_foreign_table_name(self),
", ".join(foreign_key.get_quoted_foreign_columns(self)),
)
return sql | [
"def",
"get_foreign_key_base_declaration_sql",
"(",
"self",
",",
"foreign_key",
")",
":",
"sql",
"=",
"\"\"",
"if",
"foreign_key",
".",
"get_name",
"(",
")",
":",
"sql",
"+=",
"\"CONSTRAINT %s \"",
"%",
"foreign_key",
".",
"get_quoted_name",
"(",
"self",
")",
"sql",
"+=",
"\"FOREIGN KEY (\"",
"if",
"not",
"foreign_key",
".",
"get_local_columns",
"(",
")",
":",
"raise",
"DBALException",
"(",
"'Incomplete definition. \"local\" required.'",
")",
"if",
"not",
"foreign_key",
".",
"get_foreign_columns",
"(",
")",
":",
"raise",
"DBALException",
"(",
"'Incomplete definition. \"foreign\" required.'",
")",
"if",
"not",
"foreign_key",
".",
"get_foreign_table_name",
"(",
")",
":",
"raise",
"DBALException",
"(",
"'Incomplete definition. \"foreign_table\" required.'",
")",
"sql",
"+=",
"\"%s) REFERENCES %s (%s)\"",
"%",
"(",
"\", \"",
".",
"join",
"(",
"foreign_key",
".",
"get_quoted_local_columns",
"(",
"self",
")",
")",
",",
"foreign_key",
".",
"get_quoted_foreign_table_name",
"(",
"self",
")",
",",
"\", \"",
".",
"join",
"(",
"foreign_key",
".",
"get_quoted_foreign_columns",
"(",
"self",
")",
")",
",",
")",
"return",
"sql"
] | Obtains DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
of a field declaration to be used in statements like CREATE TABLE.
:param foreign_key: The foreign key
:type foreign_key: ForeignKeyConstraint
:rtype: str | [
"Obtains",
"DBMS",
"specific",
"SQL",
"code",
"portion",
"needed",
"to",
"set",
"the",
"FOREIGN",
"KEY",
"constraint",
"of",
"a",
"field",
"declaration",
"to",
"be",
"used",
"in",
"statements",
"like",
"CREATE",
"TABLE",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L209-L240 |
231,022 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_column_declaration_list_sql | def get_column_declaration_list_sql(self, fields):
"""
Gets declaration of a number of fields in bulk.
"""
query_fields = []
for name, field in fields.items():
query_fields.append(self.get_column_declaration_sql(name, field))
return ", ".join(query_fields) | python | def get_column_declaration_list_sql(self, fields):
"""
Gets declaration of a number of fields in bulk.
"""
query_fields = []
for name, field in fields.items():
query_fields.append(self.get_column_declaration_sql(name, field))
return ", ".join(query_fields) | [
"def",
"get_column_declaration_list_sql",
"(",
"self",
",",
"fields",
")",
":",
"query_fields",
"=",
"[",
"]",
"for",
"name",
",",
"field",
"in",
"fields",
".",
"items",
"(",
")",
":",
"query_fields",
".",
"append",
"(",
"self",
".",
"get_column_declaration_sql",
"(",
"name",
",",
"field",
")",
")",
"return",
"\", \"",
".",
"join",
"(",
"query_fields",
")"
] | Gets declaration of a number of fields in bulk. | [
"Gets",
"declaration",
"of",
"a",
"number",
"of",
"fields",
"in",
"bulk",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L256-L265 |
231,023 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_create_index_sql | def get_create_index_sql(self, index, table):
"""
Returns the SQL to create an index on a table on this platform.
:param index: The index
:type index: Index
:param table: The table
:type table: Table or str
:rtype: str
"""
if isinstance(table, Table):
table = table.get_quoted_name(self)
name = index.get_quoted_name(self)
columns = index.get_quoted_columns(self)
if not columns:
raise DBALException('Incomplete definition. "columns" required.')
if index.is_primary():
return self.get_create_primary_key_sql(index, table)
query = "CREATE %sINDEX %s ON %s" % (
self.get_create_index_sql_flags(index),
name,
table,
)
query += " (%s)%s" % (
self.get_index_field_declaration_list_sql(columns),
self.get_partial_index_sql(index),
)
return query | python | def get_create_index_sql(self, index, table):
"""
Returns the SQL to create an index on a table on this platform.
:param index: The index
:type index: Index
:param table: The table
:type table: Table or str
:rtype: str
"""
if isinstance(table, Table):
table = table.get_quoted_name(self)
name = index.get_quoted_name(self)
columns = index.get_quoted_columns(self)
if not columns:
raise DBALException('Incomplete definition. "columns" required.')
if index.is_primary():
return self.get_create_primary_key_sql(index, table)
query = "CREATE %sINDEX %s ON %s" % (
self.get_create_index_sql_flags(index),
name,
table,
)
query += " (%s)%s" % (
self.get_index_field_declaration_list_sql(columns),
self.get_partial_index_sql(index),
)
return query | [
"def",
"get_create_index_sql",
"(",
"self",
",",
"index",
",",
"table",
")",
":",
"if",
"isinstance",
"(",
"table",
",",
"Table",
")",
":",
"table",
"=",
"table",
".",
"get_quoted_name",
"(",
"self",
")",
"name",
"=",
"index",
".",
"get_quoted_name",
"(",
"self",
")",
"columns",
"=",
"index",
".",
"get_quoted_columns",
"(",
"self",
")",
"if",
"not",
"columns",
":",
"raise",
"DBALException",
"(",
"'Incomplete definition. \"columns\" required.'",
")",
"if",
"index",
".",
"is_primary",
"(",
")",
":",
"return",
"self",
".",
"get_create_primary_key_sql",
"(",
"index",
",",
"table",
")",
"query",
"=",
"\"CREATE %sINDEX %s ON %s\"",
"%",
"(",
"self",
".",
"get_create_index_sql_flags",
"(",
"index",
")",
",",
"name",
",",
"table",
",",
")",
"query",
"+=",
"\" (%s)%s\"",
"%",
"(",
"self",
".",
"get_index_field_declaration_list_sql",
"(",
"columns",
")",
",",
"self",
".",
"get_partial_index_sql",
"(",
"index",
")",
",",
")",
"return",
"query"
] | Returns the SQL to create an index on a table on this platform.
:param index: The index
:type index: Index
:param table: The table
:type table: Table or str
:rtype: str | [
"Returns",
"the",
"SQL",
"to",
"create",
"an",
"index",
"on",
"a",
"table",
"on",
"this",
"platform",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L418-L452 |
231,024 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_create_primary_key_sql | def get_create_primary_key_sql(self, index, table):
"""
Returns the SQL to create an unnamed primary key constraint.
:param index: The index
:type index: Index
:param table: The table
:type table: Table or str
:rtype: str
"""
return "ALTER TABLE %s ADD PRIMARY KEY (%s)" % (
table,
self.get_index_field_declaration_list_sql(index.get_quoted_columns(self)),
) | python | def get_create_primary_key_sql(self, index, table):
"""
Returns the SQL to create an unnamed primary key constraint.
:param index: The index
:type index: Index
:param table: The table
:type table: Table or str
:rtype: str
"""
return "ALTER TABLE %s ADD PRIMARY KEY (%s)" % (
table,
self.get_index_field_declaration_list_sql(index.get_quoted_columns(self)),
) | [
"def",
"get_create_primary_key_sql",
"(",
"self",
",",
"index",
",",
"table",
")",
":",
"return",
"\"ALTER TABLE %s ADD PRIMARY KEY (%s)\"",
"%",
"(",
"table",
",",
"self",
".",
"get_index_field_declaration_list_sql",
"(",
"index",
".",
"get_quoted_columns",
"(",
"self",
")",
")",
",",
")"
] | Returns the SQL to create an unnamed primary key constraint.
:param index: The index
:type index: Index
:param table: The table
:type table: Table or str
:rtype: str | [
"Returns",
"the",
"SQL",
"to",
"create",
"an",
"unnamed",
"primary",
"key",
"constraint",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L482-L497 |
231,025 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_create_foreign_key_sql | def get_create_foreign_key_sql(self, foreign_key, table):
"""
Returns the SQL to create a new foreign key.
:rtype: sql
"""
if isinstance(table, Table):
table = table.get_quoted_name(self)
query = "ALTER TABLE %s ADD %s" % (
table,
self.get_foreign_key_declaration_sql(foreign_key),
)
return query | python | def get_create_foreign_key_sql(self, foreign_key, table):
"""
Returns the SQL to create a new foreign key.
:rtype: sql
"""
if isinstance(table, Table):
table = table.get_quoted_name(self)
query = "ALTER TABLE %s ADD %s" % (
table,
self.get_foreign_key_declaration_sql(foreign_key),
)
return query | [
"def",
"get_create_foreign_key_sql",
"(",
"self",
",",
"foreign_key",
",",
"table",
")",
":",
"if",
"isinstance",
"(",
"table",
",",
"Table",
")",
":",
"table",
"=",
"table",
".",
"get_quoted_name",
"(",
"self",
")",
"query",
"=",
"\"ALTER TABLE %s ADD %s\"",
"%",
"(",
"table",
",",
"self",
".",
"get_foreign_key_declaration_sql",
"(",
"foreign_key",
")",
",",
")",
"return",
"query"
] | Returns the SQL to create a new foreign key.
:rtype: sql | [
"Returns",
"the",
"SQL",
"to",
"create",
"a",
"new",
"foreign",
"key",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L499-L513 |
231,026 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_drop_table_sql | def get_drop_table_sql(self, table):
"""
Returns the SQL snippet to drop an existing table.
:param table: The table
:type table: Table or str
:rtype: str
"""
if isinstance(table, Table):
table = table.get_quoted_name(self)
return "DROP TABLE %s" % table | python | def get_drop_table_sql(self, table):
"""
Returns the SQL snippet to drop an existing table.
:param table: The table
:type table: Table or str
:rtype: str
"""
if isinstance(table, Table):
table = table.get_quoted_name(self)
return "DROP TABLE %s" % table | [
"def",
"get_drop_table_sql",
"(",
"self",
",",
"table",
")",
":",
"if",
"isinstance",
"(",
"table",
",",
"Table",
")",
":",
"table",
"=",
"table",
".",
"get_quoted_name",
"(",
"self",
")",
"return",
"\"DROP TABLE %s\"",
"%",
"table"
] | Returns the SQL snippet to drop an existing table.
:param table: The table
:type table: Table or str
:rtype: str | [
"Returns",
"the",
"SQL",
"snippet",
"to",
"drop",
"an",
"existing",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L515-L527 |
231,027 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.get_drop_index_sql | def get_drop_index_sql(self, index, table=None):
"""
Returns the SQL to drop an index from a table.
:param index: The index
:type index: Index or str
:param table: The table
:type table: Table or str or None
:rtype: str
"""
if isinstance(index, Index):
index = index.get_quoted_name(self)
return "DROP INDEX %s" % index | python | def get_drop_index_sql(self, index, table=None):
"""
Returns the SQL to drop an index from a table.
:param index: The index
:type index: Index or str
:param table: The table
:type table: Table or str or None
:rtype: str
"""
if isinstance(index, Index):
index = index.get_quoted_name(self)
return "DROP INDEX %s" % index | [
"def",
"get_drop_index_sql",
"(",
"self",
",",
"index",
",",
"table",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"index",
",",
"Index",
")",
":",
"index",
"=",
"index",
".",
"get_quoted_name",
"(",
"self",
")",
"return",
"\"DROP INDEX %s\"",
"%",
"index"
] | Returns the SQL to drop an index from a table.
:param index: The index
:type index: Index or str
:param table: The table
:type table: Table or str or None
:rtype: str | [
"Returns",
"the",
"SQL",
"to",
"drop",
"an",
"index",
"from",
"a",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L529-L544 |
231,028 | sdispater/orator | orator/dbal/platforms/platform.py | Platform._get_create_table_sql | def _get_create_table_sql(self, table_name, columns, options=None):
"""
Returns the SQL used to create a table.
:param table_name: The name of the table to create
:type table_name: str
:param columns: The table columns
:type columns: dict
:param options: The options
:type options: dict
:rtype: str
"""
options = options or {}
column_list_sql = self.get_column_declaration_list_sql(columns)
if options.get("unique_constraints"):
for name, definition in options["unique_constraints"].items():
column_list_sql += ", %s" % self.get_unique_constraint_declaration_sql(
name, definition
)
if options.get("primary"):
column_list_sql += ", PRIMARY KEY(%s)" % ", ".join(options["primary"])
if options.get("indexes"):
for index, definition in options["indexes"]:
column_list_sql += ", %s" % self.get_index_declaration_sql(
index, definition
)
query = "CREATE TABLE %s (%s" % (table_name, column_list_sql)
check = self.get_check_declaration_sql(columns)
if check:
query += ", %s" % check
query += ")"
sql = [query]
if options.get("foreign_keys"):
for definition in options["foreign_keys"]:
sql.append(self.get_create_foreign_key_sql(definition, table_name))
return sql | python | def _get_create_table_sql(self, table_name, columns, options=None):
"""
Returns the SQL used to create a table.
:param table_name: The name of the table to create
:type table_name: str
:param columns: The table columns
:type columns: dict
:param options: The options
:type options: dict
:rtype: str
"""
options = options or {}
column_list_sql = self.get_column_declaration_list_sql(columns)
if options.get("unique_constraints"):
for name, definition in options["unique_constraints"].items():
column_list_sql += ", %s" % self.get_unique_constraint_declaration_sql(
name, definition
)
if options.get("primary"):
column_list_sql += ", PRIMARY KEY(%s)" % ", ".join(options["primary"])
if options.get("indexes"):
for index, definition in options["indexes"]:
column_list_sql += ", %s" % self.get_index_declaration_sql(
index, definition
)
query = "CREATE TABLE %s (%s" % (table_name, column_list_sql)
check = self.get_check_declaration_sql(columns)
if check:
query += ", %s" % check
query += ")"
sql = [query]
if options.get("foreign_keys"):
for definition in options["foreign_keys"]:
sql.append(self.get_create_foreign_key_sql(definition, table_name))
return sql | [
"def",
"_get_create_table_sql",
"(",
"self",
",",
"table_name",
",",
"columns",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"column_list_sql",
"=",
"self",
".",
"get_column_declaration_list_sql",
"(",
"columns",
")",
"if",
"options",
".",
"get",
"(",
"\"unique_constraints\"",
")",
":",
"for",
"name",
",",
"definition",
"in",
"options",
"[",
"\"unique_constraints\"",
"]",
".",
"items",
"(",
")",
":",
"column_list_sql",
"+=",
"\", %s\"",
"%",
"self",
".",
"get_unique_constraint_declaration_sql",
"(",
"name",
",",
"definition",
")",
"if",
"options",
".",
"get",
"(",
"\"primary\"",
")",
":",
"column_list_sql",
"+=",
"\", PRIMARY KEY(%s)\"",
"%",
"\", \"",
".",
"join",
"(",
"options",
"[",
"\"primary\"",
"]",
")",
"if",
"options",
".",
"get",
"(",
"\"indexes\"",
")",
":",
"for",
"index",
",",
"definition",
"in",
"options",
"[",
"\"indexes\"",
"]",
":",
"column_list_sql",
"+=",
"\", %s\"",
"%",
"self",
".",
"get_index_declaration_sql",
"(",
"index",
",",
"definition",
")",
"query",
"=",
"\"CREATE TABLE %s (%s\"",
"%",
"(",
"table_name",
",",
"column_list_sql",
")",
"check",
"=",
"self",
".",
"get_check_declaration_sql",
"(",
"columns",
")",
"if",
"check",
":",
"query",
"+=",
"\", %s\"",
"%",
"check",
"query",
"+=",
"\")\"",
"sql",
"=",
"[",
"query",
"]",
"if",
"options",
".",
"get",
"(",
"\"foreign_keys\"",
")",
":",
"for",
"definition",
"in",
"options",
"[",
"\"foreign_keys\"",
"]",
":",
"sql",
".",
"append",
"(",
"self",
".",
"get_create_foreign_key_sql",
"(",
"definition",
",",
"table_name",
")",
")",
"return",
"sql"
] | Returns the SQL used to create a table.
:param table_name: The name of the table to create
:type table_name: str
:param columns: The table columns
:type columns: dict
:param options: The options
:type options: dict
:rtype: str | [
"Returns",
"the",
"SQL",
"used",
"to",
"create",
"a",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L605-L653 |
231,029 | sdispater/orator | orator/dbal/platforms/platform.py | Platform.quote_identifier | def quote_identifier(self, string):
"""
Quotes a string so that it can be safely used as a table or column name,
even if it is a reserved word of the platform. This also detects identifier
chains separated by dot and quotes them independently.
:param string: The identifier name to be quoted.
:type string: str
:return: The quoted identifier string.
:rtype: str
"""
if "." in string:
parts = list(map(self.quote_single_identifier, string.split(".")))
return ".".join(parts)
return self.quote_single_identifier(string) | python | def quote_identifier(self, string):
"""
Quotes a string so that it can be safely used as a table or column name,
even if it is a reserved word of the platform. This also detects identifier
chains separated by dot and quotes them independently.
:param string: The identifier name to be quoted.
:type string: str
:return: The quoted identifier string.
:rtype: str
"""
if "." in string:
parts = list(map(self.quote_single_identifier, string.split(".")))
return ".".join(parts)
return self.quote_single_identifier(string) | [
"def",
"quote_identifier",
"(",
"self",
",",
"string",
")",
":",
"if",
"\".\"",
"in",
"string",
":",
"parts",
"=",
"list",
"(",
"map",
"(",
"self",
".",
"quote_single_identifier",
",",
"string",
".",
"split",
"(",
"\".\"",
")",
")",
")",
"return",
"\".\"",
".",
"join",
"(",
"parts",
")",
"return",
"self",
".",
"quote_single_identifier",
"(",
"string",
")"
] | Quotes a string so that it can be safely used as a table or column name,
even if it is a reserved word of the platform. This also detects identifier
chains separated by dot and quotes them independently.
:param string: The identifier name to be quoted.
:type string: str
:return: The quoted identifier string.
:rtype: str | [
"Quotes",
"a",
"string",
"so",
"that",
"it",
"can",
"be",
"safely",
"used",
"as",
"a",
"table",
"or",
"column",
"name",
"even",
"if",
"it",
"is",
"a",
"reserved",
"word",
"of",
"the",
"platform",
".",
"This",
"also",
"detects",
"identifier",
"chains",
"separated",
"by",
"dot",
"and",
"quotes",
"them",
"independently",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L655-L672 |
231,030 | sdispater/orator | orator/connectors/connector.py | Connector._detect_database_platform | def _detect_database_platform(self):
"""
Detects and sets the database platform.
Evaluates custom platform class and version in order to set the correct platform.
:raises InvalidPlatformSpecified: if an invalid platform was specified for this connection.
"""
version = self._get_database_platform_version()
if version is not None:
self._platform = self._create_database_platform_for_version(version)
else:
self._platform = self.get_dbal_platform() | python | def _detect_database_platform(self):
"""
Detects and sets the database platform.
Evaluates custom platform class and version in order to set the correct platform.
:raises InvalidPlatformSpecified: if an invalid platform was specified for this connection.
"""
version = self._get_database_platform_version()
if version is not None:
self._platform = self._create_database_platform_for_version(version)
else:
self._platform = self.get_dbal_platform() | [
"def",
"_detect_database_platform",
"(",
"self",
")",
":",
"version",
"=",
"self",
".",
"_get_database_platform_version",
"(",
")",
"if",
"version",
"is",
"not",
"None",
":",
"self",
".",
"_platform",
"=",
"self",
".",
"_create_database_platform_for_version",
"(",
"version",
")",
"else",
":",
"self",
".",
"_platform",
"=",
"self",
".",
"get_dbal_platform",
"(",
")"
] | Detects and sets the database platform.
Evaluates custom platform class and version in order to set the correct platform.
:raises InvalidPlatformSpecified: if an invalid platform was specified for this connection. | [
"Detects",
"and",
"sets",
"the",
"database",
"platform",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/connectors/connector.py#L65-L78 |
231,031 | sdispater/orator | orator/pagination/paginator.py | Paginator._check_for_more_pages | def _check_for_more_pages(self):
"""
Check for more pages. The last item will be sliced off.
"""
self._has_more = len(self._items) > self.per_page
self._items = self._items[0 : self.per_page] | python | def _check_for_more_pages(self):
"""
Check for more pages. The last item will be sliced off.
"""
self._has_more = len(self._items) > self.per_page
self._items = self._items[0 : self.per_page] | [
"def",
"_check_for_more_pages",
"(",
"self",
")",
":",
"self",
".",
"_has_more",
"=",
"len",
"(",
"self",
".",
"_items",
")",
">",
"self",
".",
"per_page",
"self",
".",
"_items",
"=",
"self",
".",
"_items",
"[",
"0",
":",
"self",
".",
"per_page",
"]"
] | Check for more pages. The last item will be sliced off. | [
"Check",
"for",
"more",
"pages",
".",
"The",
"last",
"item",
"will",
"be",
"sliced",
"off",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/pagination/paginator.py#L55-L61 |
231,032 | sdispater/orator | orator/dbal/comparator.py | Comparator.diff_index | def diff_index(self, index1, index2):
"""
Finds the difference between the indexes index1 and index2.
Compares index1 with index2 and returns True if there are any
differences or False in case there are no differences.
:type index1: Index
:type index2: Index
:rtype: bool
"""
if index1.is_fullfilled_by(index2) and index2.is_fullfilled_by(index1):
return False
return True | python | def diff_index(self, index1, index2):
"""
Finds the difference between the indexes index1 and index2.
Compares index1 with index2 and returns True if there are any
differences or False in case there are no differences.
:type index1: Index
:type index2: Index
:rtype: bool
"""
if index1.is_fullfilled_by(index2) and index2.is_fullfilled_by(index1):
return False
return True | [
"def",
"diff_index",
"(",
"self",
",",
"index1",
",",
"index2",
")",
":",
"if",
"index1",
".",
"is_fullfilled_by",
"(",
"index2",
")",
"and",
"index2",
".",
"is_fullfilled_by",
"(",
"index1",
")",
":",
"return",
"False",
"return",
"True"
] | Finds the difference between the indexes index1 and index2.
Compares index1 with index2 and returns True if there are any
differences or False in case there are no differences.
:type index1: Index
:type index2: Index
:rtype: bool | [
"Finds",
"the",
"difference",
"between",
"the",
"indexes",
"index1",
"and",
"index2",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/comparator.py#L285-L300 |
231,033 | sdispater/orator | orator/seeds/seeder.py | Seeder.call | def call(self, klass):
"""
Seed the given connection from the given class.
:param klass: The Seeder class
:type klass: class
"""
self._resolve(klass).run()
if self._command:
self._command.line("<info>Seeded:</info> <fg=cyan>%s</>" % klass.__name__) | python | def call(self, klass):
"""
Seed the given connection from the given class.
:param klass: The Seeder class
:type klass: class
"""
self._resolve(klass).run()
if self._command:
self._command.line("<info>Seeded:</info> <fg=cyan>%s</>" % klass.__name__) | [
"def",
"call",
"(",
"self",
",",
"klass",
")",
":",
"self",
".",
"_resolve",
"(",
"klass",
")",
".",
"run",
"(",
")",
"if",
"self",
".",
"_command",
":",
"self",
".",
"_command",
".",
"line",
"(",
"\"<info>Seeded:</info> <fg=cyan>%s</>\"",
"%",
"klass",
".",
"__name__",
")"
] | Seed the given connection from the given class.
:param klass: The Seeder class
:type klass: class | [
"Seed",
"the",
"given",
"connection",
"from",
"the",
"given",
"class",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/seeds/seeder.py#L25-L35 |
231,034 | sdispater/orator | orator/seeds/seeder.py | Seeder._resolve | def _resolve(self, klass):
"""
Resolve an instance of the given seeder klass.
:param klass: The Seeder class
:type klass: class
"""
resolver = None
if self._resolver:
resolver = self._resolver
elif self._command:
resolver = self._command.resolver
instance = klass()
instance.set_connection_resolver(resolver)
if self._command:
instance.set_command(self._command)
return instance | python | def _resolve(self, klass):
"""
Resolve an instance of the given seeder klass.
:param klass: The Seeder class
:type klass: class
"""
resolver = None
if self._resolver:
resolver = self._resolver
elif self._command:
resolver = self._command.resolver
instance = klass()
instance.set_connection_resolver(resolver)
if self._command:
instance.set_command(self._command)
return instance | [
"def",
"_resolve",
"(",
"self",
",",
"klass",
")",
":",
"resolver",
"=",
"None",
"if",
"self",
".",
"_resolver",
":",
"resolver",
"=",
"self",
".",
"_resolver",
"elif",
"self",
".",
"_command",
":",
"resolver",
"=",
"self",
".",
"_command",
".",
"resolver",
"instance",
"=",
"klass",
"(",
")",
"instance",
".",
"set_connection_resolver",
"(",
"resolver",
")",
"if",
"self",
".",
"_command",
":",
"instance",
".",
"set_command",
"(",
"self",
".",
"_command",
")",
"return",
"instance"
] | Resolve an instance of the given seeder klass.
:param klass: The Seeder class
:type klass: class | [
"Resolve",
"an",
"instance",
"of",
"the",
"given",
"seeder",
"klass",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/seeds/seeder.py#L37-L57 |
231,035 | sdispater/orator | orator/query/builder.py | QueryBuilder.select | def select(self, *columns):
"""
Set the columns to be selected
:param columns: The columns to be selected
:type columns: tuple
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if not columns:
columns = ["*"]
self.columns = list(columns)
return self | python | def select(self, *columns):
"""
Set the columns to be selected
:param columns: The columns to be selected
:type columns: tuple
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if not columns:
columns = ["*"]
self.columns = list(columns)
return self | [
"def",
"select",
"(",
"self",
",",
"*",
"columns",
")",
":",
"if",
"not",
"columns",
":",
"columns",
"=",
"[",
"\"*\"",
"]",
"self",
".",
"columns",
"=",
"list",
"(",
"columns",
")",
"return",
"self"
] | Set the columns to be selected
:param columns: The columns to be selected
:type columns: tuple
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Set",
"the",
"columns",
"to",
"be",
"selected"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L90-L105 |
231,036 | sdispater/orator | orator/query/builder.py | QueryBuilder.select_raw | def select_raw(self, expression, bindings=None):
"""
Add a new raw select expression to the query
:param expression: The raw expression
:type expression: str
:param bindings: The expression bindings
:type bindings: list
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
self.add_select(QueryExpression(expression))
if bindings:
self.add_binding(bindings, "select")
return self | python | def select_raw(self, expression, bindings=None):
"""
Add a new raw select expression to the query
:param expression: The raw expression
:type expression: str
:param bindings: The expression bindings
:type bindings: list
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
self.add_select(QueryExpression(expression))
if bindings:
self.add_binding(bindings, "select")
return self | [
"def",
"select_raw",
"(",
"self",
",",
"expression",
",",
"bindings",
"=",
"None",
")",
":",
"self",
".",
"add_select",
"(",
"QueryExpression",
"(",
"expression",
")",
")",
"if",
"bindings",
":",
"self",
".",
"add_binding",
"(",
"bindings",
",",
"\"select\"",
")",
"return",
"self"
] | Add a new raw select expression to the query
:param expression: The raw expression
:type expression: str
:param bindings: The expression bindings
:type bindings: list
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"new",
"raw",
"select",
"expression",
"to",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L107-L125 |
231,037 | sdispater/orator | orator/query/builder.py | QueryBuilder.select_sub | def select_sub(self, query, as_):
"""
Add a subselect expression to the query
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param as_: The subselect alias
:type as_: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if isinstance(query, QueryBuilder):
bindings = query.get_bindings()
query = query.to_sql()
elif isinstance(query, basestring):
bindings = []
else:
raise ArgumentError("Invalid subselect")
return self.select_raw(
"(%s) AS %s" % (query, self._grammar.wrap(as_)), bindings
) | python | def select_sub(self, query, as_):
"""
Add a subselect expression to the query
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param as_: The subselect alias
:type as_: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if isinstance(query, QueryBuilder):
bindings = query.get_bindings()
query = query.to_sql()
elif isinstance(query, basestring):
bindings = []
else:
raise ArgumentError("Invalid subselect")
return self.select_raw(
"(%s) AS %s" % (query, self._grammar.wrap(as_)), bindings
) | [
"def",
"select_sub",
"(",
"self",
",",
"query",
",",
"as_",
")",
":",
"if",
"isinstance",
"(",
"query",
",",
"QueryBuilder",
")",
":",
"bindings",
"=",
"query",
".",
"get_bindings",
"(",
")",
"query",
"=",
"query",
".",
"to_sql",
"(",
")",
"elif",
"isinstance",
"(",
"query",
",",
"basestring",
")",
":",
"bindings",
"=",
"[",
"]",
"else",
":",
"raise",
"ArgumentError",
"(",
"\"Invalid subselect\"",
")",
"return",
"self",
".",
"select_raw",
"(",
"\"(%s) AS %s\"",
"%",
"(",
"query",
",",
"self",
".",
"_grammar",
".",
"wrap",
"(",
"as_",
")",
")",
",",
"bindings",
")"
] | Add a subselect expression to the query
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param as_: The subselect alias
:type as_: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"subselect",
"expression",
"to",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L127-L151 |
231,038 | sdispater/orator | orator/query/builder.py | QueryBuilder.add_select | def add_select(self, *column):
"""
Add a new select column to query
:param column: The column to add
:type column: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if not column:
column = []
self.columns += list(column)
return self | python | def add_select(self, *column):
"""
Add a new select column to query
:param column: The column to add
:type column: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if not column:
column = []
self.columns += list(column)
return self | [
"def",
"add_select",
"(",
"self",
",",
"*",
"column",
")",
":",
"if",
"not",
"column",
":",
"column",
"=",
"[",
"]",
"self",
".",
"columns",
"+=",
"list",
"(",
"column",
")",
"return",
"self"
] | Add a new select column to query
:param column: The column to add
:type column: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"new",
"select",
"column",
"to",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L153-L168 |
231,039 | sdispater/orator | orator/query/builder.py | QueryBuilder.left_join_where | def left_join_where(self, table, one, operator, two):
"""
Add a "left join where" clause to the query
:param table: The table to join with, can also be a JoinClause instance
:type table: str or JoinClause
:param one: The first column of the join condition
:type one: str
:param operator: The operator of the join condition
:type operator: str
:param two: The second column of the join condition
:type two: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
return self.join_where(table, one, operator, two, "left") | python | def left_join_where(self, table, one, operator, two):
"""
Add a "left join where" clause to the query
:param table: The table to join with, can also be a JoinClause instance
:type table: str or JoinClause
:param one: The first column of the join condition
:type one: str
:param operator: The operator of the join condition
:type operator: str
:param two: The second column of the join condition
:type two: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
return self.join_where(table, one, operator, two, "left") | [
"def",
"left_join_where",
"(",
"self",
",",
"table",
",",
"one",
",",
"operator",
",",
"two",
")",
":",
"return",
"self",
".",
"join_where",
"(",
"table",
",",
"one",
",",
"operator",
",",
"two",
",",
"\"left\"",
")"
] | Add a "left join where" clause to the query
:param table: The table to join with, can also be a JoinClause instance
:type table: str or JoinClause
:param one: The first column of the join condition
:type one: str
:param operator: The operator of the join condition
:type operator: str
:param two: The second column of the join condition
:type two: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"left",
"join",
"where",
"clause",
"to",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L280-L299 |
231,040 | sdispater/orator | orator/query/builder.py | QueryBuilder.right_join | def right_join(self, table, one=None, operator=None, two=None):
"""
Add a right join to the query
:param table: The table to join with, can also be a JoinClause instance
:type table: str or JoinClause
:param one: The first column of the join condition
:type one: str
:param operator: The operator of the join condition
:type operator: str
:param two: The second column of the join condition
:type two: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if isinstance(table, JoinClause):
table.type = "right"
return self.join(table, one, operator, two, "right") | python | def right_join(self, table, one=None, operator=None, two=None):
"""
Add a right join to the query
:param table: The table to join with, can also be a JoinClause instance
:type table: str or JoinClause
:param one: The first column of the join condition
:type one: str
:param operator: The operator of the join condition
:type operator: str
:param two: The second column of the join condition
:type two: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if isinstance(table, JoinClause):
table.type = "right"
return self.join(table, one, operator, two, "right") | [
"def",
"right_join",
"(",
"self",
",",
"table",
",",
"one",
"=",
"None",
",",
"operator",
"=",
"None",
",",
"two",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"table",
",",
"JoinClause",
")",
":",
"table",
".",
"type",
"=",
"\"right\"",
"return",
"self",
".",
"join",
"(",
"table",
",",
"one",
",",
"operator",
",",
"two",
",",
"\"right\"",
")"
] | Add a right join to the query
:param table: The table to join with, can also be a JoinClause instance
:type table: str or JoinClause
:param one: The first column of the join condition
:type one: str
:param operator: The operator of the join condition
:type operator: str
:param two: The second column of the join condition
:type two: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"right",
"join",
"to",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L301-L323 |
231,041 | sdispater/orator | orator/query/builder.py | QueryBuilder.right_join_where | def right_join_where(self, table, one, operator, two):
"""
Add a "right join where" clause to the query
:param table: The table to join with, can also be a JoinClause instance
:type table: str or JoinClause
:param one: The first column of the join condition
:type one: str
:param operator: The operator of the join condition
:type operator: str
:param two: The second column of the join condition
:type two: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
return self.join_where(table, one, operator, two, "right") | python | def right_join_where(self, table, one, operator, two):
"""
Add a "right join where" clause to the query
:param table: The table to join with, can also be a JoinClause instance
:type table: str or JoinClause
:param one: The first column of the join condition
:type one: str
:param operator: The operator of the join condition
:type operator: str
:param two: The second column of the join condition
:type two: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
return self.join_where(table, one, operator, two, "right") | [
"def",
"right_join_where",
"(",
"self",
",",
"table",
",",
"one",
",",
"operator",
",",
"two",
")",
":",
"return",
"self",
".",
"join_where",
"(",
"table",
",",
"one",
",",
"operator",
",",
"two",
",",
"\"right\"",
")"
] | Add a "right join where" clause to the query
:param table: The table to join with, can also be a JoinClause instance
:type table: str or JoinClause
:param one: The first column of the join condition
:type one: str
:param operator: The operator of the join condition
:type operator: str
:param two: The second column of the join condition
:type two: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"right",
"join",
"where",
"clause",
"to",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L325-L344 |
231,042 | sdispater/orator | orator/query/builder.py | QueryBuilder.group_by | def group_by(self, *columns):
"""
Add a "group by" clause to the query
:param columns: The columns to group by
:type columns: tuple
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
for column in columns:
self.groups.append(column)
return self | python | def group_by(self, *columns):
"""
Add a "group by" clause to the query
:param columns: The columns to group by
:type columns: tuple
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
for column in columns:
self.groups.append(column)
return self | [
"def",
"group_by",
"(",
"self",
",",
"*",
"columns",
")",
":",
"for",
"column",
"in",
"columns",
":",
"self",
".",
"groups",
".",
"append",
"(",
"column",
")",
"return",
"self"
] | Add a "group by" clause to the query
:param columns: The columns to group by
:type columns: tuple
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"group",
"by",
"clause",
"to",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L694-L707 |
231,043 | sdispater/orator | orator/query/builder.py | QueryBuilder.having_raw | def having_raw(self, sql, bindings=None, boolean="and"):
"""
Add a raw having clause to the query
:param sql: The raw query
:type sql: str
:param bindings: The query bindings
:type bindings: list
:param boolean: Boolean joiner type
:type boolean: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
type = "raw"
self.havings.append({"type": type, "sql": sql, "boolean": boolean})
self.add_binding(bindings, "having")
return self | python | def having_raw(self, sql, bindings=None, boolean="and"):
"""
Add a raw having clause to the query
:param sql: The raw query
:type sql: str
:param bindings: The query bindings
:type bindings: list
:param boolean: Boolean joiner type
:type boolean: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
type = "raw"
self.havings.append({"type": type, "sql": sql, "boolean": boolean})
self.add_binding(bindings, "having")
return self | [
"def",
"having_raw",
"(",
"self",
",",
"sql",
",",
"bindings",
"=",
"None",
",",
"boolean",
"=",
"\"and\"",
")",
":",
"type",
"=",
"\"raw\"",
"self",
".",
"havings",
".",
"append",
"(",
"{",
"\"type\"",
":",
"type",
",",
"\"sql\"",
":",
"sql",
",",
"\"boolean\"",
":",
"boolean",
"}",
")",
"self",
".",
"add_binding",
"(",
"bindings",
",",
"\"having\"",
")",
"return",
"self"
] | Add a raw having clause to the query
:param sql: The raw query
:type sql: str
:param bindings: The query bindings
:type bindings: list
:param boolean: Boolean joiner type
:type boolean: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"raw",
"having",
"clause",
"to",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L763-L785 |
231,044 | sdispater/orator | orator/query/builder.py | QueryBuilder.order_by | def order_by(self, column, direction="asc"):
"""
Add a "order by" clause to the query
:param column: The order by column
:type column: str
:param direction: The direction of the order
:type direction: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if self.unions:
prop = "union_orders"
else:
prop = "orders"
if direction.lower() == "asc":
direction = "asc"
else:
direction = "desc"
getattr(self, prop).append({"column": column, "direction": direction})
return self | python | def order_by(self, column, direction="asc"):
"""
Add a "order by" clause to the query
:param column: The order by column
:type column: str
:param direction: The direction of the order
:type direction: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if self.unions:
prop = "union_orders"
else:
prop = "orders"
if direction.lower() == "asc":
direction = "asc"
else:
direction = "desc"
getattr(self, prop).append({"column": column, "direction": direction})
return self | [
"def",
"order_by",
"(",
"self",
",",
"column",
",",
"direction",
"=",
"\"asc\"",
")",
":",
"if",
"self",
".",
"unions",
":",
"prop",
"=",
"\"union_orders\"",
"else",
":",
"prop",
"=",
"\"orders\"",
"if",
"direction",
".",
"lower",
"(",
")",
"==",
"\"asc\"",
":",
"direction",
"=",
"\"asc\"",
"else",
":",
"direction",
"=",
"\"desc\"",
"getattr",
"(",
"self",
",",
"prop",
")",
".",
"append",
"(",
"{",
"\"column\"",
":",
"column",
",",
"\"direction\"",
":",
"direction",
"}",
")",
"return",
"self"
] | Add a "order by" clause to the query
:param column: The order by column
:type column: str
:param direction: The direction of the order
:type direction: str
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"order",
"by",
"clause",
"to",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L802-L827 |
231,045 | sdispater/orator | orator/query/builder.py | QueryBuilder.order_by_raw | def order_by_raw(self, sql, bindings=None):
"""
Add a raw "order by" clause to the query
:param sql: The raw clause
:type sql: str
:param bindings: The bdings
:param bindings: list
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if bindings is None:
bindings = []
type = "raw"
self.orders.append({"type": type, "sql": sql})
self.add_binding(bindings, "order")
return self | python | def order_by_raw(self, sql, bindings=None):
"""
Add a raw "order by" clause to the query
:param sql: The raw clause
:type sql: str
:param bindings: The bdings
:param bindings: list
:return: The current QueryBuilder instance
:rtype: QueryBuilder
"""
if bindings is None:
bindings = []
type = "raw"
self.orders.append({"type": type, "sql": sql})
self.add_binding(bindings, "order")
return self | [
"def",
"order_by_raw",
"(",
"self",
",",
"sql",
",",
"bindings",
"=",
"None",
")",
":",
"if",
"bindings",
"is",
"None",
":",
"bindings",
"=",
"[",
"]",
"type",
"=",
"\"raw\"",
"self",
".",
"orders",
".",
"append",
"(",
"{",
"\"type\"",
":",
"type",
",",
"\"sql\"",
":",
"sql",
"}",
")",
"self",
".",
"add_binding",
"(",
"bindings",
",",
"\"order\"",
")",
"return",
"self"
] | Add a raw "order by" clause to the query
:param sql: The raw clause
:type sql: str
:param bindings: The bdings
:param bindings: list
:return: The current QueryBuilder instance
:rtype: QueryBuilder | [
"Add",
"a",
"raw",
"order",
"by",
"clause",
"to",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L855-L877 |
231,046 | sdispater/orator | orator/query/builder.py | QueryBuilder.get | def get(self, columns=None):
"""
Execute the query as a "select" statement
:param columns: The columns to get
:type columns: list
:return: The result
:rtype: Collection
"""
if not columns:
columns = ["*"]
original = self.columns
if not original:
self.columns = columns
results = self._processor.process_select(self, self._run_select())
self.columns = original
return Collection(results) | python | def get(self, columns=None):
"""
Execute the query as a "select" statement
:param columns: The columns to get
:type columns: list
:return: The result
:rtype: Collection
"""
if not columns:
columns = ["*"]
original = self.columns
if not original:
self.columns = columns
results = self._processor.process_select(self, self._run_select())
self.columns = original
return Collection(results) | [
"def",
"get",
"(",
"self",
",",
"columns",
"=",
"None",
")",
":",
"if",
"not",
"columns",
":",
"columns",
"=",
"[",
"\"*\"",
"]",
"original",
"=",
"self",
".",
"columns",
"if",
"not",
"original",
":",
"self",
".",
"columns",
"=",
"columns",
"results",
"=",
"self",
".",
"_processor",
".",
"process_select",
"(",
"self",
",",
"self",
".",
"_run_select",
"(",
")",
")",
"self",
".",
"columns",
"=",
"original",
"return",
"Collection",
"(",
"results",
")"
] | Execute the query as a "select" statement
:param columns: The columns to get
:type columns: list
:return: The result
:rtype: Collection | [
"Execute",
"the",
"query",
"as",
"a",
"select",
"statement"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1032-L1054 |
231,047 | sdispater/orator | orator/query/builder.py | QueryBuilder._run_select | def _run_select(self):
"""
Run the query as a "select" statement against the connection.
:return: The result
:rtype: list
"""
return self._connection.select(
self.to_sql(), self.get_bindings(), not self._use_write_connection
) | python | def _run_select(self):
"""
Run the query as a "select" statement against the connection.
:return: The result
:rtype: list
"""
return self._connection.select(
self.to_sql(), self.get_bindings(), not self._use_write_connection
) | [
"def",
"_run_select",
"(",
"self",
")",
":",
"return",
"self",
".",
"_connection",
".",
"select",
"(",
"self",
".",
"to_sql",
"(",
")",
",",
"self",
".",
"get_bindings",
"(",
")",
",",
"not",
"self",
".",
"_use_write_connection",
")"
] | Run the query as a "select" statement against the connection.
:return: The result
:rtype: list | [
"Run",
"the",
"query",
"as",
"a",
"select",
"statement",
"against",
"the",
"connection",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1056-L1065 |
231,048 | sdispater/orator | orator/query/builder.py | QueryBuilder.exists | def exists(self):
"""
Determine if any rows exist for the current query.
:return: Whether the rows exist or not
:rtype: bool
"""
limit = self.limit_
result = self.limit(1).count() > 0
self.limit(limit)
return result | python | def exists(self):
"""
Determine if any rows exist for the current query.
:return: Whether the rows exist or not
:rtype: bool
"""
limit = self.limit_
result = self.limit(1).count() > 0
self.limit(limit)
return result | [
"def",
"exists",
"(",
"self",
")",
":",
"limit",
"=",
"self",
".",
"limit_",
"result",
"=",
"self",
".",
"limit",
"(",
"1",
")",
".",
"count",
"(",
")",
">",
"0",
"self",
".",
"limit",
"(",
"limit",
")",
"return",
"result"
] | Determine if any rows exist for the current query.
:return: Whether the rows exist or not
:rtype: bool | [
"Determine",
"if",
"any",
"rows",
"exist",
"for",
"the",
"current",
"query",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1229-L1242 |
231,049 | sdispater/orator | orator/query/builder.py | QueryBuilder.count | def count(self, *columns):
"""
Retrieve the "count" result of the query
:param columns: The columns to get
:type columns: tuple
:return: The count
:rtype: int
"""
if not columns and self.distinct_:
columns = self.columns
if not columns:
columns = ["*"]
return int(self.aggregate("count", *columns)) | python | def count(self, *columns):
"""
Retrieve the "count" result of the query
:param columns: The columns to get
:type columns: tuple
:return: The count
:rtype: int
"""
if not columns and self.distinct_:
columns = self.columns
if not columns:
columns = ["*"]
return int(self.aggregate("count", *columns)) | [
"def",
"count",
"(",
"self",
",",
"*",
"columns",
")",
":",
"if",
"not",
"columns",
"and",
"self",
".",
"distinct_",
":",
"columns",
"=",
"self",
".",
"columns",
"if",
"not",
"columns",
":",
"columns",
"=",
"[",
"\"*\"",
"]",
"return",
"int",
"(",
"self",
".",
"aggregate",
"(",
"\"count\"",
",",
"*",
"columns",
")",
")"
] | Retrieve the "count" result of the query
:param columns: The columns to get
:type columns: tuple
:return: The count
:rtype: int | [
"Retrieve",
"the",
"count",
"result",
"of",
"the",
"query"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1244-L1260 |
231,050 | sdispater/orator | orator/query/builder.py | QueryBuilder.aggregate | def aggregate(self, func, *columns):
"""
Execute an aggregate function against the database
:param func: The aggregate function
:type func: str
:param columns: The columns to execute the fnction for
:type columns: tuple
:return: The aggregate result
:rtype: mixed
"""
if not columns:
columns = ["*"]
self.aggregate_ = {"function": func, "columns": columns}
previous_columns = self.columns
results = self.get(*columns).all()
self.aggregate_ = None
self.columns = previous_columns
if len(results) > 0:
return dict((k.lower(), v) for k, v in results[0].items())["aggregate"] | python | def aggregate(self, func, *columns):
"""
Execute an aggregate function against the database
:param func: The aggregate function
:type func: str
:param columns: The columns to execute the fnction for
:type columns: tuple
:return: The aggregate result
:rtype: mixed
"""
if not columns:
columns = ["*"]
self.aggregate_ = {"function": func, "columns": columns}
previous_columns = self.columns
results = self.get(*columns).all()
self.aggregate_ = None
self.columns = previous_columns
if len(results) > 0:
return dict((k.lower(), v) for k, v in results[0].items())["aggregate"] | [
"def",
"aggregate",
"(",
"self",
",",
"func",
",",
"*",
"columns",
")",
":",
"if",
"not",
"columns",
":",
"columns",
"=",
"[",
"\"*\"",
"]",
"self",
".",
"aggregate_",
"=",
"{",
"\"function\"",
":",
"func",
",",
"\"columns\"",
":",
"columns",
"}",
"previous_columns",
"=",
"self",
".",
"columns",
"results",
"=",
"self",
".",
"get",
"(",
"*",
"columns",
")",
".",
"all",
"(",
")",
"self",
".",
"aggregate_",
"=",
"None",
"self",
".",
"columns",
"=",
"previous_columns",
"if",
"len",
"(",
"results",
")",
">",
"0",
":",
"return",
"dict",
"(",
"(",
"k",
".",
"lower",
"(",
")",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"results",
"[",
"0",
"]",
".",
"items",
"(",
")",
")",
"[",
"\"aggregate\"",
"]"
] | Execute an aggregate function against the database
:param func: The aggregate function
:type func: str
:param columns: The columns to execute the fnction for
:type columns: tuple
:return: The aggregate result
:rtype: mixed | [
"Execute",
"an",
"aggregate",
"function",
"against",
"the",
"database"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1314-L1341 |
231,051 | sdispater/orator | orator/query/builder.py | QueryBuilder.insert | def insert(self, _values=None, **values):
"""
Insert a new record into the database
:param _values: The new record values
:type _values: dict or list
:param values: The new record values as keyword arguments
:type values: dict
:return: The result
:rtype: bool
"""
if not values and not _values:
return True
if not isinstance(_values, list):
if _values is not None:
values.update(_values)
values = [values]
else:
values = _values
for i, value in enumerate(values):
values[i] = OrderedDict(sorted(value.items()))
bindings = []
for record in values:
for value in record.values():
bindings.append(value)
sql = self._grammar.compile_insert(self, values)
bindings = self._clean_bindings(bindings)
return self._connection.insert(sql, bindings) | python | def insert(self, _values=None, **values):
"""
Insert a new record into the database
:param _values: The new record values
:type _values: dict or list
:param values: The new record values as keyword arguments
:type values: dict
:return: The result
:rtype: bool
"""
if not values and not _values:
return True
if not isinstance(_values, list):
if _values is not None:
values.update(_values)
values = [values]
else:
values = _values
for i, value in enumerate(values):
values[i] = OrderedDict(sorted(value.items()))
bindings = []
for record in values:
for value in record.values():
bindings.append(value)
sql = self._grammar.compile_insert(self, values)
bindings = self._clean_bindings(bindings)
return self._connection.insert(sql, bindings) | [
"def",
"insert",
"(",
"self",
",",
"_values",
"=",
"None",
",",
"*",
"*",
"values",
")",
":",
"if",
"not",
"values",
"and",
"not",
"_values",
":",
"return",
"True",
"if",
"not",
"isinstance",
"(",
"_values",
",",
"list",
")",
":",
"if",
"_values",
"is",
"not",
"None",
":",
"values",
".",
"update",
"(",
"_values",
")",
"values",
"=",
"[",
"values",
"]",
"else",
":",
"values",
"=",
"_values",
"for",
"i",
",",
"value",
"in",
"enumerate",
"(",
"values",
")",
":",
"values",
"[",
"i",
"]",
"=",
"OrderedDict",
"(",
"sorted",
"(",
"value",
".",
"items",
"(",
")",
")",
")",
"bindings",
"=",
"[",
"]",
"for",
"record",
"in",
"values",
":",
"for",
"value",
"in",
"record",
".",
"values",
"(",
")",
":",
"bindings",
".",
"append",
"(",
"value",
")",
"sql",
"=",
"self",
".",
"_grammar",
".",
"compile_insert",
"(",
"self",
",",
"values",
")",
"bindings",
"=",
"self",
".",
"_clean_bindings",
"(",
"bindings",
")",
"return",
"self",
".",
"_connection",
".",
"insert",
"(",
"sql",
",",
"bindings",
")"
] | Insert a new record into the database
:param _values: The new record values
:type _values: dict or list
:param values: The new record values as keyword arguments
:type values: dict
:return: The result
:rtype: bool | [
"Insert",
"a",
"new",
"record",
"into",
"the",
"database"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1343-L1379 |
231,052 | sdispater/orator | orator/query/builder.py | QueryBuilder.insert_get_id | def insert_get_id(self, values, sequence=None):
"""
Insert a new record and get the value of the primary key
:param values: The new record values
:type values: dict
:param sequence: The name of the primary key
:type sequence: str
:return: The value of the primary key
:rtype: int
"""
values = OrderedDict(sorted(values.items()))
sql = self._grammar.compile_insert_get_id(self, values, sequence)
values = self._clean_bindings(values.values())
return self._processor.process_insert_get_id(self, sql, values, sequence) | python | def insert_get_id(self, values, sequence=None):
"""
Insert a new record and get the value of the primary key
:param values: The new record values
:type values: dict
:param sequence: The name of the primary key
:type sequence: str
:return: The value of the primary key
:rtype: int
"""
values = OrderedDict(sorted(values.items()))
sql = self._grammar.compile_insert_get_id(self, values, sequence)
values = self._clean_bindings(values.values())
return self._processor.process_insert_get_id(self, sql, values, sequence) | [
"def",
"insert_get_id",
"(",
"self",
",",
"values",
",",
"sequence",
"=",
"None",
")",
":",
"values",
"=",
"OrderedDict",
"(",
"sorted",
"(",
"values",
".",
"items",
"(",
")",
")",
")",
"sql",
"=",
"self",
".",
"_grammar",
".",
"compile_insert_get_id",
"(",
"self",
",",
"values",
",",
"sequence",
")",
"values",
"=",
"self",
".",
"_clean_bindings",
"(",
"values",
".",
"values",
"(",
")",
")",
"return",
"self",
".",
"_processor",
".",
"process_insert_get_id",
"(",
"self",
",",
"sql",
",",
"values",
",",
"sequence",
")"
] | Insert a new record and get the value of the primary key
:param values: The new record values
:type values: dict
:param sequence: The name of the primary key
:type sequence: str
:return: The value of the primary key
:rtype: int | [
"Insert",
"a",
"new",
"record",
"and",
"get",
"the",
"value",
"of",
"the",
"primary",
"key"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1381-L1400 |
231,053 | sdispater/orator | orator/query/builder.py | QueryBuilder.truncate | def truncate(self):
"""
Run a truncate statement on the table
:rtype: None
"""
for sql, bindings in self._grammar.compile_truncate(self).items():
self._connection.statement(sql, bindings) | python | def truncate(self):
"""
Run a truncate statement on the table
:rtype: None
"""
for sql, bindings in self._grammar.compile_truncate(self).items():
self._connection.statement(sql, bindings) | [
"def",
"truncate",
"(",
"self",
")",
":",
"for",
"sql",
",",
"bindings",
"in",
"self",
".",
"_grammar",
".",
"compile_truncate",
"(",
"self",
")",
".",
"items",
"(",
")",
":",
"self",
".",
"_connection",
".",
"statement",
"(",
"sql",
",",
"bindings",
")"
] | Run a truncate statement on the table
:rtype: None | [
"Run",
"a",
"truncate",
"statement",
"on",
"the",
"table"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1492-L1499 |
231,054 | sdispater/orator | orator/query/builder.py | QueryBuilder._clean_bindings | def _clean_bindings(self, bindings):
"""
Remove all of the expressions from bindings
:param bindings: The bindings to clean
:type bindings: list
:return: The cleaned bindings
:rtype: list
"""
return list(filter(lambda b: not isinstance(b, QueryExpression), bindings)) | python | def _clean_bindings(self, bindings):
"""
Remove all of the expressions from bindings
:param bindings: The bindings to clean
:type bindings: list
:return: The cleaned bindings
:rtype: list
"""
return list(filter(lambda b: not isinstance(b, QueryExpression), bindings)) | [
"def",
"_clean_bindings",
"(",
"self",
",",
"bindings",
")",
":",
"return",
"list",
"(",
"filter",
"(",
"lambda",
"b",
":",
"not",
"isinstance",
"(",
"b",
",",
"QueryExpression",
")",
",",
"bindings",
")",
")"
] | Remove all of the expressions from bindings
:param bindings: The bindings to clean
:type bindings: list
:return: The cleaned bindings
:rtype: list | [
"Remove",
"all",
"of",
"the",
"expressions",
"from",
"bindings"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1525-L1535 |
231,055 | sdispater/orator | orator/query/builder.py | QueryBuilder.merge | def merge(self, query):
"""
Merge current query with another.
:param query: The query to merge with
:type query: QueryBuilder
"""
self.columns += query.columns
self.joins += query.joins
self.wheres += query.wheres
self.groups += query.groups
self.havings += query.havings
self.orders += query.orders
self.distinct_ = query.distinct_
if self.columns:
self.columns = Collection(self.columns).unique().all()
if query.limit_:
self.limit_ = query.limit_
if query.offset_:
self.offset_ = None
self.unions += query.unions
if query.union_limit:
self.union_limit = query.union_limit
if query.union_offset:
self.union_offset = query.union_offset
self.union_orders += query.union_orders
self.merge_bindings(query) | python | def merge(self, query):
"""
Merge current query with another.
:param query: The query to merge with
:type query: QueryBuilder
"""
self.columns += query.columns
self.joins += query.joins
self.wheres += query.wheres
self.groups += query.groups
self.havings += query.havings
self.orders += query.orders
self.distinct_ = query.distinct_
if self.columns:
self.columns = Collection(self.columns).unique().all()
if query.limit_:
self.limit_ = query.limit_
if query.offset_:
self.offset_ = None
self.unions += query.unions
if query.union_limit:
self.union_limit = query.union_limit
if query.union_offset:
self.union_offset = query.union_offset
self.union_orders += query.union_orders
self.merge_bindings(query) | [
"def",
"merge",
"(",
"self",
",",
"query",
")",
":",
"self",
".",
"columns",
"+=",
"query",
".",
"columns",
"self",
".",
"joins",
"+=",
"query",
".",
"joins",
"self",
".",
"wheres",
"+=",
"query",
".",
"wheres",
"self",
".",
"groups",
"+=",
"query",
".",
"groups",
"self",
".",
"havings",
"+=",
"query",
".",
"havings",
"self",
".",
"orders",
"+=",
"query",
".",
"orders",
"self",
".",
"distinct_",
"=",
"query",
".",
"distinct_",
"if",
"self",
".",
"columns",
":",
"self",
".",
"columns",
"=",
"Collection",
"(",
"self",
".",
"columns",
")",
".",
"unique",
"(",
")",
".",
"all",
"(",
")",
"if",
"query",
".",
"limit_",
":",
"self",
".",
"limit_",
"=",
"query",
".",
"limit_",
"if",
"query",
".",
"offset_",
":",
"self",
".",
"offset_",
"=",
"None",
"self",
".",
"unions",
"+=",
"query",
".",
"unions",
"if",
"query",
".",
"union_limit",
":",
"self",
".",
"union_limit",
"=",
"query",
".",
"union_limit",
"if",
"query",
".",
"union_offset",
":",
"self",
".",
"union_offset",
"=",
"query",
".",
"union_offset",
"self",
".",
"union_orders",
"+=",
"query",
".",
"union_orders",
"self",
".",
"merge_bindings",
"(",
"query",
")"
] | Merge current query with another.
:param query: The query to merge with
:type query: QueryBuilder | [
"Merge",
"current",
"query",
"with",
"another",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L1590-L1624 |
231,056 | sdispater/orator | orator/dbal/abstract_asset.py | AbstractAsset._set_name | def _set_name(self, name):
"""
Sets the name of this asset.
:param name: The name of the asset
:type name: str
"""
if self._is_identifier_quoted(name):
self._quoted = True
name = self._trim_quotes(name)
if "." in name:
parts = name.split(".", 1)
self._namespace = parts[0]
name = parts[1]
self._name = name | python | def _set_name(self, name):
"""
Sets the name of this asset.
:param name: The name of the asset
:type name: str
"""
if self._is_identifier_quoted(name):
self._quoted = True
name = self._trim_quotes(name)
if "." in name:
parts = name.split(".", 1)
self._namespace = parts[0]
name = parts[1]
self._name = name | [
"def",
"_set_name",
"(",
"self",
",",
"name",
")",
":",
"if",
"self",
".",
"_is_identifier_quoted",
"(",
"name",
")",
":",
"self",
".",
"_quoted",
"=",
"True",
"name",
"=",
"self",
".",
"_trim_quotes",
"(",
"name",
")",
"if",
"\".\"",
"in",
"name",
":",
"parts",
"=",
"name",
".",
"split",
"(",
"\".\"",
",",
"1",
")",
"self",
".",
"_namespace",
"=",
"parts",
"[",
"0",
"]",
"name",
"=",
"parts",
"[",
"1",
"]",
"self",
".",
"_name",
"=",
"name"
] | Sets the name of this asset.
:param name: The name of the asset
:type name: str | [
"Sets",
"the",
"name",
"of",
"this",
"asset",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/abstract_asset.py#L16-L32 |
231,057 | sdispater/orator | orator/dbal/abstract_asset.py | AbstractAsset._generate_identifier_name | def _generate_identifier_name(self, columns, prefix="", max_size=30):
"""
Generates an identifier from a list of column names obeying a certain string length.
"""
hash = ""
for column in columns:
hash += "%x" % binascii.crc32(encode(str(column)))
return (prefix + "_" + hash)[:max_size] | python | def _generate_identifier_name(self, columns, prefix="", max_size=30):
"""
Generates an identifier from a list of column names obeying a certain string length.
"""
hash = ""
for column in columns:
hash += "%x" % binascii.crc32(encode(str(column)))
return (prefix + "_" + hash)[:max_size] | [
"def",
"_generate_identifier_name",
"(",
"self",
",",
"columns",
",",
"prefix",
"=",
"\"\"",
",",
"max_size",
"=",
"30",
")",
":",
"hash",
"=",
"\"\"",
"for",
"column",
"in",
"columns",
":",
"hash",
"+=",
"\"%x\"",
"%",
"binascii",
".",
"crc32",
"(",
"encode",
"(",
"str",
"(",
"column",
")",
")",
")",
"return",
"(",
"prefix",
"+",
"\"_\"",
"+",
"hash",
")",
"[",
":",
"max_size",
"]"
] | Generates an identifier from a list of column names obeying a certain string length. | [
"Generates",
"an",
"identifier",
"from",
"a",
"list",
"of",
"column",
"names",
"obeying",
"a",
"certain",
"string",
"length",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/abstract_asset.py#L80-L88 |
231,058 | sdispater/orator | orator/orm/mixins/soft_deletes.py | SoftDeletes.only_trashed | def only_trashed(cls):
"""
Get a new query builder that only includes soft deletes
:type cls: orator.orm.model.Model
:rtype: orator.orm.builder.Builder
"""
instance = cls()
column = instance.get_qualified_deleted_at_column()
return instance.new_query_without_scope(SoftDeletingScope()).where_not_null(
column
) | python | def only_trashed(cls):
"""
Get a new query builder that only includes soft deletes
:type cls: orator.orm.model.Model
:rtype: orator.orm.builder.Builder
"""
instance = cls()
column = instance.get_qualified_deleted_at_column()
return instance.new_query_without_scope(SoftDeletingScope()).where_not_null(
column
) | [
"def",
"only_trashed",
"(",
"cls",
")",
":",
"instance",
"=",
"cls",
"(",
")",
"column",
"=",
"instance",
".",
"get_qualified_deleted_at_column",
"(",
")",
"return",
"instance",
".",
"new_query_without_scope",
"(",
"SoftDeletingScope",
"(",
")",
")",
".",
"where_not_null",
"(",
"column",
")"
] | Get a new query builder that only includes soft deletes
:type cls: orator.orm.model.Model
:rtype: orator.orm.builder.Builder | [
"Get",
"a",
"new",
"query",
"builder",
"that",
"only",
"includes",
"soft",
"deletes"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/mixins/soft_deletes.py#L92-L106 |
231,059 | sdispater/orator | orator/database_manager.py | BaseDatabaseManager.connection | def connection(self, name=None):
"""
Get a database connection instance
:param name: The connection name
:type name: str
:return: A Connection instance
:rtype: orator.connections.connection.Connection
"""
name, type = self._parse_connection_name(name)
if name not in self._connections:
logger.debug("Initiating connection %s" % name)
connection = self._make_connection(name)
self._set_connection_for_type(connection, type)
self._connections[name] = self._prepare(connection)
return self._connections[name] | python | def connection(self, name=None):
"""
Get a database connection instance
:param name: The connection name
:type name: str
:return: A Connection instance
:rtype: orator.connections.connection.Connection
"""
name, type = self._parse_connection_name(name)
if name not in self._connections:
logger.debug("Initiating connection %s" % name)
connection = self._make_connection(name)
self._set_connection_for_type(connection, type)
self._connections[name] = self._prepare(connection)
return self._connections[name] | [
"def",
"connection",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"name",
",",
"type",
"=",
"self",
".",
"_parse_connection_name",
"(",
"name",
")",
"if",
"name",
"not",
"in",
"self",
".",
"_connections",
":",
"logger",
".",
"debug",
"(",
"\"Initiating connection %s\"",
"%",
"name",
")",
"connection",
"=",
"self",
".",
"_make_connection",
"(",
"name",
")",
"self",
".",
"_set_connection_for_type",
"(",
"connection",
",",
"type",
")",
"self",
".",
"_connections",
"[",
"name",
"]",
"=",
"self",
".",
"_prepare",
"(",
"connection",
")",
"return",
"self",
".",
"_connections",
"[",
"name",
"]"
] | Get a database connection instance
:param name: The connection name
:type name: str
:return: A Connection instance
:rtype: orator.connections.connection.Connection | [
"Get",
"a",
"database",
"connection",
"instance"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/database_manager.py#L28-L48 |
231,060 | sdispater/orator | orator/orm/scopes/soft_deleting.py | SoftDeletingScope.apply | def apply(self, builder, model):
"""
Apply the scope to a given query builder.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
:param model: The model
:type model: orator.orm.Model
"""
builder.where_null(model.get_qualified_deleted_at_column())
self.extend(builder) | python | def apply(self, builder, model):
"""
Apply the scope to a given query builder.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
:param model: The model
:type model: orator.orm.Model
"""
builder.where_null(model.get_qualified_deleted_at_column())
self.extend(builder) | [
"def",
"apply",
"(",
"self",
",",
"builder",
",",
"model",
")",
":",
"builder",
".",
"where_null",
"(",
"model",
".",
"get_qualified_deleted_at_column",
"(",
")",
")",
"self",
".",
"extend",
"(",
"builder",
")"
] | Apply the scope to a given query builder.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
:param model: The model
:type model: orator.orm.Model | [
"Apply",
"the",
"scope",
"to",
"a",
"given",
"query",
"builder",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/scopes/soft_deleting.py#L10-L22 |
231,061 | sdispater/orator | orator/orm/scopes/soft_deleting.py | SoftDeletingScope._on_delete | def _on_delete(self, builder):
"""
The delete replacement function.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
"""
column = self._get_deleted_at_column(builder)
return builder.update({column: builder.get_model().fresh_timestamp()}) | python | def _on_delete(self, builder):
"""
The delete replacement function.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
"""
column = self._get_deleted_at_column(builder)
return builder.update({column: builder.get_model().fresh_timestamp()}) | [
"def",
"_on_delete",
"(",
"self",
",",
"builder",
")",
":",
"column",
"=",
"self",
".",
"_get_deleted_at_column",
"(",
"builder",
")",
"return",
"builder",
".",
"update",
"(",
"{",
"column",
":",
"builder",
".",
"get_model",
"(",
")",
".",
"fresh_timestamp",
"(",
")",
"}",
")"
] | The delete replacement function.
:param builder: The query builder
:type builder: orator.orm.builder.Builder | [
"The",
"delete",
"replacement",
"function",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/scopes/soft_deleting.py#L36-L45 |
231,062 | sdispater/orator | orator/orm/scopes/soft_deleting.py | SoftDeletingScope._get_deleted_at_column | def _get_deleted_at_column(self, builder):
"""
Get the "deleted at" column for the builder.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
:rtype: str
"""
if len(builder.get_query().joins) > 0:
return builder.get_model().get_qualified_deleted_at_column()
else:
return builder.get_model().get_deleted_at_column() | python | def _get_deleted_at_column(self, builder):
"""
Get the "deleted at" column for the builder.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
:rtype: str
"""
if len(builder.get_query().joins) > 0:
return builder.get_model().get_qualified_deleted_at_column()
else:
return builder.get_model().get_deleted_at_column() | [
"def",
"_get_deleted_at_column",
"(",
"self",
",",
"builder",
")",
":",
"if",
"len",
"(",
"builder",
".",
"get_query",
"(",
")",
".",
"joins",
")",
">",
"0",
":",
"return",
"builder",
".",
"get_model",
"(",
")",
".",
"get_qualified_deleted_at_column",
"(",
")",
"else",
":",
"return",
"builder",
".",
"get_model",
"(",
")",
".",
"get_deleted_at_column",
"(",
")"
] | Get the "deleted at" column for the builder.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
:rtype: str | [
"Get",
"the",
"deleted",
"at",
"column",
"for",
"the",
"builder",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/scopes/soft_deleting.py#L47-L59 |
231,063 | sdispater/orator | orator/orm/scopes/soft_deleting.py | SoftDeletingScope._restore | def _restore(self, builder):
"""
The restore extension.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
"""
builder.with_trashed()
return builder.update({builder.get_model().get_deleted_at_column(): None}) | python | def _restore(self, builder):
"""
The restore extension.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
"""
builder.with_trashed()
return builder.update({builder.get_model().get_deleted_at_column(): None}) | [
"def",
"_restore",
"(",
"self",
",",
"builder",
")",
":",
"builder",
".",
"with_trashed",
"(",
")",
"return",
"builder",
".",
"update",
"(",
"{",
"builder",
".",
"get_model",
"(",
")",
".",
"get_deleted_at_column",
"(",
")",
":",
"None",
"}",
")"
] | The restore extension.
:param builder: The query builder
:type builder: orator.orm.builder.Builder | [
"The",
"restore",
"extension",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/scopes/soft_deleting.py#L88-L97 |
231,064 | sdispater/orator | orator/schema/builder.py | SchemaBuilder.has_table | def has_table(self, table):
"""
Determine if the given table exists.
:param table: The table
:type table: str
:rtype: bool
"""
sql = self._grammar.compile_table_exists()
table = self._connection.get_table_prefix() + table
return len(self._connection.select(sql, [table])) > 0 | python | def has_table(self, table):
"""
Determine if the given table exists.
:param table: The table
:type table: str
:rtype: bool
"""
sql = self._grammar.compile_table_exists()
table = self._connection.get_table_prefix() + table
return len(self._connection.select(sql, [table])) > 0 | [
"def",
"has_table",
"(",
"self",
",",
"table",
")",
":",
"sql",
"=",
"self",
".",
"_grammar",
".",
"compile_table_exists",
"(",
")",
"table",
"=",
"self",
".",
"_connection",
".",
"get_table_prefix",
"(",
")",
"+",
"table",
"return",
"len",
"(",
"self",
".",
"_connection",
".",
"select",
"(",
"sql",
",",
"[",
"table",
"]",
")",
")",
">",
"0"
] | Determine if the given table exists.
:param table: The table
:type table: str
:rtype: bool | [
"Determine",
"if",
"the",
"given",
"table",
"exists",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/builder.py#L16-L29 |
231,065 | sdispater/orator | orator/schema/builder.py | SchemaBuilder.has_column | def has_column(self, table, column):
"""
Determine if the given table has a given column.
:param table: The table
:type table: str
:type column: str
:rtype: bool
"""
column = column.lower()
return column in list(map(lambda x: x.lower(), self.get_column_listing(table))) | python | def has_column(self, table, column):
"""
Determine if the given table has a given column.
:param table: The table
:type table: str
:type column: str
:rtype: bool
"""
column = column.lower()
return column in list(map(lambda x: x.lower(), self.get_column_listing(table))) | [
"def",
"has_column",
"(",
"self",
",",
"table",
",",
"column",
")",
":",
"column",
"=",
"column",
".",
"lower",
"(",
")",
"return",
"column",
"in",
"list",
"(",
"map",
"(",
"lambda",
"x",
":",
"x",
".",
"lower",
"(",
")",
",",
"self",
".",
"get_column_listing",
"(",
"table",
")",
")",
")"
] | Determine if the given table has a given column.
:param table: The table
:type table: str
:type column: str
:rtype: bool | [
"Determine",
"if",
"the",
"given",
"table",
"has",
"a",
"given",
"column",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/builder.py#L31-L44 |
231,066 | sdispater/orator | orator/schema/builder.py | SchemaBuilder.table | def table(self, table):
"""
Modify a table on the schema.
:param table: The table
"""
try:
blueprint = self._create_blueprint(table)
yield blueprint
except Exception as e:
raise
try:
self._build(blueprint)
except Exception:
raise | python | def table(self, table):
"""
Modify a table on the schema.
:param table: The table
"""
try:
blueprint = self._create_blueprint(table)
yield blueprint
except Exception as e:
raise
try:
self._build(blueprint)
except Exception:
raise | [
"def",
"table",
"(",
"self",
",",
"table",
")",
":",
"try",
":",
"blueprint",
"=",
"self",
".",
"_create_blueprint",
"(",
"table",
")",
"yield",
"blueprint",
"except",
"Exception",
"as",
"e",
":",
"raise",
"try",
":",
"self",
".",
"_build",
"(",
"blueprint",
")",
"except",
"Exception",
":",
"raise"
] | Modify a table on the schema.
:param table: The table | [
"Modify",
"a",
"table",
"on",
"the",
"schema",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/builder.py#L62-L78 |
231,067 | sdispater/orator | orator/schema/builder.py | SchemaBuilder.rename | def rename(self, from_, to):
"""
Rename a table on the schema.
"""
blueprint = self._create_blueprint(from_)
blueprint.rename(to)
self._build(blueprint) | python | def rename(self, from_, to):
"""
Rename a table on the schema.
"""
blueprint = self._create_blueprint(from_)
blueprint.rename(to)
self._build(blueprint) | [
"def",
"rename",
"(",
"self",
",",
"from_",
",",
"to",
")",
":",
"blueprint",
"=",
"self",
".",
"_create_blueprint",
"(",
"from_",
")",
"blueprint",
".",
"rename",
"(",
"to",
")",
"self",
".",
"_build",
"(",
"blueprint",
")"
] | Rename a table on the schema. | [
"Rename",
"a",
"table",
"on",
"the",
"schema",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/builder.py#L129-L137 |
231,068 | sdispater/orator | orator/commands/migrations/make_command.py | MigrateMakeCommand._write_migration | def _write_migration(self, creator, name, table, create, path):
"""
Write the migration file to disk.
"""
file_ = os.path.basename(creator.create(name, path, table, create))
return file_ | python | def _write_migration(self, creator, name, table, create, path):
"""
Write the migration file to disk.
"""
file_ = os.path.basename(creator.create(name, path, table, create))
return file_ | [
"def",
"_write_migration",
"(",
"self",
",",
"creator",
",",
"name",
",",
"table",
",",
"create",
",",
"path",
")",
":",
"file_",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"creator",
".",
"create",
"(",
"name",
",",
"path",
",",
"table",
",",
"create",
")",
")",
"return",
"file_"
] | Write the migration file to disk. | [
"Write",
"the",
"migration",
"file",
"to",
"disk",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/commands/migrations/make_command.py#L42-L48 |
231,069 | sdispater/orator | orator/query/grammars/mysql_grammar.py | MySQLQueryGrammar.compile_delete | def compile_delete(self, query):
"""
Compile a delete statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled update
:rtype: str
"""
table = self.wrap_table(query.from__)
if isinstance(query.wheres, list):
wheres = self._compile_wheres(query)
else:
wheres = ""
if query.joins:
joins = " %s" % self._compile_joins(query, query.joins)
sql = "DELETE %s FROM %s%s %s" % (table, table, joins, wheres)
else:
sql = "DELETE FROM %s %s" % (table, wheres)
sql = sql.strip()
if query.orders:
sql += " %s" % self._compile_orders(query, query.orders)
if query.limit_:
sql += " %s" % self._compile_limit(query, query.limit_)
return sql | python | def compile_delete(self, query):
"""
Compile a delete statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled update
:rtype: str
"""
table = self.wrap_table(query.from__)
if isinstance(query.wheres, list):
wheres = self._compile_wheres(query)
else:
wheres = ""
if query.joins:
joins = " %s" % self._compile_joins(query, query.joins)
sql = "DELETE %s FROM %s%s %s" % (table, table, joins, wheres)
else:
sql = "DELETE FROM %s %s" % (table, wheres)
sql = sql.strip()
if query.orders:
sql += " %s" % self._compile_orders(query, query.orders)
if query.limit_:
sql += " %s" % self._compile_limit(query, query.limit_)
return sql | [
"def",
"compile_delete",
"(",
"self",
",",
"query",
")",
":",
"table",
"=",
"self",
".",
"wrap_table",
"(",
"query",
".",
"from__",
")",
"if",
"isinstance",
"(",
"query",
".",
"wheres",
",",
"list",
")",
":",
"wheres",
"=",
"self",
".",
"_compile_wheres",
"(",
"query",
")",
"else",
":",
"wheres",
"=",
"\"\"",
"if",
"query",
".",
"joins",
":",
"joins",
"=",
"\" %s\"",
"%",
"self",
".",
"_compile_joins",
"(",
"query",
",",
"query",
".",
"joins",
")",
"sql",
"=",
"\"DELETE %s FROM %s%s %s\"",
"%",
"(",
"table",
",",
"table",
",",
"joins",
",",
"wheres",
")",
"else",
":",
"sql",
"=",
"\"DELETE FROM %s %s\"",
"%",
"(",
"table",
",",
"wheres",
")",
"sql",
"=",
"sql",
".",
"strip",
"(",
")",
"if",
"query",
".",
"orders",
":",
"sql",
"+=",
"\" %s\"",
"%",
"self",
".",
"_compile_orders",
"(",
"query",
",",
"query",
".",
"orders",
")",
"if",
"query",
".",
"limit_",
":",
"sql",
"+=",
"\" %s\"",
"%",
"self",
".",
"_compile_limit",
"(",
"query",
",",
"query",
".",
"limit_",
")",
"return",
"sql"
] | Compile a delete statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled update
:rtype: str | [
"Compile",
"a",
"delete",
"statement",
"into",
"SQL"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/mysql_grammar.py#L103-L135 |
231,070 | sdispater/orator | orator/commands/command.py | Command._check_config | def _check_config(self):
"""
Check presence of default config files.
:rtype: bool
"""
current_path = os.path.relpath(os.getcwd())
accepted_files = ["orator.yml", "orator.py"]
for accepted_file in accepted_files:
config_file = os.path.join(current_path, accepted_file)
if os.path.exists(config_file):
if self._handle_config(config_file):
return True
return False | python | def _check_config(self):
"""
Check presence of default config files.
:rtype: bool
"""
current_path = os.path.relpath(os.getcwd())
accepted_files = ["orator.yml", "orator.py"]
for accepted_file in accepted_files:
config_file = os.path.join(current_path, accepted_file)
if os.path.exists(config_file):
if self._handle_config(config_file):
return True
return False | [
"def",
"_check_config",
"(",
"self",
")",
":",
"current_path",
"=",
"os",
".",
"path",
".",
"relpath",
"(",
"os",
".",
"getcwd",
"(",
")",
")",
"accepted_files",
"=",
"[",
"\"orator.yml\"",
",",
"\"orator.py\"",
"]",
"for",
"accepted_file",
"in",
"accepted_files",
":",
"config_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"current_path",
",",
"accepted_file",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"config_file",
")",
":",
"if",
"self",
".",
"_handle_config",
"(",
"config_file",
")",
":",
"return",
"True",
"return",
"False"
] | Check presence of default config files.
:rtype: bool | [
"Check",
"presence",
"of",
"default",
"config",
"files",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/commands/command.py#L72-L87 |
231,071 | sdispater/orator | orator/commands/command.py | Command._handle_config | def _handle_config(self, config_file):
"""
Check and handle a config file.
:param config_file: The path to the config file
:type config_file: str
:rtype: bool
"""
config = self._get_config(config_file)
self.resolver = DatabaseManager(
config.get("databases", config.get("DATABASES", {}))
)
return True | python | def _handle_config(self, config_file):
"""
Check and handle a config file.
:param config_file: The path to the config file
:type config_file: str
:rtype: bool
"""
config = self._get_config(config_file)
self.resolver = DatabaseManager(
config.get("databases", config.get("DATABASES", {}))
)
return True | [
"def",
"_handle_config",
"(",
"self",
",",
"config_file",
")",
":",
"config",
"=",
"self",
".",
"_get_config",
"(",
"config_file",
")",
"self",
".",
"resolver",
"=",
"DatabaseManager",
"(",
"config",
".",
"get",
"(",
"\"databases\"",
",",
"config",
".",
"get",
"(",
"\"DATABASES\"",
",",
"{",
"}",
")",
")",
")",
"return",
"True"
] | Check and handle a config file.
:param config_file: The path to the config file
:type config_file: str
:rtype: bool | [
"Check",
"and",
"handle",
"a",
"config",
"file",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/commands/command.py#L89-L104 |
231,072 | sdispater/orator | orator/migrations/database_migration_repository.py | DatabaseMigrationRepository.log | def log(self, file, batch):
"""
Log that a migration was run.
:type file: str
:type batch: int
"""
record = {"migration": file, "batch": batch}
self.table().insert(**record) | python | def log(self, file, batch):
"""
Log that a migration was run.
:type file: str
:type batch: int
"""
record = {"migration": file, "batch": batch}
self.table().insert(**record) | [
"def",
"log",
"(",
"self",
",",
"file",
",",
"batch",
")",
":",
"record",
"=",
"{",
"\"migration\"",
":",
"file",
",",
"\"batch\"",
":",
"batch",
"}",
"self",
".",
"table",
"(",
")",
".",
"insert",
"(",
"*",
"*",
"record",
")"
] | Log that a migration was run.
:type file: str
:type batch: int | [
"Log",
"that",
"a",
"migration",
"was",
"run",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/migrations/database_migration_repository.py#L34-L43 |
231,073 | sdispater/orator | orator/migrations/database_migration_repository.py | DatabaseMigrationRepository.create_repository | def create_repository(self):
"""
Create the migration repository data store.
"""
schema = self.get_connection().get_schema_builder()
with schema.create(self._table) as table:
# The migrations table is responsible for keeping track of which of the
# migrations have actually run for the application. We'll create the
# table to hold the migration file's path as well as the batch ID.
table.string("migration")
table.integer("batch") | python | def create_repository(self):
"""
Create the migration repository data store.
"""
schema = self.get_connection().get_schema_builder()
with schema.create(self._table) as table:
# The migrations table is responsible for keeping track of which of the
# migrations have actually run for the application. We'll create the
# table to hold the migration file's path as well as the batch ID.
table.string("migration")
table.integer("batch") | [
"def",
"create_repository",
"(",
"self",
")",
":",
"schema",
"=",
"self",
".",
"get_connection",
"(",
")",
".",
"get_schema_builder",
"(",
")",
"with",
"schema",
".",
"create",
"(",
"self",
".",
"_table",
")",
"as",
"table",
":",
"# The migrations table is responsible for keeping track of which of the",
"# migrations have actually run for the application. We'll create the",
"# table to hold the migration file's path as well as the batch ID.",
"table",
".",
"string",
"(",
"\"migration\"",
")",
"table",
".",
"integer",
"(",
"\"batch\"",
")"
] | Create the migration repository data store. | [
"Create",
"the",
"migration",
"repository",
"data",
"store",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/migrations/database_migration_repository.py#L69-L80 |
231,074 | sdispater/orator | orator/migrations/database_migration_repository.py | DatabaseMigrationRepository.repository_exists | def repository_exists(self):
"""
Determine if the repository exists.
:rtype: bool
"""
schema = self.get_connection().get_schema_builder()
return schema.has_table(self._table) | python | def repository_exists(self):
"""
Determine if the repository exists.
:rtype: bool
"""
schema = self.get_connection().get_schema_builder()
return schema.has_table(self._table) | [
"def",
"repository_exists",
"(",
"self",
")",
":",
"schema",
"=",
"self",
".",
"get_connection",
"(",
")",
".",
"get_schema_builder",
"(",
")",
"return",
"schema",
".",
"has_table",
"(",
"self",
".",
"_table",
")"
] | Determine if the repository exists.
:rtype: bool | [
"Determine",
"if",
"the",
"repository",
"exists",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/migrations/database_migration_repository.py#L82-L90 |
231,075 | sdispater/orator | orator/migrations/migration_creator.py | MigrationCreator.create | def create(self, name, path, table=None, create=False):
"""
Create a new migration at the given path.
:param name: The name of the migration
:type name: str
:param path: The path of the migrations
:type path: str
:param table: The table name
:type table: str
:param create: Whether it's a create migration or not
:type create: bool
:rtype: str
"""
path = self._get_path(name, path)
if not os.path.exists(os.path.dirname(path)):
mkdir_p(os.path.dirname(path))
parent = os.path.join(os.path.dirname(path), "__init__.py")
if not os.path.exists(parent):
with open(parent, "w"):
pass
stub = self._get_stub(table, create)
with open(path, "w") as fh:
fh.write(self._populate_stub(name, stub, table))
return path | python | def create(self, name, path, table=None, create=False):
"""
Create a new migration at the given path.
:param name: The name of the migration
:type name: str
:param path: The path of the migrations
:type path: str
:param table: The table name
:type table: str
:param create: Whether it's a create migration or not
:type create: bool
:rtype: str
"""
path = self._get_path(name, path)
if not os.path.exists(os.path.dirname(path)):
mkdir_p(os.path.dirname(path))
parent = os.path.join(os.path.dirname(path), "__init__.py")
if not os.path.exists(parent):
with open(parent, "w"):
pass
stub = self._get_stub(table, create)
with open(path, "w") as fh:
fh.write(self._populate_stub(name, stub, table))
return path | [
"def",
"create",
"(",
"self",
",",
"name",
",",
"path",
",",
"table",
"=",
"None",
",",
"create",
"=",
"False",
")",
":",
"path",
"=",
"self",
".",
"_get_path",
"(",
"name",
",",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
")",
":",
"mkdir_p",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
")",
"parent",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
",",
"\"__init__.py\"",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"parent",
")",
":",
"with",
"open",
"(",
"parent",
",",
"\"w\"",
")",
":",
"pass",
"stub",
"=",
"self",
".",
"_get_stub",
"(",
"table",
",",
"create",
")",
"with",
"open",
"(",
"path",
",",
"\"w\"",
")",
"as",
"fh",
":",
"fh",
".",
"write",
"(",
"self",
".",
"_populate_stub",
"(",
"name",
",",
"stub",
",",
"table",
")",
")",
"return",
"path"
] | Create a new migration at the given path.
:param name: The name of the migration
:type name: str
:param path: The path of the migrations
:type path: str
:param table: The table name
:type table: str
:param create: Whether it's a create migration or not
:type create: bool
:rtype: str | [
"Create",
"a",
"new",
"migration",
"at",
"the",
"given",
"path",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/migrations/migration_creator.py#L21-L50 |
231,076 | sdispater/orator | orator/migrations/migration_creator.py | MigrationCreator._get_stub | def _get_stub(self, table, create):
"""
Get the migration stub template
:param table: The table name
:type table: str
:param create: Whether it's a create migration or not
:type create: bool
:rtype: str
"""
if table is None:
return BLANK_STUB
else:
if create:
stub = CREATE_STUB
else:
stub = UPDATE_STUB
return stub | python | def _get_stub(self, table, create):
"""
Get the migration stub template
:param table: The table name
:type table: str
:param create: Whether it's a create migration or not
:type create: bool
:rtype: str
"""
if table is None:
return BLANK_STUB
else:
if create:
stub = CREATE_STUB
else:
stub = UPDATE_STUB
return stub | [
"def",
"_get_stub",
"(",
"self",
",",
"table",
",",
"create",
")",
":",
"if",
"table",
"is",
"None",
":",
"return",
"BLANK_STUB",
"else",
":",
"if",
"create",
":",
"stub",
"=",
"CREATE_STUB",
"else",
":",
"stub",
"=",
"UPDATE_STUB",
"return",
"stub"
] | Get the migration stub template
:param table: The table name
:type table: str
:param create: Whether it's a create migration or not
:type create: bool
:rtype: str | [
"Get",
"the",
"migration",
"stub",
"template"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/migrations/migration_creator.py#L52-L72 |
231,077 | sdispater/orator | orator/dbal/foreign_key_constraint.py | ForeignKeyConstraint.get_quoted_local_columns | def get_quoted_local_columns(self, platform):
"""
Returns the quoted representation of the referencing table column names
the foreign key constraint is associated with.
But only if they were defined with one or the referencing table column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is returned.
:param platform: The platform to use for quotation.
:type platform: Platform
:rtype: list
"""
columns = []
for column in self._local_column_names.values():
columns.append(column.get_quoted_name(platform))
return columns | python | def get_quoted_local_columns(self, platform):
"""
Returns the quoted representation of the referencing table column names
the foreign key constraint is associated with.
But only if they were defined with one or the referencing table column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is returned.
:param platform: The platform to use for quotation.
:type platform: Platform
:rtype: list
"""
columns = []
for column in self._local_column_names.values():
columns.append(column.get_quoted_name(platform))
return columns | [
"def",
"get_quoted_local_columns",
"(",
"self",
",",
"platform",
")",
":",
"columns",
"=",
"[",
"]",
"for",
"column",
"in",
"self",
".",
"_local_column_names",
".",
"values",
"(",
")",
":",
"columns",
".",
"append",
"(",
"column",
".",
"get_quoted_name",
"(",
"platform",
")",
")",
"return",
"columns"
] | Returns the quoted representation of the referencing table column names
the foreign key constraint is associated with.
But only if they were defined with one or the referencing table column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is returned.
:param platform: The platform to use for quotation.
:type platform: Platform
:rtype: list | [
"Returns",
"the",
"quoted",
"representation",
"of",
"the",
"referencing",
"table",
"column",
"names",
"the",
"foreign",
"key",
"constraint",
"is",
"associated",
"with",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/foreign_key_constraint.py#L96-L115 |
231,078 | sdispater/orator | orator/dbal/foreign_key_constraint.py | ForeignKeyConstraint.get_quoted_foreign_columns | def get_quoted_foreign_columns(self, platform):
"""
Returns the quoted representation of the referenced table column names
the foreign key constraint is associated with.
But only if they were defined with one or the referenced table column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is returned.
:param platform: The platform to use for quotation.
:type platform: Platform
:rtype: list
"""
columns = []
for column in self._foreign_column_names.values():
columns.append(column.get_quoted_name(platform))
return columns | python | def get_quoted_foreign_columns(self, platform):
"""
Returns the quoted representation of the referenced table column names
the foreign key constraint is associated with.
But only if they were defined with one or the referenced table column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is returned.
:param platform: The platform to use for quotation.
:type platform: Platform
:rtype: list
"""
columns = []
for column in self._foreign_column_names.values():
columns.append(column.get_quoted_name(platform))
return columns | [
"def",
"get_quoted_foreign_columns",
"(",
"self",
",",
"platform",
")",
":",
"columns",
"=",
"[",
"]",
"for",
"column",
"in",
"self",
".",
"_foreign_column_names",
".",
"values",
"(",
")",
":",
"columns",
".",
"append",
"(",
"column",
".",
"get_quoted_name",
"(",
"platform",
")",
")",
"return",
"columns"
] | Returns the quoted representation of the referenced table column names
the foreign key constraint is associated with.
But only if they were defined with one or the referenced table column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is returned.
:param platform: The platform to use for quotation.
:type platform: Platform
:rtype: list | [
"Returns",
"the",
"quoted",
"representation",
"of",
"the",
"referenced",
"table",
"column",
"names",
"the",
"foreign",
"key",
"constraint",
"is",
"associated",
"with",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/foreign_key_constraint.py#L189-L208 |
231,079 | sdispater/orator | orator/dbal/foreign_key_constraint.py | ForeignKeyConstraint._on_event | def _on_event(self, event):
"""
Returns the referential action for a given database operation
on the referenced table the foreign key constraint is associated with.
:param event: Name of the database operation/event to return the referential action for.
:type event: str
:rtype: str or None
"""
if self.has_option(event):
on_event = self.get_option(event).upper()
if on_event not in ["NO ACTION", "RESTRICT"]:
return on_event
return False | python | def _on_event(self, event):
"""
Returns the referential action for a given database operation
on the referenced table the foreign key constraint is associated with.
:param event: Name of the database operation/event to return the referential action for.
:type event: str
:rtype: str or None
"""
if self.has_option(event):
on_event = self.get_option(event).upper()
if on_event not in ["NO ACTION", "RESTRICT"]:
return on_event
return False | [
"def",
"_on_event",
"(",
"self",
",",
"event",
")",
":",
"if",
"self",
".",
"has_option",
"(",
"event",
")",
":",
"on_event",
"=",
"self",
".",
"get_option",
"(",
"event",
")",
".",
"upper",
"(",
")",
"if",
"on_event",
"not",
"in",
"[",
"\"NO ACTION\"",
",",
"\"RESTRICT\"",
"]",
":",
"return",
"on_event",
"return",
"False"
] | Returns the referential action for a given database operation
on the referenced table the foreign key constraint is associated with.
:param event: Name of the database operation/event to return the referential action for.
:type event: str
:rtype: str or None | [
"Returns",
"the",
"referential",
"action",
"for",
"a",
"given",
"database",
"operation",
"on",
"the",
"referenced",
"table",
"the",
"foreign",
"key",
"constraint",
"is",
"associated",
"with",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/foreign_key_constraint.py#L246-L262 |
231,080 | sdispater/orator | orator/migrations/migrator.py | Migrator.run | def run(self, path, pretend=False):
"""
Run the outstanding migrations for a given path.
:param path: The path
:type path: str
:param pretend: Whether we execute the migrations as dry-run
:type pretend: bool
"""
self._notes = []
files = self._get_migration_files(path)
ran = self._repository.get_ran()
migrations = [f for f in files if f not in ran]
self.run_migration_list(path, migrations, pretend) | python | def run(self, path, pretend=False):
"""
Run the outstanding migrations for a given path.
:param path: The path
:type path: str
:param pretend: Whether we execute the migrations as dry-run
:type pretend: bool
"""
self._notes = []
files = self._get_migration_files(path)
ran = self._repository.get_ran()
migrations = [f for f in files if f not in ran]
self.run_migration_list(path, migrations, pretend) | [
"def",
"run",
"(",
"self",
",",
"path",
",",
"pretend",
"=",
"False",
")",
":",
"self",
".",
"_notes",
"=",
"[",
"]",
"files",
"=",
"self",
".",
"_get_migration_files",
"(",
"path",
")",
"ran",
"=",
"self",
".",
"_repository",
".",
"get_ran",
"(",
")",
"migrations",
"=",
"[",
"f",
"for",
"f",
"in",
"files",
"if",
"f",
"not",
"in",
"ran",
"]",
"self",
".",
"run_migration_list",
"(",
"path",
",",
"migrations",
",",
"pretend",
")"
] | Run the outstanding migrations for a given path.
:param path: The path
:type path: str
:param pretend: Whether we execute the migrations as dry-run
:type pretend: bool | [
"Run",
"the",
"outstanding",
"migrations",
"for",
"a",
"given",
"path",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/migrations/migrator.py#L34-L51 |
231,081 | sdispater/orator | orator/migrations/migrator.py | Migrator.run_migration_list | def run_migration_list(self, path, migrations, pretend=False):
"""
Run a list of migrations.
:type migrations: list
:type pretend: bool
"""
if not migrations:
self._note("<info>Nothing to migrate</info>")
return
batch = self._repository.get_next_batch_number()
for f in migrations:
self._run_up(path, f, batch, pretend) | python | def run_migration_list(self, path, migrations, pretend=False):
"""
Run a list of migrations.
:type migrations: list
:type pretend: bool
"""
if not migrations:
self._note("<info>Nothing to migrate</info>")
return
batch = self._repository.get_next_batch_number()
for f in migrations:
self._run_up(path, f, batch, pretend) | [
"def",
"run_migration_list",
"(",
"self",
",",
"path",
",",
"migrations",
",",
"pretend",
"=",
"False",
")",
":",
"if",
"not",
"migrations",
":",
"self",
".",
"_note",
"(",
"\"<info>Nothing to migrate</info>\"",
")",
"return",
"batch",
"=",
"self",
".",
"_repository",
".",
"get_next_batch_number",
"(",
")",
"for",
"f",
"in",
"migrations",
":",
"self",
".",
"_run_up",
"(",
"path",
",",
"f",
",",
"batch",
",",
"pretend",
")"
] | Run a list of migrations.
:type migrations: list
:type pretend: bool | [
"Run",
"a",
"list",
"of",
"migrations",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/migrations/migrator.py#L53-L69 |
231,082 | sdispater/orator | orator/migrations/migrator.py | Migrator.reset | def reset(self, path, pretend=False):
"""
Rolls all of the currently applied migrations back.
:param path: The path
:type path: str
:param pretend: Whether we execute the migrations as dry-run
:type pretend: bool
:rtype: count
"""
self._notes = []
migrations = sorted(self._repository.get_ran(), reverse=True)
count = len(migrations)
if count == 0:
self._note("<info>Nothing to rollback.</info>")
else:
for migration in migrations:
self._run_down(path, {"migration": migration}, pretend)
return count | python | def reset(self, path, pretend=False):
"""
Rolls all of the currently applied migrations back.
:param path: The path
:type path: str
:param pretend: Whether we execute the migrations as dry-run
:type pretend: bool
:rtype: count
"""
self._notes = []
migrations = sorted(self._repository.get_ran(), reverse=True)
count = len(migrations)
if count == 0:
self._note("<info>Nothing to rollback.</info>")
else:
for migration in migrations:
self._run_down(path, {"migration": migration}, pretend)
return count | [
"def",
"reset",
"(",
"self",
",",
"path",
",",
"pretend",
"=",
"False",
")",
":",
"self",
".",
"_notes",
"=",
"[",
"]",
"migrations",
"=",
"sorted",
"(",
"self",
".",
"_repository",
".",
"get_ran",
"(",
")",
",",
"reverse",
"=",
"True",
")",
"count",
"=",
"len",
"(",
"migrations",
")",
"if",
"count",
"==",
"0",
":",
"self",
".",
"_note",
"(",
"\"<info>Nothing to rollback.</info>\"",
")",
"else",
":",
"for",
"migration",
"in",
"migrations",
":",
"self",
".",
"_run_down",
"(",
"path",
",",
"{",
"\"migration\"",
":",
"migration",
"}",
",",
"pretend",
")",
"return",
"count"
] | Rolls all of the currently applied migrations back.
:param path: The path
:type path: str
:param pretend: Whether we execute the migrations as dry-run
:type pretend: bool
:rtype: count | [
"Rolls",
"all",
"of",
"the",
"currently",
"applied",
"migrations",
"back",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/migrations/migrator.py#L125-L149 |
231,083 | sdispater/orator | orator/migrations/migrator.py | Migrator._get_migration_files | def _get_migration_files(self, path):
"""
Get all of the migration files in a given path.
:type path: str
:rtype: list
"""
files = glob.glob(os.path.join(path, "[0-9]*_*.py"))
if not files:
return []
files = list(map(lambda f: os.path.basename(f).replace(".py", ""), files))
files = sorted(files)
return files | python | def _get_migration_files(self, path):
"""
Get all of the migration files in a given path.
:type path: str
:rtype: list
"""
files = glob.glob(os.path.join(path, "[0-9]*_*.py"))
if not files:
return []
files = list(map(lambda f: os.path.basename(f).replace(".py", ""), files))
files = sorted(files)
return files | [
"def",
"_get_migration_files",
"(",
"self",
",",
"path",
")",
":",
"files",
"=",
"glob",
".",
"glob",
"(",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"\"[0-9]*_*.py\"",
")",
")",
"if",
"not",
"files",
":",
"return",
"[",
"]",
"files",
"=",
"list",
"(",
"map",
"(",
"lambda",
"f",
":",
"os",
".",
"path",
".",
"basename",
"(",
"f",
")",
".",
"replace",
"(",
"\".py\"",
",",
"\"\"",
")",
",",
"files",
")",
")",
"files",
"=",
"sorted",
"(",
"files",
")",
"return",
"files"
] | Get all of the migration files in a given path.
:type path: str
:rtype: list | [
"Get",
"all",
"of",
"the",
"migration",
"files",
"in",
"a",
"given",
"path",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/migrations/migrator.py#L175-L192 |
231,084 | sdispater/orator | orator/query/grammars/postgres_grammar.py | PostgresQueryGrammar._compile_update_columns | def _compile_update_columns(self, values):
"""
Compile the columns for the update statement
:param values: The columns
:type values: dict
:return: The compiled columns
:rtype: str
"""
columns = []
for key, value in values.items():
columns.append("%s = %s" % (self.wrap(key), self.parameter(value)))
return ", ".join(columns) | python | def _compile_update_columns(self, values):
"""
Compile the columns for the update statement
:param values: The columns
:type values: dict
:return: The compiled columns
:rtype: str
"""
columns = []
for key, value in values.items():
columns.append("%s = %s" % (self.wrap(key), self.parameter(value)))
return ", ".join(columns) | [
"def",
"_compile_update_columns",
"(",
"self",
",",
"values",
")",
":",
"columns",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"values",
".",
"items",
"(",
")",
":",
"columns",
".",
"append",
"(",
"\"%s = %s\"",
"%",
"(",
"self",
".",
"wrap",
"(",
"key",
")",
",",
"self",
".",
"parameter",
"(",
"value",
")",
")",
")",
"return",
"\", \"",
".",
"join",
"(",
"columns",
")"
] | Compile the columns for the update statement
:param values: The columns
:type values: dict
:return: The compiled columns
:rtype: str | [
"Compile",
"the",
"columns",
"for",
"the",
"update",
"statement"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/postgres_grammar.py#L74-L89 |
231,085 | sdispater/orator | orator/query/grammars/postgres_grammar.py | PostgresQueryGrammar._compile_update_from | def _compile_update_from(self, query):
"""
Compile the "from" clause for an update with a join.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
if not query.joins:
return ""
froms = []
for join in query.joins:
froms.append(self.wrap_table(join.table))
if len(froms):
return " FROM %s" % ", ".join(froms)
return "" | python | def _compile_update_from(self, query):
"""
Compile the "from" clause for an update with a join.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
if not query.joins:
return ""
froms = []
for join in query.joins:
froms.append(self.wrap_table(join.table))
if len(froms):
return " FROM %s" % ", ".join(froms)
return "" | [
"def",
"_compile_update_from",
"(",
"self",
",",
"query",
")",
":",
"if",
"not",
"query",
".",
"joins",
":",
"return",
"\"\"",
"froms",
"=",
"[",
"]",
"for",
"join",
"in",
"query",
".",
"joins",
":",
"froms",
".",
"append",
"(",
"self",
".",
"wrap_table",
"(",
"join",
".",
"table",
")",
")",
"if",
"len",
"(",
"froms",
")",
":",
"return",
"\" FROM %s\"",
"%",
"\", \"",
".",
"join",
"(",
"froms",
")",
"return",
"\"\""
] | Compile the "from" clause for an update with a join.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str | [
"Compile",
"the",
"from",
"clause",
"for",
"an",
"update",
"with",
"a",
"join",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/postgres_grammar.py#L91-L112 |
231,086 | sdispater/orator | orator/query/grammars/postgres_grammar.py | PostgresQueryGrammar._compile_update_wheres | def _compile_update_wheres(self, query):
"""
Compile the additional where clauses for updates with joins.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
base_where = self._compile_wheres(query)
if not query.joins:
return base_where
join_where = self._compile_update_join_wheres(query)
if not base_where.strip():
return "WHERE %s" % self._remove_leading_boolean(join_where)
return "%s %s" % (base_where, join_where) | python | def _compile_update_wheres(self, query):
"""
Compile the additional where clauses for updates with joins.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
base_where = self._compile_wheres(query)
if not query.joins:
return base_where
join_where = self._compile_update_join_wheres(query)
if not base_where.strip():
return "WHERE %s" % self._remove_leading_boolean(join_where)
return "%s %s" % (base_where, join_where) | [
"def",
"_compile_update_wheres",
"(",
"self",
",",
"query",
")",
":",
"base_where",
"=",
"self",
".",
"_compile_wheres",
"(",
"query",
")",
"if",
"not",
"query",
".",
"joins",
":",
"return",
"base_where",
"join_where",
"=",
"self",
".",
"_compile_update_join_wheres",
"(",
"query",
")",
"if",
"not",
"base_where",
".",
"strip",
"(",
")",
":",
"return",
"\"WHERE %s\"",
"%",
"self",
".",
"_remove_leading_boolean",
"(",
"join_where",
")",
"return",
"\"%s %s\"",
"%",
"(",
"base_where",
",",
"join_where",
")"
] | Compile the additional where clauses for updates with joins.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str | [
"Compile",
"the",
"additional",
"where",
"clauses",
"for",
"updates",
"with",
"joins",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/postgres_grammar.py#L114-L134 |
231,087 | sdispater/orator | orator/query/grammars/postgres_grammar.py | PostgresQueryGrammar._compile_update_join_wheres | def _compile_update_join_wheres(self, query):
"""
Compile the "join" clauses for an update.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
join_wheres = []
for join in query.joins:
for clause in join.clauses:
join_wheres.append(self._compile_join_constraints(clause))
return " ".join(join_wheres) | python | def _compile_update_join_wheres(self, query):
"""
Compile the "join" clauses for an update.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
join_wheres = []
for join in query.joins:
for clause in join.clauses:
join_wheres.append(self._compile_join_constraints(clause))
return " ".join(join_wheres) | [
"def",
"_compile_update_join_wheres",
"(",
"self",
",",
"query",
")",
":",
"join_wheres",
"=",
"[",
"]",
"for",
"join",
"in",
"query",
".",
"joins",
":",
"for",
"clause",
"in",
"join",
".",
"clauses",
":",
"join_wheres",
".",
"append",
"(",
"self",
".",
"_compile_join_constraints",
"(",
"clause",
")",
")",
"return",
"\" \"",
".",
"join",
"(",
"join_wheres",
")"
] | Compile the "join" clauses for an update.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str | [
"Compile",
"the",
"join",
"clauses",
"for",
"an",
"update",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/postgres_grammar.py#L136-L152 |
231,088 | sdispater/orator | orator/query/grammars/postgres_grammar.py | PostgresQueryGrammar.compile_insert_get_id | def compile_insert_get_id(self, query, values, sequence=None):
"""
Compile an insert and get ID statement into SQL.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param values: The values to insert
:type values: dict
:param sequence: The id sequence
:type sequence: str
:return: The compiled statement
:rtype: str
"""
if sequence is None:
sequence = "id"
return "%s RETURNING %s" % (
self.compile_insert(query, values),
self.wrap(sequence),
) | python | def compile_insert_get_id(self, query, values, sequence=None):
"""
Compile an insert and get ID statement into SQL.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param values: The values to insert
:type values: dict
:param sequence: The id sequence
:type sequence: str
:return: The compiled statement
:rtype: str
"""
if sequence is None:
sequence = "id"
return "%s RETURNING %s" % (
self.compile_insert(query, values),
self.wrap(sequence),
) | [
"def",
"compile_insert_get_id",
"(",
"self",
",",
"query",
",",
"values",
",",
"sequence",
"=",
"None",
")",
":",
"if",
"sequence",
"is",
"None",
":",
"sequence",
"=",
"\"id\"",
"return",
"\"%s RETURNING %s\"",
"%",
"(",
"self",
".",
"compile_insert",
"(",
"query",
",",
"values",
")",
",",
"self",
".",
"wrap",
"(",
"sequence",
")",
",",
")"
] | Compile an insert and get ID statement into SQL.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param values: The values to insert
:type values: dict
:param sequence: The id sequence
:type sequence: str
:return: The compiled statement
:rtype: str | [
"Compile",
"an",
"insert",
"and",
"get",
"ID",
"statement",
"into",
"SQL",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/postgres_grammar.py#L154-L176 |
231,089 | sdispater/orator | orator/utils/qmarker.py | Qmarker.qmark | def qmark(cls, query):
"""
Convert a "qmark" query into "format" style.
"""
def sub_sequence(m):
s = m.group(0)
if s == "??":
return "?"
if s == "%":
return "%%"
else:
return "%s"
return cls.RE_QMARK.sub(sub_sequence, query) | python | def qmark(cls, query):
"""
Convert a "qmark" query into "format" style.
"""
def sub_sequence(m):
s = m.group(0)
if s == "??":
return "?"
if s == "%":
return "%%"
else:
return "%s"
return cls.RE_QMARK.sub(sub_sequence, query) | [
"def",
"qmark",
"(",
"cls",
",",
"query",
")",
":",
"def",
"sub_sequence",
"(",
"m",
")",
":",
"s",
"=",
"m",
".",
"group",
"(",
"0",
")",
"if",
"s",
"==",
"\"??\"",
":",
"return",
"\"?\"",
"if",
"s",
"==",
"\"%\"",
":",
"return",
"\"%%\"",
"else",
":",
"return",
"\"%s\"",
"return",
"cls",
".",
"RE_QMARK",
".",
"sub",
"(",
"sub_sequence",
",",
"query",
")"
] | Convert a "qmark" query into "format" style. | [
"Convert",
"a",
"qmark",
"query",
"into",
"format",
"style",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/utils/qmarker.py#L11-L25 |
231,090 | sdispater/orator | orator/orm/relations/relation.py | Relation.touch | def touch(self):
"""
Touch all of the related models for the relationship.
"""
column = self.get_related().get_updated_at_column()
self.raw_update({column: self.get_related().fresh_timestamp()}) | python | def touch(self):
"""
Touch all of the related models for the relationship.
"""
column = self.get_related().get_updated_at_column()
self.raw_update({column: self.get_related().fresh_timestamp()}) | [
"def",
"touch",
"(",
"self",
")",
":",
"column",
"=",
"self",
".",
"get_related",
"(",
")",
".",
"get_updated_at_column",
"(",
")",
"self",
".",
"raw_update",
"(",
"{",
"column",
":",
"self",
".",
"get_related",
"(",
")",
".",
"fresh_timestamp",
"(",
")",
"}",
")"
] | Touch all of the related models for the relationship. | [
"Touch",
"all",
"of",
"the",
"related",
"models",
"for",
"the",
"relationship",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/relation.py#L77-L83 |
231,091 | sdispater/orator | orator/orm/relations/relation.py | Relation.raw_update | def raw_update(self, attributes=None):
"""
Run a raw update against the base query.
:type attributes: dict
:rtype: int
"""
if attributes is None:
attributes = {}
if self._query is not None:
return self._query.update(attributes) | python | def raw_update(self, attributes=None):
"""
Run a raw update against the base query.
:type attributes: dict
:rtype: int
"""
if attributes is None:
attributes = {}
if self._query is not None:
return self._query.update(attributes) | [
"def",
"raw_update",
"(",
"self",
",",
"attributes",
"=",
"None",
")",
":",
"if",
"attributes",
"is",
"None",
":",
"attributes",
"=",
"{",
"}",
"if",
"self",
".",
"_query",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_query",
".",
"update",
"(",
"attributes",
")"
] | Run a raw update against the base query.
:type attributes: dict
:rtype: int | [
"Run",
"a",
"raw",
"update",
"against",
"the",
"base",
"query",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/relation.py#L85-L97 |
231,092 | sdispater/orator | orator/orm/relations/relation.py | Relation.wrap | def wrap(self, value):
"""
Wrap the given value with the parent's query grammar.
:rtype: str
"""
return self._parent.new_query().get_query().get_grammar().wrap(value) | python | def wrap(self, value):
"""
Wrap the given value with the parent's query grammar.
:rtype: str
"""
return self._parent.new_query().get_query().get_grammar().wrap(value) | [
"def",
"wrap",
"(",
"self",
",",
"value",
")",
":",
"return",
"self",
".",
"_parent",
".",
"new_query",
"(",
")",
".",
"get_query",
"(",
")",
".",
"get_grammar",
"(",
")",
".",
"wrap",
"(",
"value",
")"
] | Wrap the given value with the parent's query grammar.
:rtype: str | [
"Wrap",
"the",
"given",
"value",
"with",
"the",
"parent",
"s",
"query",
"grammar",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/relation.py#L199-L205 |
231,093 | awslabs/aws-cfn-template-flip | cfn_flip/__init__.py | load | def load(template):
"""
Try to guess the input format
"""
try:
data = load_json(template)
return data, "json"
except ValueError as e:
try:
data = load_yaml(template)
return data, "yaml"
except Exception:
raise e | python | def load(template):
"""
Try to guess the input format
"""
try:
data = load_json(template)
return data, "json"
except ValueError as e:
try:
data = load_yaml(template)
return data, "yaml"
except Exception:
raise e | [
"def",
"load",
"(",
"template",
")",
":",
"try",
":",
"data",
"=",
"load_json",
"(",
"template",
")",
"return",
"data",
",",
"\"json\"",
"except",
"ValueError",
"as",
"e",
":",
"try",
":",
"data",
"=",
"load_yaml",
"(",
"template",
")",
"return",
"data",
",",
"\"yaml\"",
"except",
"Exception",
":",
"raise",
"e"
] | Try to guess the input format | [
"Try",
"to",
"guess",
"the",
"input",
"format"
] | 837576bea243e3f5efb0a20b84802371272e2d33 | https://github.com/awslabs/aws-cfn-template-flip/blob/837576bea243e3f5efb0a20b84802371272e2d33/cfn_flip/__init__.py#L21-L34 |
231,094 | awslabs/aws-cfn-template-flip | cfn_flip/__init__.py | dump_yaml | def dump_yaml(data, clean_up=False, long_form=False):
"""
Output some YAML
"""
return yaml.dump(
data,
Dumper=get_dumper(clean_up, long_form),
default_flow_style=False,
allow_unicode=True
) | python | def dump_yaml(data, clean_up=False, long_form=False):
"""
Output some YAML
"""
return yaml.dump(
data,
Dumper=get_dumper(clean_up, long_form),
default_flow_style=False,
allow_unicode=True
) | [
"def",
"dump_yaml",
"(",
"data",
",",
"clean_up",
"=",
"False",
",",
"long_form",
"=",
"False",
")",
":",
"return",
"yaml",
".",
"dump",
"(",
"data",
",",
"Dumper",
"=",
"get_dumper",
"(",
"clean_up",
",",
"long_form",
")",
",",
"default_flow_style",
"=",
"False",
",",
"allow_unicode",
"=",
"True",
")"
] | Output some YAML | [
"Output",
"some",
"YAML"
] | 837576bea243e3f5efb0a20b84802371272e2d33 | https://github.com/awslabs/aws-cfn-template-flip/blob/837576bea243e3f5efb0a20b84802371272e2d33/cfn_flip/__init__.py#L37-L47 |
231,095 | awslabs/aws-cfn-template-flip | cfn_flip/__init__.py | to_json | def to_json(template, clean_up=False):
"""
Assume the input is YAML and convert to JSON
"""
data = load_yaml(template)
if clean_up:
data = clean(data)
return dump_json(data) | python | def to_json(template, clean_up=False):
"""
Assume the input is YAML and convert to JSON
"""
data = load_yaml(template)
if clean_up:
data = clean(data)
return dump_json(data) | [
"def",
"to_json",
"(",
"template",
",",
"clean_up",
"=",
"False",
")",
":",
"data",
"=",
"load_yaml",
"(",
"template",
")",
"if",
"clean_up",
":",
"data",
"=",
"clean",
"(",
"data",
")",
"return",
"dump_json",
"(",
"data",
")"
] | Assume the input is YAML and convert to JSON | [
"Assume",
"the",
"input",
"is",
"YAML",
"and",
"convert",
"to",
"JSON"
] | 837576bea243e3f5efb0a20b84802371272e2d33 | https://github.com/awslabs/aws-cfn-template-flip/blob/837576bea243e3f5efb0a20b84802371272e2d33/cfn_flip/__init__.py#L50-L60 |
231,096 | awslabs/aws-cfn-template-flip | cfn_flip/__init__.py | to_yaml | def to_yaml(template, clean_up=False, long_form=False):
"""
Assume the input is JSON and convert to YAML
"""
data = load_json(template)
if clean_up:
data = clean(data)
return dump_yaml(data, clean_up, long_form) | python | def to_yaml(template, clean_up=False, long_form=False):
"""
Assume the input is JSON and convert to YAML
"""
data = load_json(template)
if clean_up:
data = clean(data)
return dump_yaml(data, clean_up, long_form) | [
"def",
"to_yaml",
"(",
"template",
",",
"clean_up",
"=",
"False",
",",
"long_form",
"=",
"False",
")",
":",
"data",
"=",
"load_json",
"(",
"template",
")",
"if",
"clean_up",
":",
"data",
"=",
"clean",
"(",
"data",
")",
"return",
"dump_yaml",
"(",
"data",
",",
"clean_up",
",",
"long_form",
")"
] | Assume the input is JSON and convert to YAML | [
"Assume",
"the",
"input",
"is",
"JSON",
"and",
"convert",
"to",
"YAML"
] | 837576bea243e3f5efb0a20b84802371272e2d33 | https://github.com/awslabs/aws-cfn-template-flip/blob/837576bea243e3f5efb0a20b84802371272e2d33/cfn_flip/__init__.py#L63-L73 |
231,097 | awslabs/aws-cfn-template-flip | cfn_flip/__init__.py | flip | def flip(template, in_format=None, out_format=None, clean_up=False, no_flip=False, long_form=False):
"""
Figure out the input format and convert the data to the opposing output format
"""
# Do we need to figure out the input format?
if not in_format:
# Load the template as JSON?
if (out_format == "json" and no_flip) or (out_format == "yaml" and not no_flip):
in_format = "json"
elif (out_format == "yaml" and no_flip) or (out_format == "json" and not no_flip):
in_format = "yaml"
# Load the data
if in_format == "json":
data = load_json(template)
elif in_format == "yaml":
data = load_yaml(template)
else:
data, in_format = load(template)
# Clean up?
if clean_up:
data = clean(data)
# Figure out the output format
if not out_format:
if (in_format == "json" and no_flip) or (in_format == "yaml" and not no_flip):
out_format = "json"
else:
out_format = "yaml"
# Finished!
if out_format == "json":
if sys.version[0] == "3":
return dump_json(data)
else:
return dump_json(data).encode('utf-8')
return dump_yaml(data, clean_up, long_form) | python | def flip(template, in_format=None, out_format=None, clean_up=False, no_flip=False, long_form=False):
"""
Figure out the input format and convert the data to the opposing output format
"""
# Do we need to figure out the input format?
if not in_format:
# Load the template as JSON?
if (out_format == "json" and no_flip) or (out_format == "yaml" and not no_flip):
in_format = "json"
elif (out_format == "yaml" and no_flip) or (out_format == "json" and not no_flip):
in_format = "yaml"
# Load the data
if in_format == "json":
data = load_json(template)
elif in_format == "yaml":
data = load_yaml(template)
else:
data, in_format = load(template)
# Clean up?
if clean_up:
data = clean(data)
# Figure out the output format
if not out_format:
if (in_format == "json" and no_flip) or (in_format == "yaml" and not no_flip):
out_format = "json"
else:
out_format = "yaml"
# Finished!
if out_format == "json":
if sys.version[0] == "3":
return dump_json(data)
else:
return dump_json(data).encode('utf-8')
return dump_yaml(data, clean_up, long_form) | [
"def",
"flip",
"(",
"template",
",",
"in_format",
"=",
"None",
",",
"out_format",
"=",
"None",
",",
"clean_up",
"=",
"False",
",",
"no_flip",
"=",
"False",
",",
"long_form",
"=",
"False",
")",
":",
"# Do we need to figure out the input format?",
"if",
"not",
"in_format",
":",
"# Load the template as JSON?",
"if",
"(",
"out_format",
"==",
"\"json\"",
"and",
"no_flip",
")",
"or",
"(",
"out_format",
"==",
"\"yaml\"",
"and",
"not",
"no_flip",
")",
":",
"in_format",
"=",
"\"json\"",
"elif",
"(",
"out_format",
"==",
"\"yaml\"",
"and",
"no_flip",
")",
"or",
"(",
"out_format",
"==",
"\"json\"",
"and",
"not",
"no_flip",
")",
":",
"in_format",
"=",
"\"yaml\"",
"# Load the data",
"if",
"in_format",
"==",
"\"json\"",
":",
"data",
"=",
"load_json",
"(",
"template",
")",
"elif",
"in_format",
"==",
"\"yaml\"",
":",
"data",
"=",
"load_yaml",
"(",
"template",
")",
"else",
":",
"data",
",",
"in_format",
"=",
"load",
"(",
"template",
")",
"# Clean up?",
"if",
"clean_up",
":",
"data",
"=",
"clean",
"(",
"data",
")",
"# Figure out the output format",
"if",
"not",
"out_format",
":",
"if",
"(",
"in_format",
"==",
"\"json\"",
"and",
"no_flip",
")",
"or",
"(",
"in_format",
"==",
"\"yaml\"",
"and",
"not",
"no_flip",
")",
":",
"out_format",
"=",
"\"json\"",
"else",
":",
"out_format",
"=",
"\"yaml\"",
"# Finished!",
"if",
"out_format",
"==",
"\"json\"",
":",
"if",
"sys",
".",
"version",
"[",
"0",
"]",
"==",
"\"3\"",
":",
"return",
"dump_json",
"(",
"data",
")",
"else",
":",
"return",
"dump_json",
"(",
"data",
")",
".",
"encode",
"(",
"'utf-8'",
")",
"return",
"dump_yaml",
"(",
"data",
",",
"clean_up",
",",
"long_form",
")"
] | Figure out the input format and convert the data to the opposing output format | [
"Figure",
"out",
"the",
"input",
"format",
"and",
"convert",
"the",
"data",
"to",
"the",
"opposing",
"output",
"format"
] | 837576bea243e3f5efb0a20b84802371272e2d33 | https://github.com/awslabs/aws-cfn-template-flip/blob/837576bea243e3f5efb0a20b84802371272e2d33/cfn_flip/__init__.py#L76-L115 |
231,098 | awslabs/aws-cfn-template-flip | cfn_clean/__init__.py | convert_join | def convert_join(value):
"""
Fix a Join ;)
"""
if not isinstance(value, list) or len(value) != 2:
# Cowardly refuse
return value
sep, parts = value[0], value[1]
if isinstance(parts, six.string_types):
return parts
if not isinstance(parts, list):
# This looks tricky, just return the join as it was
return {
"Fn::Join": value,
}
plain_string = True
args = ODict()
new_parts = []
for part in parts:
part = clean(part)
if isinstance(part, dict):
plain_string = False
if "Ref" in part:
new_parts.append("${{{}}}".format(part["Ref"]))
elif "Fn::GetAtt" in part:
params = part["Fn::GetAtt"]
new_parts.append("${{{}}}".format(".".join(params)))
else:
for key, val in args.items():
# we want to bail if a conditional can evaluate to AWS::NoValue
if isinstance(val, dict):
if "Fn::If" in val and "AWS::NoValue" in str(val["Fn::If"]):
return {
"Fn::Join": value,
}
if val == part:
param_name = key
break
else:
param_name = "Param{}".format(len(args) + 1)
args[param_name] = part
new_parts.append("${{{}}}".format(param_name))
elif isinstance(part, six.string_types):
new_parts.append(part.replace("${", "${!"))
else:
# Doing something weird; refuse
return {
"Fn::Join": value
}
source = sep.join(new_parts)
if plain_string:
return source
if args:
return ODict((
("Fn::Sub", [source, args]),
))
return ODict((
("Fn::Sub", source),
)) | python | def convert_join(value):
"""
Fix a Join ;)
"""
if not isinstance(value, list) or len(value) != 2:
# Cowardly refuse
return value
sep, parts = value[0], value[1]
if isinstance(parts, six.string_types):
return parts
if not isinstance(parts, list):
# This looks tricky, just return the join as it was
return {
"Fn::Join": value,
}
plain_string = True
args = ODict()
new_parts = []
for part in parts:
part = clean(part)
if isinstance(part, dict):
plain_string = False
if "Ref" in part:
new_parts.append("${{{}}}".format(part["Ref"]))
elif "Fn::GetAtt" in part:
params = part["Fn::GetAtt"]
new_parts.append("${{{}}}".format(".".join(params)))
else:
for key, val in args.items():
# we want to bail if a conditional can evaluate to AWS::NoValue
if isinstance(val, dict):
if "Fn::If" in val and "AWS::NoValue" in str(val["Fn::If"]):
return {
"Fn::Join": value,
}
if val == part:
param_name = key
break
else:
param_name = "Param{}".format(len(args) + 1)
args[param_name] = part
new_parts.append("${{{}}}".format(param_name))
elif isinstance(part, six.string_types):
new_parts.append(part.replace("${", "${!"))
else:
# Doing something weird; refuse
return {
"Fn::Join": value
}
source = sep.join(new_parts)
if plain_string:
return source
if args:
return ODict((
("Fn::Sub", [source, args]),
))
return ODict((
("Fn::Sub", source),
)) | [
"def",
"convert_join",
"(",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"list",
")",
"or",
"len",
"(",
"value",
")",
"!=",
"2",
":",
"# Cowardly refuse",
"return",
"value",
"sep",
",",
"parts",
"=",
"value",
"[",
"0",
"]",
",",
"value",
"[",
"1",
"]",
"if",
"isinstance",
"(",
"parts",
",",
"six",
".",
"string_types",
")",
":",
"return",
"parts",
"if",
"not",
"isinstance",
"(",
"parts",
",",
"list",
")",
":",
"# This looks tricky, just return the join as it was",
"return",
"{",
"\"Fn::Join\"",
":",
"value",
",",
"}",
"plain_string",
"=",
"True",
"args",
"=",
"ODict",
"(",
")",
"new_parts",
"=",
"[",
"]",
"for",
"part",
"in",
"parts",
":",
"part",
"=",
"clean",
"(",
"part",
")",
"if",
"isinstance",
"(",
"part",
",",
"dict",
")",
":",
"plain_string",
"=",
"False",
"if",
"\"Ref\"",
"in",
"part",
":",
"new_parts",
".",
"append",
"(",
"\"${{{}}}\"",
".",
"format",
"(",
"part",
"[",
"\"Ref\"",
"]",
")",
")",
"elif",
"\"Fn::GetAtt\"",
"in",
"part",
":",
"params",
"=",
"part",
"[",
"\"Fn::GetAtt\"",
"]",
"new_parts",
".",
"append",
"(",
"\"${{{}}}\"",
".",
"format",
"(",
"\".\"",
".",
"join",
"(",
"params",
")",
")",
")",
"else",
":",
"for",
"key",
",",
"val",
"in",
"args",
".",
"items",
"(",
")",
":",
"# we want to bail if a conditional can evaluate to AWS::NoValue",
"if",
"isinstance",
"(",
"val",
",",
"dict",
")",
":",
"if",
"\"Fn::If\"",
"in",
"val",
"and",
"\"AWS::NoValue\"",
"in",
"str",
"(",
"val",
"[",
"\"Fn::If\"",
"]",
")",
":",
"return",
"{",
"\"Fn::Join\"",
":",
"value",
",",
"}",
"if",
"val",
"==",
"part",
":",
"param_name",
"=",
"key",
"break",
"else",
":",
"param_name",
"=",
"\"Param{}\"",
".",
"format",
"(",
"len",
"(",
"args",
")",
"+",
"1",
")",
"args",
"[",
"param_name",
"]",
"=",
"part",
"new_parts",
".",
"append",
"(",
"\"${{{}}}\"",
".",
"format",
"(",
"param_name",
")",
")",
"elif",
"isinstance",
"(",
"part",
",",
"six",
".",
"string_types",
")",
":",
"new_parts",
".",
"append",
"(",
"part",
".",
"replace",
"(",
"\"${\"",
",",
"\"${!\"",
")",
")",
"else",
":",
"# Doing something weird; refuse",
"return",
"{",
"\"Fn::Join\"",
":",
"value",
"}",
"source",
"=",
"sep",
".",
"join",
"(",
"new_parts",
")",
"if",
"plain_string",
":",
"return",
"source",
"if",
"args",
":",
"return",
"ODict",
"(",
"(",
"(",
"\"Fn::Sub\"",
",",
"[",
"source",
",",
"args",
"]",
")",
",",
")",
")",
"return",
"ODict",
"(",
"(",
"(",
"\"Fn::Sub\"",
",",
"source",
")",
",",
")",
")"
] | Fix a Join ;) | [
"Fix",
"a",
"Join",
";",
")"
] | 837576bea243e3f5efb0a20b84802371272e2d33 | https://github.com/awslabs/aws-cfn-template-flip/blob/837576bea243e3f5efb0a20b84802371272e2d33/cfn_clean/__init__.py#L18-L93 |
231,099 | awslabs/aws-cfn-template-flip | cfn_flip/yaml_dumper.py | map_representer | def map_representer(dumper, value):
"""
Deal with !Ref style function format and OrderedDict
"""
value = ODict(value.items())
if len(value.keys()) == 1:
key = list(value.keys())[0]
if key in CONVERTED_SUFFIXES:
return fn_representer(dumper, key, value[key])
if key.startswith(FN_PREFIX):
return fn_representer(dumper, key[4:], value[key])
return dumper.represent_mapping(TAG_MAP, value, flow_style=False) | python | def map_representer(dumper, value):
"""
Deal with !Ref style function format and OrderedDict
"""
value = ODict(value.items())
if len(value.keys()) == 1:
key = list(value.keys())[0]
if key in CONVERTED_SUFFIXES:
return fn_representer(dumper, key, value[key])
if key.startswith(FN_PREFIX):
return fn_representer(dumper, key[4:], value[key])
return dumper.represent_mapping(TAG_MAP, value, flow_style=False) | [
"def",
"map_representer",
"(",
"dumper",
",",
"value",
")",
":",
"value",
"=",
"ODict",
"(",
"value",
".",
"items",
"(",
")",
")",
"if",
"len",
"(",
"value",
".",
"keys",
"(",
")",
")",
"==",
"1",
":",
"key",
"=",
"list",
"(",
"value",
".",
"keys",
"(",
")",
")",
"[",
"0",
"]",
"if",
"key",
"in",
"CONVERTED_SUFFIXES",
":",
"return",
"fn_representer",
"(",
"dumper",
",",
"key",
",",
"value",
"[",
"key",
"]",
")",
"if",
"key",
".",
"startswith",
"(",
"FN_PREFIX",
")",
":",
"return",
"fn_representer",
"(",
"dumper",
",",
"key",
"[",
"4",
":",
"]",
",",
"value",
"[",
"key",
"]",
")",
"return",
"dumper",
".",
"represent_mapping",
"(",
"TAG_MAP",
",",
"value",
",",
"flow_style",
"=",
"False",
")"
] | Deal with !Ref style function format and OrderedDict | [
"Deal",
"with",
"!Ref",
"style",
"function",
"format",
"and",
"OrderedDict"
] | 837576bea243e3f5efb0a20b84802371272e2d33 | https://github.com/awslabs/aws-cfn-template-flip/blob/837576bea243e3f5efb0a20b84802371272e2d33/cfn_flip/yaml_dumper.py#L84-L100 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.