GSOC 2023: A proposal to add SurrealDB to Django

Abstract

SurrealDB is a scalable, distributed, collaborative, document-graph database, for the real-time web. It combines the database layer, the querying layer, and the API and authentication layer into one platform. It supports SQL querying from client devices, GraphQL, ACID transactions, WebSocket connections, structured and unstructured data, graph querying, full-text indexing, geospatial querying, and row-by-row permissions-based access.

The goal of this project is to add SurrealDB as a backend option for Django applications. This will allow Django developers to leverage the features and benefits of SurrealDB without having to write custom code or use third-party libraries. The project will involve implementing a database wrapper for SurrealDB that conforms to the Django database API.

Detailed design

The project will consist of the following components:

  • A database wrapper for SurrealDB that implements the required methods and attributes of the django.db.backends.base.BaseDatabaseWrapper class. The wrapper will use SurrealDB’s Python client library to communicate with the database server via WebSocket or HTTP. The wrapper will also handle schema creation and migration using SurrealDB’s SQL support.

  • A database introspection module for SurrealDB that implements the required methods and attributes of the django.db.backends.base.BaseDatabaseIntrospection class. The module will use SurrealDB’s SQL support to query the database metadata and provide information about the tables, columns, indexes, constraints, etc.

  • A database creation module for SurrealDB that implements the required methods and attributes of the django.db.backends.base.BaseDatabaseCreation class. The module will use SurrealDB’s SQL support to create and destroy test databases for running Django’s test suite.

  • A database client module for SurrealDB that implements the required methods and attributes of the django.db.backends.base.BaseDatabaseClient class. The module will provide a command-line interface for executing SQL statements directly on the database server using SurrealDB’s CLI tool.

  • A database-features module for SurrealDB that implements the required methods and attributes of the django.db.backends.base.BaseDatabaseFeatures class. The module will indicate which features are supported or not supported by SurrealDB, such as transactions, foreign keys, savepoints, etc.

  • A database operations module for SurrealDB that implements the required methods and attributes of the django.db.backends.base.BaseDatabaseOperations class. The module will provide various database-specific operations, such as quoting column names, converting values to database types, escaping wildcards, etc.

  • A database schema editor module for SurrealDB that implements the required methods and attributes of the django.db.backends.base.BaseDatabaseSchemaEditor class. The module will provide methods for creating, altering, and deleting tables, columns, indexes, constraints, etc. using SurrealDB’s SQL support.

  • A settings module that defines the configuration options for using SurrealDB as a backend for Django applications. The module will include options such as database name, host, port, username, password, SSL certificate, etc.

2 Likes

Hi @carltongibson, could you please go over the proposal when you have the time and share your thoughts?

Please be patient. I’m sure he’ll review it when he gets a chance to do so.

I’d just add my wholehearted, sincere upvote for this proposal as well. I’m already using SurrealDB with Django but would love for a more wholesome integration. I think SurrealDB complements Django quite well actually.

1 Like

I agree with the above! Surrealdb is the future and its integration can allow django to open doors to modern ways into ai, etc

<opinion>
This actually isn’t something that needs to be in Django.

This is one of those types of projects that would probably be better implemented as a third-party package, to demonstrate the viability and its value.

This wouldn’t be the first example of its type, either. A list of third-party database engines can be found at Databases | Django documentation | Django. (MongoDB is also supported by a third-party package called Djongo)
</opinion>

Hi Ayush, I’ve worked as a contractor to develop and maintain several third-party database backends (CockroachDB, Google Cloud Spanner, and Snowflake.) These projects are stewarded by the database’s company, not by the Django organization. if I were trying to make this happen, I would make my pitch to SurrealDB rather than to the Django organization.