overview.edoc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. @title epgsql - PostgreSQL driver for Erlang, internal documentation
  2. @doc
  3. This document is made mostly as internal documentation. It can be useful
  4. if you plan to contribute some patches to epgsql, want to implement
  5. custom datatypes or commands or to better understand epgsql internals.
  6. End-user interface is described in <a href="https://github.com/epgsql/epgsql#readme">README.md</a>.
  7. == Interfaces ==
  8. Epgsql has 3 end-user API interfaces:
  9. <ul>
  10. <li>{@link epgsql} - synchronous</li>
  11. <li>{@link epgsqla} - asynchronous</li>
  12. <li>{@link epgsqli} - incremental</li>
  13. </ul>
  14. == Internals ==
  15. All 3 interfaces communicate with {@link epgsql_sock} gen_server, which holds all
  16. the connection state. While `epgsql_sock' holds all the state, it doesn't know
  17. much about Client-Server communication protocol.
  18. All the communication logic between epgsql and PostgreSQL server is implemented
  19. as a {@section Commands} and `epgsql_sock' acts as an executor for those commands.
  20. PostgreSQL binary communication protocol is represented by 2 modules:
  21. <ul>
  22. <li>{@link epgsql_wire} - codecs for on-wire communication protocol messages</li>
  23. <li>{@link epgsql_binary} - interface to PostgreSQL binary data encoding protocol(see {@section Datatypes})</li>
  24. </ul>
  25. `epgsql_sock' holds an internal state of `epgsql_binary' codecs as well. The
  26. main contents of this state is the mapping between PostgreSQL unique numeric
  27. datatype IDs (OIDs) and callbacks which will be used to decode this datatype.
  28. This mapping is handled by {@link epgsql_oid_db} module and is populated at
  29. connection set-up time by {@link epgsql_cmd_connect}.
  30. Most of the connection initialization (network connection, authentication, codecs)
  31. is performed by {@link epgsql_cmd_connect} command, which is just a regular command
  32. (but quite complex one) and can be replaced by own implementation if needed.
  33. == Commands ==
  34. Client can execute a number of built-in commands as well as define their own.
  35. See {@link epgsql_command} and all the `epgsql_cmd_*' pages.
  36. There exists a <a href="pluggable_commands.md">manual</a> that explains how to
  37. implement your own command.
  38. == Datatypes ==
  39. Epgsql supports both PostgreSQL <a href="https://www.postgresql.org/docs/current/protocol-overview.html#PROTOCOL-FORMAT-CODES">text and binary</a>
  40. data encodings to transfer the data (query placeholder parameters and result rows).
  41. There are a bunch of built-in codecs and it's possible to
  42. implement custom ones as well as fine-tune some of built-ins.
  43. See {@link epgsql_codec} and all the `epgsql_codec_*' pages for more details.
  44. There exists a <a href="pluggable_types.md">manual</a> that explains how to
  45. implement your own datatype codec.