Custom Equality check for C# 9 records

Per the C#9 record proposal, the following should compile, even if not very useful without actual implementations.. // No explicit IEquatable<R> – this is synthesized! public sealed record SimpleVo { // Not virtual, as SimpleVo (R) is sealed. // Accepts SimpleVo? (R?), and not SimpleVo (R), as argument. public bool Equals(SimpleVo? other) => throw new … Read more

Return a value if no record is found

Encapsulate the query in a sub-query to transform “no row” to a null value. I tested and verified this with PostgreSQL, SQLite, SQL Server, and MySQL. SELECT (SELECT id FROM tbl WHERE id = 9823474) AS id; In Oracle you have to select from the dummy 1-row table DUAL: SELECT (SELECT id FROM tbl WHERE … Read more

HowTo: Custom Field in Lift-Record-Squeryl

you are implementing your validation logic incorrectly. The correct way to validate a Record field is to override def validations: List[ValidationFunction] where ValidationFunction is a type alias type ValidationFunction = ValueType => List[FieldError] and in your case ValueType == String. The next issue is your Domain trait. Because your call to validate is inlined into … Read more

How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration

Answer coming from : http://grokbase.com/t/gg/rogue-users/1367nscf80/how-to-update-a-record-with-mongocaseclassfield-when-case-class-contains-a-scala-enumeration#20130612woc3x7utvaoacu7tv7lzn4sr2q But more convenient directly here on StackOverFlow: Sorry, I should have chimed in here sooner. One of the long-standing problems with Rogue was that it was too easy to accidentally make a field that was not serializable as BSON, and have it fail at runtime (when you try to add … Read more

SQL – Update multiple records in one query

Try either multi-table update syntax UPDATE config t1 JOIN config t2 ON t1.config_name=”name1″ AND t2.config_name=”name2″ SET t1.config_value=”value”, t2.config_value=”value2″; Here is a SQLFiddle demo or conditional update UPDATE config SET config_value = CASE config_name WHEN ‘name1’ THEN ‘value’ WHEN ‘name2’ THEN ‘value2’ ELSE config_value END WHERE config_name IN(‘name1’, ‘name2’); Here is a SQLFiddle demo