Is it possible to use Slick 3 for accessing different schemas within the same Database? - multi-tenant

For a multi tenant application I need to create I want to evaluate how convenient is Slick for creating queries against Postgres different schemas (not to confuse with schema tables).
I'm having a hard time finding how to configure TableQuery to use dynamically the schema provided by the user. TableQuery[Users].resul should return different datasets depending on me querying tenant A or tenant B.
Is it possible with current Slick versions?

TableQuery itself will not need to be configured, as its methods only return queries and actions. Actions are run by a DatabaseDef instance, and that is what will need to be configured to access different schemas/databases/etc. Slick official documentation describes a simple way to create an instance of a DatabaseDef, which by default uses the Typesage Config library:
val db = Database.forConfig("mydb")
where "mydb" specifies a key in a property file Typesafe Config is looking at. You can create and manipulate Config instances programmatically as well, and create db instances from those. I suspect you will have to do something along the lines of creating a new Config instance (there is the convenient withValue() method to copy a Config and replace a config value at the specified key) and use that to create a new db instance for each new schema you are interested in querying.

Related

How to create return objects when schema (objectGraphType, QueryType, etc) generated during runtime

In multi tenants environment where each tenant can evolve into different database schema design after lauhching the services, graphGL solution seems not straightforward.
What I was able to complete, is using single schema 'Root' as ISchema within a wrapper schema (also as ISchema), which is actually the one exposed to other layers of GraphQL architecture, and create GraphTypes (QueryTypes, etc) as Fields of the 'Root' during runtime.
It seems good at least in creating those GraphTypes as run-time registered Fields of Root schema, however when I added resolver using resolve : context, I am not able to display the returned object(s) from repository, let's say to altair with error "Error trying to resolve field '{fieldname}'"
How can I return the data so those can be actually bound to the graphQL layers up to altair?

How to change Datastore associated to a Data View on runtime?

I'm planning to distribute load from my database making a copy on several servers (each server will have the same tables but with different company data).
In order to do this, I will need to programmatically change the Datastore associated to my Data Views. For other tables I'm using the "Before Connect" property.
It's possible to handle this in Genexus?
Thanks,
Yes, you can use dbConnection Data Type.
Just create a variable based on this data type, and use it's methods and properties to set it up when you need it to be changed...

REST client that can consume any REST API run-time and persist the data creating new tables dynamically

I'm looking for a solution with Spring / camel to consume multiple REST services during runtime and create tables to store the data from REST API and compare the data dynamically. I don't know the schema for JSON API in advance to generate the JAVA client classes to create JPA persistent entity classes during run time.
You'll need to think through this differently. Id forget about Java class POJOs that you don't have and can't create since the class structure isn't known in advance. So anything with POJO->Entity binding would be pretty useless.
One solution is to simply parse the xml or json body manually with en event-based parser (like SAX for XML) and simply build an SQL create string as you go through the document. Your field and table names would correspond to the tags in the document. Without access to an XSD or other structure description, no meta data is available for field lengths or types. Make everything really long VARCHAR? Also perhaps an XML or other kind of database might suite your problem domain better. In any case, you could include such a thing right in your Camel route as a Processor that will process the body and create the necessary tables if they don't already exist. You could even alter a table for lengths in the process when you have a field value that is longer than what's currently defined.

Is there a Global variable to pull the DataBase (initial catalog) of a shared datasource

I'm not tyring to set a dynamic datasource but just want to pull the Initial Catalog value from the Shared Datasource. The values are already hardcoded into the shared DS and I could just hardcode into the field but for other purposes I'm trying to 'pull' the value from the shared DS. I've looked around and everything want's to point me to creating dynamic but that's not the issue here
If you are using SQL Server you can add DB_NAME() as a column to your query. This will return the current database regardless of the server. There should be an equivalent expression for other languages.

How to query the session in ASP.NET MVC with a dynamic query

I want to store some user data in memory, like some in-memory noSQL database.
But later on I want to query that data with a dynamic query constructed from the user. That query is stored in a classic DB like a string, so when I need to query the data stored in memory I would like to parse that string and construct the desired query (by some known rules).
I looked at Redis and I figured out it isn't maintained for Windows anymore, I have also looked at RavenDB but it's main query language is LINQ, even though it can be created dynamic Lucene Query.
Can you suggest me another in memory DB that work with ASP.NET and can be queried with a dynamically created query? Maybe I haven't seen all the options.
I prefer name-value or JSON based noSQL so it's schema can be easyly modified without the constraints of the relation type of DBs
I would suggest to simply use sqlite. It can be easily used as an in-memory database (just open the database using ":memory:" instead of a file name).
You can use a simple 2 columns table with a primary key to emulate a key/value store.
Here are a few links you might find helpful:
http://www.sqlite.org/inmemorydb.html
How to create asp.net web application using sqlite

Resources