File: statefdw.py

package info (click to toggle)
postgresql-multicorn 1.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,244 kB
  • sloc: ansic: 3,324; python: 2,258; sql: 751; makefile: 259; sh: 81
file content (24 lines) | stat: -rw-r--r-- 624 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""A dummy foreign data wrapper"""


from . import ForeignDataWrapper
from .utils import log_to_postgres
from logging import ERROR, DEBUG, INFO, WARNING


class StateFdw(ForeignDataWrapper):
    """A dummy foreign data wrapper.

    This dummy foreign data wrapper is intended as a proof of concept of state
    keeping foreign data wrappers.

    It keeps an internal state as an integer, auto-incremented at each request.
    """

    def __init__(self, *args):
        super(StateFdw, self).__init__(*args)
        self.state = 0

    def execute(self, quals, columns):
        self.state += 1
        yield [self.state]