id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
230,900 | TheHive-Project/Cortex-Analyzers | analyzers/TorProject/tor_project.py | TorProjectClient.search_tor_node | def search_tor_node(self, ip):
"""Lookup an IP address to check if it is a known tor exit node.
:param ip: The IP address to lookup
:type ip: str
:return: Data relative to the tor node. If `ip`is a tor exit node
it will contain a `node` key with the hash of the node and
a `last_status` key with the last update time of the node.
If `ip` is not a tor exit node, the function will return an
empty dictionary.
:rtype: dict
"""
data = {}
tmp = {}
present = datetime.utcnow().replace(tzinfo=pytz.utc)
for line in self._get_raw_data().splitlines():
params = line.split(' ')
if params[0] == 'ExitNode':
tmp['node'] = params[1]
elif params[0] == 'ExitAddress':
tmp['last_status'] = params[2] + 'T' + params[3] + '+0000'
last_status = parse(tmp['last_status'])
if (self.delta is None or
(present - last_status) < self.delta):
data[params[1]] = tmp
tmp = {}
else:
pass
return data.get(ip, {}) | python | def search_tor_node(self, ip):
"""Lookup an IP address to check if it is a known tor exit node.
:param ip: The IP address to lookup
:type ip: str
:return: Data relative to the tor node. If `ip`is a tor exit node
it will contain a `node` key with the hash of the node and
a `last_status` key with the last update time of the node.
If `ip` is not a tor exit node, the function will return an
empty dictionary.
:rtype: dict
"""
data = {}
tmp = {}
present = datetime.utcnow().replace(tzinfo=pytz.utc)
for line in self._get_raw_data().splitlines():
params = line.split(' ')
if params[0] == 'ExitNode':
tmp['node'] = params[1]
elif params[0] == 'ExitAddress':
tmp['last_status'] = params[2] + 'T' + params[3] + '+0000'
last_status = parse(tmp['last_status'])
if (self.delta is None or
(present - last_status) < self.delta):
data[params[1]] = tmp
tmp = {}
else:
pass
return data.get(ip, {}) | [
"def",
"search_tor_node",
"(",
"self",
",",
"ip",
")",
":",
"data",
"=",
"{",
"}",
"tmp",
"=",
"{",
"}",
"present",
"=",
"datetime",
".",
"utcnow",
"(",
")",
".",
"replace",
"(",
"tzinfo",
"=",
"pytz",
".",
"utc",
")",
"for",
"line",
"in",
"self",
".",
"_get_raw_data",
"(",
")",
".",
"splitlines",
"(",
")",
":",
"params",
"=",
"line",
".",
"split",
"(",
"' '",
")",
"if",
"params",
"[",
"0",
"]",
"==",
"'ExitNode'",
":",
"tmp",
"[",
"'node'",
"]",
"=",
"params",
"[",
"1",
"]",
"elif",
"params",
"[",
"0",
"]",
"==",
"'ExitAddress'",
":",
"tmp",
"[",
"'last_status'",
"]",
"=",
"params",
"[",
"2",
"]",
"+",
"'T'",
"+",
"params",
"[",
"3",
"]",
"+",
"'+0000'",
"last_status",
"=",
"parse",
"(",
"tmp",
"[",
"'last_status'",
"]",
")",
"if",
"(",
"self",
".",
"delta",
"is",
"None",
"or",
"(",
"present",
"-",
"last_status",
")",
"<",
"self",
".",
"delta",
")",
":",
"data",
"[",
"params",
"[",
"1",
"]",
"]",
"=",
"tmp",
"tmp",
"=",
"{",
"}",
"else",
":",
"pass",
"return",
"data",
".",
"get",
"(",
"ip",
",",
"{",
"}",
")"
] | Lookup an IP address to check if it is a known tor exit node.
:param ip: The IP address to lookup
:type ip: str
:return: Data relative to the tor node. If `ip`is a tor exit node
it will contain a `node` key with the hash of the node and
a `last_status` key with the last update time of the node.
If `ip` is not a tor exit node, the function will return an
empty dictionary.
:rtype: dict | [
"Lookup",
"an",
"IP",
"address",
"to",
"check",
"if",
"it",
"is",
"a",
"known",
"tor",
"exit",
"node",
"."
] | 8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf | https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/TorProject/tor_project.py#L52-L80 |
230,901 | TheHive-Project/Cortex-Analyzers | analyzers/Censys/censys_analyzer.py | CensysAnalyzer.search_hosts | def search_hosts(self, ip):
"""
Searches for a host using its ipv4 address
:param ip: ipv4 address as string
:type ip: str
:return: dict
"""
c = CensysIPv4(api_id=self.__uid, api_secret=self.__api_key)
return c.view(ip) | python | def search_hosts(self, ip):
"""
Searches for a host using its ipv4 address
:param ip: ipv4 address as string
:type ip: str
:return: dict
"""
c = CensysIPv4(api_id=self.__uid, api_secret=self.__api_key)
return c.view(ip) | [
"def",
"search_hosts",
"(",
"self",
",",
"ip",
")",
":",
"c",
"=",
"CensysIPv4",
"(",
"api_id",
"=",
"self",
".",
"__uid",
",",
"api_secret",
"=",
"self",
".",
"__api_key",
")",
"return",
"c",
".",
"view",
"(",
"ip",
")"
] | Searches for a host using its ipv4 address
:param ip: ipv4 address as string
:type ip: str
:return: dict | [
"Searches",
"for",
"a",
"host",
"using",
"its",
"ipv4",
"address"
] | 8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf | https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/Censys/censys_analyzer.py#L24-L33 |
230,902 | TheHive-Project/Cortex-Analyzers | analyzers/Censys/censys_analyzer.py | CensysAnalyzer.search_certificate | def search_certificate(self, hash):
"""
Searches for a specific certificate using its hash
:param hash: certificate hash
:type hash: str
:return: dict
"""
c = CensysCertificates(api_id=self.__uid, api_secret=self.__api_key)
return c.view(hash) | python | def search_certificate(self, hash):
"""
Searches for a specific certificate using its hash
:param hash: certificate hash
:type hash: str
:return: dict
"""
c = CensysCertificates(api_id=self.__uid, api_secret=self.__api_key)
return c.view(hash) | [
"def",
"search_certificate",
"(",
"self",
",",
"hash",
")",
":",
"c",
"=",
"CensysCertificates",
"(",
"api_id",
"=",
"self",
".",
"__uid",
",",
"api_secret",
"=",
"self",
".",
"__api_key",
")",
"return",
"c",
".",
"view",
"(",
"hash",
")"
] | Searches for a specific certificate using its hash
:param hash: certificate hash
:type hash: str
:return: dict | [
"Searches",
"for",
"a",
"specific",
"certificate",
"using",
"its",
"hash"
] | 8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf | https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/Censys/censys_analyzer.py#L35-L44 |
230,903 | TheHive-Project/Cortex-Analyzers | analyzers/StopForumSpam/stopforumspam_client.py | StopforumspamClient.get_data | def get_data(self, datatype, data):
""" Look for an IP address or an email address in the spammer database.
:param datatype: Which type of data is to be looked up.
Allowed values are 'ip' or 'mail'.
:param data: The value to be looked up through the API.
:type datatype: str
:type data: str
:return: Data relative to the looked up artifact.
:rtype: dict
"""
result = {}
params = StopforumspamClient._set_payload(datatype, data)
response = self.client.get(
'https://api.stopforumspam.org/api',
params=params, proxies=self.proxies)
response.raise_for_status()
report = response.json()
if report['success']:
data = report[StopforumspamClient._type_conversion[datatype]]
result = self._data_conversion(data)
else:
pass
return result | python | def get_data(self, datatype, data):
""" Look for an IP address or an email address in the spammer database.
:param datatype: Which type of data is to be looked up.
Allowed values are 'ip' or 'mail'.
:param data: The value to be looked up through the API.
:type datatype: str
:type data: str
:return: Data relative to the looked up artifact.
:rtype: dict
"""
result = {}
params = StopforumspamClient._set_payload(datatype, data)
response = self.client.get(
'https://api.stopforumspam.org/api',
params=params, proxies=self.proxies)
response.raise_for_status()
report = response.json()
if report['success']:
data = report[StopforumspamClient._type_conversion[datatype]]
result = self._data_conversion(data)
else:
pass
return result | [
"def",
"get_data",
"(",
"self",
",",
"datatype",
",",
"data",
")",
":",
"result",
"=",
"{",
"}",
"params",
"=",
"StopforumspamClient",
".",
"_set_payload",
"(",
"datatype",
",",
"data",
")",
"response",
"=",
"self",
".",
"client",
".",
"get",
"(",
"'https://api.stopforumspam.org/api'",
",",
"params",
"=",
"params",
",",
"proxies",
"=",
"self",
".",
"proxies",
")",
"response",
".",
"raise_for_status",
"(",
")",
"report",
"=",
"response",
".",
"json",
"(",
")",
"if",
"report",
"[",
"'success'",
"]",
":",
"data",
"=",
"report",
"[",
"StopforumspamClient",
".",
"_type_conversion",
"[",
"datatype",
"]",
"]",
"result",
"=",
"self",
".",
"_data_conversion",
"(",
"data",
")",
"else",
":",
"pass",
"return",
"result"
] | Look for an IP address or an email address in the spammer database.
:param datatype: Which type of data is to be looked up.
Allowed values are 'ip' or 'mail'.
:param data: The value to be looked up through the API.
:type datatype: str
:type data: str
:return: Data relative to the looked up artifact.
:rtype: dict | [
"Look",
"for",
"an",
"IP",
"address",
"or",
"an",
"email",
"address",
"in",
"the",
"spammer",
"database",
"."
] | 8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf | https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/StopForumSpam/stopforumspam_client.py#L47-L70 |
230,904 | sdispater/orator | orator/orm/factory.py | Factory.construct | def construct(cls, faker, path_to_factories=None):
"""
Create a new factory container.
:param faker: A faker generator instance
:type faker: faker.Generator
:param path_to_factories: The path to factories
:type path_to_factories: str
:rtype: Factory
"""
factory = faker.__class__()
if path_to_factories is not None and os.path.isdir(path_to_factories):
for filename in os.listdir(path_to_factories):
if os.path.isfile(filename):
cls._resolve(path_to_factories, filename)
return factory | python | def construct(cls, faker, path_to_factories=None):
"""
Create a new factory container.
:param faker: A faker generator instance
:type faker: faker.Generator
:param path_to_factories: The path to factories
:type path_to_factories: str
:rtype: Factory
"""
factory = faker.__class__()
if path_to_factories is not None and os.path.isdir(path_to_factories):
for filename in os.listdir(path_to_factories):
if os.path.isfile(filename):
cls._resolve(path_to_factories, filename)
return factory | [
"def",
"construct",
"(",
"cls",
",",
"faker",
",",
"path_to_factories",
"=",
"None",
")",
":",
"factory",
"=",
"faker",
".",
"__class__",
"(",
")",
"if",
"path_to_factories",
"is",
"not",
"None",
"and",
"os",
".",
"path",
".",
"isdir",
"(",
"path_to_factories",
")",
":",
"for",
"filename",
"in",
"os",
".",
"listdir",
"(",
"path_to_factories",
")",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
")",
":",
"cls",
".",
"_resolve",
"(",
"path_to_factories",
",",
"filename",
")",
"return",
"factory"
] | Create a new factory container.
:param faker: A faker generator instance
:type faker: faker.Generator
:param path_to_factories: The path to factories
:type path_to_factories: str
:rtype: Factory | [
"Create",
"a",
"new",
"factory",
"container",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L25-L44 |
230,905 | sdispater/orator | orator/orm/factory.py | Factory.define | def define(self, klass, name="default"):
"""
Define a class with a given set of attributes.
:param klass: The class
:type klass: class
:param name: The short name
:type name: str
"""
def decorate(func):
@wraps(func)
def wrapped(*args, **kwargs):
return func(*args, **kwargs)
self.register(klass, func, name=name)
return wrapped
return decorate | python | def define(self, klass, name="default"):
"""
Define a class with a given set of attributes.
:param klass: The class
:type klass: class
:param name: The short name
:type name: str
"""
def decorate(func):
@wraps(func)
def wrapped(*args, **kwargs):
return func(*args, **kwargs)
self.register(klass, func, name=name)
return wrapped
return decorate | [
"def",
"define",
"(",
"self",
",",
"klass",
",",
"name",
"=",
"\"default\"",
")",
":",
"def",
"decorate",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"self",
".",
"register",
"(",
"klass",
",",
"func",
",",
"name",
"=",
"name",
")",
"return",
"wrapped",
"return",
"decorate"
] | Define a class with a given set of attributes.
:param klass: The class
:type klass: class
:param name: The short name
:type name: str | [
"Define",
"a",
"class",
"with",
"a",
"given",
"set",
"of",
"attributes",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L58-L78 |
230,906 | sdispater/orator | orator/orm/factory.py | Factory.create_as | def create_as(self, klass, name, **attributes):
"""
Create an instance of the given model and type and persist it to the database.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
:return: mixed
"""
return self.of(klass, name).create(**attributes) | python | def create_as(self, klass, name, **attributes):
"""
Create an instance of the given model and type and persist it to the database.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
:return: mixed
"""
return self.of(klass, name).create(**attributes) | [
"def",
"create_as",
"(",
"self",
",",
"klass",
",",
"name",
",",
"*",
"*",
"attributes",
")",
":",
"return",
"self",
".",
"of",
"(",
"klass",
",",
"name",
")",
".",
"create",
"(",
"*",
"*",
"attributes",
")"
] | Create an instance of the given model and type and persist it to the database.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
:return: mixed | [
"Create",
"an",
"instance",
"of",
"the",
"given",
"model",
"and",
"type",
"and",
"persist",
"it",
"to",
"the",
"database",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L127-L142 |
230,907 | sdispater/orator | orator/orm/factory.py | Factory.make_as | def make_as(self, klass, name, **attributes):
"""
Create an instance of the given model and type.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
:return: mixed
"""
return self.of(klass, name).make(**attributes) | python | def make_as(self, klass, name, **attributes):
"""
Create an instance of the given model and type.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
:return: mixed
"""
return self.of(klass, name).make(**attributes) | [
"def",
"make_as",
"(",
"self",
",",
"klass",
",",
"name",
",",
"*",
"*",
"attributes",
")",
":",
"return",
"self",
".",
"of",
"(",
"klass",
",",
"name",
")",
".",
"make",
"(",
"*",
"*",
"attributes",
")"
] | Create an instance of the given model and type.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
:return: mixed | [
"Create",
"an",
"instance",
"of",
"the",
"given",
"model",
"and",
"type",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L158-L173 |
230,908 | sdispater/orator | orator/orm/factory.py | Factory.of | def of(self, klass, name="default"):
"""
Create a builder for the given model.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:return: orator.orm.factory_builder.FactoryBuilder
"""
return FactoryBuilder(
klass, name, self._definitions, self._faker, self._resolver
) | python | def of(self, klass, name="default"):
"""
Create a builder for the given model.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:return: orator.orm.factory_builder.FactoryBuilder
"""
return FactoryBuilder(
klass, name, self._definitions, self._faker, self._resolver
) | [
"def",
"of",
"(",
"self",
",",
"klass",
",",
"name",
"=",
"\"default\"",
")",
":",
"return",
"FactoryBuilder",
"(",
"klass",
",",
"name",
",",
"self",
".",
"_definitions",
",",
"self",
".",
"_faker",
",",
"self",
".",
"_resolver",
")"
] | Create a builder for the given model.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:return: orator.orm.factory_builder.FactoryBuilder | [
"Create",
"a",
"builder",
"for",
"the",
"given",
"model",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L213-L227 |
230,909 | sdispater/orator | orator/orm/factory.py | Factory.build | def build(self, klass, name="default", amount=None):
"""
Makes a factory builder with a specified amount.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param amount: The number of models to create
:type amount: int
:return: mixed
"""
if amount is None:
if isinstance(name, int):
amount = name
name = "default"
else:
amount = 1
return self.of(klass, name).times(amount) | python | def build(self, klass, name="default", amount=None):
"""
Makes a factory builder with a specified amount.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param amount: The number of models to create
:type amount: int
:return: mixed
"""
if amount is None:
if isinstance(name, int):
amount = name
name = "default"
else:
amount = 1
return self.of(klass, name).times(amount) | [
"def",
"build",
"(",
"self",
",",
"klass",
",",
"name",
"=",
"\"default\"",
",",
"amount",
"=",
"None",
")",
":",
"if",
"amount",
"is",
"None",
":",
"if",
"isinstance",
"(",
"name",
",",
"int",
")",
":",
"amount",
"=",
"name",
"name",
"=",
"\"default\"",
"else",
":",
"amount",
"=",
"1",
"return",
"self",
".",
"of",
"(",
"klass",
",",
"name",
")",
".",
"times",
"(",
"amount",
")"
] | Makes a factory builder with a specified amount.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param amount: The number of models to create
:type amount: int
:return: mixed | [
"Makes",
"a",
"factory",
"builder",
"with",
"a",
"specified",
"amount",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L229-L251 |
230,910 | sdispater/orator | orator/schema/grammars/grammar.py | SchemaGrammar._get_renamed_diff | def _get_renamed_diff(self, blueprint, command, column, schema):
"""
Get a new column instance with the new column name.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param column: The column
:type column: orator.dbal.Column
:param schema: The schema
:type schema: orator.dbal.SchemaManager
:rtype: orator.dbal.TableDiff
"""
table_diff = self._get_table_diff(blueprint, schema)
return self._set_renamed_columns(table_diff, command, column) | python | def _get_renamed_diff(self, blueprint, command, column, schema):
"""
Get a new column instance with the new column name.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param column: The column
:type column: orator.dbal.Column
:param schema: The schema
:type schema: orator.dbal.SchemaManager
:rtype: orator.dbal.TableDiff
"""
table_diff = self._get_table_diff(blueprint, schema)
return self._set_renamed_columns(table_diff, command, column) | [
"def",
"_get_renamed_diff",
"(",
"self",
",",
"blueprint",
",",
"command",
",",
"column",
",",
"schema",
")",
":",
"table_diff",
"=",
"self",
".",
"_get_table_diff",
"(",
"blueprint",
",",
"schema",
")",
"return",
"self",
".",
"_set_renamed_columns",
"(",
"table_diff",
",",
"command",
",",
"column",
")"
] | Get a new column instance with the new column name.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param column: The column
:type column: orator.dbal.Column
:param schema: The schema
:type schema: orator.dbal.SchemaManager
:rtype: orator.dbal.TableDiff | [
"Get",
"a",
"new",
"column",
"instance",
"with",
"the",
"new",
"column",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L43-L63 |
230,911 | sdispater/orator | orator/schema/grammars/grammar.py | SchemaGrammar._set_renamed_columns | def _set_renamed_columns(self, table_diff, command, column):
"""
Set the renamed columns on the table diff.
:rtype: orator.dbal.TableDiff
"""
new_column = Column(command.to, column.get_type(), column.to_dict())
table_diff.renamed_columns = {command.from_: new_column}
return table_diff | python | def _set_renamed_columns(self, table_diff, command, column):
"""
Set the renamed columns on the table diff.
:rtype: orator.dbal.TableDiff
"""
new_column = Column(command.to, column.get_type(), column.to_dict())
table_diff.renamed_columns = {command.from_: new_column}
return table_diff | [
"def",
"_set_renamed_columns",
"(",
"self",
",",
"table_diff",
",",
"command",
",",
"column",
")",
":",
"new_column",
"=",
"Column",
"(",
"command",
".",
"to",
",",
"column",
".",
"get_type",
"(",
")",
",",
"column",
".",
"to_dict",
"(",
")",
")",
"table_diff",
".",
"renamed_columns",
"=",
"{",
"command",
".",
"from_",
":",
"new_column",
"}",
"return",
"table_diff"
] | Set the renamed columns on the table diff.
:rtype: orator.dbal.TableDiff | [
"Set",
"the",
"renamed",
"columns",
"on",
"the",
"table",
"diff",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L65-L75 |
230,912 | sdispater/orator | orator/schema/grammars/grammar.py | SchemaGrammar._get_command_by_name | def _get_command_by_name(self, blueprint, name):
"""
Get the primary key command it it exists.
"""
commands = self._get_commands_by_name(blueprint, name)
if len(commands):
return commands[0] | python | def _get_command_by_name(self, blueprint, name):
"""
Get the primary key command it it exists.
"""
commands = self._get_commands_by_name(blueprint, name)
if len(commands):
return commands[0] | [
"def",
"_get_command_by_name",
"(",
"self",
",",
"blueprint",
",",
"name",
")",
":",
"commands",
"=",
"self",
".",
"_get_commands_by_name",
"(",
"blueprint",
",",
"name",
")",
"if",
"len",
"(",
"commands",
")",
":",
"return",
"commands",
"[",
"0",
"]"
] | Get the primary key command it it exists. | [
"Get",
"the",
"primary",
"key",
"command",
"it",
"it",
"exists",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L143-L150 |
230,913 | sdispater/orator | orator/schema/grammars/grammar.py | SchemaGrammar._get_commands_by_name | def _get_commands_by_name(self, blueprint, name):
"""
Get all of the commands with a given name.
"""
return list(filter(lambda value: value.name == name, blueprint.get_commands())) | python | def _get_commands_by_name(self, blueprint, name):
"""
Get all of the commands with a given name.
"""
return list(filter(lambda value: value.name == name, blueprint.get_commands())) | [
"def",
"_get_commands_by_name",
"(",
"self",
",",
"blueprint",
",",
"name",
")",
":",
"return",
"list",
"(",
"filter",
"(",
"lambda",
"value",
":",
"value",
".",
"name",
"==",
"name",
",",
"blueprint",
".",
"get_commands",
"(",
")",
")",
")"
] | Get all of the commands with a given name. | [
"Get",
"all",
"of",
"the",
"commands",
"with",
"a",
"given",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L152-L156 |
230,914 | sdispater/orator | orator/schema/grammars/grammar.py | SchemaGrammar.prefix_list | def prefix_list(self, prefix, values):
"""
Add a prefix to a list of values.
"""
return list(map(lambda value: prefix + " " + value, values)) | python | def prefix_list(self, prefix, values):
"""
Add a prefix to a list of values.
"""
return list(map(lambda value: prefix + " " + value, values)) | [
"def",
"prefix_list",
"(",
"self",
",",
"prefix",
",",
"values",
")",
":",
"return",
"list",
"(",
"map",
"(",
"lambda",
"value",
":",
"prefix",
"+",
"\" \"",
"+",
"value",
",",
"values",
")",
")"
] | Add a prefix to a list of values. | [
"Add",
"a",
"prefix",
"to",
"a",
"list",
"of",
"values",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L169-L173 |
230,915 | sdispater/orator | orator/schema/grammars/grammar.py | SchemaGrammar._get_default_value | def _get_default_value(self, value):
"""
Format a value so that it can be used in "default" clauses.
"""
if isinstance(value, QueryExpression):
return value
if isinstance(value, bool):
return "'%s'" % int(value)
return "'%s'" % value | python | def _get_default_value(self, value):
"""
Format a value so that it can be used in "default" clauses.
"""
if isinstance(value, QueryExpression):
return value
if isinstance(value, bool):
return "'%s'" % int(value)
return "'%s'" % value | [
"def",
"_get_default_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"QueryExpression",
")",
":",
"return",
"value",
"if",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"return",
"\"'%s'\"",
"%",
"int",
"(",
"value",
")",
"return",
"\"'%s'\"",
"%",
"value"
] | Format a value so that it can be used in "default" clauses. | [
"Format",
"a",
"value",
"so",
"that",
"it",
"can",
"be",
"used",
"in",
"default",
"clauses",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L187-L197 |
230,916 | sdispater/orator | orator/schema/grammars/grammar.py | SchemaGrammar._get_changed_diff | def _get_changed_diff(self, blueprint, schema):
"""
Get the table diffrence for the given changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param schema: The schema
:type schema: orator.dbal.SchemaManager
:rtype: orator.dbal.TableDiff
"""
table = schema.list_table_details(
self.get_table_prefix() + blueprint.get_table()
)
return Comparator().diff_table(
table, self._get_table_with_column_changes(blueprint, table)
) | python | def _get_changed_diff(self, blueprint, schema):
"""
Get the table diffrence for the given changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param schema: The schema
:type schema: orator.dbal.SchemaManager
:rtype: orator.dbal.TableDiff
"""
table = schema.list_table_details(
self.get_table_prefix() + blueprint.get_table()
)
return Comparator().diff_table(
table, self._get_table_with_column_changes(blueprint, table)
) | [
"def",
"_get_changed_diff",
"(",
"self",
",",
"blueprint",
",",
"schema",
")",
":",
"table",
"=",
"schema",
".",
"list_table_details",
"(",
"self",
".",
"get_table_prefix",
"(",
")",
"+",
"blueprint",
".",
"get_table",
"(",
")",
")",
"return",
"Comparator",
"(",
")",
".",
"diff_table",
"(",
"table",
",",
"self",
".",
"_get_table_with_column_changes",
"(",
"blueprint",
",",
"table",
")",
")"
] | Get the table diffrence for the given changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param schema: The schema
:type schema: orator.dbal.SchemaManager
:rtype: orator.dbal.TableDiff | [
"Get",
"the",
"table",
"diffrence",
"for",
"the",
"given",
"changes",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L237-L255 |
230,917 | sdispater/orator | orator/schema/grammars/grammar.py | SchemaGrammar._get_table_with_column_changes | def _get_table_with_column_changes(self, blueprint, table):
"""
Get a copy of the given table after making the column changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:type table: orator.dbal.table.Table
:rtype: orator.dbal.table.Table
"""
table = table.clone()
for fluent in blueprint.get_changed_columns():
column = self._get_column_for_change(table, fluent)
for key, value in fluent.get_attributes().items():
option = self._map_fluent_option(key)
if option is not None:
method = "set_%s" % option
if hasattr(column, method):
getattr(column, method)(self._map_fluent_value(option, value))
return table | python | def _get_table_with_column_changes(self, blueprint, table):
"""
Get a copy of the given table after making the column changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:type table: orator.dbal.table.Table
:rtype: orator.dbal.table.Table
"""
table = table.clone()
for fluent in blueprint.get_changed_columns():
column = self._get_column_for_change(table, fluent)
for key, value in fluent.get_attributes().items():
option = self._map_fluent_option(key)
if option is not None:
method = "set_%s" % option
if hasattr(column, method):
getattr(column, method)(self._map_fluent_value(option, value))
return table | [
"def",
"_get_table_with_column_changes",
"(",
"self",
",",
"blueprint",
",",
"table",
")",
":",
"table",
"=",
"table",
".",
"clone",
"(",
")",
"for",
"fluent",
"in",
"blueprint",
".",
"get_changed_columns",
"(",
")",
":",
"column",
"=",
"self",
".",
"_get_column_for_change",
"(",
"table",
",",
"fluent",
")",
"for",
"key",
",",
"value",
"in",
"fluent",
".",
"get_attributes",
"(",
")",
".",
"items",
"(",
")",
":",
"option",
"=",
"self",
".",
"_map_fluent_option",
"(",
"key",
")",
"if",
"option",
"is",
"not",
"None",
":",
"method",
"=",
"\"set_%s\"",
"%",
"option",
"if",
"hasattr",
"(",
"column",
",",
"method",
")",
":",
"getattr",
"(",
"column",
",",
"method",
")",
"(",
"self",
".",
"_map_fluent_value",
"(",
"option",
",",
"value",
")",
")",
"return",
"table"
] | Get a copy of the given table after making the column changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:type table: orator.dbal.table.Table
:rtype: orator.dbal.table.Table | [
"Get",
"a",
"copy",
"of",
"the",
"given",
"table",
"after",
"making",
"the",
"column",
"changes",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L257-L282 |
230,918 | sdispater/orator | orator/schema/grammars/grammar.py | SchemaGrammar._get_column_for_change | def _get_column_for_change(self, table, fluent):
"""
Get the column instance for a column change.
:type table: orator.dbal.table.Table
:rtype: orator.dbal.column.Column
"""
return table.change_column(
fluent.name, self._get_column_change_options(fluent)
).get_column(fluent.name) | python | def _get_column_for_change(self, table, fluent):
"""
Get the column instance for a column change.
:type table: orator.dbal.table.Table
:rtype: orator.dbal.column.Column
"""
return table.change_column(
fluent.name, self._get_column_change_options(fluent)
).get_column(fluent.name) | [
"def",
"_get_column_for_change",
"(",
"self",
",",
"table",
",",
"fluent",
")",
":",
"return",
"table",
".",
"change_column",
"(",
"fluent",
".",
"name",
",",
"self",
".",
"_get_column_change_options",
"(",
"fluent",
")",
")",
".",
"get_column",
"(",
"fluent",
".",
"name",
")"
] | Get the column instance for a column change.
:type table: orator.dbal.table.Table
:rtype: orator.dbal.column.Column | [
"Get",
"the",
"column",
"instance",
"for",
"a",
"column",
"change",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L284-L294 |
230,919 | sdispater/orator | orator/orm/relations/pivot.py | Pivot._get_delete_query | def _get_delete_query(self):
"""
Get the query builder for a delete operation on the pivot.
:rtype: orator.orm.Builder
"""
foreign = self.get_attribute(self.__foreign_key)
query = self.new_query().where(self.__foreign_key, foreign)
return query.where(self.__other_key, self.get_attribute(self.__other_key)) | python | def _get_delete_query(self):
"""
Get the query builder for a delete operation on the pivot.
:rtype: orator.orm.Builder
"""
foreign = self.get_attribute(self.__foreign_key)
query = self.new_query().where(self.__foreign_key, foreign)
return query.where(self.__other_key, self.get_attribute(self.__other_key)) | [
"def",
"_get_delete_query",
"(",
"self",
")",
":",
"foreign",
"=",
"self",
".",
"get_attribute",
"(",
"self",
".",
"__foreign_key",
")",
"query",
"=",
"self",
".",
"new_query",
"(",
")",
".",
"where",
"(",
"self",
".",
"__foreign_key",
",",
"foreign",
")",
"return",
"query",
".",
"where",
"(",
"self",
".",
"__other_key",
",",
"self",
".",
"get_attribute",
"(",
"self",
".",
"__other_key",
")",
")"
] | Get the query builder for a delete operation on the pivot.
:rtype: orator.orm.Builder | [
"Get",
"the",
"query",
"builder",
"for",
"a",
"delete",
"operation",
"on",
"the",
"pivot",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/pivot.py#L63-L73 |
230,920 | sdispater/orator | orator/orm/relations/pivot.py | Pivot.set_pivot_keys | def set_pivot_keys(self, foreign_key, other_key):
"""
Set the key names for the pivot model instance
"""
self.__foreign_key = foreign_key
self.__other_key = other_key
return self | python | def set_pivot_keys(self, foreign_key, other_key):
"""
Set the key names for the pivot model instance
"""
self.__foreign_key = foreign_key
self.__other_key = other_key
return self | [
"def",
"set_pivot_keys",
"(",
"self",
",",
"foreign_key",
",",
"other_key",
")",
":",
"self",
".",
"__foreign_key",
"=",
"foreign_key",
"self",
".",
"__other_key",
"=",
"other_key",
"return",
"self"
] | Set the key names for the pivot model instance | [
"Set",
"the",
"key",
"names",
"for",
"the",
"pivot",
"model",
"instance"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/pivot.py#L89-L96 |
230,921 | sdispater/orator | orator/orm/factory_builder.py | FactoryBuilder.create | def create(self, **attributes):
"""
Create a collection of models and persist them to the database.
:param attributes: The models attributes
:type attributes: dict
:return: mixed
"""
results = self.make(**attributes)
if self._amount == 1:
if self._resolver:
results.set_connection_resolver(self._resolver)
results.save()
else:
if self._resolver:
results.each(lambda r: r.set_connection_resolver(self._resolver))
for result in results:
result.save()
return results | python | def create(self, **attributes):
"""
Create a collection of models and persist them to the database.
:param attributes: The models attributes
:type attributes: dict
:return: mixed
"""
results = self.make(**attributes)
if self._amount == 1:
if self._resolver:
results.set_connection_resolver(self._resolver)
results.save()
else:
if self._resolver:
results.each(lambda r: r.set_connection_resolver(self._resolver))
for result in results:
result.save()
return results | [
"def",
"create",
"(",
"self",
",",
"*",
"*",
"attributes",
")",
":",
"results",
"=",
"self",
".",
"make",
"(",
"*",
"*",
"attributes",
")",
"if",
"self",
".",
"_amount",
"==",
"1",
":",
"if",
"self",
".",
"_resolver",
":",
"results",
".",
"set_connection_resolver",
"(",
"self",
".",
"_resolver",
")",
"results",
".",
"save",
"(",
")",
"else",
":",
"if",
"self",
".",
"_resolver",
":",
"results",
".",
"each",
"(",
"lambda",
"r",
":",
"r",
".",
"set_connection_resolver",
"(",
"self",
".",
"_resolver",
")",
")",
"for",
"result",
"in",
"results",
":",
"result",
".",
"save",
"(",
")",
"return",
"results"
] | Create a collection of models and persist them to the database.
:param attributes: The models attributes
:type attributes: dict
:return: mixed | [
"Create",
"a",
"collection",
"of",
"models",
"and",
"persist",
"them",
"to",
"the",
"database",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory_builder.py#L41-L64 |
230,922 | sdispater/orator | orator/orm/factory_builder.py | FactoryBuilder.make | def make(self, **attributes):
"""
Create a collection of models.
:param attributes: The models attributes
:type attributes: dict
:return: mixed
"""
if self._amount == 1:
return self._make_instance(**attributes)
else:
results = []
for _ in range(self._amount):
results.append(self._make_instance(**attributes))
return Collection(results) | python | def make(self, **attributes):
"""
Create a collection of models.
:param attributes: The models attributes
:type attributes: dict
:return: mixed
"""
if self._amount == 1:
return self._make_instance(**attributes)
else:
results = []
for _ in range(self._amount):
results.append(self._make_instance(**attributes))
return Collection(results) | [
"def",
"make",
"(",
"self",
",",
"*",
"*",
"attributes",
")",
":",
"if",
"self",
".",
"_amount",
"==",
"1",
":",
"return",
"self",
".",
"_make_instance",
"(",
"*",
"*",
"attributes",
")",
"else",
":",
"results",
"=",
"[",
"]",
"for",
"_",
"in",
"range",
"(",
"self",
".",
"_amount",
")",
":",
"results",
".",
"append",
"(",
"self",
".",
"_make_instance",
"(",
"*",
"*",
"attributes",
")",
")",
"return",
"Collection",
"(",
"results",
")"
] | Create a collection of models.
:param attributes: The models attributes
:type attributes: dict
:return: mixed | [
"Create",
"a",
"collection",
"of",
"models",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory_builder.py#L66-L83 |
230,923 | sdispater/orator | orator/orm/factory_builder.py | FactoryBuilder._make_instance | def _make_instance(self, **attributes):
"""
Make an instance of the model with the given attributes.
:param attributes: The models attributes
:type attributes: dict
:return: mixed
"""
definition = self._definitions[self._klass][self._name](self._faker)
definition.update(attributes)
instance = self._klass()
instance.force_fill(**definition)
return instance | python | def _make_instance(self, **attributes):
"""
Make an instance of the model with the given attributes.
:param attributes: The models attributes
:type attributes: dict
:return: mixed
"""
definition = self._definitions[self._klass][self._name](self._faker)
definition.update(attributes)
instance = self._klass()
instance.force_fill(**definition)
return instance | [
"def",
"_make_instance",
"(",
"self",
",",
"*",
"*",
"attributes",
")",
":",
"definition",
"=",
"self",
".",
"_definitions",
"[",
"self",
".",
"_klass",
"]",
"[",
"self",
".",
"_name",
"]",
"(",
"self",
".",
"_faker",
")",
"definition",
".",
"update",
"(",
"attributes",
")",
"instance",
"=",
"self",
".",
"_klass",
"(",
")",
"instance",
".",
"force_fill",
"(",
"*",
"*",
"definition",
")",
"return",
"instance"
] | Make an instance of the model with the given attributes.
:param attributes: The models attributes
:type attributes: dict
:return: mixed | [
"Make",
"an",
"instance",
"of",
"the",
"model",
"with",
"the",
"given",
"attributes",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory_builder.py#L85-L100 |
230,924 | sdispater/orator | orator/connections/connection.py | run | def run(wrapped):
"""
Special decorator encapsulating query method.
"""
@wraps(wrapped)
def _run(self, query, bindings=None, *args, **kwargs):
self._reconnect_if_missing_connection()
start = time.time()
try:
result = wrapped(self, query, bindings, *args, **kwargs)
except Exception as e:
result = self._try_again_if_caused_by_lost_connection(
e, query, bindings, wrapped
)
t = self._get_elapsed_time(start)
self.log_query(query, bindings, t)
return result
return _run | python | def run(wrapped):
"""
Special decorator encapsulating query method.
"""
@wraps(wrapped)
def _run(self, query, bindings=None, *args, **kwargs):
self._reconnect_if_missing_connection()
start = time.time()
try:
result = wrapped(self, query, bindings, *args, **kwargs)
except Exception as e:
result = self._try_again_if_caused_by_lost_connection(
e, query, bindings, wrapped
)
t = self._get_elapsed_time(start)
self.log_query(query, bindings, t)
return result
return _run | [
"def",
"run",
"(",
"wrapped",
")",
":",
"@",
"wraps",
"(",
"wrapped",
")",
"def",
"_run",
"(",
"self",
",",
"query",
",",
"bindings",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_reconnect_if_missing_connection",
"(",
")",
"start",
"=",
"time",
".",
"time",
"(",
")",
"try",
":",
"result",
"=",
"wrapped",
"(",
"self",
",",
"query",
",",
"bindings",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"except",
"Exception",
"as",
"e",
":",
"result",
"=",
"self",
".",
"_try_again_if_caused_by_lost_connection",
"(",
"e",
",",
"query",
",",
"bindings",
",",
"wrapped",
")",
"t",
"=",
"self",
".",
"_get_elapsed_time",
"(",
"start",
")",
"self",
".",
"log_query",
"(",
"query",
",",
"bindings",
",",
"t",
")",
"return",
"result",
"return",
"_run"
] | Special decorator encapsulating query method. | [
"Special",
"decorator",
"encapsulating",
"query",
"method",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/connections/connection.py#L21-L43 |
230,925 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.where_pivot | def where_pivot(self, column, operator=None, value=None, boolean="and"):
"""
Set a where clause for a pivot table column.
:param column: The column of the where clause, can also be a QueryBuilder instance for sub where
:type column: str|Builder
:param operator: The operator of the where clause
:type operator: str
:param value: The value of the where clause
:type value: mixed
:param boolean: The boolean of the where clause
:type boolean: str
:return: self
:rtype: self
"""
self._pivot_wheres.append([column, operator, value, boolean])
return self._query.where(
"%s.%s" % (self._table, column), operator, value, boolean
) | python | def where_pivot(self, column, operator=None, value=None, boolean="and"):
"""
Set a where clause for a pivot table column.
:param column: The column of the where clause, can also be a QueryBuilder instance for sub where
:type column: str|Builder
:param operator: The operator of the where clause
:type operator: str
:param value: The value of the where clause
:type value: mixed
:param boolean: The boolean of the where clause
:type boolean: str
:return: self
:rtype: self
"""
self._pivot_wheres.append([column, operator, value, boolean])
return self._query.where(
"%s.%s" % (self._table, column), operator, value, boolean
) | [
"def",
"where_pivot",
"(",
"self",
",",
"column",
",",
"operator",
"=",
"None",
",",
"value",
"=",
"None",
",",
"boolean",
"=",
"\"and\"",
")",
":",
"self",
".",
"_pivot_wheres",
".",
"append",
"(",
"[",
"column",
",",
"operator",
",",
"value",
",",
"boolean",
"]",
")",
"return",
"self",
".",
"_query",
".",
"where",
"(",
"\"%s.%s\"",
"%",
"(",
"self",
".",
"_table",
",",
"column",
")",
",",
"operator",
",",
"value",
",",
"boolean",
")"
] | Set a where clause for a pivot table column.
:param column: The column of the where clause, can also be a QueryBuilder instance for sub where
:type column: str|Builder
:param operator: The operator of the where clause
:type operator: str
:param value: The value of the where clause
:type value: mixed
:param boolean: The boolean of the where clause
:type boolean: str
:return: self
:rtype: self | [
"Set",
"a",
"where",
"clause",
"for",
"a",
"pivot",
"table",
"column",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L62-L85 |
230,926 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.or_where_pivot | def or_where_pivot(self, column, operator=None, value=None):
"""
Set an or where clause for a pivot table column.
:param column: The column of the where clause, can also be a QueryBuilder instance for sub where
:type column: str|Builder
:param operator: The operator of the where clause
:type operator: str
:param value: The value of the where clause
:type value: mixed
:return: self
:rtype: BelongsToMany
"""
return self.where_pivot(column, operator, value, "or") | python | def or_where_pivot(self, column, operator=None, value=None):
"""
Set an or where clause for a pivot table column.
:param column: The column of the where clause, can also be a QueryBuilder instance for sub where
:type column: str|Builder
:param operator: The operator of the where clause
:type operator: str
:param value: The value of the where clause
:type value: mixed
:return: self
:rtype: BelongsToMany
"""
return self.where_pivot(column, operator, value, "or") | [
"def",
"or_where_pivot",
"(",
"self",
",",
"column",
",",
"operator",
"=",
"None",
",",
"value",
"=",
"None",
")",
":",
"return",
"self",
".",
"where_pivot",
"(",
"column",
",",
"operator",
",",
"value",
",",
"\"or\"",
")"
] | Set an or where clause for a pivot table column.
:param column: The column of the where clause, can also be a QueryBuilder instance for sub where
:type column: str|Builder
:param operator: The operator of the where clause
:type operator: str
:param value: The value of the where clause
:type value: mixed
:return: self
:rtype: BelongsToMany | [
"Set",
"an",
"or",
"where",
"clause",
"for",
"a",
"pivot",
"table",
"column",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L87-L103 |
230,927 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.first | def first(self, columns=None):
"""
Execute the query and get the first result.
:type columns: list
"""
self._query.take(1)
results = self.get(columns)
if len(results) > 0:
return results.first()
return | python | def first(self, columns=None):
"""
Execute the query and get the first result.
:type columns: list
"""
self._query.take(1)
results = self.get(columns)
if len(results) > 0:
return results.first()
return | [
"def",
"first",
"(",
"self",
",",
"columns",
"=",
"None",
")",
":",
"self",
".",
"_query",
".",
"take",
"(",
"1",
")",
"results",
"=",
"self",
".",
"get",
"(",
"columns",
")",
"if",
"len",
"(",
"results",
")",
">",
"0",
":",
"return",
"results",
".",
"first",
"(",
")",
"return"
] | Execute the query and get the first result.
:type columns: list | [
"Execute",
"the",
"query",
"and",
"get",
"the",
"first",
"result",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L105-L118 |
230,928 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.first_or_fail | def first_or_fail(self, columns=None):
"""
Execute the query and get the first result or raise an exception.
:type columns: list
:raises: ModelNotFound
"""
model = self.first(columns)
if model is not None:
return model
raise ModelNotFound(self._parent.__class__) | python | def first_or_fail(self, columns=None):
"""
Execute the query and get the first result or raise an exception.
:type columns: list
:raises: ModelNotFound
"""
model = self.first(columns)
if model is not None:
return model
raise ModelNotFound(self._parent.__class__) | [
"def",
"first_or_fail",
"(",
"self",
",",
"columns",
"=",
"None",
")",
":",
"model",
"=",
"self",
".",
"first",
"(",
"columns",
")",
"if",
"model",
"is",
"not",
"None",
":",
"return",
"model",
"raise",
"ModelNotFound",
"(",
"self",
".",
"_parent",
".",
"__class__",
")"
] | Execute the query and get the first result or raise an exception.
:type columns: list
:raises: ModelNotFound | [
"Execute",
"the",
"query",
"and",
"get",
"the",
"first",
"result",
"or",
"raise",
"an",
"exception",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L120-L132 |
230,929 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany._hydrate_pivot_relation | def _hydrate_pivot_relation(self, models):
"""
Hydrate the pivot table relationship on the models.
:type models: list
"""
for model in models:
pivot = self.new_existing_pivot(self._clean_pivot_attributes(model))
model.set_relation("pivot", pivot) | python | def _hydrate_pivot_relation(self, models):
"""
Hydrate the pivot table relationship on the models.
:type models: list
"""
for model in models:
pivot = self.new_existing_pivot(self._clean_pivot_attributes(model))
model.set_relation("pivot", pivot) | [
"def",
"_hydrate_pivot_relation",
"(",
"self",
",",
"models",
")",
":",
"for",
"model",
"in",
"models",
":",
"pivot",
"=",
"self",
".",
"new_existing_pivot",
"(",
"self",
".",
"_clean_pivot_attributes",
"(",
"model",
")",
")",
"model",
".",
"set_relation",
"(",
"\"pivot\"",
",",
"pivot",
")"
] | Hydrate the pivot table relationship on the models.
:type models: list | [
"Hydrate",
"the",
"pivot",
"table",
"relationship",
"on",
"the",
"models",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L159-L168 |
230,930 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.touch | def touch(self):
"""
Touch all of the related models of the relationship.
"""
key = self.get_related().get_key_name()
columns = self.get_related_fresh_update()
ids = self.get_related_ids()
if len(ids) > 0:
self.get_related().new_query().where_in(key, ids).update(columns) | python | def touch(self):
"""
Touch all of the related models of the relationship.
"""
key = self.get_related().get_key_name()
columns = self.get_related_fresh_update()
ids = self.get_related_ids()
if len(ids) > 0:
self.get_related().new_query().where_in(key, ids).update(columns) | [
"def",
"touch",
"(",
"self",
")",
":",
"key",
"=",
"self",
".",
"get_related",
"(",
")",
".",
"get_key_name",
"(",
")",
"columns",
"=",
"self",
".",
"get_related_fresh_update",
"(",
")",
"ids",
"=",
"self",
".",
"get_related_ids",
"(",
")",
"if",
"len",
"(",
"ids",
")",
">",
"0",
":",
"self",
".",
"get_related",
"(",
")",
".",
"new_query",
"(",
")",
".",
"where_in",
"(",
"key",
",",
"ids",
")",
".",
"update",
"(",
"columns",
")"
] | Touch all of the related models of the relationship. | [
"Touch",
"all",
"of",
"the",
"related",
"models",
"of",
"the",
"relationship",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L391-L402 |
230,931 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.get_related_ids | def get_related_ids(self):
"""
Get all of the IDs for the related models.
:rtype: list
"""
related = self.get_related()
full_key = related.get_qualified_key_name()
return self.get_query().select(full_key).lists(related.get_key_name()) | python | def get_related_ids(self):
"""
Get all of the IDs for the related models.
:rtype: list
"""
related = self.get_related()
full_key = related.get_qualified_key_name()
return self.get_query().select(full_key).lists(related.get_key_name()) | [
"def",
"get_related_ids",
"(",
"self",
")",
":",
"related",
"=",
"self",
".",
"get_related",
"(",
")",
"full_key",
"=",
"related",
".",
"get_qualified_key_name",
"(",
")",
"return",
"self",
".",
"get_query",
"(",
")",
".",
"select",
"(",
"full_key",
")",
".",
"lists",
"(",
"related",
".",
"get_key_name",
"(",
")",
")"
] | Get all of the IDs for the related models.
:rtype: list | [
"Get",
"all",
"of",
"the",
"IDs",
"for",
"the",
"related",
"models",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L404-L414 |
230,932 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.save_many | def save_many(self, models, joinings=None):
"""
Save a list of new models and attach them to the parent model
:type models: list
:type joinings: dict
:rtype: list
"""
if joinings is None:
joinings = {}
for key, model in enumerate(models):
self.save(model, joinings.get(key), False)
self.touch_if_touching()
return models | python | def save_many(self, models, joinings=None):
"""
Save a list of new models and attach them to the parent model
:type models: list
:type joinings: dict
:rtype: list
"""
if joinings is None:
joinings = {}
for key, model in enumerate(models):
self.save(model, joinings.get(key), False)
self.touch_if_touching()
return models | [
"def",
"save_many",
"(",
"self",
",",
"models",
",",
"joinings",
"=",
"None",
")",
":",
"if",
"joinings",
"is",
"None",
":",
"joinings",
"=",
"{",
"}",
"for",
"key",
",",
"model",
"in",
"enumerate",
"(",
"models",
")",
":",
"self",
".",
"save",
"(",
"model",
",",
"joinings",
".",
"get",
"(",
"key",
")",
",",
"False",
")",
"self",
".",
"touch_if_touching",
"(",
")",
"return",
"models"
] | Save a list of new models and attach them to the parent model
:type models: list
:type joinings: dict
:rtype: list | [
"Save",
"a",
"list",
"of",
"new",
"models",
"and",
"attach",
"them",
"to",
"the",
"parent",
"model"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L435-L452 |
230,933 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.first_or_create | def first_or_create(
self, _attributes=None, _joining=None, _touch=True, **attributes
):
"""
Get the first related model record matching the attributes or create it.
:param attributes: The attributes
:type attributes: dict
:rtype: Model
"""
if _attributes is not None:
attributes.update(_attributes)
instance = self._query.where(attributes).first()
if instance is None:
instance = self.create(attributes, _joining or {}, _touch)
return instance | python | def first_or_create(
self, _attributes=None, _joining=None, _touch=True, **attributes
):
"""
Get the first related model record matching the attributes or create it.
:param attributes: The attributes
:type attributes: dict
:rtype: Model
"""
if _attributes is not None:
attributes.update(_attributes)
instance = self._query.where(attributes).first()
if instance is None:
instance = self.create(attributes, _joining or {}, _touch)
return instance | [
"def",
"first_or_create",
"(",
"self",
",",
"_attributes",
"=",
"None",
",",
"_joining",
"=",
"None",
",",
"_touch",
"=",
"True",
",",
"*",
"*",
"attributes",
")",
":",
"if",
"_attributes",
"is",
"not",
"None",
":",
"attributes",
".",
"update",
"(",
"_attributes",
")",
"instance",
"=",
"self",
".",
"_query",
".",
"where",
"(",
"attributes",
")",
".",
"first",
"(",
")",
"if",
"instance",
"is",
"None",
":",
"instance",
"=",
"self",
".",
"create",
"(",
"attributes",
",",
"_joining",
"or",
"{",
"}",
",",
"_touch",
")",
"return",
"instance"
] | Get the first related model record matching the attributes or create it.
:param attributes: The attributes
:type attributes: dict
:rtype: Model | [
"Get",
"the",
"first",
"related",
"model",
"record",
"matching",
"the",
"attributes",
"or",
"create",
"it",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L490-L508 |
230,934 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.sync | def sync(self, ids, detaching=True):
"""
Sync the intermediate tables with a list of IDs or collection of models
"""
changes = {"attached": [], "detached": [], "updated": []}
if isinstance(ids, Collection):
ids = ids.model_keys()
current = self._new_pivot_query().lists(self._other_key).all()
records = self._format_sync_list(ids)
detach = [x for x in current if x not in records.keys()]
if detaching and len(detach) > 0:
self.detach(detach)
changes["detached"] = detach
changes.update(self._attach_new(records, current, False))
if len(changes["attached"]) or len(changes["updated"]):
self.touch_if_touching()
return changes | python | def sync(self, ids, detaching=True):
"""
Sync the intermediate tables with a list of IDs or collection of models
"""
changes = {"attached": [], "detached": [], "updated": []}
if isinstance(ids, Collection):
ids = ids.model_keys()
current = self._new_pivot_query().lists(self._other_key).all()
records = self._format_sync_list(ids)
detach = [x for x in current if x not in records.keys()]
if detaching and len(detach) > 0:
self.detach(detach)
changes["detached"] = detach
changes.update(self._attach_new(records, current, False))
if len(changes["attached"]) or len(changes["updated"]):
self.touch_if_touching()
return changes | [
"def",
"sync",
"(",
"self",
",",
"ids",
",",
"detaching",
"=",
"True",
")",
":",
"changes",
"=",
"{",
"\"attached\"",
":",
"[",
"]",
",",
"\"detached\"",
":",
"[",
"]",
",",
"\"updated\"",
":",
"[",
"]",
"}",
"if",
"isinstance",
"(",
"ids",
",",
"Collection",
")",
":",
"ids",
"=",
"ids",
".",
"model_keys",
"(",
")",
"current",
"=",
"self",
".",
"_new_pivot_query",
"(",
")",
".",
"lists",
"(",
"self",
".",
"_other_key",
")",
".",
"all",
"(",
")",
"records",
"=",
"self",
".",
"_format_sync_list",
"(",
"ids",
")",
"detach",
"=",
"[",
"x",
"for",
"x",
"in",
"current",
"if",
"x",
"not",
"in",
"records",
".",
"keys",
"(",
")",
"]",
"if",
"detaching",
"and",
"len",
"(",
"detach",
")",
">",
"0",
":",
"self",
".",
"detach",
"(",
"detach",
")",
"changes",
"[",
"\"detached\"",
"]",
"=",
"detach",
"changes",
".",
"update",
"(",
"self",
".",
"_attach_new",
"(",
"records",
",",
"current",
",",
"False",
")",
")",
"if",
"len",
"(",
"changes",
"[",
"\"attached\"",
"]",
")",
"or",
"len",
"(",
"changes",
"[",
"\"updated\"",
"]",
")",
":",
"self",
".",
"touch_if_touching",
"(",
")",
"return",
"changes"
] | Sync the intermediate tables with a list of IDs or collection of models | [
"Sync",
"the",
"intermediate",
"tables",
"with",
"a",
"list",
"of",
"IDs",
"or",
"collection",
"of",
"models"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L572-L597 |
230,935 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany._format_sync_list | def _format_sync_list(self, records):
"""
Format the sync list so that it is keyed by ID.
"""
results = {}
for attributes in records:
if not isinstance(attributes, dict):
id, attributes = attributes, {}
else:
id = list(attributes.keys())[0]
attributes = attributes[id]
results[id] = attributes
return results | python | def _format_sync_list(self, records):
"""
Format the sync list so that it is keyed by ID.
"""
results = {}
for attributes in records:
if not isinstance(attributes, dict):
id, attributes = attributes, {}
else:
id = list(attributes.keys())[0]
attributes = attributes[id]
results[id] = attributes
return results | [
"def",
"_format_sync_list",
"(",
"self",
",",
"records",
")",
":",
"results",
"=",
"{",
"}",
"for",
"attributes",
"in",
"records",
":",
"if",
"not",
"isinstance",
"(",
"attributes",
",",
"dict",
")",
":",
"id",
",",
"attributes",
"=",
"attributes",
",",
"{",
"}",
"else",
":",
"id",
"=",
"list",
"(",
"attributes",
".",
"keys",
"(",
")",
")",
"[",
"0",
"]",
"attributes",
"=",
"attributes",
"[",
"id",
"]",
"results",
"[",
"id",
"]",
"=",
"attributes",
"return",
"results"
] | Format the sync list so that it is keyed by ID. | [
"Format",
"the",
"sync",
"list",
"so",
"that",
"it",
"is",
"keyed",
"by",
"ID",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L599-L614 |
230,936 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.attach | def attach(self, id, attributes=None, touch=True):
"""
Attach a model to the parent.
"""
if isinstance(id, orator.orm.Model):
id = id.get_key()
query = self.new_pivot_statement()
if not isinstance(id, list):
id = [id]
query.insert(self._create_attach_records(id, attributes))
if touch:
self.touch_if_touching() | python | def attach(self, id, attributes=None, touch=True):
"""
Attach a model to the parent.
"""
if isinstance(id, orator.orm.Model):
id = id.get_key()
query = self.new_pivot_statement()
if not isinstance(id, list):
id = [id]
query.insert(self._create_attach_records(id, attributes))
if touch:
self.touch_if_touching() | [
"def",
"attach",
"(",
"self",
",",
"id",
",",
"attributes",
"=",
"None",
",",
"touch",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"id",
",",
"orator",
".",
"orm",
".",
"Model",
")",
":",
"id",
"=",
"id",
".",
"get_key",
"(",
")",
"query",
"=",
"self",
".",
"new_pivot_statement",
"(",
")",
"if",
"not",
"isinstance",
"(",
"id",
",",
"list",
")",
":",
"id",
"=",
"[",
"id",
"]",
"query",
".",
"insert",
"(",
"self",
".",
"_create_attach_records",
"(",
"id",
",",
"attributes",
")",
")",
"if",
"touch",
":",
"self",
".",
"touch_if_touching",
"(",
")"
] | Attach a model to the parent. | [
"Attach",
"a",
"model",
"to",
"the",
"parent",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L648-L663 |
230,937 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany._create_attach_records | def _create_attach_records(self, ids, attributes):
"""
Create a list of records to insert into the pivot table.
"""
records = []
timed = self._has_pivot_column(self.created_at()) or self._has_pivot_column(
self.updated_at()
)
for key, value in enumerate(ids):
records.append(self._attacher(key, value, attributes, timed))
return records | python | def _create_attach_records(self, ids, attributes):
"""
Create a list of records to insert into the pivot table.
"""
records = []
timed = self._has_pivot_column(self.created_at()) or self._has_pivot_column(
self.updated_at()
)
for key, value in enumerate(ids):
records.append(self._attacher(key, value, attributes, timed))
return records | [
"def",
"_create_attach_records",
"(",
"self",
",",
"ids",
",",
"attributes",
")",
":",
"records",
"=",
"[",
"]",
"timed",
"=",
"self",
".",
"_has_pivot_column",
"(",
"self",
".",
"created_at",
"(",
")",
")",
"or",
"self",
".",
"_has_pivot_column",
"(",
"self",
".",
"updated_at",
"(",
")",
")",
"for",
"key",
",",
"value",
"in",
"enumerate",
"(",
"ids",
")",
":",
"records",
".",
"append",
"(",
"self",
".",
"_attacher",
"(",
"key",
",",
"value",
",",
"attributes",
",",
"timed",
")",
")",
"return",
"records"
] | Create a list of records to insert into the pivot table. | [
"Create",
"a",
"list",
"of",
"records",
"to",
"insert",
"into",
"the",
"pivot",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L665-L678 |
230,938 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany._attacher | def _attacher(self, key, value, attributes, timed):
"""
Create a full attachment record payload.
"""
id, extra = self._get_attach_id(key, value, attributes)
record = self._create_attach_record(id, timed)
if extra:
record.update(extra)
return record | python | def _attacher(self, key, value, attributes, timed):
"""
Create a full attachment record payload.
"""
id, extra = self._get_attach_id(key, value, attributes)
record = self._create_attach_record(id, timed)
if extra:
record.update(extra)
return record | [
"def",
"_attacher",
"(",
"self",
",",
"key",
",",
"value",
",",
"attributes",
",",
"timed",
")",
":",
"id",
",",
"extra",
"=",
"self",
".",
"_get_attach_id",
"(",
"key",
",",
"value",
",",
"attributes",
")",
"record",
"=",
"self",
".",
"_create_attach_record",
"(",
"id",
",",
"timed",
")",
"if",
"extra",
":",
"record",
".",
"update",
"(",
"extra",
")",
"return",
"record"
] | Create a full attachment record payload. | [
"Create",
"a",
"full",
"attachment",
"record",
"payload",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L680-L691 |
230,939 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany._get_attach_id | def _get_attach_id(self, key, value, attributes):
"""
Get the attach record ID and extra attributes.
"""
if isinstance(value, dict):
key = list(value.keys())[0]
attributes.update(value[key])
return [key, attributes]
return value, attributes | python | def _get_attach_id(self, key, value, attributes):
"""
Get the attach record ID and extra attributes.
"""
if isinstance(value, dict):
key = list(value.keys())[0]
attributes.update(value[key])
return [key, attributes]
return value, attributes | [
"def",
"_get_attach_id",
"(",
"self",
",",
"key",
",",
"value",
",",
"attributes",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"key",
"=",
"list",
"(",
"value",
".",
"keys",
"(",
")",
")",
"[",
"0",
"]",
"attributes",
".",
"update",
"(",
"value",
"[",
"key",
"]",
")",
"return",
"[",
"key",
",",
"attributes",
"]",
"return",
"value",
",",
"attributes"
] | Get the attach record ID and extra attributes. | [
"Get",
"the",
"attach",
"record",
"ID",
"and",
"extra",
"attributes",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L693-L703 |
230,940 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany._set_timestamps_on_attach | def _set_timestamps_on_attach(self, record, exists=False):
"""
Set the creation an update timestamps on an attach record.
"""
fresh = self._parent.fresh_timestamp()
if not exists and self._has_pivot_column(self.created_at()):
record[self.created_at()] = fresh
if self._has_pivot_column(self.updated_at()):
record[self.updated_at()] = fresh
return record | python | def _set_timestamps_on_attach(self, record, exists=False):
"""
Set the creation an update timestamps on an attach record.
"""
fresh = self._parent.fresh_timestamp()
if not exists and self._has_pivot_column(self.created_at()):
record[self.created_at()] = fresh
if self._has_pivot_column(self.updated_at()):
record[self.updated_at()] = fresh
return record | [
"def",
"_set_timestamps_on_attach",
"(",
"self",
",",
"record",
",",
"exists",
"=",
"False",
")",
":",
"fresh",
"=",
"self",
".",
"_parent",
".",
"fresh_timestamp",
"(",
")",
"if",
"not",
"exists",
"and",
"self",
".",
"_has_pivot_column",
"(",
"self",
".",
"created_at",
"(",
")",
")",
":",
"record",
"[",
"self",
".",
"created_at",
"(",
")",
"]",
"=",
"fresh",
"if",
"self",
".",
"_has_pivot_column",
"(",
"self",
".",
"updated_at",
"(",
")",
")",
":",
"record",
"[",
"self",
".",
"updated_at",
"(",
")",
"]",
"=",
"fresh",
"return",
"record"
] | Set the creation an update timestamps on an attach record. | [
"Set",
"the",
"creation",
"an",
"update",
"timestamps",
"on",
"an",
"attach",
"record",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L720-L732 |
230,941 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.detach | def detach(self, ids=None, touch=True):
"""
Detach models from the relationship.
"""
if isinstance(ids, orator.orm.model.Model):
ids = ids.get_key()
if ids is None:
ids = []
query = self._new_pivot_query()
if not isinstance(ids, list):
ids = [ids]
if len(ids) > 0:
query.where_in(self._other_key, ids)
if touch:
self.touch_if_touching()
results = query.delete()
return results | python | def detach(self, ids=None, touch=True):
"""
Detach models from the relationship.
"""
if isinstance(ids, orator.orm.model.Model):
ids = ids.get_key()
if ids is None:
ids = []
query = self._new_pivot_query()
if not isinstance(ids, list):
ids = [ids]
if len(ids) > 0:
query.where_in(self._other_key, ids)
if touch:
self.touch_if_touching()
results = query.delete()
return results | [
"def",
"detach",
"(",
"self",
",",
"ids",
"=",
"None",
",",
"touch",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"ids",
",",
"orator",
".",
"orm",
".",
"model",
".",
"Model",
")",
":",
"ids",
"=",
"ids",
".",
"get_key",
"(",
")",
"if",
"ids",
"is",
"None",
":",
"ids",
"=",
"[",
"]",
"query",
"=",
"self",
".",
"_new_pivot_query",
"(",
")",
"if",
"not",
"isinstance",
"(",
"ids",
",",
"list",
")",
":",
"ids",
"=",
"[",
"ids",
"]",
"if",
"len",
"(",
"ids",
")",
">",
"0",
":",
"query",
".",
"where_in",
"(",
"self",
".",
"_other_key",
",",
"ids",
")",
"if",
"touch",
":",
"self",
".",
"touch_if_touching",
"(",
")",
"results",
"=",
"query",
".",
"delete",
"(",
")",
"return",
"results"
] | Detach models from the relationship. | [
"Detach",
"models",
"from",
"the",
"relationship",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L734-L757 |
230,942 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.touch_if_touching | def touch_if_touching(self):
"""
Touch if the parent model is being touched.
"""
if self._touching_parent():
self.get_parent().touch()
if self.get_parent().touches(self._relation_name):
self.touch() | python | def touch_if_touching(self):
"""
Touch if the parent model is being touched.
"""
if self._touching_parent():
self.get_parent().touch()
if self.get_parent().touches(self._relation_name):
self.touch() | [
"def",
"touch_if_touching",
"(",
"self",
")",
":",
"if",
"self",
".",
"_touching_parent",
"(",
")",
":",
"self",
".",
"get_parent",
"(",
")",
".",
"touch",
"(",
")",
"if",
"self",
".",
"get_parent",
"(",
")",
".",
"touches",
"(",
"self",
".",
"_relation_name",
")",
":",
"self",
".",
"touch",
"(",
")"
] | Touch if the parent model is being touched. | [
"Touch",
"if",
"the",
"parent",
"model",
"is",
"being",
"touched",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L759-L767 |
230,943 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.with_pivot | def with_pivot(self, *columns):
"""
Set the columns on the pivot table to retrieve.
"""
columns = list(columns)
self._pivot_columns += columns
return self | python | def with_pivot(self, *columns):
"""
Set the columns on the pivot table to retrieve.
"""
columns = list(columns)
self._pivot_columns += columns
return self | [
"def",
"with_pivot",
"(",
"self",
",",
"*",
"columns",
")",
":",
"columns",
"=",
"list",
"(",
"columns",
")",
"self",
".",
"_pivot_columns",
"+=",
"columns",
"return",
"self"
] | Set the columns on the pivot table to retrieve. | [
"Set",
"the",
"columns",
"on",
"the",
"pivot",
"table",
"to",
"retrieve",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L819-L827 |
230,944 | sdispater/orator | orator/orm/relations/belongs_to_many.py | BelongsToMany.with_timestamps | def with_timestamps(self, created_at=None, updated_at=None):
"""
Specify that the pivot table has creation and update columns.
"""
if not created_at:
created_at = self.created_at()
if not updated_at:
updated_at = self.updated_at()
return self.with_pivot(created_at, updated_at) | python | def with_timestamps(self, created_at=None, updated_at=None):
"""
Specify that the pivot table has creation and update columns.
"""
if not created_at:
created_at = self.created_at()
if not updated_at:
updated_at = self.updated_at()
return self.with_pivot(created_at, updated_at) | [
"def",
"with_timestamps",
"(",
"self",
",",
"created_at",
"=",
"None",
",",
"updated_at",
"=",
"None",
")",
":",
"if",
"not",
"created_at",
":",
"created_at",
"=",
"self",
".",
"created_at",
"(",
")",
"if",
"not",
"updated_at",
":",
"updated_at",
"=",
"self",
".",
"updated_at",
"(",
")",
"return",
"self",
".",
"with_pivot",
"(",
"created_at",
",",
"updated_at",
")"
] | Specify that the pivot table has creation and update columns. | [
"Specify",
"that",
"the",
"pivot",
"table",
"has",
"creation",
"and",
"update",
"columns",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L829-L839 |
230,945 | sdispater/orator | orator/orm/relations/belongs_to.py | BelongsTo._get_eager_model_keys | def _get_eager_model_keys(self, models):
"""
Gather the keys from a list of related models.
:type models: list
:rtype: list
"""
keys = []
for model in models:
value = getattr(model, self._foreign_key)
if value is not None and value not in keys:
keys.append(value)
if not len(keys):
return [0]
return keys | python | def _get_eager_model_keys(self, models):
"""
Gather the keys from a list of related models.
:type models: list
:rtype: list
"""
keys = []
for model in models:
value = getattr(model, self._foreign_key)
if value is not None and value not in keys:
keys.append(value)
if not len(keys):
return [0]
return keys | [
"def",
"_get_eager_model_keys",
"(",
"self",
",",
"models",
")",
":",
"keys",
"=",
"[",
"]",
"for",
"model",
"in",
"models",
":",
"value",
"=",
"getattr",
"(",
"model",
",",
"self",
".",
"_foreign_key",
")",
"if",
"value",
"is",
"not",
"None",
"and",
"value",
"not",
"in",
"keys",
":",
"keys",
".",
"append",
"(",
"value",
")",
"if",
"not",
"len",
"(",
"keys",
")",
":",
"return",
"[",
"0",
"]",
"return",
"keys"
] | Gather the keys from a list of related models.
:type models: list
:rtype: list | [
"Gather",
"the",
"keys",
"from",
"a",
"list",
"of",
"related",
"models",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to.py#L87-L106 |
230,946 | sdispater/orator | orator/orm/relations/belongs_to.py | BelongsTo.update | def update(self, _attributes=None, **attributes):
"""
Update the parent model on the relationship.
:param attributes: The update attributes
:type attributes: dict
:rtype: mixed
"""
if _attributes is not None:
attributes.update(_attributes)
instance = self.get_results()
return instance.fill(attributes).save() | python | def update(self, _attributes=None, **attributes):
"""
Update the parent model on the relationship.
:param attributes: The update attributes
:type attributes: dict
:rtype: mixed
"""
if _attributes is not None:
attributes.update(_attributes)
instance = self.get_results()
return instance.fill(attributes).save() | [
"def",
"update",
"(",
"self",
",",
"_attributes",
"=",
"None",
",",
"*",
"*",
"attributes",
")",
":",
"if",
"_attributes",
"is",
"not",
"None",
":",
"attributes",
".",
"update",
"(",
"_attributes",
")",
"instance",
"=",
"self",
".",
"get_results",
"(",
")",
"return",
"instance",
".",
"fill",
"(",
"attributes",
")",
".",
"save",
"(",
")"
] | Update the parent model on the relationship.
:param attributes: The update attributes
:type attributes: dict
:rtype: mixed | [
"Update",
"the",
"parent",
"model",
"on",
"the",
"relationship",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to.py#L177-L191 |
230,947 | sdispater/orator | orator/orm/relations/morph_to.py | MorphTo._build_dictionary | def _build_dictionary(self, models):
"""
Build a dictionary with the models.
:param models: The models
:type models: Collection
"""
for model in models:
key = getattr(model, self._morph_type, None)
if key:
foreign = getattr(model, self._foreign_key)
if key not in self._dictionary:
self._dictionary[key] = {}
if foreign not in self._dictionary[key]:
self._dictionary[key][foreign] = []
self._dictionary[key][foreign].append(model) | python | def _build_dictionary(self, models):
"""
Build a dictionary with the models.
:param models: The models
:type models: Collection
"""
for model in models:
key = getattr(model, self._morph_type, None)
if key:
foreign = getattr(model, self._foreign_key)
if key not in self._dictionary:
self._dictionary[key] = {}
if foreign not in self._dictionary[key]:
self._dictionary[key][foreign] = []
self._dictionary[key][foreign].append(model) | [
"def",
"_build_dictionary",
"(",
"self",
",",
"models",
")",
":",
"for",
"model",
"in",
"models",
":",
"key",
"=",
"getattr",
"(",
"model",
",",
"self",
".",
"_morph_type",
",",
"None",
")",
"if",
"key",
":",
"foreign",
"=",
"getattr",
"(",
"model",
",",
"self",
".",
"_foreign_key",
")",
"if",
"key",
"not",
"in",
"self",
".",
"_dictionary",
":",
"self",
".",
"_dictionary",
"[",
"key",
"]",
"=",
"{",
"}",
"if",
"foreign",
"not",
"in",
"self",
".",
"_dictionary",
"[",
"key",
"]",
":",
"self",
".",
"_dictionary",
"[",
"key",
"]",
"[",
"foreign",
"]",
"=",
"[",
"]",
"self",
".",
"_dictionary",
"[",
"key",
"]",
"[",
"foreign",
"]",
".",
"append",
"(",
"model",
")"
] | Build a dictionary with the models.
:param models: The models
:type models: Collection | [
"Build",
"a",
"dictionary",
"with",
"the",
"models",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L49-L66 |
230,948 | sdispater/orator | orator/orm/relations/morph_to.py | MorphTo.get_eager | def get_eager(self):
"""
Get the relationship for eager loading.
:rtype: Collection
"""
for type in self._dictionary.keys():
self._match_to_morph_parents(type, self._get_results_by_type(type))
return self._models | python | def get_eager(self):
"""
Get the relationship for eager loading.
:rtype: Collection
"""
for type in self._dictionary.keys():
self._match_to_morph_parents(type, self._get_results_by_type(type))
return self._models | [
"def",
"get_eager",
"(",
"self",
")",
":",
"for",
"type",
"in",
"self",
".",
"_dictionary",
".",
"keys",
"(",
")",
":",
"self",
".",
"_match_to_morph_parents",
"(",
"type",
",",
"self",
".",
"_get_results_by_type",
"(",
"type",
")",
")",
"return",
"self",
".",
"_models"
] | Get the relationship for eager loading.
:rtype: Collection | [
"Get",
"the",
"relationship",
"for",
"eager",
"loading",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L93-L102 |
230,949 | sdispater/orator | orator/orm/relations/morph_to.py | MorphTo._match_to_morph_parents | def _match_to_morph_parents(self, type, results):
"""
Match the results for a given type to their parent.
:param type: The parent type
:type type: str
:param results: The results to match to their parent
:type results: Collection
"""
for result in results:
if result.get_key() in self._dictionary.get(type, []):
for model in self._dictionary[type][result.get_key()]:
model.set_relation(
self._relation, Result(result, self, model, related=result)
) | python | def _match_to_morph_parents(self, type, results):
"""
Match the results for a given type to their parent.
:param type: The parent type
:type type: str
:param results: The results to match to their parent
:type results: Collection
"""
for result in results:
if result.get_key() in self._dictionary.get(type, []):
for model in self._dictionary[type][result.get_key()]:
model.set_relation(
self._relation, Result(result, self, model, related=result)
) | [
"def",
"_match_to_morph_parents",
"(",
"self",
",",
"type",
",",
"results",
")",
":",
"for",
"result",
"in",
"results",
":",
"if",
"result",
".",
"get_key",
"(",
")",
"in",
"self",
".",
"_dictionary",
".",
"get",
"(",
"type",
",",
"[",
"]",
")",
":",
"for",
"model",
"in",
"self",
".",
"_dictionary",
"[",
"type",
"]",
"[",
"result",
".",
"get_key",
"(",
")",
"]",
":",
"model",
".",
"set_relation",
"(",
"self",
".",
"_relation",
",",
"Result",
"(",
"result",
",",
"self",
",",
"model",
",",
"related",
"=",
"result",
")",
")"
] | Match the results for a given type to their parent.
:param type: The parent type
:type type: str
:param results: The results to match to their parent
:type results: Collection | [
"Match",
"the",
"results",
"for",
"a",
"given",
"type",
"to",
"their",
"parent",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L104-L119 |
230,950 | sdispater/orator | orator/orm/relations/morph_to.py | MorphTo._get_results_by_type | def _get_results_by_type(self, type):
"""
Get all the relation results for a type.
:param type: The type
:type type: str
:rtype: Collection
"""
instance = self._create_model_by_type(type)
key = instance.get_key_name()
query = instance.new_query()
query = self._use_with_trashed(query)
return query.where_in(key, self._gather_keys_by_type(type).all()).get() | python | def _get_results_by_type(self, type):
"""
Get all the relation results for a type.
:param type: The type
:type type: str
:rtype: Collection
"""
instance = self._create_model_by_type(type)
key = instance.get_key_name()
query = instance.new_query()
query = self._use_with_trashed(query)
return query.where_in(key, self._gather_keys_by_type(type).all()).get() | [
"def",
"_get_results_by_type",
"(",
"self",
",",
"type",
")",
":",
"instance",
"=",
"self",
".",
"_create_model_by_type",
"(",
"type",
")",
"key",
"=",
"instance",
".",
"get_key_name",
"(",
")",
"query",
"=",
"instance",
".",
"new_query",
"(",
")",
"query",
"=",
"self",
".",
"_use_with_trashed",
"(",
"query",
")",
"return",
"query",
".",
"where_in",
"(",
"key",
",",
"self",
".",
"_gather_keys_by_type",
"(",
"type",
")",
".",
"all",
"(",
")",
")",
".",
"get",
"(",
")"
] | Get all the relation results for a type.
:param type: The type
:type type: str
:rtype: Collection | [
"Get",
"all",
"the",
"relation",
"results",
"for",
"a",
"type",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L121-L138 |
230,951 | sdispater/orator | orator/orm/relations/morph_to.py | MorphTo._gather_keys_by_type | def _gather_keys_by_type(self, type):
"""
Gather all of the foreign keys for a given type.
:param type: The type
:type type: str
:rtype: BaseCollection
"""
foreign = self._foreign_key
keys = (
BaseCollection.make(list(self._dictionary[type].values()))
.map(lambda models: getattr(models[0], foreign))
.unique()
)
return keys | python | def _gather_keys_by_type(self, type):
"""
Gather all of the foreign keys for a given type.
:param type: The type
:type type: str
:rtype: BaseCollection
"""
foreign = self._foreign_key
keys = (
BaseCollection.make(list(self._dictionary[type].values()))
.map(lambda models: getattr(models[0], foreign))
.unique()
)
return keys | [
"def",
"_gather_keys_by_type",
"(",
"self",
",",
"type",
")",
":",
"foreign",
"=",
"self",
".",
"_foreign_key",
"keys",
"=",
"(",
"BaseCollection",
".",
"make",
"(",
"list",
"(",
"self",
".",
"_dictionary",
"[",
"type",
"]",
".",
"values",
"(",
")",
")",
")",
".",
"map",
"(",
"lambda",
"models",
":",
"getattr",
"(",
"models",
"[",
"0",
"]",
",",
"foreign",
")",
")",
".",
"unique",
"(",
")",
")",
"return",
"keys"
] | Gather all of the foreign keys for a given type.
:param type: The type
:type type: str
:rtype: BaseCollection | [
"Gather",
"all",
"of",
"the",
"foreign",
"keys",
"for",
"a",
"given",
"type",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L140-L157 |
230,952 | sdispater/orator | orator/dbal/table.py | Table.set_primary_key | def set_primary_key(self, columns, index_name=False):
"""
Set the primary key.
:type columns: list
:type index_name: str or bool
:rtype: Table
"""
self._add_index(
self._create_index(columns, index_name or "primary", True, True)
)
for column_name in columns:
column = self.get_column(column_name)
column.set_notnull(True)
return self | python | def set_primary_key(self, columns, index_name=False):
"""
Set the primary key.
:type columns: list
:type index_name: str or bool
:rtype: Table
"""
self._add_index(
self._create_index(columns, index_name or "primary", True, True)
)
for column_name in columns:
column = self.get_column(column_name)
column.set_notnull(True)
return self | [
"def",
"set_primary_key",
"(",
"self",
",",
"columns",
",",
"index_name",
"=",
"False",
")",
":",
"self",
".",
"_add_index",
"(",
"self",
".",
"_create_index",
"(",
"columns",
",",
"index_name",
"or",
"\"primary\"",
",",
"True",
",",
"True",
")",
")",
"for",
"column_name",
"in",
"columns",
":",
"column",
"=",
"self",
".",
"get_column",
"(",
"column_name",
")",
"column",
".",
"set_notnull",
"(",
"True",
")",
"return",
"self"
] | Set the primary key.
:type columns: list
:type index_name: str or bool
:rtype: Table | [
"Set",
"the",
"primary",
"key",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L55-L72 |
230,953 | sdispater/orator | orator/dbal/table.py | Table.drop_index | def drop_index(self, name):
"""
Drops an index from this table.
:param name: The index name
:type name: str
"""
name = self._normalize_identifier(name)
if not self.has_index(name):
raise IndexDoesNotExist(name, self._name)
del self._indexes[name] | python | def drop_index(self, name):
"""
Drops an index from this table.
:param name: The index name
:type name: str
"""
name = self._normalize_identifier(name)
if not self.has_index(name):
raise IndexDoesNotExist(name, self._name)
del self._indexes[name] | [
"def",
"drop_index",
"(",
"self",
",",
"name",
")",
":",
"name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"name",
")",
"if",
"not",
"self",
".",
"has_index",
"(",
"name",
")",
":",
"raise",
"IndexDoesNotExist",
"(",
"name",
",",
"self",
".",
"_name",
")",
"del",
"self",
".",
"_indexes",
"[",
"name",
"]"
] | Drops an index from this table.
:param name: The index name
:type name: str | [
"Drops",
"an",
"index",
"from",
"this",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L91-L102 |
230,954 | sdispater/orator | orator/dbal/table.py | Table.rename_index | def rename_index(self, old_name, new_name=None):
"""
Renames an index.
:param old_name: The name of the index to rename from.
:type old_name: str
:param new_name: The name of the index to rename to.
:type new_name: str or None
:rtype: Table
"""
old_name = self._normalize_identifier(old_name)
normalized_new_name = self._normalize_identifier(new_name)
if old_name == normalized_new_name:
return self
if not self.has_index(old_name):
raise IndexDoesNotExist(old_name, self._name)
if self.has_index(normalized_new_name):
raise IndexAlreadyExists(normalized_new_name, self._name)
old_index = self._indexes[old_name]
if old_index.is_primary():
self.drop_primary_key()
return self.set_primary_key(old_index.get_columns(), new_name)
del self._indexes[old_name]
if old_index.is_unique():
return self.add_unique_index(old_index.get_columns(), new_name)
return self.add_index(old_index.get_columns(), new_name, old_index.get_flags()) | python | def rename_index(self, old_name, new_name=None):
"""
Renames an index.
:param old_name: The name of the index to rename from.
:type old_name: str
:param new_name: The name of the index to rename to.
:type new_name: str or None
:rtype: Table
"""
old_name = self._normalize_identifier(old_name)
normalized_new_name = self._normalize_identifier(new_name)
if old_name == normalized_new_name:
return self
if not self.has_index(old_name):
raise IndexDoesNotExist(old_name, self._name)
if self.has_index(normalized_new_name):
raise IndexAlreadyExists(normalized_new_name, self._name)
old_index = self._indexes[old_name]
if old_index.is_primary():
self.drop_primary_key()
return self.set_primary_key(old_index.get_columns(), new_name)
del self._indexes[old_name]
if old_index.is_unique():
return self.add_unique_index(old_index.get_columns(), new_name)
return self.add_index(old_index.get_columns(), new_name, old_index.get_flags()) | [
"def",
"rename_index",
"(",
"self",
",",
"old_name",
",",
"new_name",
"=",
"None",
")",
":",
"old_name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"old_name",
")",
"normalized_new_name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"new_name",
")",
"if",
"old_name",
"==",
"normalized_new_name",
":",
"return",
"self",
"if",
"not",
"self",
".",
"has_index",
"(",
"old_name",
")",
":",
"raise",
"IndexDoesNotExist",
"(",
"old_name",
",",
"self",
".",
"_name",
")",
"if",
"self",
".",
"has_index",
"(",
"normalized_new_name",
")",
":",
"raise",
"IndexAlreadyExists",
"(",
"normalized_new_name",
",",
"self",
".",
"_name",
")",
"old_index",
"=",
"self",
".",
"_indexes",
"[",
"old_name",
"]",
"if",
"old_index",
".",
"is_primary",
"(",
")",
":",
"self",
".",
"drop_primary_key",
"(",
")",
"return",
"self",
".",
"set_primary_key",
"(",
"old_index",
".",
"get_columns",
"(",
")",
",",
"new_name",
")",
"del",
"self",
".",
"_indexes",
"[",
"old_name",
"]",
"if",
"old_index",
".",
"is_unique",
"(",
")",
":",
"return",
"self",
".",
"add_unique_index",
"(",
"old_index",
".",
"get_columns",
"(",
")",
",",
"new_name",
")",
"return",
"self",
".",
"add_index",
"(",
"old_index",
".",
"get_columns",
"(",
")",
",",
"new_name",
",",
"old_index",
".",
"get_flags",
"(",
")",
")"
] | Renames an index.
:param old_name: The name of the index to rename from.
:type old_name: str
:param new_name: The name of the index to rename to.
:type new_name: str or None
:rtype: Table | [
"Renames",
"an",
"index",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L114-L150 |
230,955 | sdispater/orator | orator/dbal/table.py | Table.columns_are_indexed | def columns_are_indexed(self, columns):
"""
Checks if an index begins in the order of the given columns.
:type columns: list
:rtype: bool
"""
for index in self._indexes.values():
if index.spans_columns(columns):
return True
return False | python | def columns_are_indexed(self, columns):
"""
Checks if an index begins in the order of the given columns.
:type columns: list
:rtype: bool
"""
for index in self._indexes.values():
if index.spans_columns(columns):
return True
return False | [
"def",
"columns_are_indexed",
"(",
"self",
",",
"columns",
")",
":",
"for",
"index",
"in",
"self",
".",
"_indexes",
".",
"values",
"(",
")",
":",
"if",
"index",
".",
"spans_columns",
"(",
"columns",
")",
":",
"return",
"True",
"return",
"False"
] | Checks if an index begins in the order of the given columns.
:type columns: list
:rtype: bool | [
"Checks",
"if",
"an",
"index",
"begins",
"in",
"the",
"order",
"of",
"the",
"given",
"columns",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L152-L164 |
230,956 | sdispater/orator | orator/dbal/table.py | Table._create_index | def _create_index(
self, columns, name, is_unique, is_primary, flags=None, options=None
):
"""
Creates an Index instance.
:param columns: The index columns
:type columns: list
:param name: The index name
:type name: str
:param is_unique: Whether the index is unique or not
:type is_unique: bool
:param is_primary: Whether the index is primary or not
:type is_primary: bool
:param flags: The index flags
:type: dict
:param options: The options
:type options: dict
:rtype: Index
"""
if re.match("[^a-zA-Z0-9_]+", self._normalize_identifier(name)):
raise IndexNameInvalid(name)
for column in columns:
if isinstance(column, dict):
column = list(column.keys())[0]
if not self.has_column(column):
raise ColumnDoesNotExist(column, self._name)
return Index(name, columns, is_unique, is_primary, flags, options) | python | def _create_index(
self, columns, name, is_unique, is_primary, flags=None, options=None
):
"""
Creates an Index instance.
:param columns: The index columns
:type columns: list
:param name: The index name
:type name: str
:param is_unique: Whether the index is unique or not
:type is_unique: bool
:param is_primary: Whether the index is primary or not
:type is_primary: bool
:param flags: The index flags
:type: dict
:param options: The options
:type options: dict
:rtype: Index
"""
if re.match("[^a-zA-Z0-9_]+", self._normalize_identifier(name)):
raise IndexNameInvalid(name)
for column in columns:
if isinstance(column, dict):
column = list(column.keys())[0]
if not self.has_column(column):
raise ColumnDoesNotExist(column, self._name)
return Index(name, columns, is_unique, is_primary, flags, options) | [
"def",
"_create_index",
"(",
"self",
",",
"columns",
",",
"name",
",",
"is_unique",
",",
"is_primary",
",",
"flags",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"if",
"re",
".",
"match",
"(",
"\"[^a-zA-Z0-9_]+\"",
",",
"self",
".",
"_normalize_identifier",
"(",
"name",
")",
")",
":",
"raise",
"IndexNameInvalid",
"(",
"name",
")",
"for",
"column",
"in",
"columns",
":",
"if",
"isinstance",
"(",
"column",
",",
"dict",
")",
":",
"column",
"=",
"list",
"(",
"column",
".",
"keys",
"(",
")",
")",
"[",
"0",
"]",
"if",
"not",
"self",
".",
"has_column",
"(",
"column",
")",
":",
"raise",
"ColumnDoesNotExist",
"(",
"column",
",",
"self",
".",
"_name",
")",
"return",
"Index",
"(",
"name",
",",
"columns",
",",
"is_unique",
",",
"is_primary",
",",
"flags",
",",
"options",
")"
] | Creates an Index instance.
:param columns: The index columns
:type columns: list
:param name: The index name
:type name: str
:param is_unique: Whether the index is unique or not
:type is_unique: bool
:param is_primary: Whether the index is primary or not
:type is_primary: bool
:param flags: The index flags
:type: dict
:param options: The options
:type options: dict
:rtype: Index | [
"Creates",
"an",
"Index",
"instance",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L166-L202 |
230,957 | sdispater/orator | orator/dbal/table.py | Table.add_column | def add_column(self, name, type_name, options=None):
"""
Adds a new column.
:param name: The column name
:type name: str
:param type_name: The column type
:type type_name: str
:param options: The column options
:type options: dict
:rtype: Column
"""
column = Column(name, type_name, options)
self._add_column(column)
return column | python | def add_column(self, name, type_name, options=None):
"""
Adds a new column.
:param name: The column name
:type name: str
:param type_name: The column type
:type type_name: str
:param options: The column options
:type options: dict
:rtype: Column
"""
column = Column(name, type_name, options)
self._add_column(column)
return column | [
"def",
"add_column",
"(",
"self",
",",
"name",
",",
"type_name",
",",
"options",
"=",
"None",
")",
":",
"column",
"=",
"Column",
"(",
"name",
",",
"type_name",
",",
"options",
")",
"self",
".",
"_add_column",
"(",
"column",
")",
"return",
"column"
] | Adds a new column.
:param name: The column name
:type name: str
:param type_name: The column type
:type type_name: str
:param options: The column options
:type options: dict
:rtype: Column | [
"Adds",
"a",
"new",
"column",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L204-L223 |
230,958 | sdispater/orator | orator/dbal/table.py | Table.change_column | def change_column(self, name, options):
"""
Changes column details.
:param name: The column to change.
:type name: str
:param options: The new options.
:type options: str
:rtype: Table
"""
column = self.get_column(name)
column.set_options(options)
return self | python | def change_column(self, name, options):
"""
Changes column details.
:param name: The column to change.
:type name: str
:param options: The new options.
:type options: str
:rtype: Table
"""
column = self.get_column(name)
column.set_options(options)
return self | [
"def",
"change_column",
"(",
"self",
",",
"name",
",",
"options",
")",
":",
"column",
"=",
"self",
".",
"get_column",
"(",
"name",
")",
"column",
".",
"set_options",
"(",
"options",
")",
"return",
"self"
] | Changes column details.
:param name: The column to change.
:type name: str
:param options: The new options.
:type options: str
:rtype: Table | [
"Changes",
"column",
"details",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L225-L240 |
230,959 | sdispater/orator | orator/dbal/table.py | Table.drop_column | def drop_column(self, name):
"""
Drops a Column from the Table
:param name: The name of the column
:type name: str
:rtype: Table
"""
name = self._normalize_identifier(name)
del self._columns[name]
return self | python | def drop_column(self, name):
"""
Drops a Column from the Table
:param name: The name of the column
:type name: str
:rtype: Table
"""
name = self._normalize_identifier(name)
del self._columns[name]
return self | [
"def",
"drop_column",
"(",
"self",
",",
"name",
")",
":",
"name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"name",
")",
"del",
"self",
".",
"_columns",
"[",
"name",
"]",
"return",
"self"
] | Drops a Column from the Table
:param name: The name of the column
:type name: str
:rtype: Table | [
"Drops",
"a",
"Column",
"from",
"the",
"Table"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L242-L254 |
230,960 | sdispater/orator | orator/dbal/table.py | Table.add_named_foreign_key_constraint | def add_named_foreign_key_constraint(
self, name, foreign_table, local_columns, foreign_columns, options
):
"""
Adds a foreign key constraint with a given name.
:param name: The constraint name
:type name: str
:param foreign_table: Table instance or table name
:type foreign_table: Table or str
:type local_columns: list
:type foreign_columns: list
:type options: dict
:rtype: Table
"""
if isinstance(foreign_table, Table):
for column in foreign_columns:
if not foreign_table.has_column(column):
raise ColumnDoesNotExist(column, foreign_table.get_name())
for column in local_columns:
if not self.has_column(column):
raise ColumnDoesNotExist(column, self._name)
constraint = ForeignKeyConstraint(
local_columns, foreign_table, foreign_columns, name, options
)
self._add_foreign_key_constraint(constraint)
return self | python | def add_named_foreign_key_constraint(
self, name, foreign_table, local_columns, foreign_columns, options
):
"""
Adds a foreign key constraint with a given name.
:param name: The constraint name
:type name: str
:param foreign_table: Table instance or table name
:type foreign_table: Table or str
:type local_columns: list
:type foreign_columns: list
:type options: dict
:rtype: Table
"""
if isinstance(foreign_table, Table):
for column in foreign_columns:
if not foreign_table.has_column(column):
raise ColumnDoesNotExist(column, foreign_table.get_name())
for column in local_columns:
if not self.has_column(column):
raise ColumnDoesNotExist(column, self._name)
constraint = ForeignKeyConstraint(
local_columns, foreign_table, foreign_columns, name, options
)
self._add_foreign_key_constraint(constraint)
return self | [
"def",
"add_named_foreign_key_constraint",
"(",
"self",
",",
"name",
",",
"foreign_table",
",",
"local_columns",
",",
"foreign_columns",
",",
"options",
")",
":",
"if",
"isinstance",
"(",
"foreign_table",
",",
"Table",
")",
":",
"for",
"column",
"in",
"foreign_columns",
":",
"if",
"not",
"foreign_table",
".",
"has_column",
"(",
"column",
")",
":",
"raise",
"ColumnDoesNotExist",
"(",
"column",
",",
"foreign_table",
".",
"get_name",
"(",
")",
")",
"for",
"column",
"in",
"local_columns",
":",
"if",
"not",
"self",
".",
"has_column",
"(",
"column",
")",
":",
"raise",
"ColumnDoesNotExist",
"(",
"column",
",",
"self",
".",
"_name",
")",
"constraint",
"=",
"ForeignKeyConstraint",
"(",
"local_columns",
",",
"foreign_table",
",",
"foreign_columns",
",",
"name",
",",
"options",
")",
"self",
".",
"_add_foreign_key_constraint",
"(",
"constraint",
")",
"return",
"self"
] | Adds a foreign key constraint with a given name.
:param name: The constraint name
:type name: str
:param foreign_table: Table instance or table name
:type foreign_table: Table or str
:type local_columns: list
:type foreign_columns: list
:type options: dict
:rtype: Table | [
"Adds",
"a",
"foreign",
"key",
"constraint",
"with",
"a",
"given",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L293-L328 |
230,961 | sdispater/orator | orator/dbal/table.py | Table._add_index | def _add_index(self, index):
"""
Adds an index to the table.
:param index: The index to add
:type index: Index
:rtype: Table
"""
index_name = index.get_name()
index_name = self._normalize_identifier(index_name)
replaced_implicit_indexes = []
for name, implicit_index in self._implicit_indexes.items():
if implicit_index.is_fullfilled_by(index) and name in self._indexes:
replaced_implicit_indexes.append(name)
already_exists = (
index_name in self._indexes
and index_name not in replaced_implicit_indexes
or self._primary_key_name is not False
and index.is_primary()
)
if already_exists:
raise IndexAlreadyExists(index_name, self._name)
for name in replaced_implicit_indexes:
del self._indexes[name]
del self._implicit_indexes[name]
if index.is_primary():
self._primary_key_name = index_name
self._indexes[index_name] = index
return self | python | def _add_index(self, index):
"""
Adds an index to the table.
:param index: The index to add
:type index: Index
:rtype: Table
"""
index_name = index.get_name()
index_name = self._normalize_identifier(index_name)
replaced_implicit_indexes = []
for name, implicit_index in self._implicit_indexes.items():
if implicit_index.is_fullfilled_by(index) and name in self._indexes:
replaced_implicit_indexes.append(name)
already_exists = (
index_name in self._indexes
and index_name not in replaced_implicit_indexes
or self._primary_key_name is not False
and index.is_primary()
)
if already_exists:
raise IndexAlreadyExists(index_name, self._name)
for name in replaced_implicit_indexes:
del self._indexes[name]
del self._implicit_indexes[name]
if index.is_primary():
self._primary_key_name = index_name
self._indexes[index_name] = index
return self | [
"def",
"_add_index",
"(",
"self",
",",
"index",
")",
":",
"index_name",
"=",
"index",
".",
"get_name",
"(",
")",
"index_name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"index_name",
")",
"replaced_implicit_indexes",
"=",
"[",
"]",
"for",
"name",
",",
"implicit_index",
"in",
"self",
".",
"_implicit_indexes",
".",
"items",
"(",
")",
":",
"if",
"implicit_index",
".",
"is_fullfilled_by",
"(",
"index",
")",
"and",
"name",
"in",
"self",
".",
"_indexes",
":",
"replaced_implicit_indexes",
".",
"append",
"(",
"name",
")",
"already_exists",
"=",
"(",
"index_name",
"in",
"self",
".",
"_indexes",
"and",
"index_name",
"not",
"in",
"replaced_implicit_indexes",
"or",
"self",
".",
"_primary_key_name",
"is",
"not",
"False",
"and",
"index",
".",
"is_primary",
"(",
")",
")",
"if",
"already_exists",
":",
"raise",
"IndexAlreadyExists",
"(",
"index_name",
",",
"self",
".",
"_name",
")",
"for",
"name",
"in",
"replaced_implicit_indexes",
":",
"del",
"self",
".",
"_indexes",
"[",
"name",
"]",
"del",
"self",
".",
"_implicit_indexes",
"[",
"name",
"]",
"if",
"index",
".",
"is_primary",
"(",
")",
":",
"self",
".",
"_primary_key_name",
"=",
"index_name",
"self",
".",
"_indexes",
"[",
"index_name",
"]",
"=",
"index",
"return",
"self"
] | Adds an index to the table.
:param index: The index to add
:type index: Index
:rtype: Table | [
"Adds",
"an",
"index",
"to",
"the",
"table",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L343-L378 |
230,962 | sdispater/orator | orator/dbal/table.py | Table.has_foreign_key | def has_foreign_key(self, name):
"""
Returns whether this table has a foreign key constraint with the given name.
:param name: The constraint name
:type name: str
:rtype: bool
"""
name = self._normalize_identifier(name)
return name in self._fk_constraints | python | def has_foreign_key(self, name):
"""
Returns whether this table has a foreign key constraint with the given name.
:param name: The constraint name
:type name: str
:rtype: bool
"""
name = self._normalize_identifier(name)
return name in self._fk_constraints | [
"def",
"has_foreign_key",
"(",
"self",
",",
"name",
")",
":",
"name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"name",
")",
"return",
"name",
"in",
"self",
".",
"_fk_constraints"
] | Returns whether this table has a foreign key constraint with the given name.
:param name: The constraint name
:type name: str
:rtype: bool | [
"Returns",
"whether",
"this",
"table",
"has",
"a",
"foreign",
"key",
"constraint",
"with",
"the",
"given",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L428-L439 |
230,963 | sdispater/orator | orator/dbal/table.py | Table.get_foreign_key | def get_foreign_key(self, name):
"""
Returns the foreign key constraint with the given name.
:param name: The constraint name
:type name: str
:rtype: ForeignKeyConstraint
"""
name = self._normalize_identifier(name)
if not self.has_foreign_key(name):
raise ForeignKeyDoesNotExist(name, self._name)
return self._fk_constraints[name] | python | def get_foreign_key(self, name):
"""
Returns the foreign key constraint with the given name.
:param name: The constraint name
:type name: str
:rtype: ForeignKeyConstraint
"""
name = self._normalize_identifier(name)
if not self.has_foreign_key(name):
raise ForeignKeyDoesNotExist(name, self._name)
return self._fk_constraints[name] | [
"def",
"get_foreign_key",
"(",
"self",
",",
"name",
")",
":",
"name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"name",
")",
"if",
"not",
"self",
".",
"has_foreign_key",
"(",
"name",
")",
":",
"raise",
"ForeignKeyDoesNotExist",
"(",
"name",
",",
"self",
".",
"_name",
")",
"return",
"self",
".",
"_fk_constraints",
"[",
"name",
"]"
] | Returns the foreign key constraint with the given name.
:param name: The constraint name
:type name: str
:rtype: ForeignKeyConstraint | [
"Returns",
"the",
"foreign",
"key",
"constraint",
"with",
"the",
"given",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L441-L455 |
230,964 | sdispater/orator | orator/dbal/table.py | Table.remove_foreign_key | def remove_foreign_key(self, name):
"""
Removes the foreign key constraint with the given name.
:param name: The constraint name
:type name: str
"""
name = self._normalize_identifier(name)
if not self.has_foreign_key(name):
raise ForeignKeyDoesNotExist(name, self._name)
del self._fk_constraints[name] | python | def remove_foreign_key(self, name):
"""
Removes the foreign key constraint with the given name.
:param name: The constraint name
:type name: str
"""
name = self._normalize_identifier(name)
if not self.has_foreign_key(name):
raise ForeignKeyDoesNotExist(name, self._name)
del self._fk_constraints[name] | [
"def",
"remove_foreign_key",
"(",
"self",
",",
"name",
")",
":",
"name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"name",
")",
"if",
"not",
"self",
".",
"has_foreign_key",
"(",
"name",
")",
":",
"raise",
"ForeignKeyDoesNotExist",
"(",
"name",
",",
"self",
".",
"_name",
")",
"del",
"self",
".",
"_fk_constraints",
"[",
"name",
"]"
] | Removes the foreign key constraint with the given name.
:param name: The constraint name
:type name: str | [
"Removes",
"the",
"foreign",
"key",
"constraint",
"with",
"the",
"given",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L457-L469 |
230,965 | sdispater/orator | orator/dbal/table.py | Table.get_primary_key_columns | def get_primary_key_columns(self):
"""
Returns the primary key columns.
:rtype: list
"""
if not self.has_primary_key():
raise DBALException('Table "%s" has no primary key.' % self.get_name())
return self.get_primary_key().get_columns() | python | def get_primary_key_columns(self):
"""
Returns the primary key columns.
:rtype: list
"""
if not self.has_primary_key():
raise DBALException('Table "%s" has no primary key.' % self.get_name())
return self.get_primary_key().get_columns() | [
"def",
"get_primary_key_columns",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"has_primary_key",
"(",
")",
":",
"raise",
"DBALException",
"(",
"'Table \"%s\" has no primary key.'",
"%",
"self",
".",
"get_name",
"(",
")",
")",
"return",
"self",
".",
"get_primary_key",
"(",
")",
".",
"get_columns",
"(",
")"
] | Returns the primary key columns.
:rtype: list | [
"Returns",
"the",
"primary",
"key",
"columns",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L511-L520 |
230,966 | sdispater/orator | orator/dbal/table.py | Table.has_index | def has_index(self, name):
"""
Returns whether this table has an Index with the given name.
:param name: The index name
:type name: str
:rtype: bool
"""
name = self._normalize_identifier(name)
return name in self._indexes | python | def has_index(self, name):
"""
Returns whether this table has an Index with the given name.
:param name: The index name
:type name: str
:rtype: bool
"""
name = self._normalize_identifier(name)
return name in self._indexes | [
"def",
"has_index",
"(",
"self",
",",
"name",
")",
":",
"name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"name",
")",
"return",
"name",
"in",
"self",
".",
"_indexes"
] | Returns whether this table has an Index with the given name.
:param name: The index name
:type name: str
:rtype: bool | [
"Returns",
"whether",
"this",
"table",
"has",
"an",
"Index",
"with",
"the",
"given",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L533-L544 |
230,967 | sdispater/orator | orator/dbal/table.py | Table.get_index | def get_index(self, name):
"""
Returns the Index with the given name.
:param name: The index name
:type name: str
:rtype: Index
"""
name = self._normalize_identifier(name)
if not self.has_index(name):
raise IndexDoesNotExist(name, self._name)
return self._indexes[name] | python | def get_index(self, name):
"""
Returns the Index with the given name.
:param name: The index name
:type name: str
:rtype: Index
"""
name = self._normalize_identifier(name)
if not self.has_index(name):
raise IndexDoesNotExist(name, self._name)
return self._indexes[name] | [
"def",
"get_index",
"(",
"self",
",",
"name",
")",
":",
"name",
"=",
"self",
".",
"_normalize_identifier",
"(",
"name",
")",
"if",
"not",
"self",
".",
"has_index",
"(",
"name",
")",
":",
"raise",
"IndexDoesNotExist",
"(",
"name",
",",
"self",
".",
"_name",
")",
"return",
"self",
".",
"_indexes",
"[",
"name",
"]"
] | Returns the Index with the given name.
:param name: The index name
:type name: str
:rtype: Index | [
"Returns",
"the",
"Index",
"with",
"the",
"given",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L546-L559 |
230,968 | sdispater/orator | orator/orm/builder.py | Builder.without_global_scope | def without_global_scope(self, scope):
"""
Remove a registered global scope.
:param scope: The scope to remove
:type scope: Scope or str
:rtype: Builder
"""
if isinstance(scope, basestring):
del self._scopes[scope]
return self
keys = []
for key, value in self._scopes.items():
if scope == value.__class__ or isinstance(scope, value.__class__):
keys.append(key)
for key in keys:
del self._scopes[key]
return self | python | def without_global_scope(self, scope):
"""
Remove a registered global scope.
:param scope: The scope to remove
:type scope: Scope or str
:rtype: Builder
"""
if isinstance(scope, basestring):
del self._scopes[scope]
return self
keys = []
for key, value in self._scopes.items():
if scope == value.__class__ or isinstance(scope, value.__class__):
keys.append(key)
for key in keys:
del self._scopes[key]
return self | [
"def",
"without_global_scope",
"(",
"self",
",",
"scope",
")",
":",
"if",
"isinstance",
"(",
"scope",
",",
"basestring",
")",
":",
"del",
"self",
".",
"_scopes",
"[",
"scope",
"]",
"return",
"self",
"keys",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"self",
".",
"_scopes",
".",
"items",
"(",
")",
":",
"if",
"scope",
"==",
"value",
".",
"__class__",
"or",
"isinstance",
"(",
"scope",
",",
"value",
".",
"__class__",
")",
":",
"keys",
".",
"append",
"(",
"key",
")",
"for",
"key",
"in",
"keys",
":",
"del",
"self",
".",
"_scopes",
"[",
"key",
"]",
"return",
"self"
] | Remove a registered global scope.
:param scope: The scope to remove
:type scope: Scope or str
:rtype: Builder | [
"Remove",
"a",
"registered",
"global",
"scope",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L63-L85 |
230,969 | sdispater/orator | orator/orm/builder.py | Builder.find_or_fail | def find_or_fail(self, id, columns=None):
"""
Find a model by its primary key or raise an exception
:param id: The primary key value
:type id: mixed
:param columns: The columns to retrieve
:type columns: list
:return: The found model
:rtype: orator.Model
:raises: ModelNotFound
"""
result = self.find(id, columns)
if isinstance(id, list):
if len(result) == len(set(id)):
return result
elif result:
return result
raise ModelNotFound(self._model.__class__) | python | def find_or_fail(self, id, columns=None):
"""
Find a model by its primary key or raise an exception
:param id: The primary key value
:type id: mixed
:param columns: The columns to retrieve
:type columns: list
:return: The found model
:rtype: orator.Model
:raises: ModelNotFound
"""
result = self.find(id, columns)
if isinstance(id, list):
if len(result) == len(set(id)):
return result
elif result:
return result
raise ModelNotFound(self._model.__class__) | [
"def",
"find_or_fail",
"(",
"self",
",",
"id",
",",
"columns",
"=",
"None",
")",
":",
"result",
"=",
"self",
".",
"find",
"(",
"id",
",",
"columns",
")",
"if",
"isinstance",
"(",
"id",
",",
"list",
")",
":",
"if",
"len",
"(",
"result",
")",
"==",
"len",
"(",
"set",
"(",
"id",
")",
")",
":",
"return",
"result",
"elif",
"result",
":",
"return",
"result",
"raise",
"ModelNotFound",
"(",
"self",
".",
"_model",
".",
"__class__",
")"
] | Find a model by its primary key or raise an exception
:param id: The primary key value
:type id: mixed
:param columns: The columns to retrieve
:type columns: list
:return: The found model
:rtype: orator.Model
:raises: ModelNotFound | [
"Find",
"a",
"model",
"by",
"its",
"primary",
"key",
"or",
"raise",
"an",
"exception"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L143-L166 |
230,970 | sdispater/orator | orator/orm/builder.py | Builder.first_or_fail | def first_or_fail(self, columns=None):
"""
Execute the query and get the first result or raise an exception
:param columns: The columns to get
:type columns: list
:return: The result
:rtype: mixed
"""
model = self.first(columns)
if model is not None:
return model
raise ModelNotFound(self._model.__class__) | python | def first_or_fail(self, columns=None):
"""
Execute the query and get the first result or raise an exception
:param columns: The columns to get
:type columns: list
:return: The result
:rtype: mixed
"""
model = self.first(columns)
if model is not None:
return model
raise ModelNotFound(self._model.__class__) | [
"def",
"first_or_fail",
"(",
"self",
",",
"columns",
"=",
"None",
")",
":",
"model",
"=",
"self",
".",
"first",
"(",
"columns",
")",
"if",
"model",
"is",
"not",
"None",
":",
"return",
"model",
"raise",
"ModelNotFound",
"(",
"self",
".",
"_model",
".",
"__class__",
")"
] | Execute the query and get the first result or raise an exception
:param columns: The columns to get
:type columns: list
:return: The result
:rtype: mixed | [
"Execute",
"the",
"query",
"and",
"get",
"the",
"first",
"result",
"or",
"raise",
"an",
"exception"
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L183-L198 |
230,971 | sdispater/orator | orator/orm/builder.py | Builder.pluck | def pluck(self, column):
"""
Pluck a single column from the database.
:param column: THe column to pluck
:type column: str
:return: The column value
:rtype: mixed
"""
result = self.first([column])
if result:
return result[column] | python | def pluck(self, column):
"""
Pluck a single column from the database.
:param column: THe column to pluck
:type column: str
:return: The column value
:rtype: mixed
"""
result = self.first([column])
if result:
return result[column] | [
"def",
"pluck",
"(",
"self",
",",
"column",
")",
":",
"result",
"=",
"self",
".",
"first",
"(",
"[",
"column",
"]",
")",
"if",
"result",
":",
"return",
"result",
"[",
"column",
"]"
] | Pluck a single column from the database.
:param column: THe column to pluck
:type column: str
:return: The column value
:rtype: mixed | [
"Pluck",
"a",
"single",
"column",
"from",
"the",
"database",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L221-L234 |
230,972 | sdispater/orator | orator/orm/builder.py | Builder._add_updated_at_column | def _add_updated_at_column(self, values):
"""
Add the "updated_at" column to a dictionary of values.
:param values: The values to update
:type values: dict
:return: The new dictionary of values
:rtype: dict
"""
if not self._model.uses_timestamps():
return values
column = self._model.get_updated_at_column()
if "updated_at" not in values:
values.update({column: self._model.fresh_timestamp_string()})
return values | python | def _add_updated_at_column(self, values):
"""
Add the "updated_at" column to a dictionary of values.
:param values: The values to update
:type values: dict
:return: The new dictionary of values
:rtype: dict
"""
if not self._model.uses_timestamps():
return values
column = self._model.get_updated_at_column()
if "updated_at" not in values:
values.update({column: self._model.fresh_timestamp_string()})
return values | [
"def",
"_add_updated_at_column",
"(",
"self",
",",
"values",
")",
":",
"if",
"not",
"self",
".",
"_model",
".",
"uses_timestamps",
"(",
")",
":",
"return",
"values",
"column",
"=",
"self",
".",
"_model",
".",
"get_updated_at_column",
"(",
")",
"if",
"\"updated_at\"",
"not",
"in",
"values",
":",
"values",
".",
"update",
"(",
"{",
"column",
":",
"self",
".",
"_model",
".",
"fresh_timestamp_string",
"(",
")",
"}",
")",
"return",
"values"
] | Add the "updated_at" column to a dictionary of values.
:param values: The values to update
:type values: dict
:return: The new dictionary of values
:rtype: dict | [
"Add",
"the",
"updated_at",
"column",
"to",
"a",
"dictionary",
"of",
"values",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L401-L419 |
230,973 | sdispater/orator | orator/orm/builder.py | Builder.delete | def delete(self):
"""
Delete a record from the database.
"""
if self._on_delete is not None:
return self._on_delete(self)
return self._query.delete() | python | def delete(self):
"""
Delete a record from the database.
"""
if self._on_delete is not None:
return self._on_delete(self)
return self._query.delete() | [
"def",
"delete",
"(",
"self",
")",
":",
"if",
"self",
".",
"_on_delete",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_on_delete",
"(",
"self",
")",
"return",
"self",
".",
"_query",
".",
"delete",
"(",
")"
] | Delete a record from the database. | [
"Delete",
"a",
"record",
"from",
"the",
"database",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L421-L428 |
230,974 | sdispater/orator | orator/orm/builder.py | Builder.get_relation | def get_relation(self, relation):
"""
Get the relation instance for the given relation name.
:rtype: orator.orm.relations.Relation
"""
from .relations import Relation
with Relation.no_constraints(True):
rel = getattr(self.get_model(), relation)()
nested = self._nested_relations(relation)
if len(nested) > 0:
rel.get_query().with_(nested)
return rel | python | def get_relation(self, relation):
"""
Get the relation instance for the given relation name.
:rtype: orator.orm.relations.Relation
"""
from .relations import Relation
with Relation.no_constraints(True):
rel = getattr(self.get_model(), relation)()
nested = self._nested_relations(relation)
if len(nested) > 0:
rel.get_query().with_(nested)
return rel | [
"def",
"get_relation",
"(",
"self",
",",
"relation",
")",
":",
"from",
".",
"relations",
"import",
"Relation",
"with",
"Relation",
".",
"no_constraints",
"(",
"True",
")",
":",
"rel",
"=",
"getattr",
"(",
"self",
".",
"get_model",
"(",
")",
",",
"relation",
")",
"(",
")",
"nested",
"=",
"self",
".",
"_nested_relations",
"(",
"relation",
")",
"if",
"len",
"(",
"nested",
")",
">",
"0",
":",
"rel",
".",
"get_query",
"(",
")",
".",
"with_",
"(",
"nested",
")",
"return",
"rel"
] | Get the relation instance for the given relation name.
:rtype: orator.orm.relations.Relation | [
"Get",
"the",
"relation",
"instance",
"for",
"the",
"given",
"relation",
"name",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L500-L516 |
230,975 | sdispater/orator | orator/orm/builder.py | Builder._nested_relations | def _nested_relations(self, relation):
"""
Get the deeply nested relations for a given top-level relation.
:rtype: dict
"""
nested = {}
for name, constraints in self._eager_load.items():
if self._is_nested(name, relation):
nested[name[len(relation + ".") :]] = constraints
return nested | python | def _nested_relations(self, relation):
"""
Get the deeply nested relations for a given top-level relation.
:rtype: dict
"""
nested = {}
for name, constraints in self._eager_load.items():
if self._is_nested(name, relation):
nested[name[len(relation + ".") :]] = constraints
return nested | [
"def",
"_nested_relations",
"(",
"self",
",",
"relation",
")",
":",
"nested",
"=",
"{",
"}",
"for",
"name",
",",
"constraints",
"in",
"self",
".",
"_eager_load",
".",
"items",
"(",
")",
":",
"if",
"self",
".",
"_is_nested",
"(",
"name",
",",
"relation",
")",
":",
"nested",
"[",
"name",
"[",
"len",
"(",
"relation",
"+",
"\".\"",
")",
":",
"]",
"]",
"=",
"constraints",
"return",
"nested"
] | Get the deeply nested relations for a given top-level relation.
:rtype: dict | [
"Get",
"the",
"deeply",
"nested",
"relations",
"for",
"a",
"given",
"top",
"-",
"level",
"relation",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L518-L530 |
230,976 | sdispater/orator | orator/orm/builder.py | Builder._is_nested | def _is_nested(self, name, relation):
"""
Determine if the relationship is nested.
:type name: str
:type relation: str
:rtype: bool
"""
dots = name.find(".")
return dots and name.startswith(relation + ".") | python | def _is_nested(self, name, relation):
"""
Determine if the relationship is nested.
:type name: str
:type relation: str
:rtype: bool
"""
dots = name.find(".")
return dots and name.startswith(relation + ".") | [
"def",
"_is_nested",
"(",
"self",
",",
"name",
",",
"relation",
")",
":",
"dots",
"=",
"name",
".",
"find",
"(",
"\".\"",
")",
"return",
"dots",
"and",
"name",
".",
"startswith",
"(",
"relation",
"+",
"\".\"",
")"
] | Determine if the relationship is nested.
:type name: str
:type relation: str
:rtype: bool | [
"Determine",
"if",
"the",
"relationship",
"is",
"nested",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L532-L543 |
230,977 | sdispater/orator | orator/orm/builder.py | Builder.where_exists | def where_exists(self, query, boolean="and", negate=False):
"""
Add an exists clause to the query.
:param query: The exists query
:type query: Builder or QueryBuilder
:type boolean: str
:type negate: bool
:rtype: Builder
"""
if isinstance(query, Builder):
query = query.get_query()
self.get_query().where_exists(query, boolean, negate)
return self | python | def where_exists(self, query, boolean="and", negate=False):
"""
Add an exists clause to the query.
:param query: The exists query
:type query: Builder or QueryBuilder
:type boolean: str
:type negate: bool
:rtype: Builder
"""
if isinstance(query, Builder):
query = query.get_query()
self.get_query().where_exists(query, boolean, negate)
return self | [
"def",
"where_exists",
"(",
"self",
",",
"query",
",",
"boolean",
"=",
"\"and\"",
",",
"negate",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"query",
",",
"Builder",
")",
":",
"query",
"=",
"query",
".",
"get_query",
"(",
")",
"self",
".",
"get_query",
"(",
")",
".",
"where_exists",
"(",
"query",
",",
"boolean",
",",
"negate",
")",
"return",
"self"
] | Add an exists clause to the query.
:param query: The exists query
:type query: Builder or QueryBuilder
:type boolean: str
:type negate: bool
:rtype: Builder | [
"Add",
"an",
"exists",
"clause",
"to",
"the",
"query",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L589-L607 |
230,978 | sdispater/orator | orator/orm/builder.py | Builder.has | def has(self, relation, operator=">=", count=1, boolean="and", extra=None):
"""
Add a relationship count condition to the query.
:param relation: The relation to count
:type relation: str
:param operator: The operator
:type operator: str
:param count: The count
:type count: int
:param boolean: The boolean value
:type boolean: str
:param extra: The extra query
:type extra: Builder or callable
:type: Builder
"""
if relation.find(".") >= 0:
return self._has_nested(relation, operator, count, boolean, extra)
relation = self._get_has_relation_query(relation)
query = relation.get_relation_count_query(
relation.get_related().new_query(), self
)
# TODO: extra query
if extra:
if callable(extra):
extra(query)
return self._add_has_where(
query.apply_scopes(), relation, operator, count, boolean
) | python | def has(self, relation, operator=">=", count=1, boolean="and", extra=None):
"""
Add a relationship count condition to the query.
:param relation: The relation to count
:type relation: str
:param operator: The operator
:type operator: str
:param count: The count
:type count: int
:param boolean: The boolean value
:type boolean: str
:param extra: The extra query
:type extra: Builder or callable
:type: Builder
"""
if relation.find(".") >= 0:
return self._has_nested(relation, operator, count, boolean, extra)
relation = self._get_has_relation_query(relation)
query = relation.get_relation_count_query(
relation.get_related().new_query(), self
)
# TODO: extra query
if extra:
if callable(extra):
extra(query)
return self._add_has_where(
query.apply_scopes(), relation, operator, count, boolean
) | [
"def",
"has",
"(",
"self",
",",
"relation",
",",
"operator",
"=",
"\">=\"",
",",
"count",
"=",
"1",
",",
"boolean",
"=",
"\"and\"",
",",
"extra",
"=",
"None",
")",
":",
"if",
"relation",
".",
"find",
"(",
"\".\"",
")",
">=",
"0",
":",
"return",
"self",
".",
"_has_nested",
"(",
"relation",
",",
"operator",
",",
"count",
",",
"boolean",
",",
"extra",
")",
"relation",
"=",
"self",
".",
"_get_has_relation_query",
"(",
"relation",
")",
"query",
"=",
"relation",
".",
"get_relation_count_query",
"(",
"relation",
".",
"get_related",
"(",
")",
".",
"new_query",
"(",
")",
",",
"self",
")",
"# TODO: extra query",
"if",
"extra",
":",
"if",
"callable",
"(",
"extra",
")",
":",
"extra",
"(",
"query",
")",
"return",
"self",
".",
"_add_has_where",
"(",
"query",
".",
"apply_scopes",
"(",
")",
",",
"relation",
",",
"operator",
",",
"count",
",",
"boolean",
")"
] | Add a relationship count condition to the query.
:param relation: The relation to count
:type relation: str
:param operator: The operator
:type operator: str
:param count: The count
:type count: int
:param boolean: The boolean value
:type boolean: str
:param extra: The extra query
:type extra: Builder or callable
:type: Builder | [
"Add",
"a",
"relationship",
"count",
"condition",
"to",
"the",
"query",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L646-L683 |
230,979 | sdispater/orator | orator/orm/builder.py | Builder._add_has_where | def _add_has_where(self, has_query, relation, operator, count, boolean):
"""
Add the "has" condition where clause to the query.
:param has_query: The has query
:type has_query: Builder
:param relation: The relation to count
:type relation: orator.orm.relations.Relation
:param operator: The operator
:type operator: str
:param count: The count
:type count: int
:param boolean: The boolean value
:type boolean: str
:rtype: Builder
"""
self._merge_model_defined_relation_wheres_to_has_query(has_query, relation)
if isinstance(count, basestring) and count.isdigit():
count = QueryExpression(count)
return self.where(
QueryExpression("(%s)" % has_query.to_sql()), operator, count, boolean
) | python | def _add_has_where(self, has_query, relation, operator, count, boolean):
"""
Add the "has" condition where clause to the query.
:param has_query: The has query
:type has_query: Builder
:param relation: The relation to count
:type relation: orator.orm.relations.Relation
:param operator: The operator
:type operator: str
:param count: The count
:type count: int
:param boolean: The boolean value
:type boolean: str
:rtype: Builder
"""
self._merge_model_defined_relation_wheres_to_has_query(has_query, relation)
if isinstance(count, basestring) and count.isdigit():
count = QueryExpression(count)
return self.where(
QueryExpression("(%s)" % has_query.to_sql()), operator, count, boolean
) | [
"def",
"_add_has_where",
"(",
"self",
",",
"has_query",
",",
"relation",
",",
"operator",
",",
"count",
",",
"boolean",
")",
":",
"self",
".",
"_merge_model_defined_relation_wheres_to_has_query",
"(",
"has_query",
",",
"relation",
")",
"if",
"isinstance",
"(",
"count",
",",
"basestring",
")",
"and",
"count",
".",
"isdigit",
"(",
")",
":",
"count",
"=",
"QueryExpression",
"(",
"count",
")",
"return",
"self",
".",
"where",
"(",
"QueryExpression",
"(",
"\"(%s)\"",
"%",
"has_query",
".",
"to_sql",
"(",
")",
")",
",",
"operator",
",",
"count",
",",
"boolean",
")"
] | Add the "has" condition where clause to the query.
:param has_query: The has query
:type has_query: Builder
:param relation: The relation to count
:type relation: orator.orm.relations.Relation
:param operator: The operator
:type operator: str
:param count: The count
:type count: int
:param boolean: The boolean value
:type boolean: str
:rtype: Builder | [
"Add",
"the",
"has",
"condition",
"where",
"clause",
"to",
"the",
"query",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L804-L832 |
230,980 | sdispater/orator | orator/orm/builder.py | Builder._merge_model_defined_relation_wheres_to_has_query | def _merge_model_defined_relation_wheres_to_has_query(self, has_query, relation):
"""
Merge the "wheres" from a relation query to a has query.
:param has_query: The has query
:type has_query: Builder
:param relation: The relation to count
:type relation: orator.orm.relations.Relation
"""
relation_query = relation.get_base_query()
has_query.merge_wheres(relation_query.wheres, relation_query.get_bindings())
self._query.add_binding(has_query.get_query().get_bindings(), "where") | python | def _merge_model_defined_relation_wheres_to_has_query(self, has_query, relation):
"""
Merge the "wheres" from a relation query to a has query.
:param has_query: The has query
:type has_query: Builder
:param relation: The relation to count
:type relation: orator.orm.relations.Relation
"""
relation_query = relation.get_base_query()
has_query.merge_wheres(relation_query.wheres, relation_query.get_bindings())
self._query.add_binding(has_query.get_query().get_bindings(), "where") | [
"def",
"_merge_model_defined_relation_wheres_to_has_query",
"(",
"self",
",",
"has_query",
",",
"relation",
")",
":",
"relation_query",
"=",
"relation",
".",
"get_base_query",
"(",
")",
"has_query",
".",
"merge_wheres",
"(",
"relation_query",
".",
"wheres",
",",
"relation_query",
".",
"get_bindings",
"(",
")",
")",
"self",
".",
"_query",
".",
"add_binding",
"(",
"has_query",
".",
"get_query",
"(",
")",
".",
"get_bindings",
"(",
")",
",",
"\"where\"",
")"
] | Merge the "wheres" from a relation query to a has query.
:param has_query: The has query
:type has_query: Builder
:param relation: The relation to count
:type relation: orator.orm.relations.Relation | [
"Merge",
"the",
"wheres",
"from",
"a",
"relation",
"query",
"to",
"a",
"has",
"query",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L834-L848 |
230,981 | sdispater/orator | orator/orm/builder.py | Builder.apply_scopes | def apply_scopes(self):
"""
Get the underlying query builder instance with applied global scopes.
:type: Builder
"""
if not self._scopes:
return self
builder = copy.copy(self)
query = builder.get_query()
# We will keep track of how many wheres are on the query before running the
# scope so that we can properly group the added scope constraints in the
# query as their own isolated nested where statement and avoid issues.
original_where_count = len(query.wheres)
where_counts = [0, original_where_count]
for scope in self._scopes.values():
self._apply_scope(scope, builder)
# Again, we will keep track of the count each time we add where clauses so that
# we will properly isolate each set of scope constraints inside of their own
# nested where clause to avoid any conflicts or issues with logical order.
where_counts.append(len(query.wheres))
if self._should_nest_wheres_for_scope(query, original_where_count):
self._nest_wheres_for_scope(query, Collection(where_counts).unique().all())
return builder | python | def apply_scopes(self):
"""
Get the underlying query builder instance with applied global scopes.
:type: Builder
"""
if not self._scopes:
return self
builder = copy.copy(self)
query = builder.get_query()
# We will keep track of how many wheres are on the query before running the
# scope so that we can properly group the added scope constraints in the
# query as their own isolated nested where statement and avoid issues.
original_where_count = len(query.wheres)
where_counts = [0, original_where_count]
for scope in self._scopes.values():
self._apply_scope(scope, builder)
# Again, we will keep track of the count each time we add where clauses so that
# we will properly isolate each set of scope constraints inside of their own
# nested where clause to avoid any conflicts or issues with logical order.
where_counts.append(len(query.wheres))
if self._should_nest_wheres_for_scope(query, original_where_count):
self._nest_wheres_for_scope(query, Collection(where_counts).unique().all())
return builder | [
"def",
"apply_scopes",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_scopes",
":",
"return",
"self",
"builder",
"=",
"copy",
".",
"copy",
"(",
"self",
")",
"query",
"=",
"builder",
".",
"get_query",
"(",
")",
"# We will keep track of how many wheres are on the query before running the",
"# scope so that we can properly group the added scope constraints in the",
"# query as their own isolated nested where statement and avoid issues.",
"original_where_count",
"=",
"len",
"(",
"query",
".",
"wheres",
")",
"where_counts",
"=",
"[",
"0",
",",
"original_where_count",
"]",
"for",
"scope",
"in",
"self",
".",
"_scopes",
".",
"values",
"(",
")",
":",
"self",
".",
"_apply_scope",
"(",
"scope",
",",
"builder",
")",
"# Again, we will keep track of the count each time we add where clauses so that",
"# we will properly isolate each set of scope constraints inside of their own",
"# nested where clause to avoid any conflicts or issues with logical order.",
"where_counts",
".",
"append",
"(",
"len",
"(",
"query",
".",
"wheres",
")",
")",
"if",
"self",
".",
"_should_nest_wheres_for_scope",
"(",
"query",
",",
"original_where_count",
")",
":",
"self",
".",
"_nest_wheres_for_scope",
"(",
"query",
",",
"Collection",
"(",
"where_counts",
")",
".",
"unique",
"(",
")",
".",
"all",
"(",
")",
")",
"return",
"builder"
] | Get the underlying query builder instance with applied global scopes.
:type: Builder | [
"Get",
"the",
"underlying",
"query",
"builder",
"instance",
"with",
"applied",
"global",
"scopes",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L953-L984 |
230,982 | sdispater/orator | orator/orm/builder.py | Builder._apply_scope | def _apply_scope(self, scope, builder):
"""
Apply a single scope on the given builder instance.
:param scope: The scope to apply
:type scope: callable or Scope
:param builder: The builder to apply the scope to
:type builder: Builder
"""
if callable(scope):
scope(builder)
elif isinstance(scope, Scope):
scope.apply(builder, self.get_model()) | python | def _apply_scope(self, scope, builder):
"""
Apply a single scope on the given builder instance.
:param scope: The scope to apply
:type scope: callable or Scope
:param builder: The builder to apply the scope to
:type builder: Builder
"""
if callable(scope):
scope(builder)
elif isinstance(scope, Scope):
scope.apply(builder, self.get_model()) | [
"def",
"_apply_scope",
"(",
"self",
",",
"scope",
",",
"builder",
")",
":",
"if",
"callable",
"(",
"scope",
")",
":",
"scope",
"(",
"builder",
")",
"elif",
"isinstance",
"(",
"scope",
",",
"Scope",
")",
":",
"scope",
".",
"apply",
"(",
"builder",
",",
"self",
".",
"get_model",
"(",
")",
")"
] | Apply a single scope on the given builder instance.
:param scope: The scope to apply
:type scope: callable or Scope
:param builder: The builder to apply the scope to
:type builder: Builder | [
"Apply",
"a",
"single",
"scope",
"on",
"the",
"given",
"builder",
"instance",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L986-L999 |
230,983 | sdispater/orator | orator/orm/builder.py | Builder._nest_wheres_for_scope | def _nest_wheres_for_scope(self, query, where_counts):
"""
Nest where conditions of the builder and each global scope.
:type query: QueryBuilder
:type where_counts: list
"""
# Here, we totally remove all of the where clauses since we are going to
# rebuild them as nested queries by slicing the groups of wheres into
# their own sections. This is to prevent any confusing logic order.
wheres = query.wheres
query.wheres = []
# We will take the first offset (typically 0) of where clauses and start
# slicing out every scope's where clauses into their own nested where
# groups for improved isolation of every scope's added constraints.
previous_count = where_counts.pop(0)
for where_count in where_counts:
query.wheres.append(
self._slice_where_conditions(
wheres, previous_count, where_count - previous_count
)
)
previous_count = where_count | python | def _nest_wheres_for_scope(self, query, where_counts):
"""
Nest where conditions of the builder and each global scope.
:type query: QueryBuilder
:type where_counts: list
"""
# Here, we totally remove all of the where clauses since we are going to
# rebuild them as nested queries by slicing the groups of wheres into
# their own sections. This is to prevent any confusing logic order.
wheres = query.wheres
query.wheres = []
# We will take the first offset (typically 0) of where clauses and start
# slicing out every scope's where clauses into their own nested where
# groups for improved isolation of every scope's added constraints.
previous_count = where_counts.pop(0)
for where_count in where_counts:
query.wheres.append(
self._slice_where_conditions(
wheres, previous_count, where_count - previous_count
)
)
previous_count = where_count | [
"def",
"_nest_wheres_for_scope",
"(",
"self",
",",
"query",
",",
"where_counts",
")",
":",
"# Here, we totally remove all of the where clauses since we are going to",
"# rebuild them as nested queries by slicing the groups of wheres into",
"# their own sections. This is to prevent any confusing logic order.",
"wheres",
"=",
"query",
".",
"wheres",
"query",
".",
"wheres",
"=",
"[",
"]",
"# We will take the first offset (typically 0) of where clauses and start",
"# slicing out every scope's where clauses into their own nested where",
"# groups for improved isolation of every scope's added constraints.",
"previous_count",
"=",
"where_counts",
".",
"pop",
"(",
"0",
")",
"for",
"where_count",
"in",
"where_counts",
":",
"query",
".",
"wheres",
".",
"append",
"(",
"self",
".",
"_slice_where_conditions",
"(",
"wheres",
",",
"previous_count",
",",
"where_count",
"-",
"previous_count",
")",
")",
"previous_count",
"=",
"where_count"
] | Nest where conditions of the builder and each global scope.
:type query: QueryBuilder
:type where_counts: list | [
"Nest",
"where",
"conditions",
"of",
"the",
"builder",
"and",
"each",
"global",
"scope",
"."
] | bd90bf198ee897751848f9a92e49d18e60a74136 | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L1012-L1038 |
230,984 | 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):
"""
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"} | [
"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\"",
"}"
] | 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 |
230,985 | 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):
"""
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 | [
"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 |
230,986 | 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):
"""
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),
) | [
"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",
")",
",",
")"
] | 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 |
230,987 | 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):
"""
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 | [
"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"
] | 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 |
230,988 | 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):
"""
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) | [
"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 |
230,989 | 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):
"""
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 | [
"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"
] | 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 |
230,990 | 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):
"""
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() | [
"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",
"(",
")"
] | 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 |
230,991 | 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):
"""
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) | [
"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 |
230,992 | 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):
"""
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
) | [
"def",
"integer",
"(",
"self",
",",
"column",
",",
"auto_increment",
"=",
"False",
",",
"unsigned",
"=",
"False",
")",
":",
"return",
"self",
".",
"_add_column",
"(",
"\"integer\"",
",",
"column",
",",
"auto_increment",
"=",
"auto_increment",
",",
"unsigned",
"=",
"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 |
230,993 | 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):
"""
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
) | [
"def",
"small_integer",
"(",
"self",
",",
"column",
",",
"auto_increment",
"=",
"False",
",",
"unsigned",
"=",
"False",
")",
":",
"return",
"self",
".",
"_add_column",
"(",
"\"small_integer\"",
",",
"column",
",",
"auto_increment",
"=",
"auto_increment",
",",
"unsigned",
"=",
"unsigned",
")"
] | 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 |
230,994 | 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):
"""
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) | [
"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 |
230,995 | 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):
"""
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) | [
"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 |
230,996 | 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):
"""
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) | [
"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 |
230,997 | 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):
"""
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) | [
"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 |
230,998 | 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):
"""
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) | [
"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 |
230,999 | 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):
"""
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") | [
"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\"",
")"
] | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.