def init_db(configuration: Configuration):
    if configuration.debug:
        local_dir = _try_dir("/opt/too-simple", _IN_USER_DIR)
        database = SqliteDatabase(f"{local_dir}/debug.db")
    else:

        host, port = configuration.pg_db_url.split(":")
        connection_kwargs = dict(host=host,
                                 port=port,
                                 user=configuration.pg_username,
                                 password=configuration.pg_password)
        _create_psql_database(configuration.pg_database, **connection_kwargs)
        database = PostgresqlDatabase(configuration.pg_database,
                                      **connection_kwargs)

    DB.initialize(database)
    if not database.table_exists(Entity.__name__):
        database.create_tables([Entity])
        database.commit()
Пример #2
0
                      client_.status)

        elif command == 2:
            print('Add information')
            add_surname = input('Surname - ')
            add_name = input('Name - ')
            add_age = int(input('Age - '))
            add_sex = input('Sex - ')
            add_status = input('Status - ')
            add_client = Client(surname=add_surname,
                                name=add_name,
                                age=add_age,
                                sex=add_sex,
                                status=add_status)
            add_client.save()
            db.commit()
            print('Information has been added')

        elif command == 3:
            print('Input name and surname of client')
            change_surname = input('Surname - ')
            change_name = input('Name - ')
            change_client = Client.get(Client.surname == change_surname
                                       and Client.name == change_name)
            print('Input information')
            change_client.surname = input('Surname - ')
            change_client.name = input('Name - ')
            change_client.age = int(input('Age - '))
            change_client.sex = input('Sex- ')
            change_client.status = input('Status - ')
            change_client.save()