import sys
import datetime
sys.path.append('/Volumes/Sandisk/Projects/bravaorm')
import bravaorm
from model import *

def json_serial(obj):
    if isinstance(obj, datetime.datetime):
        return obj.isoformat()
    raise TypeError ("Type %s not serializable" % type(obj))

def main():
    conn = bravaorm.Connection(db_user="root", db_password="root", db_host="localhost", db_port=3306, db_database="gofans", log_level="debug")
    adms = conn.administradores.include("modulos").all
    print(f"Total adms: {len(adms)}")
    
    import json
    for ad in adms:
        print(json.dumps(ad.toJSON(), indent=2, default=json_serial))

    print("\nFim")
    conn.close()

if __name__ == "__main__":
    main()
