Showing 1 of 1 files from the diff.

@@ -75,24 +75,20 @@
Loading
75 75
76 76
class Record(Mapping):
77 77
    def __init__(
78 -
        self, row: asyncpg.Record, result_columns: tuple, dialect: Dialect
78 +
        self,
79 +
        row: asyncpg.Record,
80 +
        result_columns: tuple,
81 +
        dialect: Dialect,
82 +
        column_maps: typing.Tuple[
83 +
            typing.Mapping[typing.Any, typing.Tuple[int, TypeEngine]],
84 +
            typing.Mapping[int, typing.Tuple[int, TypeEngine]],
85 +
            typing.Mapping[str, typing.Tuple[int, TypeEngine]],
86 +
        ],
79 87
    ) -> None:
80 88
        self._row = row
81 89
        self._result_columns = result_columns
82 90
        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)
91 +
        self._column_map, self._column_map_int, self._column_map_full = column_maps
96 92
97 93
    def __getitem__(self, key: typing.Any) -> typing.Any:
98 94
        if len(self._column_map) == 0:  # raw query
@@ -120,6 +116,21 @@
Loading
120 116
    def __len__(self) -> int:
121 117
        return len(self._row)
122 118
119 +
    @classmethod
120 +
    def _create_column_maps(
121 +
        cls, result_columns: tuple
122 +
    ) -> typing.Tuple[
123 +
        typing.Mapping[typing.Any, typing.Tuple[int, TypeEngine]],
124 +
        typing.Mapping[int, typing.Tuple[int, TypeEngine]],
125 +
        typing.Mapping[str, typing.Tuple[int, TypeEngine]],
126 +
    ]:
127 +
        column_map, column_map_int, column_map_full = {}, {}, {}
128 +
        for idx, (column_name, _, column, datatype) in enumerate(result_columns):
129 +
            column_map[column_name] = (idx, datatype)
130 +
            column_map_int[idx] = (idx, datatype)
131 +
            column_map_full[str(column[0])] = (idx, datatype)
132 +
        return column_map, column_map_int, column_map_full
133 +
123 134
124 135
class PostgresConnection(ConnectionBackend):
125 136
    def __init__(self, database: PostgresBackend, dialect: Dialect):
@@ -142,7 +153,9 @@
Loading
142 153
        assert self._connection is not None, "Connection is not acquired"
143 154
        query, args, result_columns = self._compile(query)
144 155
        rows = await self._connection.fetch(query, *args)
145 -
        return [Record(row, result_columns, self._dialect) for row in rows]
156 +
        dialect = self._dialect
157 +
        column_maps = Record._create_column_maps(result_columns)
158 +
        return [Record(row, result_columns, dialect, column_maps) for row in rows]
146 159
147 160
    async def fetch_one(self, query: ClauseElement) -> typing.Optional[typing.Mapping]:
148 161
        assert self._connection is not None, "Connection is not acquired"
@@ -150,7 +163,12 @@
Loading
150 163
        row = await self._connection.fetchrow(query, *args)
151 164
        if row is None:
152 165
            return None
153 -
        return Record(row, result_columns, self._dialect)
166 +
        return Record(
167 +
            row,
168 +
            result_columns,
169 +
            self._dialect,
170 +
            Record._create_column_maps(result_columns),
171 +
        )
154 172
155 173
    async def execute(self, query: ClauseElement) -> typing.Any:
156 174
        assert self._connection is not None, "Connection is not acquired"
@@ -171,8 +189,9 @@
Loading
171 189
    ) -> typing.AsyncGenerator[typing.Any, None]:
172 190
        assert self._connection is not None, "Connection is not acquired"
173 191
        query, args, result_columns = self._compile(query)
192 +
        column_maps = Record._create_column_maps(result_columns)
174 193
        async for row in self._connection.cursor(query, *args):
175 -
            yield Record(row, result_columns, self._dialect)
194 +
            yield Record(row, result_columns, self._dialect, column_maps)
176 195
177 196
    def transaction(self) -> TransactionBackend:
178 197
        return PostgresTransaction(connection=self)
Files Coverage
databases 100.00%
tests 100.00%
Project Totals (14 files) 100.00%
Notifications are pending CI completion. Periodically Codecov will check the CI state, when complete notifications will be submitted. Push notifications now.
403.1
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
403.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