Can constructors be async?

Since it is not possible to make an async constructor, I use a static async method that returns a class instance created by a private constructor. This is not elegant but it works ok. public class ViewModel { public ObservableCollection<TData> Data { get; set; } //static async method that behave like a constructor async public … Read more

How to see the raw SQL queries Django is running?

See the docs FAQ: “How can I see the raw SQL queries Django is running?” django.db.connection.queries contains a list of the SQL queries: from django.db import connection print(connection.queries) Querysets also have a query attribute containing the query to be executed: print(MyModel.objects.filter(name=”my name”).query) Note that the output of the query is not valid SQL, because: “Django … Read more

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory in Ionic 3

For a non-Angular general answer for those who land on this question from Google: Every time you face this error it’s probably because of a memory leak or difference between how Node.js <= 10 and Node.js > 10 manage memory. Usually just increasing the memory allocated to Node.js will allow your program to run but … Read more

SQL join: selecting the last records in a one-to-many relationship

This is an example of the greatest-n-per-group problem that has appeared regularly on StackOverflow. Here’s how I usually recommend solving it: SELECT c.*, p1.* FROM customer c JOIN purchase p1 ON (c.id = p1.customer_id) LEFT OUTER JOIN purchase p2 ON (c.id = p2.customer_id AND (p1.date < p2.date OR (p1.date = p2.date AND p1.id < p2.id))) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)