Inserts - Flaarum Tutorials (Python) Golang
Insertion Method
The insert class expects a dict for its data. Accepted types in the dict are int and str Flaarum provides no statements for inserts. One would need to use a function call for insertions.
Sample Code
import pyflaarum
cl = pyflaarum.flaacl("127.0.0.1", "not-yet-ready", "first_proj")
try:
cl.ping()
except:
print("error connecting")
try:
to_insert = {"field1": "data", "field2": "data too", "field3": 456}
ret_id = cl.insert_row("table1", to_insert)
print(ret_id)
except pyflaarum.flaa_error as fe:
if fe.code == 11:
print("print server error")
print(fe.message)
elif fe.code == 20:
print("validation error")
print(fe.message)
except Exception as e:
print(e)
The flaarum lib expects the address of the database, its keystring (like a password) and the name of the project.
All Error Codes
- 10: Connection Error
- 11: Error happended on server
- 12: Statements Error
- 20: Validation error
- 21: Errors relating to unique constraints
- 22: Errors relating to required constraints
- 23: Errors relating to foreign keys
- 24: Type errors