Question: I am using SqlAlchemy, a python ORM library. And I used to access database directly from business layer directly by calling SqlAlchemy API.

But then I found that would cause too much time to run all my test cases and now I think maybe I should create a DB access layer, so I can use mock objects during test instead of access database directly.

I think there are 2 choices to do that :

1. use a single class which contains a DB connection and many methods like addUser/delUser/updateUser, addBook/delBook/updateBook. But this means this *class* will be very large.
2. Another approach is create different manager classes like "UserManager", "BookManager". But that means I have to pass a list of managers to Business layer, which seems a little Cumbersome.

How will you organize a database layer?

Answer: 
I would set up a database connection during testing that connects to a in memory database instead. Like so:

```
sqlite_memory_db = create_engine('sqlite://')

```

That will be pretty much as fast as you can get, you are also not connecting to a real database, but just a temporary one in memory, so you don't have to worry about the changes done by your tests remaining after the test, etc. And you don't have to mock anything.
SQLAlchemy has some facilities for [making mocking easier](http://svn.sqlalchemy.org/sqlalchemy/trunk/lib/sqlalchemy/engine/strategies.py) -- maybe that would be easier than trying to rewrite whole sections of your project?