berlindb / core

All of the required core code
MIT License
252 stars 27 forks source link

db_global abstraction layer? #69

Open alexstandiford opened 3 years ago

alexstandiford commented 3 years ago

If we truly want to make BerlinDB compatible with systems outside of WordPress, it may be prudent to make a change to how Base::get_db() works. Not all systems utilize a DB global in the way WordPress does, and few classes actually have the exact same methods as $wpdb.

It may be best to consider creating an interface that allows BerlinDB to interact with other database systems dynamically. This could implement the methods that Berlin calls directly from $wpdb. This would allow people to translate their system into Berlin's system.

Instead of having BerlinDB look for a global, perhaps it would fetch the specified instance, check if it implements, and use it.

This would require an extra file to make WPDB work with it, which is kind-of a bummer, but I think that's a small price to-pay. Since 2.0 is compatible with Composer, this interface and implementation could be somehow added as a composer package. This would make installing a WP-compatible version of Berlin as simple as running composer require berlindb/wordpress, or something similar.

Further, I can see this pattern being used in other places, such as an object cache implementation.

JJJ commented 3 years ago

Completely agree. I think it's perfectly OK for there to be a new file for this.