models
Module with database tables definitions.
Helper classes and utility functions for data management are defined here.
Modules:
Name | Description |
---|---|
auth |
Module with classes and functions used for authentication and password handling. |
Classes:
Name | Description |
---|---|
Credentials |
Table with users credentials, used only if basic authentication is active. |
Encrypted |
Allows storing and retrieving password hashes using PasswordHash. |
Flags |
Table with global flags used by Data-Lunch. |
Menu |
Table with menu items. |
Orders |
Table with items that belongs to an order. |
Password |
Allows storing and retrieving password hashes using PasswordHash. |
PrivilegedUsers |
Table with user that have privileges (normal users and admin). |
Stats |
Table with number of users that ate a lunch, grouped by guest type. |
Users |
Table with users that placed an order. |
Functions:
Name | Description |
---|---|
create_database |
Function to create the database through SQLAlchemy models. |
create_engine |
Factory function for SQLAlchemy engine. |
create_exclusive_session |
Factory function for database exclusive session. |
create_session |
Factory function for database session. |
get_db_dialect |
Return database type (postgresql, sqlite, etc.) based on the database object passed as input. |
get_flag |
Get the value of a flag. |
session_add_with_upsert |
Use an upsert statement for postgresql to add a new record to a table, |
set_flag |
Set a key,value pair inside |
set_sqlite_pragma |
Force foreign key constraints for sqlite connections. |
Attributes:
Name | Type | Description |
---|---|---|
Data |
DeclarativeMeta
|
SQLAlchemy declarative base. |
SCHEMA |
str
|
Schema name from environment (may be overridden by configuration files). |
log |
Logger
|
Module logger. |
metadata_obj |
MetaData
|
Database metadata (SQLAlchemy). |
Data
module-attribute
Data: DeclarativeMeta = declarative_base(
metadata=metadata_obj
)
SQLAlchemy declarative base.
SCHEMA
module-attribute
SCHEMA: str = get('DATA_LUNCH_DB_SCHEMA', None)
Schema name from environment (may be overridden by configuration files).
metadata_obj
module-attribute
metadata_obj: MetaData = MetaData(schema=SCHEMA)
Database metadata (SQLAlchemy).
Credentials
Bases: Data
Table with users credentials, used only if basic authentication is active.
Methods:
Name | Description |
---|---|
__repr__ |
Simple object representation. |
clear |
Clear table and return deleted rows. |
read_as_df |
Read table as pandas DataFrame. |
Attributes:
Name | Type | Description |
---|---|---|
__tablename__ |
str
|
Name of the table. |
password_encrypted |
Column
|
Encryped password. |
password_hash |
Column
|
Hashed password. |
user |
Column
|
Username. |
Source code in dlunch/models.py
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
|
__tablename__
class-attribute
instance-attribute
__tablename__: str = 'credentials'
Name of the table.
password_encrypted
class-attribute
instance-attribute
password_encrypted: Column = Column(
Encrypted(150),
unique=False,
nullable=True,
default=None,
server_default=None,
)
Encryped password.
Used only if basic authentication and guest users are both active.
password_hash
class-attribute
instance-attribute
password_hash: Column = Column(
Password(150), unique=False, nullable=False
)
Hashed password.
user
class-attribute
instance-attribute
user: Column = Column(
String(100),
primary_key=True,
sqlite_on_conflict_primary_key="REPLACE",
)
Username.
__repr__
__repr__() -> str
Simple object representation.
Returns:
Type | Description |
---|---|
str
|
string representation. |
Source code in dlunch/models.py
804 805 806 807 808 809 810 |
|
clear
classmethod
clear(config: DictConfig) -> int
Clear table and return deleted rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
int
|
deleted rows. |
Source code in dlunch/models.py
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
|
read_as_df
classmethod
read_as_df(config: DictConfig, **kwargs) -> DataFrame
Read table as pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
dataframe with table content. |
Source code in dlunch/models.py
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 |
|
Encrypted
Bases: TypeDecorator
Allows storing and retrieving password hashes using PasswordHash.
Methods:
Name | Description |
---|---|
process_bind_param |
Ensure the value is a PasswordEncrypt and then return the encrypted password. |
process_result_value |
Convert the hash to a PasswordEncrypt, if it's non-NULL. |
validator |
Provides a validator/converter used by @validates. |
Attributes:
Name | Type | Description |
---|---|---|
impl |
String
|
Base column implementation. |
Source code in dlunch/models.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
impl
class-attribute
instance-attribute
impl: String = String
Base column implementation.
process_bind_param
process_bind_param(
value: PasswordEncrypt | str | None, dialect
) -> str | None
Ensure the value is a PasswordEncrypt and then return the encrypted password.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
PasswordEncrypt | str | None
|
input value (plain password or encrypted or |
required |
dialect
|
Any
|
dialect (not used). |
required |
Returns:
Type | Description |
---|---|
str | None
|
encrypted password or |
Source code in dlunch/models.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
process_result_value
process_result_value(
value: str | None, dialect
) -> PasswordEncrypt | None
Convert the hash to a PasswordEncrypt, if it's non-NULL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str | None
|
input value (plain password or encrypted or |
required |
dialect
|
Any
|
dialect (not used). |
required |
Returns:
Type | Description |
---|---|
PasswordEncrypt | None
|
encrypted password as object or |
Source code in dlunch/models.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
validator
validator(
password: PasswordEncrypt | str | None,
) -> PasswordEncrypt | None
Provides a validator/converter used by @validates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
password
|
PasswordEncrypt | str | None
|
input value (plain password or encrypted or |
required |
Returns:
Type | Description |
---|---|
PasswordEncrypt | None
|
encrypted password as object or |
Source code in dlunch/models.py
210 211 212 213 214 215 216 217 218 219 220 221 |
|
Flags
Bases: Data
Table with global flags used by Data-Lunch.
'No more orders' flag and guest override flags are stored here.
Methods:
Name | Description |
---|---|
__repr__ |
Simple object representation. |
clear |
Clear table and return deleted rows. |
clear_guest_override |
Clear 'guest_override' flags and return deleted rows |
read_as_df |
Read table as pandas DataFrame. |
Attributes:
Name | Type | Description |
---|---|---|
__tablename__ |
str
|
Name of the table. |
id |
Column
|
Flag ID (name). |
value |
Column
|
Flag value. |
Source code in dlunch/models.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
|
id
class-attribute
instance-attribute
id: Column = Column(
String(50),
primary_key=True,
nullable=False,
sqlite_on_conflict_primary_key="REPLACE",
)
Flag ID (name).
value
class-attribute
instance-attribute
value: Column = Column(Boolean, nullable=False)
Flag value.
__repr__
__repr__() -> str
Simple object representation.
Returns:
Type | Description |
---|---|
str
|
string representation. |
Source code in dlunch/models.py
659 660 661 662 663 664 665 |
|
clear
classmethod
clear(config: DictConfig) -> int
Clear table and return deleted rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
int
|
deleted rows. |
Source code in dlunch/models.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
|
clear_guest_override
classmethod
clear_guest_override(config: DictConfig) -> int
Clear 'guest_override' flags and return deleted rows
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
int
|
deleted rows. |
Source code in dlunch/models.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
|
read_as_df
classmethod
read_as_df(config: DictConfig, **kwargs) -> DataFrame
Read table as pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
dataframe with table content. |
Source code in dlunch/models.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
|
Menu
Bases: Data
Table with menu items.
Methods:
Name | Description |
---|---|
__repr__ |
Simple object representation. |
clear |
Clear table and return deleted rows. |
read_as_df |
Read table as pandas DataFrame. |
Attributes:
Name | Type | Description |
---|---|---|
__tablename__ |
str
|
Name of the table. |
id |
Column
|
Menu item ID. |
item |
Column
|
Item name. |
orders |
DeclarativeMeta
|
Orders connected to each menu item. |
Source code in dlunch/models.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
id
class-attribute
instance-attribute
id: Column = Column(
Integer, Identity(start=1, cycle=True), primary_key=True
)
Menu item ID.
item
class-attribute
instance-attribute
item: Column = Column(
String(250), unique=False, nullable=False
)
Item name.
orders
class-attribute
instance-attribute
orders: DeclarativeMeta = relationship(
"Orders",
back_populates="menu_item",
cascade="all, delete-orphan",
passive_deletes=True,
)
Orders connected to each menu item.
__repr__
__repr__() -> str
Simple object representation.
Returns:
Type | Description |
---|---|
str
|
string representation. |
Source code in dlunch/models.py
317 318 319 320 321 322 323 |
|
clear
classmethod
clear(config: DictConfig) -> int
Clear table and return deleted rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
int
|
deleted rows. |
Source code in dlunch/models.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
read_as_df
classmethod
read_as_df(config: DictConfig, **kwargs) -> DataFrame
Read table as pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
dataframe with table content. |
Source code in dlunch/models.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
Orders
Bases: Data
Table with items that belongs to an order.
Methods:
Name | Description |
---|---|
__repr__ |
Simple object representation. |
clear |
Clear table and return deleted rows. |
read_as_df |
Read table as pandas DataFrame. |
Attributes:
Name | Type | Description |
---|---|---|
__tablename__ |
str
|
Name of the table. |
id |
Column
|
Order ID. |
menu_item |
DeclarativeMeta
|
Menu items connected to each order (see |
menu_item_id |
Column
|
ID of the menu item included in the order. |
note |
Column
|
Note field attached to the order. |
user |
Column
|
User that placed the order. |
user_record |
DeclarativeMeta
|
User connected to this order. |
Source code in dlunch/models.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
id
class-attribute
instance-attribute
id: Column = Column(
Integer, Identity(start=1, cycle=True), primary_key=True
)
Order ID.
menu_item
class-attribute
instance-attribute
menu_item: DeclarativeMeta = relationship(
"Menu", back_populates="orders"
)
Menu items connected to each order (see menu
table).
menu_item_id
class-attribute
instance-attribute
menu_item_id: Column = Column(
Integer,
ForeignKey("menu.id", ondelete="CASCADE"),
nullable=False,
)
ID of the menu item included in the order.
note
class-attribute
instance-attribute
note: Column = Column(
String(300), unique=False, nullable=True
)
Note field attached to the order.
user
class-attribute
instance-attribute
user: Column = Column(
String(100),
ForeignKey("users.id", ondelete="CASCADE"),
index=True,
nullable=False,
)
User that placed the order.
user_record
class-attribute
instance-attribute
user_record: DeclarativeMeta = relationship(
"Users", back_populates="orders", uselist=False
)
User connected to this order.
__repr__
__repr__() -> str
Simple object representation.
Returns:
Type | Description |
---|---|
str
|
string representation. |
Source code in dlunch/models.py
398 399 400 401 402 403 404 |
|
clear
classmethod
clear(config: DictConfig) -> int
Clear table and return deleted rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
int
|
deleted rows. |
Source code in dlunch/models.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
read_as_df
classmethod
read_as_df(config: DictConfig, **kwargs) -> DataFrame
Read table as pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
dataframe with table content. |
Source code in dlunch/models.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
Password
Bases: TypeDecorator
Allows storing and retrieving password hashes using PasswordHash.
Methods:
Name | Description |
---|---|
process_bind_param |
Ensure the value is a PasswordHash and then return its hash. |
process_result_value |
Convert the hash to a PasswordHash, if it's non-NULL. |
validator |
Provides a validator/converter used by @validates. |
Attributes:
Name | Type | Description |
---|---|---|
impl |
String
|
Base column implementation. |
Source code in dlunch/models.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
impl
class-attribute
instance-attribute
impl: String = String
Base column implementation.
process_bind_param
process_bind_param(
value: PasswordHash | str | None, dialect
) -> str
Ensure the value is a PasswordHash and then return its hash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
PasswordHash | str
|
input value (plain password or hash, or |
required |
dialect
|
Any
|
dialect (not used). |
required |
Returns:
Type | Description |
---|---|
str
|
password hash. |
Source code in dlunch/models.py
98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
process_result_value
process_result_value(
value: str | None, dialect
) -> PasswordHash | None
Convert the hash to a PasswordHash, if it's non-NULL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str | None
|
password hash (or |
required |
dialect
|
Any
|
dialect (not used). |
required |
Returns:
Type | Description |
---|---|
PasswordHash | None
|
hashed password as object or |
Source code in dlunch/models.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
validator
validator(
password: PasswordHash | str | None,
) -> PasswordHash | None
Provides a validator/converter used by @validates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
password
|
PasswordHash | str | None
|
input value (plain password or hash or |
required |
Returns:
Type | Description |
---|---|
PasswordHash | None
|
hashed password as object or |
Source code in dlunch/models.py
127 128 129 130 131 132 133 134 135 136 137 138 |
|
PrivilegedUsers
Bases: Data
Table with user that have privileges (normal users and admin).
If enabled guests are all the authenticated users that do not belong to this table
(see config key auth.authorize_guest_users
and basic_auth.guest_user
)
Methods:
Name | Description |
---|---|
__repr__ |
Simple object representation. |
clear |
Clear table and return deleted rows. |
read_as_df |
Read table as pandas DataFrame. |
Attributes:
Name | Type | Description |
---|---|---|
__tablename__ |
str
|
Name of the table. |
admin |
Column
|
Admin flag (true if admin). |
user |
Column
|
User name. |
Source code in dlunch/models.py
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
|
__tablename__
class-attribute
instance-attribute
__tablename__: str = 'privileged_users'
Name of the table.
admin
class-attribute
instance-attribute
admin: Column = Column(
Boolean,
nullable=False,
default=False,
server_default=false(),
)
Admin flag (true if admin).
user
class-attribute
instance-attribute
user: Column = Column(
String(100),
primary_key=True,
sqlite_on_conflict_primary_key="REPLACE",
)
User name.
__repr__
__repr__() -> str
Simple object representation.
Returns:
Type | Description |
---|---|
str
|
string representation. |
Source code in dlunch/models.py
730 731 732 733 734 735 736 |
|
clear
classmethod
clear(config: DictConfig) -> int
Clear table and return deleted rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
int
|
deleted rows. |
Source code in dlunch/models.py
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
|
read_as_df
classmethod
read_as_df(config: DictConfig, **kwargs) -> DataFrame
Read table as pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
dataframe with table content. |
Source code in dlunch/models.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
|
Stats
Bases: Data
Table with number of users that ate a lunch, grouped by guest type.
Methods:
Name | Description |
---|---|
__repr__ |
Simple object representation. |
clear |
Clear table and return deleted rows. |
read_as_df |
Read table as pandas DataFrame. |
Attributes:
Name | Type | Description |
---|---|---|
__table_args__ |
tuple
|
Table arguments, used to create primary key (ON CONFLICT options for composite |
__tablename__ |
str
|
Name of the table. |
date |
Column
|
Day to which the statistics refers to. |
guest |
Column
|
Different kind of guests are identified by the value defined in config files |
hungry_people |
Column
|
Number of people that ate in a certain day. |
Source code in dlunch/models.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
|
__table_args__
class-attribute
instance-attribute
__table_args__: tuple = PrimaryKeyConstraint(
"date",
"guest",
name="stats_pkey",
sqlite_on_conflict="REPLACE",
)
Table arguments, used to create primary key (ON CONFLICT options for composite primary key is available only with table_args).
date
class-attribute
instance-attribute
date: Column = Column(
Date, nullable=False, server_default=current_date()
)
Day to which the statistics refers to.
guest
class-attribute
instance-attribute
guest: Column = Column(
String(20),
nullable=True,
default="NotAGuest",
server_default="NotAGuest",
)
Different kind of guests are identified by the value defined in config files
(see config key panel.guest_types
).
'NotAGuest' is the value used for locals.
hungry_people
class-attribute
instance-attribute
hungry_people: Column = Column(
Integer, nullable=False, default=0, server_default="0"
)
Number of people that ate in a certain day. different kind of guests are identified by the value in guest column.
__repr__
__repr__() -> str
Simple object representation.
Returns:
Type | Description |
---|---|
str
|
string representation. |
Source code in dlunch/models.py
567 568 569 570 571 572 573 |
|
clear
classmethod
clear(config: DictConfig) -> int
Clear table and return deleted rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
int
|
deleted rows. |
Source code in dlunch/models.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
|
read_as_df
classmethod
read_as_df(config: DictConfig, **kwargs) -> DataFrame
Read table as pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
dataframe with table content. |
Source code in dlunch/models.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
|
Users
Bases: Data
Table with users that placed an order.
Methods:
Name | Description |
---|---|
__repr__ |
Simple object representation. |
clear |
Clear table and return deleted rows. |
read_as_df |
Read table as pandas DataFrame. |
Attributes:
Name | Type | Description |
---|---|---|
__tablename__ |
str
|
Name of the table. |
guest |
Column
|
Guest flag (true if guest). |
id |
Column
|
User ID. |
lunch_time |
Column
|
User selected lunch time. |
orders |
DeclarativeMeta
|
Orders connected to each user. |
takeaway |
Column
|
Takeaway flag (true if takeaway). |
Source code in dlunch/models.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
|
guest
class-attribute
instance-attribute
guest: Column = Column(
String(20),
nullable=False,
default="NotAGuest",
server_default="NotAGuest",
)
Guest flag (true if guest).
id
class-attribute
instance-attribute
id: Column = Column(
String(100), primary_key=True, nullable=False
)
User ID.
lunch_time
class-attribute
instance-attribute
lunch_time: Column = Column(
String(7), index=True, nullable=False
)
User selected lunch time.
orders
class-attribute
instance-attribute
orders: DeclarativeMeta = relationship(
"Orders",
back_populates="user_record",
cascade="all, delete-orphan",
passive_deletes=True,
)
Orders connected to each user.
takeaway
class-attribute
instance-attribute
takeaway: Column = Column(
Boolean,
nullable=False,
default=False,
server_default=false(),
)
Takeaway flag (true if takeaway).
__repr__
__repr__() -> str
Simple object representation.
Returns:
Type | Description |
---|---|
str
|
string representation. |
Source code in dlunch/models.py
480 481 482 483 484 485 486 |
|
clear
classmethod
clear(config: DictConfig) -> int
Clear table and return deleted rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
int
|
deleted rows. |
Source code in dlunch/models.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
|
read_as_df
classmethod
read_as_df(config: DictConfig, **kwargs) -> DataFrame
Read table as pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
dataframe with table content. |
Source code in dlunch/models.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
|
create_database
create_database(
config: DictConfig, add_basic_auth_users=False
) -> None
Function to create the database through SQLAlchemy models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
add_basic_auth_users
|
bool
|
set to true to add admin and guest users. These users are of interest only if 'basic authentication' is selected. Defaults to False. |
False
|
Source code in dlunch/models.py
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 |
|
create_engine
create_engine(config: DictConfig) -> Engine
Factory function for SQLAlchemy engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
Engine
|
SQLAlchemy engine. |
Source code in dlunch/models.py
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
|
create_exclusive_session
create_exclusive_session(config: DictConfig) -> Session
Factory function for database exclusive session. Database is locked until the transaction is completed (to be used to avoid race conditions).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
Session
|
SQLAlchemy exclusive session. |
Note
This function is not used inside Data-Lunch code.
Source code in dlunch/models.py
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 |
|
create_session
create_session(config: DictConfig) -> Session
Factory function for database session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
Session
|
SQLAlchemy session. |
Source code in dlunch/models.py
933 934 935 936 937 938 939 940 941 942 943 944 945 |
|
get_db_dialect
get_db_dialect(
db_obj: Session | Connection | Connection,
) -> str
Return database type (postgresql, sqlite, etc.) based on the database object passed as input.
If a session is passed, the database type is set based on an internal map (see models._DBTYPE_MAP
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_obj
|
Session | Connection | Connection
|
session or connection object. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
db_obj shall be a session or a connection object. |
Returns:
Type | Description |
---|---|
str
|
database dialect. |
Source code in dlunch/models.py
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 |
|
get_flag
Get the value of a flag. Optionally select the values to return if the flag is missing (default to None).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
id
|
str
|
flag id (name). |
required |
value_if_missing
|
bool | None
|
value to return if the flag does not exist. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
bool | None
|
flag value. |
Source code in dlunch/models.py
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 |
|
session_add_with_upsert
Use an upsert statement for postgresql to add a new record to a table, a simple session add otherwise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
SQLAlchemy session object. |
required |
constraint
|
str
|
constraint used for upsert (usually the primary key) |
required |
new_record
|
Stats | Flags
|
table resord (valid tables are |
required |
Source code in dlunch/models.py
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 |
|
set_flag
Set a key,value pair inside flag
table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DictConfig
|
Hydra configuration dictionary. |
required |
id
|
str
|
flag id (name). |
required |
value
|
bool
|
flag value. |
required |
Source code in dlunch/models.py
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
|
set_sqlite_pragma
set_sqlite_pragma(dbapi_connection, connection_record)
Force foreign key constraints for sqlite connections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dbapi_connection
|
Any
|
connection to database. Shall have a |
required |
connection_record
|
Any
|
connection record (not used). |
required |
Source code in dlunch/models.py
77 78 79 80 81 82 83 84 85 86 87 88 |
|