Coverage for gws-app/gws/plugin/postgres/finder.py: 0%
29 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""PostgreSQL finder."""
3from typing import Optional, cast
5import gws
6import gws.base.database
7import gws.base.model
8import gws.base.search
9import gws.config.util
12@gws.ext.config.finder('postgres')
13class Config(gws.base.search.finder.Config):
14 """Search in a PostgreSQL table."""
16 dbUid: Optional[str]
17 """UID of the database provider."""
18 tableName: str
19 """Table to search, optionally schema-qualified."""
20 sqlFilter: Optional[str]
21 """SQL condition added to all search queries."""
24@gws.ext.object.finder('postgres')
25class Object(gws.base.search.finder.Object):
26 """Finder that searches a PostgreSQL table through its ``postgres`` models."""
28 db: gws.DatabaseProvider
29 """Database provider."""
30 tableName: str
31 """Table to search."""
33 def configure(self):
34 self.tableName = self.cfg('tableName') or self.cfg('_defaultTableName')
35 self.configure_provider()
36 self.configure_models()
37 self.configure_templates()
39 # it's difficult to decide if we support keyword/geometry search,
40 # because different models can have different rules
42 self.supportsKeywordSearch = True
43 self.supportsGeometrySearch = True
44 self.supportsFilterSearch = True
46 def configure_provider(self):
47 """Set the database provider from ``dbUid``, or the first ``postgres`` provider.
49 Returns:
50 ``True`` if a provider was set.
52 Raises:
53 ``gws.Error``: If no provider is found.
54 """
55 return gws.config.util.configure_database_provider_for(self)
57 def configure_models(self):
58 return gws.config.util.configure_models_for(self, with_default=True)
60 def create_model(self, cfg):
61 """Create a ``postgres`` model for the table of the finder.
63 The model gets the database provider, the table and the ``sqlFilter`` of the finder.
65 Args:
66 cfg: Model configuration, or ``None`` for the default model.
68 Returns:
69 The model object.
70 """
71 return self.create_child(
72 gws.ext.object.model,
73 cfg,
74 type=self.extType,
75 sqlFilter=self.cfg('sqlFilter'),
76 _defaultDb=self.db,
77 _defaultTableName=self.tableName
78 )