How boto dyanmodb2 create table in region / understand create_table syntax? - boto

I'm trying to figure out how to create a table in a specific region using boto and dynamodb2. Previously I created a Table object which had a clear constructor, but does not appear to take a region parameter. Now I am trying to use create_table on the connection object, but the syntax is entirely different and not clearly documented.
So either, how do I use the create_table function or how can I specifiy a region for the Table constructor?

The Table constructor also takes a connection parameter. The region of the Connection object is then used to construct the table.

Related

How to define data type in mySql stored procedure to accept list of object as an in parameter?

I have 'one to many' relationship in two tables. In that case I want to write a store procedured in mySql which can accept the list of child table object and update the tables. The challenge I am facing is what will be the data type of the in parameter for list of object.
You can try to use VARCHAR(65535) in MySQL.
There is no list data type in MySQL.
Given the info that you are coming from Oracle DB, you might wanna know that MySQL does not have a strict concept of objects. And, as answered here, unfortunately, you cannot create a custom data type on your own.
The way to work around it is to imagine a table as a class. Thus, your objects will become records of the said table.
You have to settle for one of the following approaches:
Concatenated IDs: Store the concatenated IDs you want to operate on in a string equivalent datatype- like VARCHAR(5000) or TEXT. This way you can either split and loop over the string or compose a prepared statement dynamically and execute it.
Use a temporary table: Fetch the child table objects, on the fly, into the temporary table and process them. This way, once you create the temporary table with the fields & constraints that you like, you can use
SELECT ... INTO TEMPORARY_TABLE_NAME to populate the table accordingly. The SELECT statement should fetch the properties you need.
Depending on the size of the data, you might want to choose the temp table approach for larger data sets.
You can use Text data type for store large amount of data in single variable
you can define in sp as:
In Variable_name TEXT

How to create a model with multiple tables in Rails?

In my Rails application I am linking into a MySQL database from the legacy PHP application. The naming conventions are incorrect, so am making use of self.table_name to connect models to their respective tables.
I have a requirement to show information from multiple tables into one resource. All these tables have the same column structure. Can I create a model that pulls information from each of these tables? How do I do that? I have been playing around with find_by_sql but am yet to have any success
EDIT: This is all to be read only, no updating is required.
From your question I believe you are planning to load a other models from one particular model. My suggest is to use a polymorphic relationship.
class MainModel
has_many :sub_model, polymorphic: true
end
class Item1
belong_to :main_model, as: :sub_model
end
class Item2
belong_to :main_model, as: :sub_model
end
Now in the view you will have to write your data as follows.
#main_model.sub_model.name | #main_model.sub_model.value
Since all the other models/tables has the same structure you won't have to change the attribute.
And when updating it, you just accept the values of the sub_models as a nested attribute and they will update the corresponding model.
For more details on how to setup a polymorphic relationship visit Setting up a polymorphic association

Entity Framework 4.2 - How to realize TPT-Inheritance with Database-generated Primarykey Value?

I want to use the EF (4.2) in the following scenario:
There exists a database already (so I chose the database-first approach) and it is a SQL Anywhere DB.
I want to use persistence-ignorant business objects, so I use the DbContext Template to generate POCO classes from the EDM.
There is one simple inheritance hierarchy among my entities: an abstract base entity and two concrete derived entities.
In the database there is one table for each type of the inheritance hierarchy (Table-Per-Type Strategy).
Each of these three tables has a primary key column (Id, type:integer), and the association of a concrete entity to the base entity is done by having the same Id in both tables (that means that the primary key (Id) of the concrete type tables is at the same time a foreign key to the base table; a pretty common approach I think).
I had to define the Inheritance manually in the designer, since the EDM assistant does not automatically recognize, that is want to have an inheritance association between the described entities.
Until this point there wasn't any bigger problem. Now to the issue at hand:
There is a restriction for the database I use: Primarykey values have to be generated by the database, using a database function.
I want to call this function in a before-insert-trigger defined on the base-table.
To let the entity framework know that a value is generated by the database, I set the StoreGeneratedPattern property of the Id Property of the base-entity to Identity (As I understood, this is the way to tell EF to get the generated value after inserting a new instance of an entity).
When I create a new instance of a derived entity, add it to the corresponding DbSet of the DbContext and call SaveChanges on the context, a DbUpdateException is thrown, stating that a foreignkey constraint is violated.
By checking the request-log of the DB, I see that the base entity got inserted in the base table, but on inserting the row in the derived table, the above mentioned error occurs, because it obviously doesn't use the newly generated Id of the new entry in the base table.
Since I don't think there is much I can do on a database level against that, the question is, if the EDM or DbContext can be configured (or modified) to insert the base row first, then take the generated Id and use it for insertion of the derived row.
I know there are several way to avoid this situation (not using inheritance, using a stored procedure to insert a new derived entity, calling the id-generating db-function before inserting and set the Id property myself on the entity), but at the moment the above-described behavior would be the most preferable, so I want to make sure not to overlook something before deciding for any "plan B".
Any suggestions on this topic are much appreciated,
Thanks in advance.
Here is the code of the trigger:
ALTER TRIGGER "TRG_GENERATE_ID" before insert order 1 on
BASE_TABLE
referencing new as NewEntry
for each row
begin
declare NewID integer;
set NewID = F_GET_NEW_ID('BASE_TABLE', NewEntry.SOME_OTHER_ID);
set NewEntry.ID = NewID
end
The function "F_GET_NEW_ID" is called in the trigger to generate the new ID for a new entry in the base table. It has two parameters:
"Tablename" -> The name of the table for which a new ID should be generated,
and a second parameter that takes the value of a standardcolumn in all tables of the database (it is required to generate the new ID).

Linq-to-SQL- A stored procedure returns field which is not there in Mapped Table Info

We are using Linq-to-SQL with stored Procedures we need help on one of our problem. We are having user tables which is having all field required for user table like firstname,lastname and other fields that table is also there in our DBML files.Now the problem is that we are having a stored procedure that is mapped to table->User returning a field called fullname (Combination of firstname and lastname)which is not there in usertable. So what is the best way to slove this.
Another thing is that one of other stored procedure return inner join of two tables with mix columns in this case how can i mapped that stored procedure with Table mapped info class in our dbml files.
We recommend you to use a computed property defined in the partial class. It will not be influenced by code regeneration in case any changes are made to the model.
For the table with mixed columns one of possible solutions is to create a view in the database with a structure identical to the set of mixed columns.

ibatis check for exist before creating value

I have a property definition table and second one that holds the actual property values:
table propdef: id, name, description
table props: id, propdefid, userid, value
This way i can dynamically create properties for my users. When I want to update a property for a user I have to check the props table if a propdefid/userid row exists and then either use update or create on this.
Right now I am first querying the db and then deciding on what to do in my java code. Is there a way to do that in the ibatis sqlmap - without extra logic in my java code?
I am using mysql as db.
before you go any farther, you need to stop and read this article: http://tonyandrews.blogspot.com/2004/10/otlt-and-eav-two-big-design-mistakes.html
if you still decide that EAV is the way to go, there is still hope. i can't advise at the ibatis/java level, but i can tell you to look at INSERT ... ON DUPLICATE KEY UPDATE. this change your two statements in to one.