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 len ( values ) == 1 : return super ( SQLiteQueryGrammar , self ) . compile_insert ( query , values ) names = self . columnize ( values [ 0 ] . keys ( ) ) columns = [ ] 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