INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Get a list with the values of a given column
:param column: The column to get the values for
:type column: str
:param key: The key
:type key: str
:return: The list of values
:rtype: Collection or dict | def lists(self, column, key=None):
"""
Get a list with the values of a given column
:param column: The column to get the values for
:type column: str
:param key: The key
:type key: str
:return: The list of values
:rtype: Collection or dict
"""
... |
Determine if any rows exist for the current query.
:return: Whether the rows exist or not
:rtype: bool | 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 |
Retrieve the "count" result of the query
:param columns: The columns to get
:type columns: tuple
:return: The count
:rtype: int | 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 colum... |
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 | 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
:rt... |
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 | 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... |
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 | 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 prima... |
Update a record in the database
:param values: The values of the update
:type values: dict
:return: The number of records affected
:rtype: int | def update(self, _values=None, **values):
"""
Update a record in the database
:param values: The values of the update
:type values: dict
:return: The number of records affected
:rtype: int
"""
if _values is not None:
values.update(_values)
... |
Run a truncate statement on the table
:rtype: None | 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) |
Remove all of the expressions from bindings
:param bindings: The bindings to clean
:type bindings: list
:return: The cleaned bindings
:rtype: list | 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... |
Merge current query with another.
:param query: The query to merge with
:type query: QueryBuilder | 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
... |
Sets the name of this asset.
:param name: The name of the asset
:type name: str | 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 =... |
Generates an identifier from a list of column names obeying a certain string length. | 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 (pref... |
This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used. | def deprecated(func):
"""This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used."""
@functools.wraps(func)
def new_func(*args, **kwargs):
if PY3K:
func_code = func.__code__
else:
... |
Force a hard delete on a soft deleted model. | def force_delete(self):
"""
Force a hard delete on a soft deleted model.
"""
self.__force_deleting__ = True
self.delete()
self.__force_deleting__ = False |
Restore a soft-deleted model instance. | def restore(self):
"""
Restore a soft-deleted model instance.
"""
if self._fire_model_event("restoring") is False:
return False
setattr(self, self.get_deleted_at_column(), None)
self.set_exists(True)
result = self.save()
self._fire_model_ev... |
Perform the actual delete query on this model instance. | def _run_soft_delete(self):
"""
Perform the actual delete query on this model instance.
"""
query = self.new_query().where(self.get_key_name(), self.get_key())
time = self.fresh_timestamp()
setattr(self, self.get_deleted_at_column(), time)
query.update({self.get... |
Get a new query builder that only includes soft deletes
:type cls: orator.orm.model.Model
:rtype: orator.orm.builder.Builder | 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_w... |
Compile a rename column command.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param connection: The connection
:type connection: orator.connections.Connection
:rtype: list | def compile_rename_column(self, blueprint, command, connection):
"""
Compile a rename column command.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param connection: The connection
:type co... |
Get the dbal column type.
:param type_: The fluent type
:type type_: str
:rtype: str | def _get_dbal_column_type(self, type_):
"""
Get the dbal column type.
:param type_: The fluent type
:type type_: str
:rtype: str
"""
type_ = type_.lower()
if type_ == "enum":
return "string"
return super(SQLiteSchemaGrammar, self)._... |
Executes the command. | def handle(self):
"""
Executes the command.
"""
if not self.confirm_to_proceed(
"<question>Are you sure you want to refresh the database?:</question> "
):
return
database = self.option("database")
options = [("--force", True)]
if... |
Get a database connection instance
:param name: The connection name
:type name: str
:return: A Connection instance
:rtype: orator.connections.connection.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)
... |
Executes the command. | def handle(self):
"""
Executes the command.
"""
if not self.confirm_to_proceed(
"<question>Are you sure you want to rollback the last migration?:</question> "
):
return
database = self.option("database")
repository = DatabaseMigrationRepos... |
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 | 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_de... |
The delete replacement function.
:param builder: The query builder
:type builder: orator.orm.builder.Builder | 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()... |
Get the "deleted at" column for the builder.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
:rtype: str | 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().... |
The restore extension.
:param builder: The query builder
:type builder: orator.orm.builder.Builder | 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}) |
Match the eagerly loaded results to their parents.
:type models: list
:type results: Collection
:type relation: str | def match(self, models, results, relation):
"""
Match the eagerly loaded results to their parents.
:type models: list
:type results: Collection
:type relation: str
"""
return self.match_one(models, results, relation) |
Determine if the given table exists.
:param table: The table
:type table: str
:rtype: bool | 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._conne... |
Determine if the given table has a given column.
:param table: The table
:type table: str
:type column: str
:rtype: bool | 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.ge... |
Get the column listing for a given table.
:param table: The table
:type table: str
:rtype: list | def get_column_listing(self, table):
"""
Get the column listing for a given table.
:param table: The table
:type table: str
:rtype: list
"""
table = self._connection.get_table_prefix() + table
results = self._connection.select(self._grammar.compile_colu... |
Modify a table on the schema.
:param table: The 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)
... |
Drop a table from the schema.
:param table: The table
:type table: str | def drop(self, table):
"""
Drop a table from the schema.
:param table: The table
:type table: str
"""
blueprint = self._create_blueprint(table)
blueprint.drop()
self._build(blueprint) |
Drop a table from the schema.
:param table: The table
:type table: str | def drop_if_exists(self, table):
"""
Drop a table from the schema.
:param table: The table
:type table: str
"""
blueprint = self._create_blueprint(table)
blueprint.drop_if_exists()
self._build(blueprint) |
Rename a table on the schema. | def rename(self, from_, to):
"""
Rename a table on the schema.
"""
blueprint = self._create_blueprint(from_)
blueprint.rename(to)
self._build(blueprint) |
Process an "insert get ID" query.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param sql: The sql query to execute
:type sql: str
:param values: The value bindings
:type values: list
:param sequence: The ids sequence
:type sequence:... | def process_insert_get_id(self, query, sql, values, sequence=None):
"""
Process an "insert get ID" query.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param sql: The sql query to execute
:type sql: str
:param values: The value bindings
... |
Executes the command. | def handle(self):
"""
Executes the command.
"""
creator = MigrationCreator()
name = self.argument("name")
table = self.option("table")
create = bool(self.option("create"))
if not table and create is not False:
table = create
path = s... |
Write the migration file to disk. | 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_ |
Load a set of relationships onto the collection. | def load(self, *relations):
"""
Load a set of relationships onto the collection.
"""
if len(self.items) > 0:
query = self.first().new_query().with_(*relations)
self._set_items(query.eager_load_relations(self.items))
return self |
Compile a select query into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str | def compile_select(self, query):
"""
Compile a select query into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
sql = super(MySQLQueryGrammar, self).compile_select(query)
if query.un... |
Compile a delete statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled update
:rtype: str | 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.where... |
Executes the command. | def execute(self, i, o):
"""
Executes the command.
"""
self.set_style("question", fg="blue")
if self.needs_config and not self.resolver:
self._handle_config(self.option("config"))
return self.handle() |
Check presence of default config files.
:rtype: bool | 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_pat... |
Check and handle a config file.
:param config_file: The path to the config file
:type config_file: str
:rtype: bool | 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 the config.
:rtype: dict | def _get_config(self, path=None):
"""
Get the config.
:rtype: dict
"""
if not path and not self.option("config"):
raise Exception("The --config|-c option is missing.")
if not path:
path = self.option("config")
filename, ext = os.path.spl... |
Set the constraints for an eager load of the relation.
:type models: list | def add_eager_constraints(self, models):
"""
Set the constraints for an eager load of the relation.
:type models: list
"""
table = self._parent.get_table()
self._query.where_in("%s.%s" % (table, self._first_key), self.get_keys(models)) |
Build model dictionary keyed by the relation's foreign key.
:param results: The results
:type results: Collection
:rtype: dict | def _build_dictionary(self, results):
"""
Build model dictionary keyed by the relation's foreign key.
:param results: The results
:type results: Collection
:rtype: dict
"""
foreign = self._first_key
dictionary = {}
for result in results:
... |
Set the select clause for the relation query.
:param columns: The columns
:type columns: list
:rtype: list | def _get_select_columns(self, columns=None):
"""
Set the select clause for the relation query.
:param columns: The columns
:type columns: list
:rtype: list
"""
if columns == ["*"] or columns is None:
columns = ["%s.*" % self._related.get_table()]
... |
Log that a migration was run.
:type file: str
:type batch: int | 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) |
Create the migration repository data store. | 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
# migrat... |
Determine if the repository exists.
:rtype: bool | def repository_exists(self):
"""
Determine if the repository exists.
:rtype: bool
"""
schema = self.get_connection().get_schema_builder()
return schema.has_table(self._table) |
Set the base constraints of the relation query | def add_constraints(self):
"""
Set the base constraints of the relation query
"""
if self._constraints:
super(MorphOneOrMany, self).add_constraints()
self._query.where(self._morph_type, self._morph_name) |
Attach a model instance to the parent models.
:param model: The model instance to attach
:type model: Model
:rtype: Model | def save(self, model):
"""
Attach a model instance to the parent models.
:param model: The model instance to attach
:type model: Model
:rtype: Model
"""
model.set_attribute(self.get_plain_morph_type(), self._morph_name)
return super(MorphOneOrMany, self... |
Get the first related model record matching the attributes or instantiate it.
:param attributes: The attributes
:type attributes: dict
:rtype: Model | def first_or_new(self, _attributes=None, **attributes):
"""
Get the first related model record matching the attributes or instantiate it.
:param attributes: The attributes
:type attributes: dict
:rtype: Model
"""
if _attributes is not None:
attribut... |
Create a new instance of the related model.
:param attributes: The attributes
:type attributes: dict
:rtype: Model | def create(self, _attributes=None, **attributes):
"""
Create a new instance of the related model.
:param attributes: The attributes
:type attributes: dict
:rtype: Model
"""
if _attributes is not None:
attributes.update(_attributes)
instance ... |
Set the foreign ID and type for creation a related model. | def _set_foreign_attributes_for_create(self, model):
"""
Set the foreign ID and type for creation a related model.
"""
model.set_attribute(self.get_plain_foreign_key(), self.get_parent_key())
model.set_attribute(self.get_plain_morph_type(), self._morph_name) |
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
:t... | 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: ... |
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 | 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 B... |
Process an "insert get ID" query.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param sql: The sql query to execute
:type sql: str
:param values: The value bindings
:type values: list
:param sequence: The ids sequence
:type sequence:... | def process_insert_get_id(self, query, sql, values, sequence=None):
"""
Process an "insert get ID" query.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param sql: The sql query to execute
:type sql: str
:param values: The value bindings
... |
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 ret... | 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 platf... |
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 retur... | 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 platf... |
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 | 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
... |
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 | 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... |
Run a list of migrations.
:type migrations: list
:type pretend: bool | 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... |
Run "up" a migration instance.
:type migration_file: str
:type batch: int
:type pretend: bool | def _run_up(self, path, migration_file, batch, pretend=False):
"""
Run "up" a migration instance.
:type migration_file: str
:type batch: int
:type pretend: bool
"""
migration = self._resolve(path, migration_file)
if pretend:
return self._pr... |
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 | 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 = ... |
Run "down" a migration instance. | def _run_down(self, path, migration, pretend=False):
"""
Run "down" a migration instance.
"""
migration_file = migration["migration"]
instance = self._resolve(path, migration_file)
if pretend:
return self._pretend_to_run(instance, "down")
if instanc... |
Get all of the migration files in a given path.
:type path: str
:rtype: list | 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.basen... |
Pretend to run the migration.
:param migration: The migration
:type migration: orator.migrations.migration.Migration
:param method: The method to execute
:type method: str | def _pretend_to_run(self, migration, method):
"""
Pretend to run the migration.
:param migration: The migration
:type migration: orator.migrations.migration.Migration
:param method: The method to execute
:type method: str
"""
self._note("")
names... |
Get all of the queries that would be run for a migration.
:param migration: The migration
:type migration: orator.migrations.migration.Migration
:param method: The method to execute
:type method: str
:rtype: list | def _get_queries(self, migration, method):
"""
Get all of the queries that would be run for a migration.
:param migration: The migration
:type migration: orator.migrations.migration.Migration
:param method: The method to execute
:type method: str
:rtype: list
... |
Resolve a migration instance from a file.
:param migration_file: The migration file
:type migration_file: str
:rtype: orator.migrations.migration.Migration | def _resolve(self, path, migration_file):
"""
Resolve a migration instance from a file.
:param migration_file: The migration file
:type migration_file: str
:rtype: orator.migrations.migration.Migration
"""
name = "_".join(migration_file.split("_")[4:])
m... |
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: list | def get_pre_alter_table_index_foreign_key_sql(self, diff):
"""
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: list
"""
if not isinstance(diff.from_table, Table):
raise DBALException(
"Sqlite platform requires ... |
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: list | def get_post_alter_table_index_foreign_key_sql(self, diff):
"""
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: list
"""
if not isinstance(diff.from_table, Table):
raise DBALException(
"Sqlite platform requires... |
Get the ALTER TABLE SQL statement
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: list | def get_alter_table_sql(self, diff):
"""
Get the ALTER TABLE SQL statement
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: list
"""
sql = self._get_simple_alter_table_sql(diff)
if sql is not False:
return sql
... |
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: dict | def _get_indexes_in_altered_table(self, diff):
"""
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: dict
"""
indexes = diff.from_table.get_indexes()
column_names = self._get_column_names_in_altered_table(diff)
for key, ind... |
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: dict | def _get_column_names_in_altered_table(self, diff):
"""
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: dict
"""
columns = OrderedDict()
for column_name, column in diff.from_table.get_columns().items():
columns[column... |
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: dict | def _get_foreign_keys_in_altered_table(self, diff):
"""
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: dict
"""
foreign_keys = diff.from_table.get_foreign_keys()
column_names = self._get_column_names_in_altered_table(diff)
... |
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: dict | def _get_primary_index_in_altered_table(self, diff):
"""
:param diff: The table diff
:type diff: orator.dbal.table_diff.TableDiff
:rtype: dict
"""
primary_index = {}
for index in self._get_indexes_in_altered_table(diff).values():
if index.is_primary(... |
Executes the command. | def handle(self):
"""
Executes the command.
"""
database = self.option("database")
self.resolver.set_default_connection(database)
repository = DatabaseMigrationRepository(self.resolver, "migrations")
migrator = Migrator(repository, self.resolver)
if no... |
Compile an update statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param values: The update values
:type values: dict
:return: The compiled update
:rtype: str | def compile_update(self, query, values):
"""
Compile an update statement into SQL
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param values: The update values
:type values: dict
:return: The compiled update
:rtype: str
"""
... |
Compile the columns for the update statement
:param values: The columns
:type values: dict
:return: The compiled columns
:rtype: str | def _compile_update_columns(self, values):
"""
Compile the columns for the update statement
:param values: The columns
:type values: dict
:return: The compiled columns
:rtype: str
"""
columns = []
for key, value in values.items():
co... |
Compile the "from" clause for an update with a join.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str | def _compile_update_from(self, query):
"""
Compile the "from" clause for an update with a join.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
if not query.joins:
return ""
f... |
Compile the additional where clauses for updates with joins.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str | def _compile_update_wheres(self, query):
"""
Compile the additional where clauses for updates with joins.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
base_where = self._compile_wheres(query)
... |
Compile the "join" clauses for an update.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str | def _compile_update_join_wheres(self, query):
"""
Compile the "join" clauses for an update.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:return: The compiled sql
:rtype: str
"""
join_wheres = []
for join in query.joins:
... |
Compile an insert and get ID statement into SQL.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param values: The values to insert
:type values: dict
:param sequence: The id sequence
:type sequence: str
:return: The compiled statement
... | def compile_insert_get_id(self, query, values, sequence=None):
"""
Compile an insert and get ID statement into SQL.
:param query: A QueryBuilder instance
:type query: QueryBuilder
:param values: The values to insert
:type values: dict
:param sequence: The id se... |
Convert a "qmark" query into "format" style. | def qmark(cls, query):
"""
Convert a "qmark" query into "format" style.
"""
def sub_sequence(m):
s = m.group(0)
if s == "??":
return "?"
if s == "%":
return "%%"
else:
return "%s"
re... |
Touch all of the related models for the relationship. | def touch(self):
"""
Touch all of the related models for the relationship.
"""
column = self.get_related().get_updated_at_column()
self.raw_update({column: self.get_related().fresh_timestamp()}) |
Run a raw update against the base query.
:type attributes: dict
:rtype: int | def raw_update(self, attributes=None):
"""
Run a raw update against the base query.
:type attributes: dict
:rtype: int
"""
if attributes is None:
attributes = {}
if self._query is not None:
return self._query.update(attributes) |
Add the constraints for a relationship count query.
:type query: Builder
:type parent: Builder
:rtype: Builder | def get_relation_count_query(self, query, parent):
"""
Add the constraints for a relationship count query.
:type query: Builder
:type parent: Builder
:rtype: Builder
"""
query.select(QueryExpression("COUNT(*)"))
key = self.wrap(self.get_qualified_parent... |
Runs a callback with constraints disabled on the relation. | def no_constraints(cls, with_subclasses=False):
"""
Runs a callback with constraints disabled on the relation.
"""
cls._constraints = False
if with_subclasses:
for klass in cls.__subclasses__():
klass._constraints = False
try:
yie... |
Wrap the given value with the parent's query grammar.
:rtype: str | def wrap(self, value):
"""
Wrap the given value with the parent's query grammar.
:rtype: str
"""
return self._parent.new_query().get_query().get_grammar().wrap(value) |
Try to guess the input format | def load(template):
"""
Try to guess the input format
"""
try:
data = load_json(template)
return data, "json"
except ValueError as e:
try:
data = load_yaml(template)
return data, "yaml"
except Exception:
raise e |
Output some YAML | def dump_yaml(data, clean_up=False, long_form=False):
"""
Output some YAML
"""
return yaml.dump(
data,
Dumper=get_dumper(clean_up, long_form),
default_flow_style=False,
allow_unicode=True
) |
Assume the input is YAML and convert to JSON | def to_json(template, clean_up=False):
"""
Assume the input is YAML and convert to JSON
"""
data = load_yaml(template)
if clean_up:
data = clean(data)
return dump_json(data) |
Assume the input is JSON and convert to YAML | def to_yaml(template, clean_up=False, long_form=False):
"""
Assume the input is JSON and convert to YAML
"""
data = load_json(template)
if clean_up:
data = clean(data)
return dump_yaml(data, clean_up, long_form) |
Figure out the input format and convert the data to the opposing output format | def flip(template, in_format=None, out_format=None, clean_up=False, no_flip=False, long_form=False):
"""
Figure out the input format and convert the data to the opposing output format
"""
# Do we need to figure out the input format?
if not in_format:
# Load the template as JSON?
if ... |
Fix a Join ;) | def convert_join(value):
"""
Fix a Join ;)
"""
if not isinstance(value, list) or len(value) != 2:
# Cowardly refuse
return value
sep, parts = value[0], value[1]
if isinstance(parts, six.string_types):
return parts
if not isinstance(parts, list):
# This loo... |
Clean up the source:
* Replace use of Fn::Join with Fn::Sub | def clean(source):
"""
Clean up the source:
* Replace use of Fn::Join with Fn::Sub
"""
if isinstance(source, dict):
for key, value in source.items():
if key == "Fn::Join":
return convert_join(value)
else:
source[key] = clean(value)
... |
Deal with !Ref style function format and OrderedDict | def map_representer(dumper, value):
"""
Deal with !Ref style function format and OrderedDict
"""
value = ODict(value.items())
if len(value.keys()) == 1:
key = list(value.keys())[0]
if key in CONVERTED_SUFFIXES:
return fn_representer(dumper, key, value[key])
if... |
Deal with !Ref style function format | def multi_constructor(loader, tag_suffix, node):
"""
Deal with !Ref style function format
"""
if tag_suffix not in UNCONVERTED_SUFFIXES:
tag_suffix = "{}{}".format(FN_PREFIX, tag_suffix)
constructor = None
if tag_suffix == "Fn::GetAtt":
constructor = construct_getatt
elif ... |
Reconstruct !GetAtt into a list | def construct_getatt(node):
"""
Reconstruct !GetAtt into a list
"""
if isinstance(node.value, six.text_type):
return node.value.split(".", 1)
elif isinstance(node.value, list):
return [s.value for s in node.value]
else:
raise ValueError("Unexpected node type: {}".format(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.