Base mixin
Utility base class for dataclasses.
BaseMixin
Mixin base class for dataclasses.
Source code in src/snailz/_base_mixin.py
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 63 64 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 | |
as_json(indent=JSON_INDENT)
Convert this object to a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int
|
Indentation. |
JSON_INDENT
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string representation of persistable fields. |
Source code in src/snailz/_base_mixin.py
18 19 20 21 22 23 24 25 26 27 28 | |
persistable()
Create persistable dictionary from object by ignoring all keys
listed in class-level pivot_keys member.
Source code in src/snailz/_base_mixin.py
30 31 32 33 34 35 36 | |
not_null_keys()
Generate set of keys for non-null values in object.
Source code in src/snailz/_base_mixin.py
38 39 40 41 42 | |
persistable_keys()
Generate list of keys to persist for object by ignoring all
keys listed in class-level pivot_keys member.
Source code in src/snailz/_base_mixin.py
44 45 46 47 48 49 50 51 | |
save_csv(outdir, objects)
classmethod
Save objects of derived class as CSV. Derived classes should override this and up-call to save scalar properties, then save properties that need to be pivoted to long form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outdir
|
Path | str
|
Output directory. |
required |
objects
|
list[Any]
|
Objects to save. |
required |
Source code in src/snailz/_base_mixin.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
save_db(db, objects)
classmethod
Save objects of derived class to database. Derived classes should override this and up-call to save scalar properties, then save properties that need to be pivoted to long form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Database
|
Database connector. |
required |
objects
|
list[Any]
|
Objects to save. |
required |
Source code in src/snailz/_base_mixin.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |