From f9528ee16d35eb0ca8a1285d2d73c6c925a6e551 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 11:45:41 -0500 Subject: [PATCH] Add Lake model --- models/lake.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 models/lake.py diff --git a/models/lake.py b/models/lake.py new file mode 100644 index 0000000..81447f7 --- /dev/null +++ b/models/lake.py @@ -0,0 +1,34 @@ +Here's a SQLAlchemy model for the "Lake" entity with the description "generate list of lakes in paris": + +```python +from sqlalchemy import Column, String, Text, DateTime +from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy.sql import func +from app.api.db.base_class import Base + +class Lake(Base): + __tablename__ = "lakes" + + id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) + name = Column(String, nullable=False, unique=True, index=True) + description = Column(Text, nullable=True) + location = Column(String, nullable=False) + + created_at = Column(DateTime, server_default=func.now()) + updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now()) + + def __repr__(self): + return f"Lake(id={self.id}, name='{self.name}', location='{self.location}')" +``` + +Explanation: + +- `__tablename__` is set to "lakes" for the table name. +- `id` is the primary key column using `UUID` from the `postgresql` dialect. +- `name` is a required `String` column, unique, and indexed for efficient searches. +- `description` is an optional `Text` column for storing longer descriptions. +- `location` is a required `String` column for storing the location of the lake. +- `created_at` and `updated_at` are `DateTime` columns for tracking when the record was created and last updated, using the database server's default time functions. +- `__repr__` is a custom string representation of the object, useful for debugging. + +This model assumes you're using PostgreSQL as the database and have set up the `Base` class correctly. It also assumes you have the necessary imports from SQLAlchemy and the `app.api.db.base_class` module. \ No newline at end of file