public DbConnection Open() { if (string.IsNullOrEmpty(_connectionString) && _connectionStringFactory == null) { throw new ArgumentNullException($"Please construct {nameof(SqliteConnectionFactory)} with a connection string or factory to use parameterless Open"); } var connectionString = string.IsNullOrEmpty(_connectionString) ? _connectionStringFactory.GetConnectionString() : _connectionString; return(Open(connectionString)); }
public async Task <MyClass> GetDetails(int Id) { var connectionString = _connectionStringFactory.GetConnectionString(); con = new Connection(connectionString); //and after that other logic..... }
public UsersContext(IConnectionStringFactory connectionStringFactory) : base(new SQLiteDataProvider(), connectionStringFactory.GetConnectionString("users.db")) { var b = MappingSchema.GetFluentMappingBuilder(); b.Entity <User>().HasTableName("Users") .Property(n => n.Key).IsIdentity().IsPrimaryKey() .Property(n => n.TelegramId).IsNullable(); }
private NpgsqlConnection NewConnectionAsync() { var connectionString = _connectionStringFactory.GetConnectionString(); _logger.Debug($"Hitting connection string {connectionString}"); var connection = new NpgsqlConnection(connectionString); connection.Open(); return(connection); }
public IDbConnection CreateConnection() { IDbConnection connection = databaseProvider.CreateConnection(); if (connection != null) { connection.ConnectionString = connectionStringFactory.GetConnectionString(); return(connection); } return(null); }
public MongoRepositoryFactory(IConnectionStringFactory connectionStringFactory) { _connectionStringFactory = connectionStringFactory; var connectionString = _connectionStringFactory.GetConnectionString(); if (string.IsNullOrEmpty(connectionString) || string.IsNullOrWhiteSpace(connectionString)) { throw new ArgumentException("Connection string cannot be null or empty", "connectionString"); } _connectionString = connectionString; }
public ReadingListContext(IConnectionStringFactory connectionStringFactory) : base(new SQLiteDataProvider(), connectionStringFactory.GetConnectionString("reading_list.db")) { var b = MappingSchema.GetFluentMappingBuilder(); b.Entity <ReadingListEntry>().HasTableName("ReadingListEntries") .Property(n => n.Key).IsIdentity().IsPrimaryKey() .Property(n => n.Author) .Property(n => n.Title) .Property(n => n.Status) .Property(n => n.ReadingStarted).IsNullable() .Property(n => n.ReadingCompleted).IsNullable() .Property(n => n.DaysReading).IsNotColumn(); }
public DbConnection GetConnection(string name) { var connString = _stringFactory.GetConnectionString(name); if (!_storage.TryGetValue(connString, out DbConnection conn)) { conn = _dbProviderFactory.CreateConnection(); conn.ConnectionString = connString; _storage.Add(connString, conn); } return(conn); }
public async Task <PreferencesEntity> GetUserPreferencesAsync(string userId) { if (String.IsNullOrWhiteSpace(userId)) { return(null); } using (MySqlConnection conn = new MySqlConnection(connectionStringFactory.GetConnectionString())) { // returns null if no record found var preferences = await conn.QueryFirstOrDefaultAsync <PreferencesEntity>(@" SELECT ID, UserID, SoonDays, ImminentDays FROM preferences WHERE UserID = @userId;" , new { userId }); return(preferences); } }
public void ConnectToDataBase() { var connectionString = _connectionString.GetConnectionString(); MongoClientSettings settings = MongoClientSettings.FromUrl( new MongoUrl(connectionString) ); settings.SslSettings = new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 }; var mongoClient = new MongoClient(settings); var server = mongoClient.GetServer(); server.GetDatabaseNames().ToList().ForEach(Console.WriteLine); var db = server.GetDatabase("test"); var collection = db.GetCollection <MongoRepository.Entity>("entities"); collection.Insert(new Player { NickName = "Jack" }); }
public ActivityPlannerContext(IConnectionStringFactory connectionStringFactory) : base(new SQLiteDataProvider(), connectionStringFactory.GetConnectionString("activity_planner.db")) { var b = MappingSchema.GetFluentMappingBuilder(); b.Entity <Group>().HasTableName("Groups") .Property(n => n.Key).IsIdentity().IsPrimaryKey() .Property(n => n.Name); b.Entity <Activity>().HasTableName("Activities") .Property(n => n.Key).IsIdentity().IsPrimaryKey() .Property(n => n.GroupKey) .Property(n => n.Name); b.Entity <ActivityOccurrence>().HasTableName("ActivityOccurrences") .Property(n => n.Key).IsIdentity().IsPrimaryKey() .Property(n => n.ActivityKey) .Property(n => n.Note).IsNullable() .Property(n => n.Highlighted) .Property(n => n.Missed) .Property(n => n.When) .Property(n => n.Ongoing).IsNotColumn(); }
public async Task <long> AddReminderAsync(string userId, ReminderEntity reminder) { using (MySqlConnection conn = new MySqlConnection(connectionStringFactory.GetConnectionString())) { await conn.ExecuteAsync(@" INSERT INTO reminders ( UserID, Title, Description, ForDate, Created, Recurrence, Importance ) VALUES ( @userId, @title, @description, @fordate, UTC_TIMESTAMP(), @recurrence, @importance );" , new { userId, title = reminder.Title, description = reminder.Description, fordate = reminder.ForDate, recurrence = reminder.Recurrence, importance = reminder.Importance }); return(await conn.QueryFirstAsync <long>("SELECT LAST_INSERT_ID();")); } }
public FinancialPlannerContext(IConnectionStringFactory connectionStringFactory) : base(new SQLiteDataProvider(), connectionStringFactory.GetConnectionString("financial_planner.db")) { }
public DailySurveyContext(IConnectionStringFactory connectionStringFactory) : base(new SQLiteDataProvider(), connectionStringFactory.GetConnectionString("daily_survey.db")) { }