jimfunk / django-postgresql-netfields

Proper INET and CIDR fields for Django running on PostgreSQL
BSD 3-Clause "New" or "Revised" License
154 stars 65 forks source link

It would be nice to have functional equivalents in SQLite #109

Closed alper closed 3 years ago

alper commented 3 years ago

I see now that the package name and the project name are different here, but for local testing of netfields, it would be nice to have functional parity using other database engines particularly SQLite.

I see there are some unmaintained extensions there that maybe fill in some of the gaps but it seems like a bigger project in general to tackle this.

https://github.com/mobigroup/sqlite3-inet

jimfunk commented 3 years ago

I took a look at that extension, but unfortunately it appears to be missing IPv6 support and a number of the query operators. It also appears to be unmaintained.

It would probably be cleaner to start a new project for that, but it would also require updates or a replacement for the SQLite extension. If such a thing existed AND was fully functional, then it could be a useful addition here, but I am not interested in taking on such an effort.

If the purpose of such a thing is for testing, it's not's hard to set up PostgreSQL and a user that can create test databases.

cbwest3-ntnx commented 3 years ago

@jimfunk, I'm interested in SQLite parity as well. I would prefer to use netfields+Postgres for our project (we run Postgres in prod), but it's hard to ditch the speed of SQLite for local testing during development.

Would it be feasible to mirror the Postgres functionality for the SQLite backend using a naive column type and do Postgres function equivalents in Python, even if performance is subpar? It seems like a significant code change. Would the project be receptive to such a change? Thanks!

cbwest3-ntnx commented 3 years ago

Upon further review, it seems Django doesn't allow one to implement Functions and Lookups in Python to bridge a feature gap between databases, which I assume is due to the lazy execution of QuerySets. Django functions and lookups only craft custom SQL expressions to meet syntax expectations of whatever the database backend.

jimfunk commented 3 years ago

Yes, the functionality here is a lot more than simply storing addresses and converting data upon retrieval. It's about making queries such as "address is in a range." Those kinds of things would require database support. Supposedly that can be done, but it would be module on the SQLite side.

For testing, I simply use a local PostgreSQL instance with a user that can create databases. It's very fast and you don't have to worry about missing any sort of error that would only happen in production.