MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / define_tables

Method define_tables

test/sql/test_defaults.py:385–504  ·  view source on GitHub ↗
(cls, metadata)

Source from the content-addressed store, hash-verified

383
384 @classmethod
385 def define_tables(cls, metadata):
386 default_generator = cls.default_generator = {"x": 50}
387
388 def mydefault():
389 default_generator["x"] += 1
390 return default_generator["x"]
391
392 def myupdate_with_ctx(ctx):
393 conn = ctx.connection
394 return conn.execute(sa.select(sa.text("13"))).scalar()
395
396 def mydefault_using_connection(ctx):
397 conn = ctx.connection
398 return conn.execute(sa.select(sa.text("12"))).scalar()
399
400 use_function_defaults = testing.against("postgresql", "mssql")
401 is_oracle = testing.against("oracle")
402
403 class MyClass:
404 @classmethod
405 def gen_default(cls, ctx):
406 return "hi"
407
408 class MyType(TypeDecorator):
409 impl = String(50)
410 cache_ok = True
411
412 def process_bind_param(self, value, dialect):
413 if value is not None:
414 value = "BIND" + value
415 return value
416
417 cls.f = 6
418 cls.f2 = 11
419 with testing.db.connect() as conn:
420 currenttime = cls.currenttime = func.current_date(type_=sa.Date)
421 if is_oracle:
422 ts = conn.scalar(
423 sa.select(
424 func.trunc(
425 func.current_timestamp(),
426 sa.literal_column("'DAY'"),
427 type_=sa.Date,
428 )
429 )
430 )
431 currenttime = cls.currenttime = func.trunc(
432 currenttime, sa.literal_column("'DAY'"), type_=sa.Date
433 )
434 def1 = currenttime
435 def2 = func.trunc(
436 sa.text("current_timestamp"),
437 sa.literal_column("'DAY'"),
438 type_=sa.Date,
439 )
440
441 deftype = sa.Date
442 elif use_function_defaults:

Callers

nothing calls this directly

Calls 12

TableClass · 0.90
ColumnClass · 0.90
StringClass · 0.90
current_dateMethod · 0.80
truncMethod · 0.80
current_timestampMethod · 0.80
MyTypeClass · 0.70
againstMethod · 0.45
connectMethod · 0.45
scalarMethod · 0.45
selectMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected