API Reference
neodb.core.NeoDB
An in-memory database that manages named collections.
Attributes:
| Name | Type | Description |
|---|---|---|
dbname |
The name of the database. |
|
collections |
A dictionary of collection names to NeoCollection instances. |
Source code in neodb/core.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
__init__(dbname='neodb')
Initializes NeoDB with the given database name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dbname
|
The name of the database. Defaults to "neodb". |
'neodb'
|
Source code in neodb/core.py
9 10 11 12 13 14 15 16 17 | |
collection(collection_name=None)
Gets or creates a collection by name.
If no name is provided, an auto-generated name is used (e.g., "Collection_1", "Collection_2"). If a collection with the given name already exists, the existing instance is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
The name of the collection. Defaults to None, which triggers auto-naming. |
None
|
Returns:
| Type | Description |
|---|---|
|
The NeoCollection instance for the given name. |
Source code in neodb/core.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
drop_collection(collection_name)
Drops a collection by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
str
|
The name of the collection to drop. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the collection existed and was dropped, False otherwise. |
Source code in neodb/core.py
50 51 52 53 54 55 56 57 58 59 60 61 62 | |
list_collections()
Lists all collection names in the database.
Returns:
| Type | Description |
|---|---|
list
|
A list of collection name strings. |
Source code in neodb/core.py
42 43 44 45 46 47 48 | |
neodb.core.NeoCollection
A key-value store with optional indexing support.
Records are stored as simple key-value pairs. Optional indexes allow fast lookups by index name and value. A reverse index is maintained for efficient cleanup on delete or update.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
The name of the collection. |
|
records |
A dictionary mapping keys to their values. |
|
indexes |
A forward index mapping
|
|
reverse_indexes |
A reverse index mapping
|
Source code in neodb/core.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
__init__(collection_name)
Initializes a NeoCollection with the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
The name of the collection. |
required |
Source code in neodb/core.py
81 82 83 84 85 86 87 88 89 90 | |
delete(key)
Deletes a record and cleans up its indexes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
The key to delete. |
required |
Returns:
| Type | Description |
|---|---|
|
True if the key existed and was deleted, False otherwise. |
Source code in neodb/core.py
142 143 144 145 146 147 148 149 150 151 152 | |
find_keys(index_name, index_value)
Finds all keys matching a given index name and value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_name
|
The name of the index to search. |
required | |
index_value
|
The index value to match. |
required |
Returns:
| Type | Description |
|---|---|
|
A set of keys matching the index, or an empty set if no |
|
|
match is found. |
Source code in neodb/core.py
154 155 156 157 158 159 160 161 162 163 164 165 | |
get(key)
Retrieves the value for a given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
The key to look up. |
required |
Returns:
| Type | Description |
|---|---|
|
The stored value, or None if the key does not exist. |
Source code in neodb/core.py
92 93 94 95 96 97 98 99 100 101 102 | |
put(key, value, indexes=None)
Stores a value under the given key with optional indexes.
If the key already exists, the old value and its indexes are replaced. Index entries are automatically maintained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
The key to store the value under. |
required | |
value
|
The value to store. |
required | |
indexes
|
An optional dictionary of |
None
|
Source code in neodb/core.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |