1 /** 2 * Copyright © DiamondMVC 2019 3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE) 4 * Author: Jacob Jensen (bausshf) 5 */ 6 module diamond.data.mapping.engines.mssql; 7 8 import diamond.core.apptype; 9 10 static if (hasMsSql) 11 { 12 import std..string : format; 13 import std.variant : Variant; 14 15 import diamond.data.mapping.engines.sqlshared; 16 17 public 18 { 19 import diamond.data.mapping.engines.mssql.mssqladapter; 20 import diamond.data.mapping.engines.mssql.mssqlentityformatter; 21 import diamond.data.mapping.engines.mssql.mssqlmodel; 22 } 23 24 /// A variant db parameter type. 25 alias DbParam = Variant; 26 27 /// The connection string format. 28 private enum connectionStringFormat = "odbc://%s/%s/?user=%s,password=%s,driver=FreeTDS,database=%s"; 29 30 /// The db connection string. 31 private static __gshared string _dbConnectionString; 32 33 /// Collection of mssql connection pools. 34 // private static __gshared POOL_NAME[string] _pools; 35 36 package(diamond.data.mapping.engines) 37 { 38 // mixin CreatePool!(POOL_NAME); 39 } 40 41 /// Initializing Mssql 42 package(diamond) void initializeMsSql() 43 { 44 import diamond.core.webconfig; 45 46 if (!webConfig) 47 { 48 loadWebConfig(); 49 } 50 51 if (!webConfig.dbConnections || !webConfig.dbConnections.mssql) 52 { 53 return; 54 } 55 56 auto dbConfig = webConfig.dbConnections.mssql.get("default", null); 57 58 if (!dbConfig) 59 { 60 return; 61 } 62 63 _dbConnectionString = connectionStringFormat.format( 64 dbConfig.host, dbConfig.namedInstance, 65 dbConfig.user, dbConfig.password, 66 dbConfig.database 67 ); 68 69 // _pools[_dbConnectionString] = new POOL_NAME(_dbConnectionString); 70 71 import diamond.data.mapping.engines.mssql.mssqlmodel; 72 73 initializeMsSqlAdapter(_dbConnectionString); 74 } 75 76 @property 77 { 78 /// Gets the connection string. 79 auto dbConnectionString() 80 { 81 return _dbConnectionString; 82 } 83 } 84 85 /// The mssql adapter. 86 private __gshared MsSqlRawAdapter _adapter; 87 88 /** 89 * Initializes the mssql adapter. 90 * Params: 91 * connectionString = The connection string of the mssql adapter. 92 */ 93 package(diamond) void initializeMsSqlAdapter(string connectionString) 94 { 95 _adapter = new MsSqlRawAdapter(connectionString); 96 } 97 98 @property 99 { 100 /// Gets the mssql adapter. 101 MsSqlRawAdapter msSqlAdapter() { return _adapter; } 102 } 103 104 }