SQLite Queries Xamarin.Forms
public class LocalDB
{
private SQLiteConnection _sqlconnection;
bool returnvalue;
public LocalDB()
{
//Getting conection and Creating table
_sqlconnection = DependencyService.Get<ISQLite>().GetConnection();
_sqlconnection.CreateTable<SampleModel>();
}
//Get all
public IEnumerable<SampleModel> GetAllLocation()
{
return (from t in _sqlconnection.Table<SampleModel>() select t).ToList();
}
//Get specific
public SampleModel GetSingleLocation(int id)
{
return _sqlconnection.Table<SampleModel>().FirstOrDefault(t => t.ID == id);
}
//Delete specific
public void DeleteLocation(int id)
{
_sqlconnection.Delete<SampleModel>(id);
}
//Add new to DB
public void AddLocation(SampleModel location)
{
_sqlconnection.Insert(location);
}
//Delete All Data from Table
public void DeleteAllSavedLocations()
{
_sqlconnection.DeleteAll<SampleModel>();
}
public void DeleteTrackedData(int id)
{
_sqlconnection.Delete<SampleModel>(id);
}
//Count the Data in LocalDB
public bool IsOfflineLocationsFound()
{
int rowCount;
rowCount = _sqlconnection.Table<SampleModel>().Count();
if (rowCount > 0)
{
returnvalue = true;
}
return returnvalue;
}
public User singleuser(string user)
{
return _sqlconnection.Query<User>("select * from [User] where email = ?", user).FirstOrDefault();
}
}
{
private SQLiteConnection _sqlconnection;
bool returnvalue;
public LocalDB()
{
//Getting conection and Creating table
_sqlconnection = DependencyService.Get<ISQLite>().GetConnection();
_sqlconnection.CreateTable<SampleModel>();
}
//Get all
public IEnumerable<SampleModel> GetAllLocation()
{
return (from t in _sqlconnection.Table<SampleModel>() select t).ToList();
}
//Get specific
public SampleModel GetSingleLocation(int id)
{
return _sqlconnection.Table<SampleModel>().FirstOrDefault(t => t.ID == id);
}
//Delete specific
public void DeleteLocation(int id)
{
_sqlconnection.Delete<SampleModel>(id);
}
//Add new to DB
public void AddLocation(SampleModel location)
{
_sqlconnection.Insert(location);
}
//Delete All Data from Table
public void DeleteAllSavedLocations()
{
_sqlconnection.DeleteAll<SampleModel>();
}
public void DeleteTrackedData(int id)
{
_sqlconnection.Delete<SampleModel>(id);
}
//Count the Data in LocalDB
public bool IsOfflineLocationsFound()
{
int rowCount;
rowCount = _sqlconnection.Table<SampleModel>().Count();
if (rowCount > 0)
{
returnvalue = true;
}
return returnvalue;
}
public User singleuser(string user)
{
return _sqlconnection.Query<User>("select * from [User] where email = ?", user).FirstOrDefault();
}
}
Comments
Post a Comment