Issue: Issue: integration with PostgreSQL 
Author: havannavar
State: closed
Created: 2015-02-12 10:20:01

Hi Charles,

I m trying to integrate between playhouse.flask_utils. FlaskDB and postgresql, but unable to do so.

here is my code and exception

``` python
DATABASE = {
    'name': 'testdb',
    'engine': 'playhouse.pool.PooledPostgresqlDatabase',
    'user': 'sats',
    'max_connections': 32,
    'stale_timeout': 600,
}

app = Flask(__name__)
app.config.from_object(__name__)
database = FlaskDB(app)

class BaseModel(database.Model):
    class Meta:
        database = database

class User(BaseModel):
    class Meta:
        db_table = 'user_auth'

    id = IntegerField(primary_key=True)
    username = CharField(null=True)
    password = CharField(null=True)

@app.route('/api/newuser', methods=['POST'])
def new_user():
    username = request.json.get('username')
     password = request.json.get('password')
        if username is None or password is None:
            abort(400)    # missing arguments
            return 'Either username or password is null'
        try:
            if User.get(username=username) is not None:
                return 'user exists'    # existing user
        except Exception:
            user = User(username=username,id=101,password=password)
            User.save(user)
            #user = User.get(username=username)
```

And the exception is  AttributeError: 'FlaskDB' object has no attribute 'rows_affected'

Full stacktrace:

```
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/WorkSpace/python/flask-peewee-rest/src/testflaskutildb.py", line 99, in new_user

    User.save(user)
  File "/Library/Python/2.7/site-packages/peewee.py", line 3887, in save
    rows = self.update(**field_dict).where(self._pk_expr()).execute()
  File "/Library/Python/2.7/site-packages/peewee.py", line 2614, in execute
    return self.database.rows_affected(self._execute())
AttributeError: 'FlaskDB' object has no attribute 'rows_affected'
```

I have tried different options of DB configuration but not working with postgres
From stack trace, i feel it only supports only Sqlite db


For future reference please take the time to format your code.


This is the issue:

``` python
class BaseModel(database.Model):
    class Meta:
        database = database
```

Setting the `database` to the `FlaskDB` wrapper will not work because peewee models expect the `Meta.database` attribute to be a _peewee_ `Database` subclass. So you should change your code to:

``` python
class BaseModel(database.Model):
    pass
```

Also, you don't technically need a `BaseModel` because that's effectively what `database.Model` is.


thanks it works