Admin service implementation for CRUD operations on entities.
This service provides database-agnostic CRUD operations on any entity managed by the admin interface. It coordinates between schema providers, permission checks, and database operations.
Responsibilities:
Admin service implementation for CRUD operations on entities. This service provides database-agnostic CRUD operations on any entity managed by the admin interface. It coordinates between schema providers, permission checks, and database operations. Responsibilities: - Execute CRUD operations with observability - Apply pagination, filtering, sorting - Validate permissions and entity access - Transform data between DB and application formats - Handle soft/hard deletes, children included, as the config says
(build-filter-where adapter filters)Build WHERE clause for field-specific filters.
Week 1: Simple equality filters Week 2: Advanced operators (gt, lt, contains, in, between, etc.)
Args:
adapter: the database's DBAdapter; text operators ignore case through its like
filters: Map of field -> value (Week 1) or field -> filter-map (Week 2)
Week 1: {:role :admin :active true}
Week 2: {:created-at {:op :gte :value "2024-01-01"}
:status {:op :in :values [:active :pending]}}
Returns: HoneySQL WHERE clause (nil if no filters)
Example: (build-filter-where adapter {:role :admin :active true}) ;=> [:and [:= :role :admin] [:= :active true]]
(build-filter-where adapter {:price {:op :gte :value 100} :status {:op :in :values [:active :pending]}}) ;=> [:and [:>= :price 100] [:in :status [:active :pending]]]
Build WHERE clause for field-specific filters.
Week 1: Simple equality filters
Week 2: Advanced operators (gt, lt, contains, in, between, etc.)
Args:
adapter: the database's DBAdapter; text operators ignore case through its `like`
filters: Map of field -> value (Week 1) or field -> filter-map (Week 2)
Week 1: {:role :admin :active true}
Week 2: {:created-at {:op :gte :value "2024-01-01"}
:status {:op :in :values [:active :pending]}}
Returns:
HoneySQL WHERE clause (nil if no filters)
Example:
(build-filter-where adapter {:role :admin :active true})
;=> [:and [:= :role :admin] [:= :active true]]
(build-filter-where adapter {:price {:op :gte :value 100}
:status {:op :in :values [:active :pending]}})
;=> [:and [:>= :price 100] [:in :status [:active :pending]]](build-ordering sort-field sort-dir default-field)Build ORDER BY clause.
Args: sort-field: Keyword field to sort by sort-dir: :asc or :desc default-field: Fallback field if sort-field not provided
Returns: Vector for HoneySQL :order-by clause
Example: (build-ordering :email :asc :id) ;=> [[:email :asc]]
Build ORDER BY clause. Args: sort-field: Keyword field to sort by sort-dir: :asc or :desc default-field: Fallback field if sort-field not provided Returns: Vector for HoneySQL :order-by clause Example: (build-ordering :email :asc :id) ;=> [[:email :asc]]
(build-pagination options config)Build pagination clause with safe bounds checking.
Args: options: Map with :limit, :offset, or :page and :page-size config: Admin configuration map with pagination defaults
Returns: Map with :limit and :offset
Examples: (build-pagination {:limit 20 :offset 10} config) (build-pagination {:page 2 :page-size 25} config)
Build pagination clause with safe bounds checking.
Args:
options: Map with :limit, :offset, or :page and :page-size
config: Admin configuration map with pagination defaults
Returns:
Map with :limit and :offset
Examples:
(build-pagination {:limit 20 :offset 10} config)
(build-pagination {:page 2 :page-size 25} config)(build-search-where adapter search-term search-fields)Build WHERE clause for case-insensitive text search across multiple fields.
Args:
adapter: the database's DBAdapter, whose like ignores case on every engine
search-term: String to search for
search-fields: Vector of field keywords to search in
Returns: HoneySQL WHERE clause (nil if no search term)
Example: (build-search-where postgres-adapter john [:email :name]) => [:or (like adapter :email :contains john) (like adapter :name :contains john)]
Build WHERE clause for case-insensitive text search across multiple fields.
Args:
adapter: the database's DBAdapter, whose `like` ignores case on every engine
search-term: String to search for
search-fields: Vector of field keywords to search in
Returns:
HoneySQL WHERE clause (nil if no search term)
Example:
(build-search-where postgres-adapter john [:email :name])
=> [:or (like adapter :email :contains john)
(like adapter :name :contains john)](combine-where-clauses clauses)Combine multiple WHERE clauses with AND.
Args: clauses: Vector of WHERE clause expressions (nils are filtered)
Returns: Combined WHERE clause or nil
Example: (combine-where-clauses [[:= :active true] nil [:like :email "%@example.com%"]]) ;=> [:and [:= :active true] [:like :email "%@example.com%"]]
Combine multiple WHERE clauses with AND. Args: clauses: Vector of WHERE clause expressions (nils are filtered) Returns: Combined WHERE clause or nil Example: (combine-where-clauses [[:= :active true] nil [:like :email "%@example.com%"]]) ;=> [:and [:= :active true] [:like :email "%@example.com%"]]
(create-admin-service db-ctx schema-provider logger error-reporter config)(create-admin-service db-ctx
schema-provider
logger
error-reporter
config
event-publisher)(create-admin-service db-ctx
schema-provider
logger
error-reporter
config
event-publisher
workflows)(create-admin-service db-ctx
schema-provider
logger
error-reporter
config
event-publisher
workflows
writers)Create new AdminService instance.
Args: db-ctx: Database context map with :adapter and :datasource schema-provider: ISchemaProvider implementation logger: Logger instance for operation logging error-reporter: Error reporter for exception tracking config: Admin configuration map with pagination settings event-publisher: optional wagoe.events IEventPublisher (BOU-492) workflows: optional IEntityWorkflows; deletes remove workflow instances (BOU-563) writers: optional {keyword IEntityWriter}, named by an entity's :writer (BOU-665)
Returns: AdminService instance implementing IAdminService
Create new AdminService instance.
Args:
db-ctx: Database context map with :adapter and :datasource
schema-provider: ISchemaProvider implementation
logger: Logger instance for operation logging
error-reporter: Error reporter for exception tracking
config: Admin configuration map with pagination settings
event-publisher: optional wagoe.events IEventPublisher (BOU-492)
workflows: optional IEntityWorkflows; deletes remove workflow instances (BOU-563)
writers: optional {keyword IEntityWriter}, named by an entity's :writer (BOU-665)
Returns:
AdminService instance implementing IAdminService(delete-removing this entity-name ids)Delete like bulk-delete-entities; return {:entity :id :prior} per row removed.
Delete like bulk-delete-entities; return {:entity :id :prior} per row removed.
(prepare-values-for-db m)m with its UUIDs as strings. An Instant is left for the adapter to encode
(BOU-655).
`m` with its UUIDs as strings. An Instant is left for the adapter to encode (BOU-655).
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |