@@ -10,7 +10,120 @@ meta: Example code for understanding how to use the Engine class from the sqlalc
1010Engine is a class within the sqlalchemy.engine module of the SQLAlchemy project.
1111
1212
13- ## Example 1 from GINO
13+ ## Example 1 from CTFd
14+ [ CTFd] ( https://github.com/CTFd/CTFd )
15+ ([ homepage] ( https://ctfd.io/ ) ) is a
16+ [ capture the flag (CTF) hacking web app] ( https://cybersecurity.att.com/blogs/security-essentials/capture-the-flag-ctf-what-is-it-for-a-newbie )
17+ built with [ SQLAlchemy] ( /sqlalchemy.html ) and [ Flask] ( /flask.html ) .
18+ The application can be used as-is to run CTF events, or the code can be
19+ modified for custom rules on hacking scenarios. CTFd is open sourced under the
20+ [ Apache License 2.0] ( https://github.com/CTFd/CTFd/blob/master/LICENSE ) .
21+
22+ [ ** CTFd / CTFd / __ init__ .py** ] ( https://github.com/CTFd/CTFd/blob/master/./CTFd/__init__.py )
23+
24+ ``` python
25+ # __init__.py
26+ import datetime
27+ import os
28+ import sys
29+ import weakref
30+ from distutils.version import StrictVersion
31+
32+ import jinja2
33+ from flask import Flask, Request
34+ from flask_migrate import upgrade
35+ from jinja2 import FileSystemLoader
36+ from jinja2.sandbox import SandboxedEnvironment
37+ from werkzeug.middleware.proxy_fix import ProxyFix
38+ from werkzeug.utils import cached_property
39+
40+ from CTFd import utils
41+ from CTFd.plugins import init_plugins
42+ from CTFd.utils.crypto import sha256
43+ from CTFd.utils.initialization import (
44+ init_events,
45+ init_logs,
46+ init_request_processors,
47+ init_template_filters,
48+ init_template_globals,
49+ )
50+ from CTFd.utils.migrations import create_database, migrations, stamp_latest_revision
51+ from CTFd.utils.sessions import CachingSessionInterface
52+ from CTFd.utils.updates import update_check
53+
54+ __version__ = " 3.0.0b2"
55+
56+
57+ class CTFdRequest (Request ):
58+ @cached_property
59+ def path (self ):
60+ return self .script_root + super (CTFdRequest, self ).path
61+
62+
63+ # # ... source file abbreviated to get to Engine examples ...
64+
65+
66+ }
67+ )
68+ app.jinja_loader = jinja2.ChoiceLoader([app.theme_loader, app.plugin_loader])
69+
70+ from CTFd.models import ( # noqa: F401
71+ db,
72+ Teams,
73+ Solves,
74+ Challenges,
75+ Fails,
76+ Flags,
77+ Tags,
78+ Files,
79+ Tracking,
80+ )
81+
82+ url = create_database()
83+
84+ app.config[" SQLALCHEMY_DATABASE_URI" ] = str (url)
85+
86+ db.init_app(app)
87+
88+ migrations.init_app(app, db)
89+
90+ if url.drivername.startswith(" sqlite" ):
91+ ~~ from sqlalchemy.engine import Engine
92+ from sqlalchemy import event
93+
94+ ~~ @ event.listens_for(Engine, " connect" )
95+ def set_sqlite_pragma (dbapi_connection , connection_record ):
96+ cursor = dbapi_connection.cursor()
97+ cursor.execute(" PRAGMA foreign_keys=ON" )
98+ cursor.close()
99+
100+ db.create_all()
101+ stamp_latest_revision()
102+ else :
103+ upgrade()
104+
105+ from CTFd.models import ma
106+
107+ ma.init_app(app)
108+
109+ app.db = db
110+ app.VERSION = __version__
111+
112+ from CTFd.cache import cache
113+
114+ cache.init_app(app)
115+ app.cache = cache
116+
117+ reverse_proxy = app.config.get(" REVERSE_PROXY" )
118+ if reverse_proxy:
119+
120+
121+ # # ... source file continues with no further Engine examples...
122+
123+ ```
124+
125+
126+ ## Example 2 from GINO
14127[ GINO] ( https://github.com/fantix/gino )
15128([ project documentation] ( https://python-gino.readthedocs.io/en/latest/ )
16129and
0 commit comments