🏠 Room Database āĻ•ী āϧāϰāύেāϰ āĻĄাāϟা āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰে? 🏠

 

🏠 Room Database āĻ•ী āϧāϰāύেāϰ āĻĄাāϟা āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰে? 🏠

Room Database āĻŽূāϞāϤ SQLite-āĻāϰ āωāĻĒāϰ āĻ­িāϤ্āϤি āĻ•āϰে āϤৈāϰি, āϝা āφāĻŽাāĻĻেāϰ āĻ…্āϝাāύ্āĻĄ্āϰāϝ়েāĻĄ āĻ…্āϝাāĻĒে āϏ্āϟ্āϰাāĻ•āϚাāϰ্āĻĄ āĻĄাāϟা (Structured Data) āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āϏাāĻšাāϝ্āϝ āĻ•āϰে। āĻ•িāύ্āϤু āĻĒ্āϰāĻļ্āύ āĻšāϞো, Room āĻ•ী āϧāϰāύেāϰ āĻĄাāϟা āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰে? 🤔


đŸŽ¯ ā§§. āϏাāϧাāϰāĻŖ āĻĒ্āϰিāĻŽিāϟিāĻ­ āĻĄাāϟা āϟাāχāĻĒ (Primitive Data Types)

Room āϏāϰাāϏāϰি āύিāϚেāϰ āĻĄাāϟা āϟাāχāĻĒāĻ—ুāϞো āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰে:

āĻĄাāϟা āϟাāχāĻĒ āωāĻĻাāĻšāϰāĻŖ
int 10, -5, 1000
long 1700000000L (Timestamp)
float 12.34f
double 99.99
boolean true, false
String "Hello Room"

Example:

@Entity
public class User {
    @PrimaryKey(autoGenerate = true)
    public int id;
    
    public String name;
    
    public int age;
    
    public boolean isActive;
}

💡 āĻāĻ–াāύে int, String, boolean āϟাāχāĻĒেāϰ āĻĄাāϟা Room āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰে।


đŸŽ¯ ⧍. Date āĻŦা Timestamp āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা

Room āϏāϰাāϏāϰি Date āϟাāχāĻĒ āϏাāĻĒোāϰ্āϟ āĻ•āϰে āύা। āĻāϜāύ্āϝ āφāĻŽাāĻĻেāϰ TypeConverter āĻŦ্āϝāĻŦāĻšাāϰ āĻ•āϰāϤে āĻšā§Ÿ।

Example:

public class Converters {
    @TypeConverter
    public static Long fromDate(Date date) {
        return date == null ? null : date.getTime();
    }

    @TypeConverter
    public static Date toDate(Long timestamp) {
        return timestamp == null ? null : new Date(timestamp);
    }
}

💡 āĻāĻ–āύ āφāĻŽāϰা Date āϟাāχāĻĒ āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰāĻŦো, āĻ•াāϰāĻŖ āĻāϟি long āϟাāχāĻĒে āĻ•āύāĻ­াāϰ্āϟ āĻšāϚ্āĻ›ে


đŸŽ¯ ā§Š. List & Array āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা

Room List<> āĻŦা Array āϏāϰাāϏāϰি āϏাāĻĒোāϰ্āϟ āĻ•āϰে āύা, āĻ•িāύ্āϤু āφāĻŽāϰা JSON String āĻšিāϏেāĻŦে āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰি।

Example (List āϏেāĻ­ āĻ•āϰা):

public class Converters {
    @TypeConverter
    public static String fromList(List<String> list) {
        return list == null ? null : new Gson().toJson(list);
    }

    @TypeConverter
    public static List<String> toList(String value) {
        return value == null ? null : new Gson().fromJson(value, new TypeToken<List<String>>(){}.getType());
    }
}

💡 āĻāĻ–āύ List<String> āĻĄাāϟা Room Database-āĻ āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āϝাāĻŦে! 🚀


đŸŽ¯ ā§Ē. Enum āϟাāχāĻĒ āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা

āφāĻŽāϰা āϝāĻĻি Enum (āϝেāĻŽāύ: EASY, MEDIUM, HARD) āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āϚাāχ, āϤাāĻšāϞে āĻāϟাāĻ•ে String āĻŦা Int āφāĻ•াāϰে āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻšāĻŦে।

Example:

public enum Difficulty {
    EASY, MEDIUM, HARD
}

TypeConverter āĻĻি⧟ে Enum āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা:

public class Converters {
    @TypeConverter
    public static String fromDifficulty(Difficulty difficulty) {
        return difficulty == null ? null : difficulty.name();
    }

    @TypeConverter
    public static Difficulty toDifficulty(String value) {
        return value == null ? null : Difficulty.valueOf(value);
    }
}

💡 āĻāĻ–āύ Difficulty Enum Room Database-āĻ String āĻšিāϏেāĻŦে āϏংāϰāĻ•্āώāĻŖ āĻšāĻŦে


đŸŽ¯ ā§Ģ. Custom Object āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা

Room Custom Object āϏāϰাāϏāϰি āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰে āύা। āĻāϜāύ্āϝ TypeConverter āĻŦ্āϝāĻŦāĻšাāϰ āĻ•āϰāϤে āĻšāĻŦে।

Example:

public class Address {
    public String street;
    public String city;
}

Address āĻ•āύāĻ­াāϰ্āϟাāϰ:

public class Converters {
    @TypeConverter
    public static String fromAddress(Address address) {
        return new Gson().toJson(address);
    }

    @TypeConverter
    public static Address toAddress(String value) {
        return new Gson().fromJson(value, Address.class);
    }
}

💡 āĻāĻ–āύ Address Object āφāĻŽāϰা JSON āĻšিāϏেāĻŦে āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰāĻŦো! 🎉


đŸŽ¯ ā§Ŧ. Bitmap āĻŦা Image āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা

Room Image (Bitmap) āϏāϰাāϏāϰি āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰে āύা। āĻāϜāύ্āϝ āĻāϟাāĻ•ে Byte Array āϤে āĻ•āύāĻ­াāϰ্āϟ āĻ•āϰāϤে āĻšāĻŦে।

Bitmap āĻ•āύāĻ­াāϰ্āϟাāϰ:

public class Converters {
    @TypeConverter
    public static byte[] fromBitmap(Bitmap bitmap) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        return stream.toByteArray();
    }

    @TypeConverter
    public static Bitmap toBitmap(byte[] bytes) {
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    }
}

💡 āĻāĻ–āύ Bitmap → Byte Array → Database āĻ āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āϝাāĻŦে! đŸ–ŧ️


đŸŽ¯ ā§­. Foreign Key (Relation) āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা

Room āĻāĻ•āϟি āϟেāĻŦিāϞেāϰ āϏাāĻĨে āφāϰেāĻ•āϟি āϟেāĻŦিāϞ āϏংāϝুāĻ•্āϤ āϰাāĻ–āϤে āĻĒাāϰে

Example:
āφāĻŽাāĻĻেāϰ User āϟেāĻŦিāϞ āĻāĻŦং Address āϟেāĻŦিāϞ āĻĨাāĻ•āϞে:

@Entity
public class User {
    @PrimaryKey(autoGenerate = true)
    public int id;
    
    public String name;
    
    public int addressId; // Foreign Key
}

💡 āĻāĻ–াāύে User āϟেāĻŦিāϞেāϰ addressId āĻ…āύ্āϝ āϟেāĻŦিāϞেāϰ Address ID-āĻāϰ āϏাāĻĨে āϝুāĻ•্āϤ


āϏাāϰাংāĻļ:

āĻĄাāϟা āϟাāχāĻĒ āĻ•ীāĻ­াāĻŦে āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āϝা⧟?
int, long, float, double, boolean āϏāϰাāϏāϰি āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āϝা⧟
String āϏāϰাāϏāϰি āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āϝা⧟
Date TypeConverter āĻĻি⧟ে Long āĻ āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āĻšā§Ÿ
List<Integer>, List<String> JSON String āĻšিāϏেāĻŦে āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻšā§Ÿ
Enum (EASY, MEDIUM, HARD) TypeConverter āĻĻি⧟ে String āĻŦা int āĻ āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āĻšā§Ÿ
Custom Object (Address, Profile) JSON String āĻšিāϏেāĻŦে āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āĻšā§Ÿ
Bitmap (Image) Byte Array āĻšিāϏেāĻŦে āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āĻšā§Ÿ
Foreign Key (Relation) āĻ…āύ্āϝ āϟেāĻŦিāϞেāϰ ID āϏংāϰāĻ•্āώāĻŖ āĻ•āϰে

đŸ”Ĩ Conclusion:

Room Database āĻĒ্āϰা⧟ āϏāĻŦ āϧāϰāύেāϰ āĻĄাāϟা āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻĒাāϰে, āϤāĻŦে āĻ•িāĻ›ু āĻ•্āώেāϤ্āϰে TypeConverter āĻŦ্āϝāĻŦāĻšাāϰ āĻ•āϰāϤে āĻšā§Ÿ

📌 āĻŽূāϞ āĻŽেāϏেāϜ:

  • āϏাāϧাāϰāĻŖ āĻĄাāϟা (int, String, boolean) āϏāϰাāϏāϰি āϏংāϰāĻ•্āώāĻŖ āĻ•āϰা āϝা⧟
  • āϜāϟিāϞ āĻĄাāϟা (Date, List, Enum, Object) TypeConverter āĻĻি⧟ে āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻšā§Ÿ
  • Image & File Byte Array āϤে āĻ•āύāĻ­াāϰ্āϟ āĻ•āϰāϤে āĻšā§Ÿ

āĻāĻ–āύ āϤুāĻŽি Room-āĻ āĻ•ীāĻ­াāĻŦে āĻ•োāύ āĻĄাāϟা āϏংāϰāĻ•্āώāĻŖ āĻ•āϰāϤে āĻšā§Ÿ, āϤা āĻĒুāϰোāĻĒুāϰি āĻŦুāĻāϤে āĻĒেāϰেāĻ›ো! 🚀đŸ”Ĩ

Comments

Popular posts from this blog

AI (Artificial Intelligence) āϏāĻšāϜāĻ­াāĻŦে āĻŦোāĻাāϰ āϜāύ্āϝ āĻāĻ•āĻĻāĻŽ āĻŽāϏ্āϤিāώ্āĻ•-āĻŦাāύ্āϧāĻŦ āĻŦ্āϝাāĻ–্āϝা 🧠🤖

🧠 Regex āĻ•ী?

Kotlin-āĻ āĻ­েāϰিāϝ়েāĻŦāϞ āϘোāώāĻŖা āĻ•āϰাāϰ āĻĻুāχ āωāĻĒাāϝ়