Skip to content

Commit 7b722ce

Browse files
authored
Merge pull request #49 from gilzoide/feature/struct-insert
Add support for updating a struct passed to Insert using `ref T`
2 parents bab4be6 + c46b579 commit 7b722ce

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22
## [Unreleased](https://github.com/gilzoide/unity-sqlite-net/compare/1.2.0...HEAD)
3+
### Added
4+
- Add support for updating a struct passed to `Insert` with overload accepting `ref T`
5+
36
### Fixed
47
- Support for struct return types in queries
58

Runtime/SQLiteExtensions.cs

+35
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,39 @@ static SQLite3()
8181
#endif
8282
}
8383
}
84+
85+
public static class ISQLiteConnectionExtensions
86+
{
87+
public static int Insert<T>(this ISQLiteConnection connection, ref T obj)
88+
{
89+
object boxed = obj;
90+
int result = connection.Insert(boxed);
91+
obj = (T) boxed;
92+
return result;
93+
}
94+
95+
public static int Insert<T>(this ISQLiteConnection connection, ref T obj, Type objType)
96+
{
97+
object boxed = obj;
98+
int result = connection.Insert(boxed, objType);
99+
obj = (T) boxed;
100+
return result;
101+
}
102+
103+
public static int Insert<T>(this ISQLiteConnection connection, ref T obj, string extra)
104+
{
105+
object boxed = obj;
106+
int result = connection.Insert(boxed, extra);
107+
obj = (T) boxed;
108+
return result;
109+
}
110+
111+
public static int Insert<T>(this ISQLiteConnection connection, ref T obj, string extra, Type objType)
112+
{
113+
object boxed = obj;
114+
int result = connection.Insert(boxed, extra, objType);
115+
obj = (T) boxed;
116+
return result;
117+
}
118+
}
84119
}

0 commit comments

Comments
 (0)