项目作者: Fe-Bell

项目描述 :
Generic file-based database framework written in .NET Standard 2.0.
高级语言: C#
项目地址: git://github.com/Fe-Bell/OpenDBF.git
创建时间: 2020-07-27T20:16:15Z
项目社区:https://github.com/Fe-Bell/OpenDBF

开源协议:MIT License

下载




.NET Core

OpenDBF

The Open Database Framework is a free and open source database library based on object serialization to file.

OpendDBF is a child project of ReflectXMLDB.

The project was written with .NET Standard 2.0,
which is compatible with .NET Core 2.0+, .NET Framework 4.6.1+ and .NET 5.0+.

OpenDBF is cross platform and can run in any OS that supports .NET Core 2.0 or higher.

Features

  • Multithread and process safety.
  • Supports XML, JSON and DAT file formats.
  • Provides high-level methods to read/write data to the database files.
  • Compatible with Linq.
  • It is completely open source and under the very permissive MIT License.!

More to come!

Get started

Download OpenDBF from nuget.

OpenDBF offers the traditional Get, Insert, Remove and Update methods commonly found in other database frameworks.
It creates a single file for all database objects and also supports zip compression with the use of Pack/Unpack methods.

There are two steps to get OpenDBF running:

  1. Custom objects must inherit from OpenDBF.Shared.Interface.ICollectableObject and be serializable so they can be inserted in the databse.

Example:

  1. [Serializable]
  2. public class Sample : ICollectableObject
  3. {
  4. public string GUID { get; set; }
  5. public uint EID { get; set; }
  6. public string SomeData { get; set; }
  7. }
  1. Users must create an instance of an IDatabaseFramework. OpenDBF.Core offers a FrameworkFactory for that. It is also possible to manually instantiate these frameworks.

Example:

  1. //Initializes the database framework.
  2. var dh = FrameworkFactory.GetFramework(FrameworkFactory.Framework_e.JSON);
  3. //Creates the workspace.
  4. string workspace = Path.Combine(Directory.GetCurrentDirectory(), @"DBSample");
  5. dh.SetWorkspace(workspace);
  6. //Creates a list of objects to be inserted.
  7. //Sample inherits from ICollectableObject and is in the same namespace of SampleDatabase
  8. List<Sample> samples = new List<Sample>();
  9. for (int i = 0; i < 10; i++)
  10. {
  11. samples.Add(new Sample() { SomeData = string.Format("Data{0}", i) });
  12. }
  13. //Inserts the items in the database.
  14. dh.Insert(samples);
  15. //Gets all samples in the database.
  16. var queryAllSamples = dh.Get<Sample>();
  17. //Gets all samples that have Data5 as the value of the SomeData property.
  18. var querySomeSamples = dh.Get<Sample>(x => x.SomeData == "Data5");
  19. //Removes some of the items in the database.
  20. dh.Remove<Sample>(querySomeSamples);
  21. //Saves the database to a file
  22. dh.Commit();
  23. //Exports the database to a .db file.
  24. dh.Pack(Path.Combine(Directory.GetCurrentDirectory(), @"Place"), "copyOfSampleDatabase1");
  25. //Removes all "samples" from the database
  26. dh.DropTable<Sample>();
  27. //Clears internal resources.
  28. dh.Dispose();

Happy coding!

License

Licensed under MIT License.