Skip to content

Commit 86ea5ba

Browse files
author
James William Pye
committed
Add pg.lib pkg dir to libpath and remove mentions of module libraries.
We don't really want modlibs to be used.
1 parent e8e3ecd commit 86ea5ba

2 files changed

Lines changed: 11 additions & 77 deletions

File tree

postgresql/documentation/lib.py

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,10 @@
189189
190190
After a library is created, it must be loaded before it can be bound using
191191
programmer interfaces. The `postgresql.lib.load` interface provides the
192-
primary entry point for loading libraries. ``load()`` accepts `str` objects
193-
and modules. If given a module, it will create a
194-
`postgresql.lib.ModuleLibrary` from the given module, and if a `str` object is
195-
given it will create a `postgresql.lib.ILF` instance.
192+
primary entry point for loading libraries.
196193
197194
When ``load`` is given a string, it identifies if a directory separator is in
198-
the string, if there is it will treat the string as a path to the ILF to be
195+
the string, if there is it will treat the string as a *path* to the ILF to be
199196
loaded. If no separator is found, it will treat the string as the library
200197
name fragment and look for "lib{NAME}.sql" in the directories listed in
201198
`postgresql.sys.libpath`.
@@ -336,78 +333,6 @@
336333
... FROM STDIN``, the iterable must produce COPY lines.
337334
338335
339-
Module Libraries
340-
================
341-
342-
Module libraries allow query libraries to be distributed as Python modules.
343-
While not as portable as ILFs, they are convenient for Python projects
344-
as no additional file management is required in order to use them.
345-
346-
Module libraries are designed to *not* require special dependencies in order to
347-
annotate symbols. Rather, simple module protocols are used in order to
348-
annotate symbols.
349-
350-
For instance, in order to make a preloaded Symbol, the symbol name needs to be
351-
added to the ``__preload__`` collection in the module defining the symbol.
352-
353-
libmod.py::
354-
355-
__preload__ = set()
356-
this_symbol = "SELECT $1::text AS useless"
357-
__preload__.add('this_symbol')
358-
359-
360-
Symbol Annotations
361-
------------------
362-
363-
Module libraries perform symbol annotation by using specially named collection
364-
objects to denote the characteristics of a symbol. The names of the collection
365-
objects in a library module are consistent with statement method names:
366-
367-
``__rows__``
368-
For each named symbol, use `postgresql.api.PreparedStatement.rows` as the
369-
default execution method.
370-
371-
``__chunks__``
372-
For each named symbol, use `postgresql.api.PreparedStatement.chunks` as the
373-
default execution method.
374-
375-
``__first__``
376-
For each named symbol, use `postgresql.api.PreparedStatement.first` as the
377-
default execution method.
378-
379-
``__declare__``
380-
For each named symbol, use `postgresql.api.PreparedStatement.declare` as the
381-
default execution method.
382-
383-
``__load_rows__``
384-
For each named symbol, use `postgresql.api.PreparedStatement.load_rows` as the
385-
default execution method.
386-
387-
``__load_chunks__``
388-
For each named symbol, use `postgresql.api.PreparedStatement.load_chunks` as
389-
the default execution method.
390-
391-
The symbol names stored in the above objects must *not* intersect.
392-
393-
Additionally, symbols can be constants and preloaded using:
394-
395-
``__preload__``
396-
Create Bound Symbols for each named symbol when the Library is bound.
397-
398-
``__const__``
399-
Resolve the results of the query when the Library is bound and return the
400-
results when the symbol is referenced.
401-
402-
The objects used to store the symbol names should be Python `set` objects.
403-
404-
To use a module library, import the module and give it to
405-
`postgresql.lib.load`::
406-
407-
>>> import libmod
408-
>>> l = pg_lib.load(libmod)
409-
410-
411336
Audience and Motivation
412337
=======================
413338

postgresql/lib/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
from .. import sys as pg_sys
2525
from .. import exceptions as pg_exc
2626

27+
try:
28+
libdir = os.path.abspath(os.path.dirname(__file__))
29+
except NameError:
30+
pass
31+
else:
32+
if os.path.exists(libdir):
33+
pg_sys.libpath.insert(0, libdir)
34+
del libdir
35+
2736
__all__ = [
2837
'Library',
2938
'ModuleLibrary',

0 commit comments

Comments
 (0)