Skip to content

Quick start ​

Installation ​

mooSQL is an internal library; packages are published on the internal GitLab. You can obtain the installer from the GitLab project or use other channels.

From GitLab ​

  1. Sign in to GitLab and open the u8common project.
  2. Open the pack6.0.0 folder.
  3. Run the installer inside to install the published package.

Other channels ​

  1. Contact the maintainers to request a package.
  2. Install when you receive it.

Install or upgrade ​

  1. Run the installer from the package and click Execute.
  2. After installation, right-click the solution root and choose Clean Solution or Rebuild Solution.
  3. Clean, then rebuild and run the project.

Packages ​

Overview ​

  • mooSQL.pure — core, minimal dependencies, no dialect definitions.
  • mooSQL.Ext — extensions and dialects (databases, JSON, NPOI, etc.).

Most projects reference mooSQL.Ext only.

When searching NuGet, use your local package folder, e.g. C:\Users\Administrator\.nuget\packages (replace the user name on other accounts).

Configuration and integration ​

mooSQL does not depend on a specific app framework. DB configuration and integration are implemented in your app. The usual pattern is a static DBCash class that loads DB settings and initializes a global DBInsCash instance.

c#
public partial class DBCash
{
    private static DBInsCash cash = null;


    /// <summary>
    /// Get DB instance by index
    /// </summary>
    /// <param name="position"></param>
    /// <returns></returns>
    public static DBInstance GetDBInstance(int position) {
        if (cash == null) {
            initFactory();

        }
        try {
            return cash.getInstance(position);
        }
        catch(Exception ex) 
        {
            loadDBConfig();
            return cash.getInstance(position);
        }
        
    }

    private static void initFactory() {
        var builder= new DBClientBuilder();
        var cache = new MooCache();

        cash = builder
            .useCache(cache)
            .useEnityAnalyser(new SugarEnitiyParser())
            .doBuild();

        loadDBConfig();

    }

    /// <summary>
    /// Get DB instance by name
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public static DBInstance GetDBInstance(string name)
    {
        if (cash == null)
        {
            initFactory();
        }
        try
        {
            return cash.getInstance(name);
        }
        catch (Exception ex)
        {
            loadDBConfig();
            return cash.getInstance(name);
        }

    }


    private static int loadDBConfig() {

        var myConfigs = App.GetOptions<DBCoonfigOptions>();
        if (myConfigs != null && myConfigs.Connections !=null && myConfigs.Connections.Count > 0) {
            cash.addConfig(myConfigs.Connections);
        }

        return cc;
    }



    public static SQLKit useSQL(int position)
    {

        var db= GetDBInstance(position);
        var kit = new SQLKit();
        kit.setDBInstance(db);
        return kit;
    }

    public static SQLKit newKit(string name)
    {

        var db = GetDBInstance(name);
        var kit = new SQLKit();
        kit.setDBInstance(db);
        return kit;
    }

    public static ITable<T> useEntity<T>(int position) { 
        var db = GetDBInstance(position);

        //var connect = new DataContext(db);

        return new Table<T>(db);

    }

    public static DbBus<T> useBus<T>(int position)
    {
        var db = GetDBInstance(position);

        var connect = new DbContext();
        var fac = new EntityVisitFactory();
        connect.Factory = fac;
        connect.DB = db;
        return new EnDbBus<T>(connect,typeof(T), fac);
    }


    public static BulkTable newBulk(string tableName, int position) { 
        BulkTable bk= new BulkTable(tableName,GetDBInstance(position));
        bk.getBulkTable();
        return bk;
    }

    public static BatchSQL newBatchSQL(int position)
    {

        var db = GetDBInstance(position);
        var kit = new SQLKit();
        kit.setDBInstance(db);
        var res = new BatchSQL(kit);
        return res;
    }
    public static SooRepository<T> useRepo<T>(int position) where T : class, new()
    {
        var db = GetDBInstance(position);
        return db.useRepo<T>();
    }

    public static SooUnitOfWork useUnitOfWork(int position)
    {
        var db = GetDBInstance(position);
        return db.useWork();
    }
    public static SooUnitOfWork useWork(int position)
    {
        var db = GetDBInstance(position);
        return db.useWork();
    }

    public static SQLClip useClip(int position)
    {
        var db = GetDBInstance(position);
        return db.useClip();
    }
}