SQLAlchemy update if unique key exists

From version 1.2 SQLAlchemy will support on_duplicate_key_update for MySQL There is also examples of how to use it: from sqlalchemy.dialects.mysql import insert insert_stmt = insert(my_table).values( id=’some_existing_id’, data=”inserted value”) on_duplicate_key_stmt = insert_stmt.on_duplicate_key_update( data=insert_stmt.values.data, status=”U” ) conn.execute(on_duplicate_key_stmt) From version 1.1 SQLAlchemy support on_conflict_do_update for PostgreSQL Examples: from sqlalchemy.dialects.postgresql import insert insert_stmt = insert(my_table).values( id=’some_existing_id’, data=”inserted value”) do_update_stmt … Read more

Can’t auto-generate IDENTITY with AddRange in Entity Framework

What was causing the problem? Enumerables! Take a look at the EDIT section in my question for the solution. EDIT: posting the updated code here as answer. The problem was in the way I used enumerables. Bottom line is you should never trust lazy loading when you need consistent results right away. public class Request … Read more

Map string column in Entity Framework to Enum

Probably a nicer version. OrderStateIdentifier field is used for both JSON serialization and database field, while OrderState is only used in the code for convenience. public string OrderStateIdentifier { get { return OrderState.ToString(); } set { OrderState = value.ToEnum<OrderState>(); } } [NotMapped] [JsonIgnore] public OrderState OrderState { get; set; } public static class EnumHelper { … Read more

Django Left Outer Join

First of all, there is no a way (atm Django 1.9.7) to have a representation with Django’s ORM of the raw query you posted, exactly as you want; however, you can get the same desired result with something like: >>> Topic.objects.annotate( f=Case( When( record__user=johnny, then=F(‘record__value’) ), output_field=IntegerField() ) ).order_by( ‘id’, ‘name’, ‘f’ ).distinct( ‘id’, ‘name’ … Read more

Closest equivalent to SQLAlchemy for Java/Scala [closed]

One of the notable things about SQLAlchemy is that it makes tables first class objects. Thus the core API is really written around table objects, and the API therefore is essentially relational in nature. Thus at this level even if the API is OO, it is essentially reflecting RDBMS objects or functions such as Tables, … Read more

How do you map a “Map” in hibernate using annotations?

You could simply use the JPA annotation @MapKey (note that the JPA annotation is different from the Hibernate one, the Hibernate @MapKey maps a database column holding the map key, while the JPA’s annotation maps the property to be used as the map’s key). @javax.persistence.OneToMany(cascade = CascadeType.ALL) @javax.persistence.MapKey(name = “name”) private Map<String, Person> nameToPerson = … Read more