Example #1
0
# Add regex function to SqliteDatabase
OP_REGEXP = 'regexp'


def regexp(lhs, rhs):
    return Expression(lhs, 'regexp', rhs)

SqliteDatabase.register_ops({OP_REGEXP: 'REGEXP'})


# Create database reference
db = SqliteDatabase(DB_PATH)


# Define REGEXP function in sqlite database connection
conn = db.get_conn()


def regex_matches(regex, string):
    return bool(re.search(regex, string, flags=re.IGNORECASE))


conn.create_function('REGEXP', 2, regex_matches)


# Models
class Event(Model):
    summary = CharField()
    start = DateTimeField()
    end = DateTimeField()
    description = CharField()
Example #2
0
)

from ... import adt, config, events, getinput

settings = config.get_options()

if settings.use_sqlite:
    database = SqliteDatabase(str(settings.db_filename))
else:
    database = MySQLDatabase(
        settings.db_name,
        user=settings.db_username,
        passwd=settings.db_password,
        charset="utf8",
    )
    database.get_conn().ping(True)


ModelT = TypeVar("ModelT", bound="BaseModel")
_getters: Dict[Tuple[Type[Model], str], "_NameGetter[Any]"] = {}


class _FieldEditor(object):
    """For easily editing fields. This is exposed as object.e."""

    def __init__(self, instance: Any = None) -> None:
        self.instance = instance

    def __get__(self, instance: Any, instance_type: Any) -> "_FieldEditor":
        return self.__class__(instance)
Example #3
0
# Add regex function to SqliteDatabase
OP_REGEXP = 'regexp'


def regexp(lhs, rhs):
    return Expression(lhs, 'regexp', rhs)


SqliteDatabase.register_ops({OP_REGEXP: 'REGEXP'})

# Create database reference
db = SqliteDatabase(DB_PATH)

# Define REGEXP function in sqlite database connection
conn = db.get_conn()


def regex_matches(regex, string):
    return bool(re.search(regex, string, flags=re.IGNORECASE))


conn.create_function('REGEXP', 2, regex_matches)


# Models
class Event(Model):
    calendar = CharField()
    uid = CharField()
    summary = CharField()
    start = DateTimeField()