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 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
244,800 | sdispater/orator | orator/orm/builder.py | Builder._slice_where_conditions | def _slice_where_conditions(self, wheres, offset, length):
"""
Create a where list with sliced where conditions.
:type wheres: list
:type offset: int
:type length: int
:rtype: list
"""
where_group = self.get_query().for_nested_where()
where_group.wheres = wheres[offset : (offset + length)]
return {"type": "nested", "query": where_group, "boolean": "and"} | python | def _slice_where_conditions(self, wheres, offset, length):
where_group = self.get_query().for_nested_where()
where_group.wheres = wheres[offset : (offset + length)]
return {"type": "nested", "query": where_group, "boolean": "and"} | [
"def",
"_slice_where_conditions",
"(",
"self",
",",
"wheres",
",",
"offset",
",",
"length",
")",
":",
"where_group",
"=",
"self",
".",
"get_query",
"(",
")",
".",
"for_nested_where",
"(",
")",
"where_group",
".",
"wheres",
"=",
"wheres",
"[",
"offset",
":"... | Create a where list with sliced where conditions.
:type wheres: list
:type offset: int
:type length: int
:rtype: list | [
"Create",
"a",
"where",
"list",
"with",
"sliced",
"where",
"conditions",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L1040-L1053 |
244,801 | sdispater/orator | orator/orm/builder.py | Builder.set_model | def set_model(self, model):
"""
Set a model instance for the model being queried.
:param model: The model instance
:type model: orator.orm.Model
:return: The current Builder instance
:rtype: Builder
"""
self._model = model
self._query.from_(model.get_table())
return self | python | def set_model(self, model):
self._model = model
self._query.from_(model.get_table())
return self | [
"def",
"set_model",
"(",
"self",
",",
"model",
")",
":",
"self",
".",
"_model",
"=",
"model",
"self",
".",
"_query",
".",
"from_",
"(",
"model",
".",
"get_table",
"(",
")",
")",
"return",
"self"
] | Set a model instance for the model being queried.
:param model: The model instance
:type model: orator.orm.Model
:return: The current Builder instance
:rtype: Builder | [
"Set",
"a",
"model",
"instance",
"for",
"the",
"model",
"being",
"queried",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L1108-L1122 |
244,802 | sdispater/orator | orator/query/grammars/sqlite_grammar.py | SQLiteQueryGrammar.compile_insert | def compile_insert(self, query, values):
"""
Compile insert statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param values: The insert values
:type values: dict or list
:return: The compiled insert
:rtype: str
"""
table = self.wrap_table(query.from__)
if not isinstance(values, list):
values = [values]
# If there is only one row to insert, we just use the normal grammar
if len(values) == 1:
return super(SQLiteQueryGrammar, self).compile_insert(query, values)
names = self.columnize(values[0].keys())
columns = []
# SQLite requires us to build the multi-row insert as a listing of select with
# unions joining them together. So we'll build out this list of columns and
# then join them all together with select unions to complete the queries.
for column in values[0].keys():
columns.append("%s AS %s" % (self.get_marker(), self.wrap(column)))
columns = [", ".join(columns)] * len(values)
return "INSERT INTO %s (%s) SELECT %s" % (
table,
names,
" UNION ALL SELECT ".join(columns),
) | python | def compile_insert(self, query, values):
table = self.wrap_table(query.from__)
if not isinstance(values, list):
values = [values]
# If there is only one row to insert, we just use the normal grammar
if len(values) == 1:
return super(SQLiteQueryGrammar, self).compile_insert(query, values)
names = self.columnize(values[0].keys())
columns = []
# SQLite requires us to build the multi-row insert as a listing of select with
# unions joining them together. So we'll build out this list of columns and
# then join them all together with select unions to complete the queries.
for column in values[0].keys():
columns.append("%s AS %s" % (self.get_marker(), self.wrap(column)))
columns = [", ".join(columns)] * len(values)
return "INSERT INTO %s (%s) SELECT %s" % (
table,
names,
" UNION ALL SELECT ".join(columns),
) | [
"def",
"compile_insert",
"(",
"self",
",",
"query",
",",
"values",
")",
":",
"table",
"=",
"self",
".",
"wrap_table",
"(",
"query",
".",
"from__",
")",
"if",
"not",
"isinstance",
"(",
"values",
",",
"list",
")",
":",
"values",
"=",
"[",
"values",
"]"... | Compile insert statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param values: The insert values
:type values: dict or list
:return: The compiled insert
:rtype: str | [
"Compile",
"insert",
"statement",
"into",
"SQL"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/sqlite_grammar.py#L26-L64 |
244,803 | sdispater/orator | orator/query/grammars/sqlite_grammar.py | SQLiteQueryGrammar.compile_truncate | def compile_truncate(self, query):
"""
Compile a truncate statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled truncate statement
:rtype: str
"""
sql = {
"DELETE FROM sqlite_sequence WHERE name = %s"
% self.get_marker(): [query.from__]
}
sql["DELETE FROM %s" % self.wrap_table(query.from__)] = []
return sql | python | def compile_truncate(self, query):
sql = {
"DELETE FROM sqlite_sequence WHERE name = %s"
% self.get_marker(): [query.from__]
}
sql["DELETE FROM %s" % self.wrap_table(query.from__)] = []
return sql | [
"def",
"compile_truncate",
"(",
"self",
",",
"query",
")",
":",
"sql",
"=",
"{",
"\"DELETE FROM sqlite_sequence WHERE name = %s\"",
"%",
"self",
".",
"get_marker",
"(",
")",
":",
"[",
"query",
".",
"from__",
"]",
"}",
"sql",
"[",
"\"DELETE FROM %s\"",
"%",
"... | Compile a truncate statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled truncate statement
:rtype: str | [
"Compile",
"a",
"truncate",
"statement",
"into",
"SQL"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/sqlite_grammar.py#L66-L83 |
244,804 | sdispater/orator | orator/schema/blueprint.py | Blueprint.build | def build(self, connection, grammar):
"""
Execute the blueprint against the database.
:param connection: The connection to use
:type connection: orator.connections.Connection
:param grammar: The grammar to user
:type grammar: orator.query.grammars.QueryGrammar
"""
for statement in self.to_sql(connection, grammar):
connection.statement(statement) | python | def build(self, connection, grammar):
for statement in self.to_sql(connection, grammar):
connection.statement(statement) | [
"def",
"build",
"(",
"self",
",",
"connection",
",",
"grammar",
")",
":",
"for",
"statement",
"in",
"self",
".",
"to_sql",
"(",
"connection",
",",
"grammar",
")",
":",
"connection",
".",
"statement",
"(",
"statement",
")"
] | Execute the blueprint against the database.
:param connection: The connection to use
:type connection: orator.connections.Connection
:param grammar: The grammar to user
:type grammar: orator.query.grammars.QueryGrammar | [
"Execute",
"the",
"blueprint",
"against",
"the",
"database",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L19-L30 |
244,805 | sdispater/orator | orator/schema/blueprint.py | Blueprint.to_sql | def to_sql(self, connection, grammar):
"""
Get the raw SQL statements for the blueprint.
:param connection: The connection to use
:type connection: orator.connections.Connection
:param grammar: The grammar to user
:type grammar: orator.schema.grammars.SchemaGrammar
:rtype: list
"""
self._add_implied_commands()
statements = []
for command in self._commands:
method = "compile_%s" % command.name
if hasattr(grammar, method):
sql = getattr(grammar, method)(self, command, connection)
if sql is not None:
if isinstance(sql, list):
statements += sql
else:
statements.append(sql)
return statements | python | def to_sql(self, connection, grammar):
self._add_implied_commands()
statements = []
for command in self._commands:
method = "compile_%s" % command.name
if hasattr(grammar, method):
sql = getattr(grammar, method)(self, command, connection)
if sql is not None:
if isinstance(sql, list):
statements += sql
else:
statements.append(sql)
return statements | [
"def",
"to_sql",
"(",
"self",
",",
"connection",
",",
"grammar",
")",
":",
"self",
".",
"_add_implied_commands",
"(",
")",
"statements",
"=",
"[",
"]",
"for",
"command",
"in",
"self",
".",
"_commands",
":",
"method",
"=",
"\"compile_%s\"",
"%",
"command",
... | Get the raw SQL statements for the blueprint.
:param connection: The connection to use
:type connection: orator.connections.Connection
:param grammar: The grammar to user
:type grammar: orator.schema.grammars.SchemaGrammar
:rtype: list | [
"Get",
"the",
"raw",
"SQL",
"statements",
"for",
"the",
"blueprint",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L32-L59 |
244,806 | sdispater/orator | orator/schema/blueprint.py | Blueprint._add_implied_commands | def _add_implied_commands(self):
"""
Add the commands that are implied by the blueprint.
"""
if len(self.get_added_columns()) and not self._creating():
self._commands.insert(0, self._create_command("add"))
if len(self.get_changed_columns()) and not self._creating():
self._commands.insert(0, self._create_command("change"))
return self._add_fluent_indexes() | python | def _add_implied_commands(self):
if len(self.get_added_columns()) and not self._creating():
self._commands.insert(0, self._create_command("add"))
if len(self.get_changed_columns()) and not self._creating():
self._commands.insert(0, self._create_command("change"))
return self._add_fluent_indexes() | [
"def",
"_add_implied_commands",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"get_added_columns",
"(",
")",
")",
"and",
"not",
"self",
".",
"_creating",
"(",
")",
":",
"self",
".",
"_commands",
".",
"insert",
"(",
"0",
",",
"self",
".",
"_cr... | Add the commands that are implied by the blueprint. | [
"Add",
"the",
"commands",
"that",
"are",
"implied",
"by",
"the",
"blueprint",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L61-L71 |
244,807 | sdispater/orator | orator/schema/blueprint.py | Blueprint.drop_column | def drop_column(self, *columns):
"""
Indicates that the given columns should be dropped.
:param columns: The columns to drop
:type columns: tuple
:rtype: Fluent
"""
columns = list(columns)
return self._add_command("drop_column", columns=columns) | python | def drop_column(self, *columns):
columns = list(columns)
return self._add_command("drop_column", columns=columns) | [
"def",
"drop_column",
"(",
"self",
",",
"*",
"columns",
")",
":",
"columns",
"=",
"list",
"(",
"columns",
")",
"return",
"self",
".",
"_add_command",
"(",
"\"drop_column\"",
",",
"columns",
"=",
"columns",
")"
] | Indicates that the given columns should be dropped.
:param columns: The columns to drop
:type columns: tuple
:rtype: Fluent | [
"Indicates",
"that",
"the",
"given",
"columns",
"should",
"be",
"dropped",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L128-L139 |
244,808 | sdispater/orator | orator/schema/blueprint.py | Blueprint.integer | def integer(self, column, auto_increment=False, unsigned=False):
"""
Create a new integer column on the table.
:param column: The column
:type column: str
:type auto_increment: bool
:type unsigned: bool
:rtype: Fluent
"""
return self._add_column(
"integer", column, auto_increment=auto_increment, unsigned=unsigned
) | python | def integer(self, column, auto_increment=False, unsigned=False):
return self._add_column(
"integer", column, auto_increment=auto_increment, unsigned=unsigned
) | [
"def",
"integer",
"(",
"self",
",",
"column",
",",
"auto_increment",
"=",
"False",
",",
"unsigned",
"=",
"False",
")",
":",
"return",
"self",
".",
"_add_column",
"(",
"\"integer\"",
",",
"column",
",",
"auto_increment",
"=",
"auto_increment",
",",
"unsigned"... | Create a new integer column on the table.
:param column: The column
:type column: str
:type auto_increment: bool
:type unsigned: bool
:rtype: Fluent | [
"Create",
"a",
"new",
"integer",
"column",
"on",
"the",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L358-L373 |
244,809 | sdispater/orator | orator/schema/blueprint.py | Blueprint.small_integer | def small_integer(self, column, auto_increment=False, unsigned=False):
"""
Create a new small integer column on the table.
:param column: The column
:type column: str
:type auto_increment: bool
:type unsigned: bool
:rtype: Fluent
"""
return self._add_column(
"small_integer", column, auto_increment=auto_increment, unsigned=unsigned
) | python | def small_integer(self, column, auto_increment=False, unsigned=False):
return self._add_column(
"small_integer", column, auto_increment=auto_increment, unsigned=unsigned
) | [
"def",
"small_integer",
"(",
"self",
",",
"column",
",",
"auto_increment",
"=",
"False",
",",
"unsigned",
"=",
"False",
")",
":",
"return",
"self",
".",
"_add_column",
"(",
"\"small_integer\"",
",",
"column",
",",
"auto_increment",
"=",
"auto_increment",
",",
... | Create a new small integer column on the table.
:param column: The column
:type column: str
:type auto_increment: bool
:type unsigned: bool
:rtype: Fluent | [
"Create",
"a",
"new",
"small",
"integer",
"column",
"on",
"the",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L426-L441 |
244,810 | sdispater/orator | orator/schema/blueprint.py | Blueprint.unsigned_integer | def unsigned_integer(self, column, auto_increment=False):
"""
Create a new unisgned integer column on the table.
:param column: The column
:type column: str
:type auto_increment: bool
:rtype: Fluent
"""
return self.integer(column, auto_increment, True) | python | def unsigned_integer(self, column, auto_increment=False):
return self.integer(column, auto_increment, True) | [
"def",
"unsigned_integer",
"(",
"self",
",",
"column",
",",
"auto_increment",
"=",
"False",
")",
":",
"return",
"self",
".",
"integer",
"(",
"column",
",",
"auto_increment",
",",
"True",
")"
] | Create a new unisgned integer column on the table.
:param column: The column
:type column: str
:type auto_increment: bool
:rtype: Fluent | [
"Create",
"a",
"new",
"unisgned",
"integer",
"column",
"on",
"the",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L443-L454 |
244,811 | sdispater/orator | orator/schema/blueprint.py | Blueprint.unsigned_big_integer | def unsigned_big_integer(self, column, auto_increment=False):
"""
Create a new unsigned big integer column on the table.
:param column: The column
:type column: str
:type auto_increment: bool
:rtype: Fluent
"""
return self.big_integer(column, auto_increment, True) | python | def unsigned_big_integer(self, column, auto_increment=False):
return self.big_integer(column, auto_increment, True) | [
"def",
"unsigned_big_integer",
"(",
"self",
",",
"column",
",",
"auto_increment",
"=",
"False",
")",
":",
"return",
"self",
".",
"big_integer",
"(",
"column",
",",
"auto_increment",
",",
"True",
")"
] | Create a new unsigned big integer column on the table.
:param column: The column
:type column: str
:type auto_increment: bool
:rtype: Fluent | [
"Create",
"a",
"new",
"unsigned",
"big",
"integer",
"column",
"on",
"the",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L456-L467 |
244,812 | sdispater/orator | orator/schema/blueprint.py | Blueprint.float | def float(self, column, total=8, places=2):
"""
Create a new float column on the table.
:param column: The column
:type column: str
:type total: int
:type places: 2
:rtype: Fluent
"""
return self._add_column("float", column, total=total, places=places) | python | def float(self, column, total=8, places=2):
return self._add_column("float", column, total=total, places=places) | [
"def",
"float",
"(",
"self",
",",
"column",
",",
"total",
"=",
"8",
",",
"places",
"=",
"2",
")",
":",
"return",
"self",
".",
"_add_column",
"(",
"\"float\"",
",",
"column",
",",
"total",
"=",
"total",
",",
"places",
"=",
"places",
")"
] | Create a new float column on the table.
:param column: The column
:type column: str
:type total: int
:type places: 2
:rtype: Fluent | [
"Create",
"a",
"new",
"float",
"column",
"on",
"the",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L469-L482 |
244,813 | sdispater/orator | orator/schema/blueprint.py | Blueprint.double | def double(self, column, total=None, places=None):
"""
Create a new double column on the table.
:param column: The column
:type column: str
:type total: int
:type places: 2
:rtype: Fluent
"""
return self._add_column("double", column, total=total, places=places) | python | def double(self, column, total=None, places=None):
return self._add_column("double", column, total=total, places=places) | [
"def",
"double",
"(",
"self",
",",
"column",
",",
"total",
"=",
"None",
",",
"places",
"=",
"None",
")",
":",
"return",
"self",
".",
"_add_column",
"(",
"\"double\"",
",",
"column",
",",
"total",
"=",
"total",
",",
"places",
"=",
"places",
")"
] | Create a new double column on the table.
:param column: The column
:type column: str
:type total: int
:type places: 2
:rtype: Fluent | [
"Create",
"a",
"new",
"double",
"column",
"on",
"the",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L484-L497 |
244,814 | sdispater/orator | orator/schema/blueprint.py | Blueprint.decimal | def decimal(self, column, total=8, places=2):
"""
Create a new decimal column on the table.
:param column: The column
:type column: str
:type total: int
:type places: 2
:rtype: Fluent
"""
return self._add_column("decimal", column, total=total, places=places) | python | def decimal(self, column, total=8, places=2):
return self._add_column("decimal", column, total=total, places=places) | [
"def",
"decimal",
"(",
"self",
",",
"column",
",",
"total",
"=",
"8",
",",
"places",
"=",
"2",
")",
":",
"return",
"self",
".",
"_add_column",
"(",
"\"decimal\"",
",",
"column",
",",
"total",
"=",
"total",
",",
"places",
"=",
"places",
")"
] | Create a new decimal column on the table.
:param column: The column
:type column: str
:type total: int
:type places: 2
:rtype: Fluent | [
"Create",
"a",
"new",
"decimal",
"column",
"on",
"the",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L499-L512 |
244,815 | sdispater/orator | orator/schema/blueprint.py | Blueprint.timestamps | def timestamps(self, use_current=True):
"""
Create creation and update timestamps to the table.
:rtype: Fluent
"""
if use_current:
self.timestamp("created_at").use_current()
self.timestamp("updated_at").use_current()
else:
self.timestamp("created_at")
self.timestamp("updated_at") | python | def timestamps(self, use_current=True):
if use_current:
self.timestamp("created_at").use_current()
self.timestamp("updated_at").use_current()
else:
self.timestamp("created_at")
self.timestamp("updated_at") | [
"def",
"timestamps",
"(",
"self",
",",
"use_current",
"=",
"True",
")",
":",
"if",
"use_current",
":",
"self",
".",
"timestamp",
"(",
"\"created_at\"",
")",
".",
"use_current",
"(",
")",
"self",
".",
"timestamp",
"(",
"\"updated_at\"",
")",
".",
"use_curre... | Create creation and update timestamps to the table.
:rtype: Fluent | [
"Create",
"creation",
"and",
"update",
"timestamps",
"to",
"the",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L602-L613 |
244,816 | 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):
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",
"(",
"[",
"\"... | 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 |
244,817 | 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):
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",
... | 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 |
244,818 | 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):
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",
".",
... | 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 |
244,819 | 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):
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 |
244,820 | 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):
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... | 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 |
244,821 | 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):
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",... | 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 |
244,822 | 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):
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",
... | 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 |
244,823 | 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):
# 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",
"... | 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 |
244,824 | 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):
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... | 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 |
244,825 | 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):
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_col... | 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 |
244,826 | 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):
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 |
244,827 | 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):
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",
"+=",
"\" DEF... | 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 |
244,828 | 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):
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",
"(... | 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 |
244,829 | 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):
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_timestamp... | 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 |
244,830 | 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):
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",
"(",
"\"+\"",
",",
"\".\"",
")",
"cl... | 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 |
244,831 | 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):
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\"",
... | 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 |
244,832 | 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):
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",
")",
":",
"const... | 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 |
244,833 | 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):
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",
"DBALEx... | 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 |
244,834 | 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):
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",
")",
"r... | 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 |
244,835 | 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):
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",
"+=",
... | 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 |
244,836 | 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):
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... | 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 |
244,837 | 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):
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",
")",
... | 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 |
244,838 | 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):
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_... | 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 |
244,839 | 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):
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",
"("... | 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 |
244,840 | 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):
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",
"(",
"sel... | 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 |
244,841 | 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):
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\"",
... | 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 |
244,842 | 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):
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 |
244,843 | 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):
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\"",
"%",
"i... | 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 |
244,844 | 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):
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",... | 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 |
244,845 | 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):
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",
"\".... | 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",
... | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L655-L672 |
244,846 | 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):
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",
"(",... | 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 |
244,847 | 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):
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 |
244,848 | 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):
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 |
244,849 | 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):
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",
... | 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 |
244,850 | 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):
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",
".",
"resol... | 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 |
244,851 | 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):
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 |
244,852 | 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):
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\... | 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 |
244,853 | 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_):
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",
"i... | 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 |
244,854 | 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):
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 |
244,855 | 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):
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 |
244,856 | 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):
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",... | 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 |
244,857 | 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):
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 |
244,858 | 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):
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 |
244,859 | 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"):
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",
",",
... | 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 |
244,860 | 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"):
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",
"(",
")",
"==",
"\"as... | 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 |
244,861 | 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):
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",
... | 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 |
244,862 | 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):
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"... | 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 |
244,863 | 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):
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 |
244,864 | 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):
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 |
244,865 | 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):
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",
"(",
... | 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 |
244,866 | 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):
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",
"}",
"p... | 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 |
244,867 | 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):
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",
... | 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 |
244,868 | 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):
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",
... | 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 |
244,869 | 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):
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 |
244,870 | 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):
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 |
244,871 | 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):
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",
... | 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 |
244,872 | 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):
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",
"... | 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 |
244,873 | 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):
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",
"(",
"... | 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 |
244,874 | 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):
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",
"(",
")",
")",
".",
"whe... | 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 |
244,875 | 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):
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",
"(",
"\"Initia... | 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 |
244,876 | 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):
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 |
244,877 | 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):
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 |
244,878 | 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):
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",
"(",... | 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 |
244,879 | 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):
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 |
244,880 | 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):
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",
... | 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 |
244,881 | 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):
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_c... | 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 |
244,882 | 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):
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",
"(",
"bluep... | 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 |
244,883 | 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):
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 |
244,884 | 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):
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",
",",
"... | 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 |
244,885 | 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):
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_where... | 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 |
244,886 | 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):
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... | 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 |
244,887 | 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):
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",
".",
"g... | 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 |
244,888 | 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):
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 |
244,889 | 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):
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 r... | 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 |
244,890 | 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):
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 |
244,891 | 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):
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",
"(",
... | 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 |
244,892 | 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):
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 |
244,893 | 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):
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",
"... | 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 |
244,894 | 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):
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",... | 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 |
244,895 | 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):
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\... | 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 |
244,896 | 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):
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",
"(",
... | 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 |
244,897 | 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):
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",
".",
"_re... | 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 |
244,898 | 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):
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... | 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 |
244,899 | 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):
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",
"=",
"... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.