1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

MySQL Data Type for storing inventory?

Discussion in 'Development' started by Levi, Apr 7, 2019.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    what data type should i use for storing inventory in mysql?

    I json_encode and decode

    varchar(255)?
    or longtext?
    or what?
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    How are you encoding the inventory contents? They can be stored as a BLOB (or maybe a lengthy VARBINARY) if you serialize them using BigEndianNBTStream.
     
  3. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    in an array
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Sorry, I skipped over the part where you said you json encode them. You could directly go with the JSON data type if you're on MySQL 8.0 or else TEXT would do.
     
  5. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    does text have a llimit?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yeah. Actually, since you're json_encoding them, go with LONGTEXT as the encoded data is definitely much longer in comparison to items encoded in binary using the BigEndianNBTStream ce.PNG
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You shouldn't use JSON at all. Store the items of an inventory in separate rows. Only use JSON when you cannot determine the types present.
     
  9. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Then I create 16 rows or the max slot in a chest?[/QUOTE]
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    [/QUOTE]
    Create one row for each item and link them to a chest using foreign keys.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.