public static async Task <ISearchIndex> OpenOrInit(IPostgresConnectionInfo i) { var address = i.PostgresHost; var password = i.PostgresPassword; var dbName = i.PostgresDbName; var connectionStringPreformatted = CreateConnectionString(address, "{0}", password); var dbExists = false; await WithConnection(string.Format(connectionStringPreformatted, "postgres"), async c => { dbExists = await c.ExecuteCommandScalar($"SELECT 1 FROM pg_database WHERE datname='{dbName}'") != null; if (!dbExists) { await c.ExecuteCommandNonQuery($"CREATE DATABASE {dbName}"); } }); var connectionString = string.Format(connectionStringPreformatted, dbName); if (!dbExists) { await WithConnection(connectionString, async connection => { await connection.ExecuteCommandNonQuery("CREATE EXTENSION rdkit"); await connection.ExecuteCommandNonQuery("CREATE TABLE mr (id SERIAL primary key, ref text, smiles text UNIQUE, mol mol UNIQUE, fp bfp)"); await connection.ExecuteCommandNonQuery("CREATE INDEX ms_fp_idx ON mr USING gist(fp)"); await connection.ExecuteCommandNonQuery("CREATE INDEX ms_mol_idx ON mr USING gist(mol)"); }); } return(new RDKitIndex(connectionString)); }
public static string CreateConnectionString(IPostgresConnectionInfo i) => CreateConnectionString(i.PostgresHost, i.PostgresDbName, i.PostgresPassword);