@@ -416,6 +416,7 @@ defmodule Ecto.Repo do
416
416
application environment. It must return `{:ok, keyword}` with the updated
417
417
list of configuration or `:ignore` (only in the `:supervisor` case).
418
418
"""
419
+ @ doc group: "User callbacks"
419
420
@ callback init ( context :: :supervisor | :runtime , config :: Keyword . t ( ) ) ::
420
421
{ :ok , Keyword . t ( ) } | :ignore
421
422
@@ -424,6 +425,7 @@ defmodule Ecto.Repo do
424
425
@ doc """
425
426
Returns the adapter tied to the repository.
426
427
"""
428
+ @ doc group: "Runtime API"
427
429
@ callback __adapter__ :: Ecto.Adapter . t ( )
428
430
429
431
@ doc """
@@ -432,6 +434,7 @@ defmodule Ecto.Repo do
432
434
If the `c:init/2` callback is implemented in the repository,
433
435
it will be invoked with the first argument set to `:runtime`.
434
436
"""
437
+ @ doc group: "Runtime API"
435
438
@ callback config ( ) :: Keyword . t ( )
436
439
437
440
@ doc """
@@ -446,6 +449,7 @@ defmodule Ecto.Repo do
446
449
See the configuration in the moduledoc for options shared between adapters,
447
450
for adapter-specific configuration see the adapter's documentation.
448
451
"""
452
+ @ doc group: "Runtime API"
449
453
@ callback start_link ( opts :: Keyword . t ( ) ) ::
450
454
{ :ok , pid }
451
455
| { :error , { :already_started , pid } }
@@ -454,6 +458,7 @@ defmodule Ecto.Repo do
454
458
@ doc """
455
459
Shuts down the repository.
456
460
"""
461
+ @ doc group: "Runtime API"
457
462
@ callback stop ( timeout ) :: :ok
458
463
459
464
@ doc """
@@ -474,6 +479,7 @@ defmodule Ecto.Repo do
474
479
See the ["Shared options"](#module-shared-options) section at the module
475
480
documentation for more options.
476
481
"""
482
+ @ doc group: "Transaction API"
477
483
@ callback checkout ( ( ( ) -> result ) , opts :: Keyword . t ( ) ) :: result when result: var
478
484
479
485
@ doc """
@@ -496,14 +502,15 @@ defmodule Ecto.Repo do
496
502
end)
497
503
498
504
"""
505
+ @ doc group: "Transaction API"
499
506
@ callback checked_out? ( ) :: boolean
500
507
501
508
@ doc """
502
- Loads `data` into a struct or a map.
509
+ Loads `data` into a schema or a map.
503
510
504
- The first argument can be a a schema module, or a
505
- map (of types) and determines the return value:
506
- a struct or a map, respectively.
511
+ The first argument can be a a schema module or a map (of types).
512
+ The first argument determines the return value: a struct or a map,
513
+ respectively.
507
514
508
515
The second argument `data` specifies fields and values that are to be loaded.
509
516
It can be a map, a keyword list, or a `{fields, values}` tuple.
@@ -540,8 +547,9 @@ defmodule Ecto.Repo do
540
547
[%User{...}, ...]
541
548
542
549
"""
550
+ @ doc group: "Schema API"
543
551
@ callback load (
544
- module_or_map :: module | map ( ) ,
552
+ schema_or_map :: module | map ( ) ,
545
553
data :: map ( ) | Keyword . t ( ) | { list , list }
546
554
) :: Ecto.Schema . t ( ) | map ( )
547
555
@@ -550,6 +558,7 @@ defmodule Ecto.Repo do
550
558
551
559
See `c:put_dynamic_repo/1` for more information.
552
560
"""
561
+ @ doc group: "Runtime API"
553
562
@ callback get_dynamic_repo ( ) :: atom ( ) | pid ( )
554
563
555
564
@ doc """
@@ -585,6 +594,7 @@ defmodule Ecto.Repo do
585
594
**Note this feature is experimental and may be changed or removed in future
586
595
releases.**
587
596
"""
597
+ @ doc group: "Runtime API"
588
598
@ callback put_dynamic_repo ( name_or_pid :: atom ( ) | pid ( ) ) :: atom ( ) | pid ( )
589
599
590
600
## Ecto.Adapter.Queryable
@@ -619,6 +629,7 @@ defmodule Ecto.Repo do
619
629
MyRepo.get(Post, 42, prefix: "public")
620
630
621
631
"""
632
+ @ doc group: "Query API"
622
633
@ callback get ( queryable :: Ecto.Queryable . t ( ) , id :: term , opts :: Keyword . t ( ) ) ::
623
634
Ecto.Schema . t ( ) | nil
624
635
@@ -644,6 +655,7 @@ defmodule Ecto.Repo do
644
655
MyRepo.get!(Post, 42, prefix: "public")
645
656
646
657
"""
658
+ @ doc group: "Query API"
647
659
@ callback get! ( queryable :: Ecto.Queryable . t ( ) , id :: term , opts :: Keyword . t ( ) ) ::
648
660
Ecto.Schema . t ( )
649
661
@@ -671,6 +683,7 @@ defmodule Ecto.Repo do
671
683
MyRepo.get_by(Post, [title: "My post"], prefix: "public")
672
684
673
685
"""
686
+ @ doc group: "Query API"
674
687
@ callback get_by (
675
688
queryable :: Ecto.Queryable . t ( ) ,
676
689
clauses :: Keyword . t ( ) | map ,
@@ -702,6 +715,7 @@ defmodule Ecto.Repo do
702
715
MyRepo.get_by!(Post, [title: "My post"], prefix: "public")
703
716
704
717
"""
718
+ @ doc group: "Query API"
705
719
@ callback get_by! (
706
720
queryable :: Ecto.Queryable . t ( ) ,
707
721
clauses :: Keyword . t ( ) | map ,
@@ -726,6 +740,7 @@ defmodule Ecto.Repo do
726
740
MyRepo.reload([deleted_post, post1])
727
741
[nil, %Post{}]
728
742
"""
743
+ @ doc group: "Schema API"
729
744
@ callback reload (
730
745
struct_or_structs :: Ecto.Schema . t ( ) | [ Ecto.Schema . t ( ) ] ,
731
746
opts :: Keyword . t ( )
@@ -744,6 +759,7 @@ defmodule Ecto.Repo do
744
759
MyRepo.reload!([post1, post2])
745
760
[%Post{}, %Post{}]
746
761
"""
762
+ @ doc group: "Schema API"
747
763
@ callback reload! ( struct_or_structs , opts :: Keyword . t ( ) ) :: struct_or_structs
748
764
when struct_or_structs: Ecto.Schema . t ( ) | [ Ecto.Schema . t ( ) ]
749
765
@@ -781,6 +797,7 @@ defmodule Ecto.Repo do
781
797
Repo.aggregate(Post, :count, prefix: "private")
782
798
783
799
"""
800
+ @ doc group: "Query API"
784
801
@ callback aggregate (
785
802
queryable :: Ecto.Queryable . t ( ) ,
786
803
aggregate :: :count ,
@@ -805,6 +822,7 @@ defmodule Ecto.Repo do
805
822
query = from Post, limit: 10
806
823
Repo.aggregate(query, :avg, :visits)
807
824
"""
825
+ @ doc group: "Query API"
808
826
@ callback aggregate (
809
827
queryable :: Ecto.Queryable . t ( ) ,
810
828
aggregate :: :avg | :count | :max | :min | :sum ,
@@ -842,6 +860,7 @@ defmodule Ecto.Repo do
842
860
query = from p in Post, where: p.like_count > 10
843
861
Repo.exists?(query)
844
862
"""
863
+ @ doc group: "Query API"
845
864
@ callback exists? ( queryable :: Ecto.Queryable . t ( ) , opts :: Keyword . t ( ) ) :: boolean ( )
846
865
847
866
@ doc """
@@ -868,6 +887,7 @@ defmodule Ecto.Repo do
868
887
query = from p in Post, join: c in assoc(p, :comments), where: p.id == ^post_id
869
888
Repo.one(query, prefix: "private")
870
889
"""
890
+ @ doc group: "Query API"
871
891
@ callback one ( queryable :: Ecto.Queryable . t ( ) , opts :: Keyword . t ( ) ) ::
872
892
Ecto.Schema . t ( ) | nil
873
893
@@ -888,6 +908,7 @@ defmodule Ecto.Repo do
888
908
See the ["Shared options"](#module-shared-options) section at the module
889
909
documentation for more options.
890
910
"""
911
+ @ doc group: "Query API"
891
912
@ callback one! ( queryable :: Ecto.Queryable . t ( ) , opts :: Keyword . t ( ) ) ::
892
913
Ecto.Schema . t ( )
893
914
@@ -936,6 +957,7 @@ defmodule Ecto.Repo do
936
957
937
958
The query given to preload may also preload its own associations.
938
959
"""
960
+ @ doc group: "Schema API"
939
961
@ callback preload ( structs_or_struct_or_nil , preloads :: term , opts :: Keyword . t ( ) ) ::
940
962
structs_or_struct_or_nil
941
963
when structs_or_struct_or_nil: [ Ecto.Schema . t ( ) ] | Ecto.Schema . t ( ) | nil
@@ -975,6 +997,7 @@ defmodule Ecto.Repo do
975
997
made from associations and preloads. It is not invoked for each
976
998
individual join inside a query.
977
999
"""
1000
+ @ doc group: "User callbacks"
978
1001
@ callback prepare_query ( operation , query :: Ecto.Query . t ( ) , opts :: Keyword . t ( ) ) ::
979
1002
{ Ecto.Query . t ( ) , Keyword . t ( ) }
980
1003
when operation: :all | :update_all | :delete_all | :stream | :insert_all
@@ -993,6 +1016,7 @@ defmodule Ecto.Repo do
993
1016
this callback will be invoked once at the beginning, but the
994
1017
options returned here will be passed to all following operations.
995
1018
"""
1019
+ @ doc group: "User callbacks"
996
1020
@ callback default_options ( operation ) :: Keyword . t ( )
997
1021
when operation: :all | :insert_all | :update_all | :delete_all | :stream |
998
1022
:transaction | :insert | :update | :delete | :insert_or_update
@@ -1021,6 +1045,7 @@ defmodule Ecto.Repo do
1021
1045
select: p.title
1022
1046
MyRepo.all(query)
1023
1047
"""
1048
+ @ doc group: "Query API"
1024
1049
@ callback all ( queryable :: Ecto.Queryable . t ( ) , opts :: Keyword . t ( ) ) :: [ Ecto.Schema . t ( ) ]
1025
1050
1026
1051
@ doc """
@@ -1057,6 +1082,7 @@ defmodule Ecto.Repo do
1057
1082
Enum.to_list(stream)
1058
1083
end)
1059
1084
"""
1085
+ @ doc group: "Query API"
1060
1086
@ callback stream ( queryable :: Ecto.Queryable . t ( ) , opts :: Keyword . t ( ) ) :: Enum . t ( )
1061
1087
1062
1088
@ doc """
@@ -1101,6 +1127,7 @@ defmodule Ecto.Repo do
1101
1127
|> MyRepo.update_all([])
1102
1128
1103
1129
"""
1130
+ @ doc group: "Query API"
1104
1131
@ callback update_all (
1105
1132
queryable :: Ecto.Queryable . t ( ) ,
1106
1133
updates :: Keyword . t ( ) ,
@@ -1130,6 +1157,7 @@ defmodule Ecto.Repo do
1130
1157
1131
1158
from(p in Post, where: p.id < 10) |> MyRepo.delete_all
1132
1159
"""
1160
+ @ doc group: "Query API"
1133
1161
@ callback delete_all ( queryable :: Ecto.Queryable . t ( ) , opts :: Keyword . t ( ) ) ::
1134
1162
{ integer , nil | [ term ] }
1135
1163
@@ -1303,6 +1331,7 @@ defmodule Ecto.Repo do
1303
1331
so they are not currently compatible with MySQL
1304
1332
1305
1333
"""
1334
+ @ doc group: "Schema API"
1306
1335
@ callback insert_all (
1307
1336
schema_or_source :: binary | { binary , module } | module ,
1308
1337
entries_or_query :: [ map | [ { atom , term | Ecto.Query . t } ] ] | Ecto.Query . t ,
@@ -1474,6 +1503,7 @@ defmodule Ecto.Repo do
1474
1503
at the same time is not recommended, as Ecto will be unable to actually
1475
1504
track the proper status of the association.
1476
1505
"""
1506
+ @ doc group: "Schema API"
1477
1507
@ callback insert (
1478
1508
struct_or_changeset :: Ecto.Schema . t ( ) | Ecto.Changeset . t ( ) ,
1479
1509
opts :: Keyword . t ( )
@@ -1535,6 +1565,7 @@ defmodule Ecto.Repo do
1535
1565
{:error, changeset} -> # Something went wrong
1536
1566
end
1537
1567
"""
1568
+ @ doc group: "Schema API"
1538
1569
@ callback update ( changeset :: Ecto.Changeset . t ( ) , opts :: Keyword . t ( ) ) ::
1539
1570
{ :ok , Ecto.Schema . t ( ) } | { :error , Ecto.Changeset . t ( ) }
1540
1571
@@ -1585,6 +1616,7 @@ defmodule Ecto.Repo do
1585
1616
{:error, changeset} -> # Something went wrong
1586
1617
end
1587
1618
"""
1619
+ @ doc group: "Schema API"
1588
1620
@ callback insert_or_update ( changeset :: Ecto.Changeset . t ( ) , opts :: Keyword . t ( ) ) ::
1589
1621
{ :ok , Ecto.Schema . t ( ) } | { :error , Ecto.Changeset . t ( ) }
1590
1622
@@ -1626,6 +1658,7 @@ defmodule Ecto.Repo do
1626
1658
end
1627
1659
1628
1660
"""
1661
+ @ doc group: "Schema API"
1629
1662
@ callback delete (
1630
1663
struct_or_changeset :: Ecto.Schema . t ( ) | Ecto.Changeset . t ( ) ,
1631
1664
opts :: Keyword . t ( )
@@ -1634,6 +1667,7 @@ defmodule Ecto.Repo do
1634
1667
@ doc """
1635
1668
Same as `c:insert/2` but returns the struct or raises if the changeset is invalid.
1636
1669
"""
1670
+ @ doc group: "Schema API"
1637
1671
@ callback insert! (
1638
1672
struct_or_changeset :: Ecto.Schema . t ( ) | Ecto.Changeset . t ( ) ,
1639
1673
opts :: Keyword . t ( )
@@ -1642,19 +1676,22 @@ defmodule Ecto.Repo do
1642
1676
@ doc """
1643
1677
Same as `c:update/2` but returns the struct or raises if the changeset is invalid.
1644
1678
"""
1679
+ @ doc group: "Schema API"
1645
1680
@ callback update! ( changeset :: Ecto.Changeset . t ( ) , opts :: Keyword . t ( ) ) ::
1646
1681
Ecto.Schema . t ( )
1647
1682
1648
1683
@ doc """
1649
1684
Same as `c:insert_or_update/2` but returns the struct or raises if the changeset
1650
1685
is invalid.
1651
1686
"""
1687
+ @ doc group: "Schema API"
1652
1688
@ callback insert_or_update! ( changeset :: Ecto.Changeset . t ( ) , opts :: Keyword . t ( ) ) ::
1653
1689
Ecto.Schema . t ( )
1654
1690
1655
1691
@ doc """
1656
1692
Same as `c:delete/2` but returns the struct or raises if the changeset is invalid.
1657
1693
"""
1694
+ @ doc group: "Schema API"
1658
1695
@ callback delete! (
1659
1696
struct_or_changeset :: Ecto.Schema . t ( ) | Ecto.Changeset . t ( ) ,
1660
1697
opts :: Keyword . t ( )
@@ -1735,6 +1772,7 @@ defmodule Ecto.Repo do
1735
1772
|> MyRepo.transaction
1736
1773
1737
1774
"""
1775
+ @ doc group: "Transaction API"
1738
1776
@ callback transaction ( fun_or_multi :: fun | Ecto.Multi . t ( ) , opts :: Keyword . t ( ) ) ::
1739
1777
{ :ok , any }
1740
1778
| { :error , any }
@@ -1762,6 +1800,7 @@ defmodule Ecto.Repo do
1762
1800
end)
1763
1801
1764
1802
"""
1803
+ @ doc group: "Transaction API"
1765
1804
@ callback in_transaction? ( ) :: boolean
1766
1805
1767
1806
@ doc """
@@ -1771,5 +1810,6 @@ defmodule Ecto.Repo do
1771
1810
1772
1811
Note that calling `rollback` causes the code in the transaction to stop executing.
1773
1812
"""
1813
+ @ doc group: "Transaction API"
1774
1814
@ callback rollback ( value :: any ) :: no_return
1775
1815
end
0 commit comments