Github as a repository for database (sqlite)
In making http://isthistaxilegal.apphb.com I neede to have a database. I decided to have sqlite, since it needs just a file and the dll’s.( Side Note: The good dll’s for sqlite and .net core are not the original ones, that have a dependency of .NET Framework – but Microsoft.Data.Sqlite ) . But how to deploy this every time?
Simplest way: Verify at start if the file exists, and , if not, download from GitHub
The code is
var url ="https://raw.githubusercontent.com/ignatandrei/IsThisTaxiLegal/master/datas/taxis.sqlite3"; using (var client = new HttpClient()) { using (var result = await client.GetAsync(url)) { if (result.IsSuccessStatusCode) { var bytes=await result.Content.ReadAsByteArrayAsync(); File.WriteAllBytes("taxis.sqlite3",bytes); } } }
And the idea is not so bad – having the database at github and download every time is a good idea…
Leave a Reply