Changes between Version 2 and Version 3 of JSON1Extension
- Timestamp:
- Aug 14, 2020, 1:40:39 AM (4 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
JSON1Extension
v2 v3 5 5 ================================== 6 6 7 To use **django.db.models.JSONField** on SQLite, you need to enable the `JSON1 extension`__ on Python's `sqlite3`__ library. If the extension is not enabled on your installation, a system error (``fields.E180``) will be raised. To check if the extension is enabled on your installation, you can do a query with one of the functions included in the extension, e.g. ``JSON()``. For example:: 7 To use **django.db.models.JSONField** on SQLite, you need to enable the `JSON1 extension`__ 8 on Python's `sqlite3`__ library. If the extension is not enabled on your installation, a system error 9 (``fields.E180``) will be raised. To check if the extension is enabled on your installation, you can 10 do a query with one of the functions included in the extension, e.g. ``JSON()``. For example:: 8 11 9 12 >>> import sqlite3 … … 12 15 >>> cursor.execute('SELECT JSON(\'{"a": "b"}\')') 13 16 14 If the query doesn't throw any errors, then the JSON1 extension is already enabled. Otherwise, follow the instructions below according to your operating system to set it up correctly. 17 If the query doesn't throw any errors, then the JSON1 extension is already enabled. Otherwise, 18 follow the instructions below according to your operating system to set it up correctly. 15 19 16 20 .. __: https://www.sqlite.org/json1.html … … 20 24 ===== 21 25 22 On most major Linux distributions, the JSON1 extension is included in their SQLite and/or Python packages and enabled by default. If that's not the case on your installation, then do the following: 26 On most major Linux distributions, the JSON1 extension is included in their SQLite and/or Python 27 packages and enabled by default. If that's not the case on your installation, then do the following: 23 28 24 29 - Download the `SQLite amalgamation`__, with or without the configuration script. 25 30 - Extract the source code archive and enter the directory of the result. 26 - Compile the source code using the ``-DSQLITE_ENABLE_JSON1`` flag to enable the JSON1 extension. For example:: 31 - Compile the source code using the ``-DSQLITE_ENABLE_JSON1`` flag to enable the JSON1 32 extension. For example:: 27 33 28 34 gcc -DSQLITE_ENABLE_JSON1 -c -fPIC sqlite3.c … … 34 40 35 41 - Place the resulting file (``libsqlite3.so``) in a desired directory, e.g. ``/usr/lib/sqlite3/``. 36 - Set the ``LD_PRELOAD`` environment variable to use your compiled SQLite every time you run Django. For example:: 42 - Set the ``LD_PRELOAD`` environment variable to use your compiled SQLite every time you run 43 Django. For example:: 37 44 38 45 export LD_PRELOAD=/usr/lib/sqlite3/libsqlite3.so … … 46 53 ===== 47 54 48 On macOS, follow the instructions for Linux above, but instead of setting the ``LD_PRELOAD`` environment variable, use ``DYLD_LIBRARY_PATH``. For example:: 55 `As of Python 3.7`__, the official Python installer on macOS already includes the JSON1 56 extension by default. If you're using an earlier version of Python, you can follow the instructions 57 for Linux above, but instead of setting the ``LD_PRELOAD`` environment variable, use 58 ``DYLD_LIBRARY_PATH``. For example:: 49 59 50 60 export DYLD_LIBRARY_PATH=/usr/lib/sqlite3 61 62 .. __: https://github.com/python/cpython/commit/9625bf520e08828e36bc3b1d043af679eb5f993d 51 63 52 64 Windows 53 65 ======= 54 66 67 `As of Python 3.9`__, the official Python installer on Windows already includes the JSON1 68 extension by default. If you're using an earlier version of Python, you can do the following: 69 70 .. __: https://github.com/python/cpython/commit/58d6f2ee3aeb699156d4784acccd2910d27982e7 71 55 72 - Download the `precompiled DLL`__ that matches your Python installation (32-bit or 64-bit). 56 - Locate your Python installation. By default, it should be in ``%localappdata%\Programs\Python\PythonXX``, where ``XX`` is the Python version. For example, it's located in ``C:\Users\<username>\AppData\Local\Programs\Python\Python37``. If you added Python installation directory to your ``PATH`` environment variable, you can run the command ``where python`` on a command prompt to locate it. 73 - Locate your Python installation. By default, it should be in 74 ``%localappdata%\Programs\Python\PythonXX``, where ``XX`` is the Python version. For 75 example, it's located in ``C:\Users\<username>\AppData\Local\Programs\Python\Python37``. 76 If you added Python installation directory to your ``PATH`` environment variable, you can run the 77 command ``where python`` on a command prompt to locate it. 57 78 - Enter the ``DLLs`` directory in your Python installation. 58 79 - Rename (or delete) ``sqlite3.dll`` inside the ``DLLs`` directory.