-- PostgreSQL database dump
--
-\restrict pljGpSA3LcghRNp7l8VhB9577BShEv8iwmjIVnsBJjUDBiyXWHsvzLrsdBLd4g5
+\restrict pZMXIfcg6Z3bqZxjE81zS0hcdaYCb5acZyYejnUVfbZS81irldi5kwkQVbA7Prg
-- Dumped from database version 17.6 (Debian 17.6-0+deb13u1)
-- Dumped by pg_dump version 17.6 (Debian 17.6-0+deb13u1)
deleted_by text,
license text NOT NULL,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
- description text
+ description text,
+ total_domains integer DEFAULT 0 NOT NULL
);
-- PostgreSQL database dump complete
--
-\unrestrict pljGpSA3LcghRNp7l8VhB9577BShEv8iwmjIVnsBJjUDBiyXWHsvzLrsdBLd4g5
+\unrestrict pZMXIfcg6Z3bqZxjE81zS0hcdaYCb5acZyYejnUVfbZS81irldi5kwkQVbA7Prg
return True
def __len__(self):
- stmt = (
- sqlmodel
- .select(
- sqlmodel.func.count(
- self.__domains.c.name,
- ),
- )
- )
-
- return self.backend.db.fetch_one(stmt)
+ return self.total_domains
def __hash__(self):
# Only hashable once the object has an ID
return self.backend.db.fetch(stmt)
+ # Total Domains
+ total_domains : int
+
# Delete!
def delete(self, deleted_by):
if updated:
self.updated_at = sqlmodel.func.current_timestamp()
+ # Update the stats
+ self.__update_stats()
+
+ def __update_stats(self):
+ stmt = (
+ sqlmodel
+ .select(
+ sqlmodel.func.count(
+ self.__domains.c.name,
+ ),
+ )
+ )
+
+ # Store the number of total domains
+ self.total_domains = self.backend.db.fetch_one(stmt)
+
# Export!
def export(self, f, format, **kwargs):