Search code examples
pythonc#litedb

LiteDb compatibility between different languages


I have a .Net app that saves this class in LiteDb:

public class GSR_raw
    {
        public string SystemStamp { get; set; }

        public float unknow { get; set; }

        public float s { get; set; }

        public float UnixTimeStamp { get; set; }

        public float InternalSignal { get; set; }

        public float Conductance { get; set; }

        public float uS { get; set; }

    }

This, of course, generates a .DB file that i'm unable to read using python.

This is the definition of the class in python:

class GSR_raw:

    def __init__(self, SystemStamp: str, unknow: float, s: float,UnixTimeStamp: float, InternalSignal: float, Conductance: float, uS: float):
        self.SystemStamp = SystemStamp
        self.unknow = unknow
        self.s = s
        self.UnixTimeStamp = UnixTimeStamp
        self.InternalSignal = InternalSignal
        self.Conductance = Conductance
        self.uS = uS

    def __repr__(self) -> str:
        return str(self.__dict__)

The error message says: "No table of <class 'classes.GSR_raw'> exists in this database"

The python code that tries to read:

def get_raw_data(path):

    disk_db = DiskDatabase(path)
    temp_data = list(disk_db.select(GSR_raw))

The path is correct as I have already test it.

Is this a problem of compatibility of some sort?


Solution

  • From the code that you've posted I assume that for python you are using this litedb package, and for C# this LiteDB.

    Those are two different databases, it is no wonder that you can't get your object with python db client.

    If you want to work with same objects in different languages, I think, it is better to use some kind of a contract and language agnostic serialization, you can take a look at apache thrift, protobuf or if those seems to be an overkill - simple json serialization.