peewee-async icon indicating copy to clipboard operation
peewee-async copied to clipboard

Test database

Open de-don opened this issue 5 years ago • 3 comments

How I can create database for testing without real database? Like: database = SqliteDatabase(':memory:')

de-don avatar Mar 12 '19 03:03 de-don

I needed the same thing, so I took the liberty of creating my own SqliteDatabase class (it might exist, but couldn't find anything). Thought someone might find it useful.

https://gist.github.com/xsduan/09fb145da3da3a78f5ca844b155f27aa

Some caveats:

  • Since I only needed it to play around with during development without setting up an entire mysql/postgres server, it's a very "works on my machine" deal, e.g. connection pooling is just creating new connections, though I made my best effort to make it presentable.
  • I just copied most of the stuff from the AsyncPostgres* and AsyncMysql* classes until they worked more or less, and only verified that it works on the readme example. I may very well have missed a few things.
  • :memory: Does Not Work. No idea why (maybe something about concurrency?), but writing to file seems like a fair enough compromise to me.

I dunno if sqlite is "useful" enough to make it part of the core, so I'm happy to let it stay a recipe.

xsduan avatar Mar 24 '19 18:03 xsduan

@xsduan Each new connection to sqlite with :memory: database creates its own database, distinct from the others, that is removed upon disconnect. Haven't tried the gist yet but may this be the reason for "does not work"?

altunyurt avatar May 21 '19 18:05 altunyurt

Async driver for sqlite is not provided actually.

rudyryk avatar May 21 '19 18:05 rudyryk