Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SQLite :memory: databases. #551

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

claytonrcarter
Copy link

These were some fairly simple changes that don't really add support for SQLite :memory: databases, so much as they unlock support for them.

Use Case:
Unit testing code that uses PHP-AR without relying on a live db connection. I can use sqlite://:memory: for my testing environment, run migrations in my test set_up(), then run tests. Super fast. ⚡

Notes:

  • $cached_connection was needed in SqliteAdapter so that a new, empty db wasn’t created on every call to a Model.
  • Added tests for :memory: databases by just running all SQLite tests again with sqlite://:memory: as DSN instead of sqlite://test.db. It would be good for someone to confirm that this is really testing what it should be testing.
  • I did not setup OCI for testing, but all other adapters passed tests.

$cached_connection was needed so that new, empty db wasn’t created on every call.
}
catch (ActiveRecord\DatabaseException $e)
{
$this->assertFalse(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be using $this->fail('optional message');

@koenpunt
Copy link
Collaborator

Think this looks fine, apart from the comment before. Although have not tested it yet.

@claytonrcarter
Copy link
Author

Fixed the assertion. Thanks!

@@ -177,6 +178,9 @@ public static function parse_connection_url($connection_url)
{
$url = @parse_url($connection_url);

if ( $url['scheme'] == "sqlite" && $url['host'] == ":memory" )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind dropping whitespace between parens?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. I think I found and fixed them all. Thanks!

@SeinopSys
Copy link

Is this expected to be merged? I'd like to use a memory adapter but I can't on the current release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants