MCPcopy
hub / github.com/reflex-dev/reflex / get_engine

Function get_engine

reflex/model.py:89–120  ·  view source on GitHub ↗

Get the database engine. Args: url: the DB url to use. Returns: The database engine. Raises: ValueError: If the database url is None.

(url: str | None = None)

Source from the content-addressed store, hash-verified

87 return kwargs
88
89 def get_engine(url: str | None = None) -> sqlalchemy.engine.Engine:
90 """Get the database engine.
91
92 Args:
93 url: the DB url to use.
94
95 Returns:
96 The database engine.
97
98 Raises:
99 ValueError: If the database url is None.
100 """
101 conf = get_config()
102 url = url or conf.db_url
103 if url is None:
104 msg = "No database url configured"
105 raise ValueError(msg)
106
107 global _ENGINE
108 if url in _ENGINE:
109 return _ENGINE[url]
110
111 if not environment.ALEMBIC_CONFIG.get().exists():
112 console.warn(
113 "Database is not initialized, run [bold]reflex db init[/bold] first.",
114 dedupe=True,
115 )
116 _ENGINE[url] = sqlalchemy.engine.create_engine(
117 url,
118 **get_engine_args(url),
119 )
120 return _ENGINE[url]
121
122 def create_all():
123 """Create all the tables."""

Callers 10

test_automigrationFunction · 0.90
test_automigrationFunction · 0.90
_setup_admin_dashMethod · 0.90
create_allFunction · 0.85
sqla_sessionFunction · 0.85
get_migration_historyFunction · 0.85
migrateFunction · 0.85
get_db_statusFunction · 0.85
get_db_engineMethod · 0.85
sessionFunction · 0.85

Calls 4

get_configFunction · 0.90
get_engine_argsFunction · 0.85
existsMethod · 0.80
getMethod · 0.45

Tested by 2

test_automigrationFunction · 0.72
test_automigrationFunction · 0.72