Exemplo n.º 1
0
        /// <summary>
        ///     Opens an existing or creates a new database at the given file path.
        /// </summary>
        /// <param name="databasePath"></param>
        /// <param name="supportedTypes">The list of custom types which are to be stored in / retrieved from the database</param>
        /// <returns></returns>
        public static IDatabase OpenOrCreate(string databasePath, IEnumerable <Type> supportedTypes)
        {
            if (!File.Exists(databasePath))
            {
                Log.DebugFormat("Creating new database '{0}'...", databasePath);

                SQLiteConnection.CreateFile(databasePath);
            }
            else
            {
                Log.DebugFormat("Opening database '{0}'...", databasePath);
            }

            var connectionString = CreateConnectionString(databasePath);
            var connection       = new SQLiteConnection(connectionString);

            try
            {
                connection.Open();
                CreateTablesIfNecessary(connection);
                var database = new IsabelDb(connection, databasePath, supportedTypes, true, false);

                Log.DebugFormat("Successfully openeing database '{0}'!", databasePath);

                return(database);
            }
            catch (Exception)
            {
                connection.Dispose();
                throw;
            }
        }
Exemplo n.º 2
0
 public Transaction(IsabelDb database, SQLiteTransaction transaction, IReadOnlyList <IInternalCollection> collections)
 {
     _database    = database;
     _transaction = transaction;
     _collections = collections;
 }