QuerySet
class¶
edgy.QuerySet
¶
QuerySet(model_class=None, database=None, filter_clauses=None, or_clauses=None, select_related=None, prefetch_related=None, limit_count=None, limit_offset=None, order_by=None, group_by=None, distinct_on=None, only_fields=None, defer_fields=None, embed_parent=None, using_schema=None, table=None, exclude_secrets=False)
Bases: BaseQuerySet
, QuerySetProtocol
QuerySet object used for query retrieving.
PARAMETER | DESCRIPTION |
---|---|
model_class |
TYPE:
|
database |
TYPE:
|
filter_clauses |
TYPE:
|
or_clauses |
TYPE:
|
select_related |
TYPE:
|
prefetch_related |
TYPE:
|
limit_count |
TYPE:
|
limit_offset |
TYPE:
|
order_by |
TYPE:
|
group_by |
TYPE:
|
distinct_on |
TYPE:
|
only_fields |
TYPE:
|
defer_fields |
TYPE:
|
embed_parent |
TYPE:
|
using_schema |
TYPE:
|
table |
TYPE:
|
exclude_secrets |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
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 169 |
|
filter_clauses
instance-attribute
¶
filter_clauses = [] if filter_clauses is None else filter_clauses
_select_related
instance-attribute
¶
_select_related = [] if select_related is None else select_related
_prefetch_related
instance-attribute
¶
_prefetch_related = [] if prefetch_related is None else prefetch_related
execute
async
¶
execute()
Source code in edgy/core/db/querysets/protocols.py
16 17 |
|
_extract_model_references
¶
_extract_model_references(extracted_values, model_class)
Exracts any possible model references from the EdgyModel and returns a dictionary.
PARAMETER | DESCRIPTION |
---|---|
extracted_values |
TYPE:
|
model_class |
TYPE:
|
Source code in edgy/core/utils/models.py
61 62 63 64 65 66 67 68 69 70 |
|
_extract_values_from_field
¶
_extract_values_from_field(extracted_values, model_class=None, is_update=False, is_partial=False)
Extracts all the default values from the given fields and returns the raw value corresponding to each field.
PARAMETER | DESCRIPTION |
---|---|
extracted_values |
TYPE:
|
model_class |
TYPE:
|
is_update |
TYPE:
|
is_partial |
TYPE:
|
Source code in edgy/core/utils/models.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 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 |
|
_update_auto_now_fields
¶
_update_auto_now_fields(values, fields)
Updates the auto_now
fields
PARAMETER | DESCRIPTION |
---|---|
values |
TYPE:
|
fields |
TYPE:
|
Source code in edgy/core/utils/models.py
40 41 42 43 44 45 46 47 |
|
_resolve_value
¶
_resolve_value(value)
PARAMETER | DESCRIPTION |
---|---|
value |
TYPE:
|
Source code in edgy/core/utils/models.py
49 50 51 52 53 54 55 56 57 |
|
prefetch_related
¶
prefetch_related(*prefetch)
Performs a reverse lookup for the foreignkeys. This is different from the select_related. Select related performs a follows the SQL foreign relation whereas the prefetch_related follows the python relations.
PARAMETER | DESCRIPTION |
---|---|
*prefetch |
TYPE:
|
Source code in edgy/core/db/querysets/prefetch.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
using
¶
using(schema)
Enables and switches the db schema.
Generates the registry object pointing to the desired schema using the same connection.
PARAMETER | DESCRIPTION |
---|---|
schema |
TYPE:
|
Source code in edgy/core/db/querysets/mixins.py
59 60 61 62 63 64 65 66 67 |
|
using_with_db
¶
using_with_db(connection_name, schema=None)
Enables and switches the database connection.
Generates the new queryset using the selected connection provided in the extra of the model registry.
PARAMETER | DESCRIPTION |
---|---|
connection_name |
TYPE:
|
schema |
TYPE:
|
Source code in edgy/core/db/querysets/mixins.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
_build_order_by_expression
¶
_build_order_by_expression(order_by, expression)
Builds the order by expression
PARAMETER | DESCRIPTION |
---|---|
order_by |
TYPE:
|
expression |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
171 172 173 174 175 |
|
_build_group_by_expression
¶
_build_group_by_expression(group_by, expression)
Builds the group by expression
PARAMETER | DESCRIPTION |
---|---|
group_by |
TYPE:
|
expression |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
177 178 179 180 181 |
|
_build_filter_clauses_expression
¶
_build_filter_clauses_expression(filter_clauses, expression)
Builds the filter clauses expression
PARAMETER | DESCRIPTION |
---|---|
filter_clauses |
TYPE:
|
expression |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
183 184 185 186 187 188 189 190 |
|
_build_or_clauses_expression
¶
_build_or_clauses_expression(or_clauses, expression)
Builds the filter clauses expression
PARAMETER | DESCRIPTION |
---|---|
or_clauses |
TYPE:
|
expression |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
192 193 194 195 196 197 198 199 |
|
_build_select_distinct
¶
_build_select_distinct(distinct_on, expression)
Filters selects only specific fields. Leave empty to use simple distinct
PARAMETER | DESCRIPTION |
---|---|
distinct_on |
TYPE:
|
expression |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
201 202 203 204 205 206 207 |
|
_build_tables_select_from_relationship
¶
_build_tables_select_from_relationship()
Builds the tables relationships and joins. When a table contains more than one foreign key pointing to the same destination table, a lookup for the related field is made to understand from which foreign key the table is looked up from.
Source code in edgy/core/db/querysets/base.py
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 |
|
_select_from_relationship_clause_generator
staticmethod
¶
_select_from_relationship_clause_generator(select_from, foreign_key, table, reverse, former_table=None)
PARAMETER | DESCRIPTION |
---|---|
select_from |
TYPE:
|
foreign_key |
TYPE:
|
table |
TYPE:
|
reverse |
TYPE:
|
former_table |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
_validate_only_and_defer
¶
_validate_only_and_defer()
Source code in edgy/core/db/querysets/base.py
270 271 272 |
|
_secret_recursive_names
¶
_secret_recursive_names(model_class, columns=None)
Recursively gets the names of the fields excluding the secrets.
PARAMETER | DESCRIPTION |
---|---|
model_class |
TYPE:
|
columns |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
_build_select
¶
_build_select()
Builds the query select based on the given parameters and filters.
Source code in edgy/core/db/querysets/base.py
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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
_filter_query
¶
_filter_query(exclude=False, or_=False, **kwargs)
PARAMETER | DESCRIPTION |
---|---|
exclude |
TYPE:
|
or_ |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
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 405 406 407 408 409 410 411 412 413 414 415 416 |
|
_validate_kwargs
¶
_validate_kwargs(**kwargs)
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
418 419 |
|
_prepare_order_by
¶
_prepare_order_by(order_by)
PARAMETER | DESCRIPTION |
---|---|
order_by |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
421 422 423 424 425 |
|
_prepare_group_by
¶
_prepare_group_by(group_by)
PARAMETER | DESCRIPTION |
---|---|
group_by |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
427 428 429 430 |
|
_prepare_fields_for_distinct
¶
_prepare_fields_for_distinct(distinct_on)
PARAMETER | DESCRIPTION |
---|---|
distinct_on |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
432 433 |
|
_clone
¶
_clone()
Return a copy of the current QuerySet that's ready for another operation.
Source code in edgy/core/db/querysets/base.py
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 |
|
__aiter__
async
¶
__aiter__()
Source code in edgy/core/db/querysets/base.py
489 490 491 |
|
_set_query_expression
¶
_set_query_expression(expression)
Sets the value of the sql property to the expression used.
PARAMETER | DESCRIPTION |
---|---|
expression |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
493 494 495 496 497 498 |
|
_filter_or_exclude
¶
_filter_or_exclude(clause=None, exclude=False, **kwargs)
Filters or excludes a given clause for a specific QuerySet.
PARAMETER | DESCRIPTION |
---|---|
clause |
TYPE:
|
exclude |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
|
filter
¶
filter(clause=None, **kwargs)
Filters the QuerySet by the given kwargs and clause.
PARAMETER | DESCRIPTION |
---|---|
clause |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
516 517 518 519 520 521 522 523 524 |
|
or_
¶
or_(clause=None, **kwargs)
Filters the QuerySet by the OR operand.
PARAMETER | DESCRIPTION |
---|---|
clause |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
526 527 528 529 530 531 532 533 534 535 536 |
|
and_
¶
and_(clause=None, **kwargs)
Filters the QuerySet by the AND operand.
PARAMETER | DESCRIPTION |
---|---|
clause |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
538 539 540 541 542 543 544 545 546 547 548 |
|
not_
¶
not_(clause=None, **kwargs)
Filters the QuerySet by the NOT operand.
PARAMETER | DESCRIPTION |
---|---|
clause |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
550 551 552 553 554 555 556 557 558 559 560 |
|
exclude
¶
exclude(clause=None, **kwargs)
Exactly the same as the filter but for the exclude.
PARAMETER | DESCRIPTION |
---|---|
clause |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
562 563 564 565 566 567 568 569 570 571 572 |
|
exclude_secrets
¶
exclude_secrets(clause=None, **kwargs)
Excludes any field that contains the secret=True
declared from being leaked.
PARAMETER | DESCRIPTION |
---|---|
clause |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
574 575 576 577 578 579 580 581 582 583 584 585 |
|
lookup
¶
lookup(term)
Broader way of searching for a given term
PARAMETER | DESCRIPTION |
---|---|
term |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
|
order_by
¶
order_by(*order_by)
Returns a QuerySet ordered by the given fields.
PARAMETER | DESCRIPTION |
---|---|
*order_by |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
610 611 612 613 614 615 616 |
|
limit
¶
limit(limit_count)
Returns a QuerySet limited by.
PARAMETER | DESCRIPTION |
---|---|
limit_count |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
618 619 620 621 622 623 624 |
|
offset
¶
offset(offset)
Returns a Queryset limited by the offset.
PARAMETER | DESCRIPTION |
---|---|
offset |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
626 627 628 629 630 631 632 |
|
group_by
¶
group_by(*group_by)
Returns the values grouped by the given fields.
PARAMETER | DESCRIPTION |
---|---|
*group_by |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
634 635 636 637 638 639 640 |
|
distinct
¶
distinct(*distinct_on)
Returns a queryset with distinct results.
PARAMETER | DESCRIPTION |
---|---|
*distinct_on |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
642 643 644 645 646 647 648 |
|
only
¶
only(*fields)
Returns a list of models with the selected only fields and always the primary key.
PARAMETER | DESCRIPTION |
---|---|
*fields |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
|
defer
¶
defer(*fields)
Returns a list of models with the selected only fields and always the primary key.
PARAMETER | DESCRIPTION |
---|---|
*fields |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
672 673 674 675 676 677 678 679 |
|
select_related
¶
select_related(related)
Returns a QuerySet that will “follow” foreign-key relationships, selecting additional related-object data when it executes its query.
This is a performance booster which results in a single more complex query but means
later use of foreign-key relationships won’t require database queries.
PARAMETER | DESCRIPTION |
---|---|
related |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 |
|
values
async
¶
values(fields=None, exclude=None, exclude_none=False, flatten=False, **kwargs)
Returns the results in a python dictionary format.
PARAMETER | DESCRIPTION |
---|---|
fields |
TYPE:
|
exclude |
TYPE:
|
exclude_none |
TYPE:
|
flatten |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
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 |
|
values_list
async
¶
values_list(fields=None, exclude=None, exclude_none=False, flat=False)
Returns the results in a python dictionary format.
PARAMETER | DESCRIPTION |
---|---|
fields |
TYPE:
|
exclude |
TYPE:
|
exclude_none |
TYPE:
|
flat |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
735 736 737 738 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 |
|
exists
async
¶
exists(**kwargs)
Returns a boolean indicating if a record exists or not.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
766 767 768 769 770 771 772 773 774 775 |
|
count
async
¶
count(**kwargs)
Returns an indicating the total records.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
777 778 779 780 781 782 783 784 785 786 |
|
get_or_none
async
¶
get_or_none(**kwargs)
Fetch one object matching the parameters or returns None.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
|
embed_parent_in_result
¶
embed_parent_in_result(result)
PARAMETER | DESCRIPTION |
---|---|
result |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
808 809 810 811 812 813 814 |
|
_all
async
¶
_all(**kwargs)
Executes the query.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
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 845 846 847 848 849 850 851 852 853 854 |
|
all
¶
all(**kwargs)
Returns the queryset records based on specific filters
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
856 857 858 859 860 861 862 |
|
get
async
¶
get(**kwargs)
Returns a single record based on the given kwargs.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 |
|
first
async
¶
first(**kwargs)
Returns the first record of a given queryset.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
896 897 898 899 900 901 902 903 904 905 906 907 |
|
last
async
¶
last(**kwargs)
Returns the last record of a given queryset.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
909 910 911 912 913 914 915 916 917 918 919 920 |
|
create
async
¶
create(**kwargs)
Creates a record in a specific table.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
922 923 924 925 926 927 928 929 930 |
|
bulk_create
async
¶
bulk_create(objs)
Bulk creates records in a table
PARAMETER | DESCRIPTION |
---|---|
objs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
932 933 934 935 936 937 938 939 940 941 |
|
bulk_update
async
¶
bulk_update(objs, fields)
Bulk updates records in a table.
A similar solution was suggested here: https://github.com/encode/orm/pull/148
It is thought to be a clean approach to a simple problem so it was added here and refactored to be compatible with Edgy.
PARAMETER | DESCRIPTION |
---|---|
objs |
TYPE:
|
fields |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
943 944 945 946 947 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 |
|
delete
async
¶
delete()
Source code in edgy/core/db/querysets/base.py
977 978 979 980 981 982 983 984 985 986 987 988 989 |
|
update
async
¶
update(**kwargs)
Updates a record in a specific table with the given kwargs.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
|
get_or_create
async
¶
get_or_create(defaults, **kwargs)
Creates a record in a specific table or updates if already exists.
PARAMETER | DESCRIPTION |
---|---|
defaults |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 |
|
update_or_create
async
¶
update_or_create(defaults, **kwargs)
Updates a record in a specific table or creates a new one.
PARAMETER | DESCRIPTION |
---|---|
defaults |
TYPE:
|
**kwargs |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
|
contains
async
¶
contains(instance)
Returns true if the QuerySet contains the provided object. False if otherwise.
PARAMETER | DESCRIPTION |
---|---|
instance |
TYPE:
|
Source code in edgy/core/db/querysets/base.py
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 |
|
_execute
async
¶
_execute()
Source code in edgy/core/db/querysets/base.py
1053 1054 1055 1056 |
|