Showing 1 of 1 files from the diff.

@@ -75,24 +75,16 @@
Loading
75 75
76 76
class Record(Mapping):
77 77
    def __init__(
78 -
        self, row: asyncpg.Record, result_columns: tuple, dialect: Dialect
78 +
        self, row: asyncpg.Record, result_columns: tuple, dialect: Dialect,
79 +
        column_maps: typing.Tuple[
80 +
            typing.Mapping[str, typing.Tuple[int, TypeEngine]],
81 +
            typing.Mapping[str, typing.Tuple[int, TypeEngine]],
82 +
            typing.Mapping[str, typing.Tuple[int, TypeEngine]]],
79 83
    ) -> None:
80 84
        self._row = row
81 85
        self._result_columns = result_columns
82 86
        self._dialect = dialect
83 -
        self._column_map = (
84 -
            {}
85 -
        )  # type: typing.Mapping[str, typing.Tuple[int, TypeEngine]]
86 -
        self._column_map_int = (
87 -
            {}
88 -
        )  # type: typing.Mapping[int, typing.Tuple[int, TypeEngine]]
89 -
        self._column_map_full = (
90 -
            {}
91 -
        )  # type: typing.Mapping[str, typing.Tuple[int, TypeEngine]]
92 -
        for idx, (column_name, _, column, datatype) in enumerate(self._result_columns):
93 -
            self._column_map[column_name] = (idx, datatype)
94 -
            self._column_map_int[idx] = (idx, datatype)
95 -
            self._column_map_full[str(column[0])] = (idx, datatype)
87 +
        self._column_map, self._column_map_int, self._column_map_full = column_maps
96 88
97 89
    def __getitem__(self, key: typing.Any) -> typing.Any:
98 90
        if len(self._column_map) == 0:  # raw query
@@ -120,6 +112,18 @@
Loading
120 112
    def __len__(self) -> int:
121 113
        return len(self._row)
122 114
115 +
    @classmethod
116 +
    def _create_column_maps(cls, result_columns: tuple) -> typing.Tuple[
117 +
        typing.Mapping[str, typing.Tuple[int, TypeEngine]],
118 +
        typing.Mapping[str, typing.Tuple[int, TypeEngine]],
119 +
        typing.Mapping[str, typing.Tuple[int, TypeEngine]]]:
120 +
        column_map, column_map_int, column_map_full = {}, {}, {}
121 +
        for idx, (column_name, _, column, datatype) in enumerate(result_columns):
122 +
            column_map[column_name] = (idx, datatype)
123 +
            column_map_int[idx] = (idx, datatype)
124 +
            column_map_full[str(column[0])] = (idx, datatype)
125 +
        return column_map, column_map_int, column_map_full
126 +
123 127
124 128
class PostgresConnection(ConnectionBackend):
125 129
    def __init__(self, database: PostgresBackend, dialect: Dialect):
@@ -142,7 +146,9 @@
Loading
142 146
        assert self._connection is not None, "Connection is not acquired"
143 147
        query, args, result_columns = self._compile(query)
144 148
        rows = await self._connection.fetch(query, *args)
145 -
        return [Record(row, result_columns, self._dialect) for row in rows]
149 +
        dialect = self._dialect
150 +
        column_maps = Record._create_column_maps(result_columns)
151 +
        return [Record(row, result_columns, dialect, column_maps) for row in rows]
146 152
147 153
    async def fetch_one(self, query: ClauseElement) -> typing.Optional[typing.Mapping]:
148 154
        assert self._connection is not None, "Connection is not acquired"
@@ -150,7 +156,8 @@
Loading
150 156
        row = await self._connection.fetchrow(query, *args)
151 157
        if row is None:
152 158
            return None
153 -
        return Record(row, result_columns, self._dialect)
159 +
        return Record(row, result_columns, self._dialect,
160 +
                      Record._create_column_maps(result_columns))
154 161
155 162
    async def execute(self, query: ClauseElement) -> typing.Any:
156 163
        assert self._connection is not None, "Connection is not acquired"
@@ -171,8 +178,9 @@
Loading
171 178
    ) -> typing.AsyncGenerator[typing.Any, None]:
172 179
        assert self._connection is not None, "Connection is not acquired"
173 180
        query, args, result_columns = self._compile(query)
181 +
        column_maps = Record._create_column_maps(result_columns)
174 182
        async for row in self._connection.cursor(query, *args):
175 -
            yield Record(row, result_columns, self._dialect)
183 +
            yield Record(row, result_columns, self._dialect, column_maps)
176 184
177 185
    def transaction(self) -> TransactionBackend:
178 186
        return PostgresTransaction(connection=self)
Files Coverage
databases 100.00%
tests 100.00%
Project Totals (14 files) 100.00%
401.1
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
401.2
TRAVIS_PYTHON_VERSION=3.7
TRAVIS_OS_NAME=linux
1
coverage:
2
  precision: 2
3
  round: down
4
  range: "80...100"
5

6
  status:
7
    project: yes
8
    patch: no
9
    changes: no
10

11
comment: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading