

Sqlite studio for mac code#
This code is inside the AppDelegate.cs file. Basically this means that the Library folder is inside the Personal folder, only I cannot get the path to the Library folder as straight forward as I can with the Personal folder, so I need to combine a couple of strings to access it. Instead I navigate to the parent directory, and then over to another directory: the Library folder. In this case I also access the personal folder to quickly get that path, but that is not the path where the database is to be stored. Very similar to what we do in the case of Android, except that the directory where the database file is stored needs to be different. This method makes sure that these strings are correctly combined into a string that is formatted as a path.Įventually, I am passing the dbPath to the second overload of the App's constuctor. Notice that I use the Path's Combine method to combine this two strings together (the name of the file and the path of the directory where it will be stored). In the case of Android, the database has to be stored in the personal folder.

Hence I will create an overload of the App's constructor that will have the same functionality, but will also add some functionality of its own. Since each project is already calling this method, we may as well use this code for them to pass the platform-specific path the project will work with.

The reason I explain this is because it will be precisely the App class' constructor that we will use to receive a string from those projects. This class is in the shared project, and the constructor is the one that establishes the first view to be displayed, this is how each platform initializes itself with the code inside the shared project (whether that is a PCL. To be able to get that platform-specific folder path, I want you to notice that inside the MainActivity.cs (Android project), the AppDelegate.cs (iOS project), and the (UWP project) there is a call to the XamarinNotesApp.App's constructor. So this is the only code that can't be shared since each platform must specify this. The database pathĮach platform will require a different path where to store the database file, mainly because each platform has a different directory structure. The "sqlite-net-pcl" package is the one to add, don't be confused by the fact that it has PCL in its name, it will work perfectly with a.
Sqlite studio for mac for mac#
In Visual Studio 2017 all you need to do is right click on the solution and select "Manage NuGet packages for solution", in the case of Visual Studio for Mac you will have to go to each project, right click on the References folder and select "add reference". This is the package that already contains all the functionality needed regarding connections and CRUD requests to an SQLite database, you will then have to add it to all your projects. NET Standard, but the implementation is identical, except for the folder where you need to reference the SQLite packages.įYI you can find all the code for this example in this repository. If you are using Visual Studio for Mac, UWP won't be an option, and maybe your code sharing strategy will be PCL instead of. NET Standard library as a code sharing strategy and that I will cover Android, iOS and UWP implementation. I do want to specify that I created this project using a. If you are not familiar with XAML maybe check one of my previous posts first. While I will briefly explain the code that I use to define the interface, I will focus on the SQLite functionality itself, not really talking about the event handlers and the definition of elements inside the XAML file. Specifically, we will be creating a simple notes app, with a couple of views: one where the user will see the list of notes and another one for creating a note. I don't need to argue that databases are of great importance in almost any kind of application, so in this post, I will cover the usage of local SQLite databases inside a Xamarin Forms app.
