Skip to content

Add support for updating a struct passed to Insert using ref T #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
35 changes: 35 additions & 0 deletions Runtime/SQLiteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,39 @@ static SQLite3()
#endif
}
}

public static class ISQLiteConnectionExtensions
{
public static int Insert<T>(this ISQLiteConnection connection, ref T obj)
{
object boxed = obj;
int result = connection.Insert(boxed);
obj = (T) boxed;
return result;
}

public static int Insert<T>(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<T>(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<T>(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;
}
}
}