Module osbot_utils.helpers.sqlite.models.Sqlite__Field__Type

Expand source code
import sys
import types
from decimal import Decimal
from enum import Enum, auto
from osbot_utils.decorators.methods.cache import cache

if sys.version_info >= (3, 10):
    NoneType = types.NoneType
else:
    NoneType = type(None)


class Sqlite__Field__Type(Enum):
    BOOLEAN = bool
    DECIMAL = Decimal
    INTEGER = int
    TEXT    = str
    BLOB    = bytes
    REAL    = float
    NUMERIC = 'numeric'                         # special case to have some support for using NUMERIC in the Create Table
    UNKNOWN = NoneType                          # special type to handle cases when the type is not known # todo: handle this on the table creation stage

    def __repr__(self):
        return f'Sqlite__Field__Type.{self.name}'

    def __str__(self):
        return self.name

    @classmethod
    @cache
    def type_map(cls):
        type_map = {}
        for member in cls:
            if member.value not in [auto()]:
                type_map[member.value] = member
        return type_map

    @classmethod
    @cache
    def enum_map(cls):
        return {member.name: member.value for member in cls}

Classes

class Sqlite__Field__Type (*args, **kwds)

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

Color.RED

  • value lookup:

Color(1)

  • name lookup:

Color['RED']

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

Expand source code
class Sqlite__Field__Type(Enum):
    BOOLEAN = bool
    DECIMAL = Decimal
    INTEGER = int
    TEXT    = str
    BLOB    = bytes
    REAL    = float
    NUMERIC = 'numeric'                         # special case to have some support for using NUMERIC in the Create Table
    UNKNOWN = NoneType                          # special type to handle cases when the type is not known # todo: handle this on the table creation stage

    def __repr__(self):
        return f'Sqlite__Field__Type.{self.name}'

    def __str__(self):
        return self.name

    @classmethod
    @cache
    def type_map(cls):
        type_map = {}
        for member in cls:
            if member.value not in [auto()]:
                type_map[member.value] = member
        return type_map

    @classmethod
    @cache
    def enum_map(cls):
        return {member.name: member.value for member in cls}

Ancestors

  • enum.Enum

Class variables

var BLOB
var BOOLEAN
var DECIMAL
var INTEGER
var NUMERIC
var REAL
var TEXT
var UNKNOWN

Static methods

def enum_map(cls)
Expand source code
@classmethod
@cache
def enum_map(cls):
    return {member.name: member.value for member in cls}
def type_map(cls)
Expand source code
@classmethod
@cache
def type_map(cls):
    type_map = {}
    for member in cls:
        if member.value not in [auto()]:
            type_map[member.value] = member
    return type_map