Exemple #1
0
        /// <summary>
        /// Initialize database using any read/write Stream (like MemoryStream)
        /// </summary>
        public LiteDatabase(Stream stream, BsonMapper mapper = null)
        {
            LitePlatform.ThrowIfNotInitialized();

            _mapper = mapper ?? BsonMapper.Global;
            _engine = new LazyLoad <DbEngine>(() => new DbEngine(new StreamDiskService(stream), _log));
        }
        /// <summary>
        /// Starts LiteDB database using a connection string for file system database
        /// </summary>
        public LiteDatabase(ConnectionString connectionString, BsonMapper mapper = null)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }

            _connectionString = connectionString;
            _log.Level        = _connectionString.Log;

            if (_connectionString.Upgrade)
            {
                LiteEngine.Upgrade(_connectionString.Filename, _connectionString.Password);
            }

            _mapper = mapper ?? BsonMapper.Global;

            var options = new FileOptions
            {
                InitialSize = _connectionString.InitialSize,
                LimitSize   = _connectionString.LimitSize,
                Journal     = _connectionString.Journal
            };

            _engine = new LazyLoad <LiteEngine>(() => new LiteEngine(new FileDiskService(_connectionString.Filename, options), _connectionString.Password, _connectionString.Timeout, _connectionString.CacheSize, _log));
        }
Exemple #3
0
 /// <summary>
 /// Starts LiteDB database using full parameters
 /// </summary>
 public LiteDatabase(IDiskService diskService, ushort version = 0)
 {
     _engine = new LazyLoad <DbEngine>(
         () => new DbEngine(diskService, _log),
         () => this.InitializeMapper(),
         () => this.UpdateDbVersion(version));
 }
Exemple #4
0
 /// <summary>
 /// Starts LiteDB database using a connectionString for filesystem database
 /// </summary>
 public LiteDatabase(string connectionString)
 {
     _engine = new LazyLoad <DbEngine>(
         () => new DbEngine(new FileDiskService(connectionString, _log), _log),
         () => this.InitializeMapper(),
         () => this.InitializeDbVersion());
 }
Exemple #5
0
 /// <summary>
 /// Initialize database using any read/write Stream (like MemoryStream)
 /// </summary>
 public LiteDatabase(Stream stream, ushort version = 0)
 {
     _engine = new LazyLoad <DbEngine>(
         () => new DbEngine(new StreamDiskService(stream), _log),
         () => this.InitializeMapper(),
         () => this.UpdateDbVersion(version));
 }
Exemple #6
0
        /// <summary>
        /// Starts LiteDB database using a connection string for file system database
        /// </summary>
        public LiteDatabase(ConnectionString connectionString, BsonMapper mapper = null, Logger log = null)
        {
            _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));

            Log       = log ?? new Logger();
            Log.Level = log?.Level ?? _connectionString.Log;

            if (_connectionString.Upgrade)
            {
                LiteEngine.Upgrade(_connectionString.Filename, _connectionString.Password);
            }

            Mapper = mapper ?? BsonMapper.Global;

            var options = new FileOptions
            {
#if HAVE_SYNC_OVER_ASYNC
                Async = _connectionString.Async,
#endif
#if HAVE_FLUSH_DISK
                Flush = _connectionString.Flush,
#endif
                InitialSize = _connectionString.InitialSize,
                LimitSize   = _connectionString.LimitSize,
                Journal     = _connectionString.Journal,
                FileMode    = _connectionString.Mode
            };

            _engine = new LazyLoad <LiteEngine>(() => new LiteEngine(new FileDiskService(_connectionString.Filename, options), _connectionString.Password, _connectionString.Timeout, _connectionString.CacheSize, Log, _connectionString.UtcDate));
        }
        public LiteCollection(string name, LazyLoad <LiteEngine> engine, BsonMapper mapper, Logger log)
        {
            _name     = name ?? mapper.ResolveCollectionName(typeof(T));
            _engine   = engine;
            _mapper   = mapper;
            _log      = log;
            _visitor  = new QueryVisitor <T>(mapper);
            _includes = new List <string>();

            // if strong typed collection, get _id member mapped (if exists)
            if (typeof(T) != typeof(BsonDocument))
            {
                var entity = mapper.GetEntityMapper(typeof(T));
                _id = entity.Id;

                if (_id != null && _id.AutoId)
                {
                    _autoId =
                        _id.DataType == typeof(ObjectId) ? BsonType.ObjectId :
                        _id.DataType == typeof(Guid) ? BsonType.Guid :
                        _id.DataType == typeof(DateTime) ? BsonType.DateTime :
                        _id.DataType == typeof(Int32) ? BsonType.Int32 :
                        _id.DataType == typeof(Int64) ? BsonType.Int64 :
                        BsonType.Null;
                }
            }
        }
Exemple #8
0
 /// <summary>
 /// Starts LiteDB database using full parameters
 /// </summary>
 public LiteDatabase(IDiskService diskService)
 {
     this.InitializeMapper();
     _engine = new LazyLoad <DbEngine>(
         () => new DbEngine(diskService, _log),
         () => this.InitializeMapper(),
         () => this.InitializeDbVersion());
 }
Exemple #9
0
 /// <summary>
 /// Initialize database using any read/write Stream (like MemoryStream)
 /// </summary>
 public LiteDatabase(Stream stream)
 {
     this.InitializeMapper();
     _engine = new LazyLoad <DbEngine>(
         () => new DbEngine(new StreamDiskService(stream), _log),
         () => this.InitializeMapper(),
         () => this.InitializeDbVersion());
 }
Exemple #10
0
 public LiteCollection(string name, LazyLoad <LiteEngine> engine, BsonMapper mapper, Logger log)
 {
     _name     = name;
     _engine   = engine;
     _mapper   = mapper;
     _log      = log;
     _visitor  = new QueryVisitor <T>(mapper);
     _includes = new List <Action <BsonDocument> >();
 }
Exemple #11
0
        /// <summary>
        /// Starts LiteDB database using a connection string for filesystem database
        /// </summary>
        public LiteDatabase(string connectionString)
        {
            var conn      = new ConnectionString(connectionString);
            var version   = conn.GetValue <ushort>("version", 0);
            var encrypted = !StringExtensions.IsNullOrWhiteSpace(conn.GetValue <string>("password", null));

            _engine = new LazyLoad <DbEngine>(
                () => new DbEngine(encrypted ? new EncryptedDiskService(conn, _log) : new FileDiskService(conn, _log), _log),
                () => this.InitializeMapper(),
                () => this.UpdateDbVersion(version));
        }
Exemple #12
0
        /// <summary>
        /// Starts LiteDB database using a custom IDiskService with all parameters available
        /// </summary>
        /// <param name="diskService">Custom implementation of persist data layer</param>
        /// <param name="mapper">Instance of BsonMapper that map poco classes to document</param>
        /// <param name="password">Password to encrypt you datafile</param>
        /// <param name="timeout">Locker timeout for concurrent access</param>
        /// <param name="cacheSize">Max memory pages used before flush data in Journal file (when available)</param>
        /// <param name="log">Custom log implementation</param>
        public LiteDatabase(IDiskService diskService, BsonMapper mapper = null, string password = null, TimeSpan?timeout = null, int cacheSize = 5000, Logger log = null)
        {
            if (diskService == null)
            {
                throw new ArgumentNullException("diskService");
            }

            _mapper = mapper ?? BsonMapper.Global;

            _engine = new LazyLoad <LiteEngine>(() => new LiteEngine(diskService, password: password, timeout: timeout, cacheSize: cacheSize, log: _log));
        }
Exemple #13
0
        /// <summary>
        /// Starts LiteDB database using a Stream disk
        /// </summary>
        public LiteDatabase(Stream stream, BsonMapper mapper = null, string password = null)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            _mapper = mapper ?? BsonMapper.Global;

            _engine = new LazyLoad <LiteEngine>(() => new LiteEngine(new StreamDiskService(stream), password: password, log: _log));
        }
Exemple #14
0
        /// <summary>
        /// Starts LiteDB database using a connection string for filesystem database
        /// </summary>
        public LiteDatabase(string connectionString, BsonMapper mapper = null)
        {
            LitePlatform.ThrowIfNotInitialized();

            var conn = new ConnectionString(connectionString);

            _mapper = mapper ?? BsonMapper.Global;

            var encrypted = !StringExtensions.IsNullOrWhiteSpace(conn.GetValue <string>("password", null));

            _engine = new LazyLoad <DbEngine>(() => new DbEngine(encrypted ? new EncryptedDiskService(conn, _log) : new FileDiskService(conn, _log), _log));
        }
Exemple #15
0
        /// <summary>
        /// Starts LiteDB database using a Stream disk
        /// </summary>
        public LiteDatabase(Stream stream, BsonMapper mapper = null, string password = null, bool disposeStream = false)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            Mapper = mapper ?? BsonMapper.Global;
            Log    = new Logger();

            _engine = new LazyLoad <LiteEngine>(() => new LiteEngine(new StreamDiskService(stream, disposeStream), password: password, log: Log));
        }
Exemple #16
0
        /// <summary>
        /// Starts LiteDB database using a connection string for filesystem database
        /// </summary>
        public LiteDatabase(string connectionString, BsonMapper mapper = null)
        {
            _connectionString = new ConnectionString(connectionString);

            _mapper = mapper ?? BsonMapper.Global;

            var options = new FileOptions
            {
                InitialSize = _connectionString.InitialSize,
                LimitSize   = _connectionString.LimitSize,
                Journal     = _connectionString.Journal,
                Timeout     = _connectionString.Timeout
            };

            _engine = new LazyLoad <LiteEngine>(() => new LiteEngine(new FileDiskService(_connectionString.Filename, options), _connectionString.Password, _connectionString.Timeout, _connectionString.AutoCommit, _connectionString.CacheSize, _log));
        }
Exemple #17
0
 /// <summary>
 /// Starts LiteDB database using a custom IDiskService with all parameters avaiable
 /// </summary>
 /// <param name="diskService">Custom implementation of persist data layer</param>
 /// <param name="mapper">Instance of BsonMapper that map poco classes to document</param>
 /// <param name="password">Password to encrypt you datafile</param>
 /// <param name="timeout">Locker timeout for concurrent access</param>
 /// <param name="autocommit">If auto commit after any write operation</param>
 /// <param name="cacheSize">Max memory pages used before flush data in Journal file (when avaiable)</param>
 /// <param name="log">Custom log implementation</param>
 public LiteDatabase(IDiskService diskService, BsonMapper mapper = null, string password = null, TimeSpan?timeout = null, bool autocommit = true, int cacheSize = 5000, Logger log = null)
 {
     _mapper = mapper ?? BsonMapper.Global;
     _engine = new LazyLoad <LiteEngine>(() => new LiteEngine(diskService, password: password, timeout: timeout, autocommit: autocommit, cacheSize: cacheSize, log: _log));
 }
Exemple #18
0
 /// <summary>
 /// Starts LiteDB database using a Stream disk
 /// </summary>
 public LiteDatabase(Stream stream, BsonMapper mapper = null, string password = null)
 {
     _mapper = mapper ?? BsonMapper.Global;
     _engine = new LazyLoad <LiteEngine>(() => new LiteEngine(new StreamDiskService(stream), password: password, log: _log));
 }