schultek / stormberry

Access your postgres database effortlessly from dart code.
https://pub.dev/packages/stormberry
MIT License
66 stars 16 forks source link

why is the isClosed true after successfully connected #72

Open vfiruz97 opened 9 months ago

vfiruz97 commented 9 months ago

I have a problem in the production for reason. There is an issue almost like this issue#57 one. When occur any issue like passing wrong column name or smthg like that and after that sometimes we get closed connection and next queries fall with error Due to closed connection. As I declare my db variable final so I can fix my issue by reloading server. Now I want to check connection state before get Database instance and decide to whether reinitiate connection or not.


void main() async {
  final db = Database(
        '''
  );

  await db.open();
  print('isClosed: ${db.connection().isClosed}');
}

Just for Notice My postgres is running in a different Docker container and my server is running in a different one. When any error occurs on the postgres site, its docker restarts and my server loses connection. How I can check state and reinitiate connection? I am open for any solution

postgress_db:
    container_name: "rohtj_db"
    image: postgres:16
    restart: always
    volumes:
      - ./rohtj_db/data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: rohtjdb
      POSTGRES_USER: rohtjdbuser
      POSTGRES_PASSWORD: ------
      PGDATA: /var/lib/postgresql/data/pgdata
    ports:
      - 5434:5432
    expose:
      - 5434
    networks:
      - rohtj-backend
schultek commented 7 months ago

Please check if this issue still happens with version `0.14.0