|
2 | 2 | Core Data Types |
3 | 3 | =============== |
4 | 4 |
|
5 | | -The core types supported by Cypher all map to core types in Python. |
6 | | -Booleans, Integers, Floats and Strings can all be stored as single value or array properties. |
7 | | -Byte Arrays can also be stored but do not have a single value equivalent. |
8 | | - |
9 | | -============= ======== ============== =========================== ============= |
10 | | -Cypher Type Property Array Property Python 2 Type Python 3 Type |
11 | | -============= ======== ============== =========================== ============= |
12 | | -Null *no* *no* :const:`None` :const:`None` |
13 | | -Boolean *yes* *yes* ``bool`` ``bool`` |
14 | | -Integer *yes* *yes* ``int``/``long`` :sup:`[1]` ``int`` |
15 | | -Float *yes* *yes* ``float`` ``float`` |
16 | | -String *yes* *yes* ``unicode`` :sup:`[2]` ``str`` |
17 | | -Byte Array *no* *yes* ``bytearray`` ``bytearray`` |
18 | | -List *no* *no* ``list`` ``list`` |
19 | | -Map *no* *no* ``dict`` ``dict`` |
20 | | -============= ======== ============== =========================== ============= |
| 5 | +.. note:: |
| 6 | + The Python types mentioned here are based on Python 3. |
| 7 | + Differences for Python 2 are highlighted in the `footnotes <#footnotes-for-python-2-users>`_. |
| 8 | + |
| 9 | +Cypher supports a set of core data types that all map to built-in types in Python. |
| 10 | +These include the common `Boolean`, `Integer`, `Float` and `String` types as well as `List` and `Map` that can hold heterogenous collections of any other type. |
| 11 | +The core types with their general mappings are listed below: |
| 12 | + |
| 13 | +================ ============= |
| 14 | +Cypher Type Python Type |
| 15 | +================ ============= |
| 16 | +Null :const:`None` |
| 17 | +Boolean ``bool`` |
| 18 | +Integer ``int`` |
| 19 | +Float ``float`` |
| 20 | +String ``str`` |
| 21 | +Bytes :sup:`[1]` ``bytearray`` |
| 22 | +List ``list`` |
| 23 | +Map ``dict`` |
| 24 | +================ ============= |
21 | 25 |
|
22 | 26 | .. admonition:: Notes |
23 | 27 |
|
24 | | - 1. While Cypher uses 64-bit signed integers, `int` can only hold integers up to `sys.maxint` in Python 2; `long` is used for values above this. |
25 | | - 2. In Python 2, a ``str`` passed as a parameter will always be implicitly converted to ``unicode`` via UTF-8. |
| 28 | + 1. `Bytes` is not an actual Cypher type but is transparently passed through when used in parameters or query results. |
| 29 | + |
| 30 | + |
| 31 | +In reality, the actual conversions and coercions that occur as values are passed through the system are more complex than just a simple mapping. |
| 32 | +The diagram below illustrates the actual mappings between the various layers, from driver to data store, for the core types. |
| 33 | + |
| 34 | +.. image:: ../_images/core_type_mappings.svg |
| 35 | + :target: ../_images/core_type_mappings.svg |
| 36 | + |
| 37 | + |
| 38 | +Footnotes for Python 2 users |
| 39 | +============================ |
| 40 | + |
| 41 | +1. While Cypher uses 64-bit signed integers, ``int`` can only hold integers up to ``sys.maxint`` in Python 2; ``long`` is used for values above this. |
| 42 | +2. Python 2 uses ``unicode`` instead of ``str`` for Unicode text. |
| 43 | + However, a Python 2 ``str`` passed as a parameter will always be implicitly converted to ``unicode`` via UTF-8. |
0 commit comments