From f7bd3d75e73f2d06d83d533ee347dc2846cf9b30 Mon Sep 17 00:00:00 2001 From: gilzoide Date: Sat, 1 Feb 2025 14:31:03 -0300 Subject: [PATCH 1/2] Add support for Inserting struct and get updated values back --- Runtime/SQLiteExtensions.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Runtime/SQLiteExtensions.cs b/Runtime/SQLiteExtensions.cs index 2140832..e682b16 100644 --- a/Runtime/SQLiteExtensions.cs +++ b/Runtime/SQLiteExtensions.cs @@ -81,4 +81,39 @@ static SQLite3() #endif } } + + public static class ISQLiteConnectionExtensions + { + public static int Insert(this ISQLiteConnection connection, ref T obj) + { + object boxed = obj; + int result = connection.Insert(boxed); + obj = (T) boxed; + return result; + } + + public static int Insert(this ISQLiteConnection connection, ref T obj, Type objType) + { + object boxed = obj; + int result = connection.Insert(boxed, objType); + obj = (T) boxed; + return result; + } + + public static int Insert(this ISQLiteConnection connection, ref T obj, string extra) + { + object boxed = obj; + int result = connection.Insert(boxed, extra); + obj = (T) boxed; + return result; + } + + public static int Insert(this ISQLiteConnection connection, ref T obj, string extra, Type objType) + { + object boxed = obj; + int result = connection.Insert(boxed, extra, objType); + obj = (T) boxed; + return result; + } + } } From c46b579bcea7072556e4e77b0d71f8c95da9d497 Mon Sep 17 00:00:00 2001 From: gilzoide Date: Sat, 1 Feb 2025 14:36:42 -0300 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08f3a3c..3d5877a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog ## [Unreleased](https://github.com/gilzoide/unity-sqlite-net/compare/1.2.0...HEAD) +### Added +- Add support for updating a struct passed to `Insert` with overload accepting `ref T` + ### Fixed - Support for struct return types in queries