platypush/plugins/db/__init__.py
def insert(self, table, records, engine=None, key_columns=None,
               on_duplicate_update=False, *args, **kwargs):
        """
        Inserts records (as a list of hashes) into a table.

        :param table: Table name
        :type table: str
        :param records: Records to be inserted (as a list of hashes)
        :type records: list
        :param engine: Engine to be used (default: default class engine)
        :type engine: str
        :param key_columns: Set it to specify the names of the key columns for ``table``. Set it if you want your statement to be executed with the ``on_duplicate_update`` flag.
        :type key_columns: list
        :param on_duplicate_update: If set, update the records in case of duplicate rows (default: False). If set, you'll need to specify ``key_columns`` as well.
        :type on_duplicate_update: bool
        :param args: Extra arguments that will be passed to ``sqlalchemy.create_engine`` (see https://docs.sqlalchemy.org/en/latest/core/engines.html)
        :param kwargs: Extra kwargs that will be passed to ``sqlalchemy.create_engine`` (seehttps:///docs.sqlalchemy.org/en/latest/core/engines.html)

        Example:

            Request::

                {
                    "type": "request",
                    "target": "your_host",
                    "action": "db.insert",
                    "args": {
                        "table": "table",
                        "engine": "sqlite:///:memory:",
                        "records": [
                            {
                                "id": 1,
                                "name": foo
                            },

                            {
                                "id": 2,
                                "name": bar
                            }
                        ]
                    }
                }
        """

        if key_columns is None:
            key_columns = []

        engine = self._get_engine(engine, *args, **kwargs)

        for record in records:
            table, engine = self._get_table(table, engine=engine, *args, **kwargs)
            insert = table.insert().values(**record)

            try:
                engine.execute(insert)
            except Exception as e:
                if on_duplicate_update and key_columns:
                    self.update(table=table, records=records,
                                key_columns=key_columns, engine=engine,
                                *args, **kwargs)
                else:
                    raise e

        Inserts records (as a list of hashes) into a table.

        :param table: Table name
        :type table: str
        :param records: Records to be inserted (as a list of hashes)
        :type records: list
        :param engine: Engine to be used (default: default class engine)
        :type engine: str
        :param key_columns: Set it to specify the names of the key columns for ``table``. Set it if you want your statement to be executed with the ``on_duplicate_update`` flag.
        :type key_columns: list
        :param on_duplicate_update: If set, update the records in case of duplicate rows (default: False). If set, you'll need to specify ``key_columns`` as well.
        :type on_duplicate_update: bool
        :param args: Extra arguments that will be passed to ``sqlalchemy.create_engine`` (see https://docs.sqlalchemy.org/en/latest/core/engines.html)
        :param kwargs: Extra kwargs that will be passed to ``sqlalchemy.create_engine`` (seehttps:///docs.sqlalchemy.org/en/latest/core/engines.html)

        Example:

            Request::

                {
                    "type": "request",
                    "target": "your_host",
                    "action": "db.insert",
                    "args": {
                        "table": "table",
                        "engine": "sqlite:///:memory:",
                        "records": [
                            {
                                "id": 1,
                                "name": foo
                            },

                            {
                                "id": 2,
                                "name": bar
                            }
                        ]
                    }
                }
        
Inserts records (as a list of hashes) into a table.
Inserts records ( as a list of hashes ) into a table .
def insert(self, table, records, engine=None, key_columns=None,
               on_duplicate_update=False, *args, **kwargs):
        if key_columns is None:
            key_columns = []
        engine = self._get_engine(engine, *args, **kwargs)
        for record in records:
            table, engine = self._get_table(table, engine=engine, *args, **kwargs)
            insert = table.insert().values(**record)
            try:
                engine.execute(insert)
            except Exception as e:
                if on_duplicate_update and key_columns:
                    self.update(table=table, records=records,
                                key_columns=key_columns, engine=engine,
                                *args, **kwargs)
                else:
                    raise e
def insert ( self , table , records , engine = None , key_columns = None , on_duplicate_update = False , * args , ** kwargs ) : if key_columns is None : key_columns = [ ] engine = self . _get_engine ( engine , * args , ** kwargs ) for record in records : table , engine = self . _get_table ( table , engine = engine , * args , ** kwargs ) insert = table . insert ( ) . values ( ** record ) try : engine . execute ( insert ) except Exception as e : if on_duplicate_update and key_columns : self . update ( table = table , records = records , key_columns = key_columns , engine = engine , * args , ** kwargs ) else : raise e
Inserts records (as a list of hashes) into a table.
Inserts records ( as a list of hashes ) into a table .
"""
        Inserts records (as a list of hashes) into a table.

        :param table: Table name
        :type table: str
        :param records: Records to be inserted (as a list of hashes)
        :type records: list
        :param engine: Engine to be used (default: default class engine)
        :type engine: str
        :param key_columns: Set it to specify the names of the key columns for ``table``. Set it if you want your statement to be executed with the ``on_duplicate_update`` flag.
        :type key_columns: list
        :param on_duplicate_update: If set, update the records in case of duplicate rows (default: False). If set, you'll need to specify ``key_columns`` as well.
        :type on_duplicate_update: bool
        :param args: Extra arguments that will be passed to ``sqlalchemy.create_engine`` (see https://docs.sqlalchemy.org/en/latest/core/engines.html)
        :param kwargs: Extra kwargs that will be passed to ``sqlalchemy.create_engine`` (seehttps:///docs.sqlalchemy.org/en/latest/core/engines.html)

        Example:

            Request::

                {
                    "type": "request",
                    "target": "your_host",
                    "action": "db.insert",
                    "args": {
                        "table": "table",
                        "engine": "sqlite:///:memory:",
                        "records": [
                            {
                                "id": 1,
                                "name": foo
                            },

                            {
                                "id": 2,
                                "name": bar
                            }
                        ]
                    }
                }
        """
self
table
None
records
Records to be inserted (as a list of hashes)
Records to be inserted ( as a list of hashes )
engine
Engine to be used (default: default class engine)
Engine to be used ( default : default class engine )
key_columns
Set it to specify the names of the key columns for ``table``. Set it if you want your statement to be executed with the ``on_duplicate_update`` flag.
Set it to specify the names of the key columns for ` ` table ` ` . Set it if you want your statement to be executed with the ` ` on_duplicate_update ` ` flag .
on_duplicate_update
If set, update the records in case of duplicate rows (default: False). If set, you'll need to specify ``key_columns`` as well.
If set update the records in case of duplicate rows ( default : False ) . If set you ' ll need to specify ` ` key_columns ` ` as well .
args
Extra arguments that will be passed to ``sqlalchemy.create_engine``
Extra arguments that will be passed to ` ` sqlalchemy . create_engine ` `
kwargs
Extra kwargs that will be passed to ``sqlalchemy.create_engine``
Example.






Extra kwargs that will be passed to ` ` sqlalchemy . create_engine ` ` Example .