In PostgreSQL, it is easy to add a GUID column and fill it:
ALTER TABLE public."thetable" ADD aggregateid uuid DEFAULT gen_random_uuid() NOT NULL;
ALTER TABLE public."thetable" ADD CONSTRAINT thetable_unique UNIQUE (aggregateid);
Technical tips for various products and programming languages
In PostgreSQL, it is easy to add a GUID column and fill it:
ALTER TABLE public."thetable" ADD aggregateid uuid DEFAULT gen_random_uuid() NOT NULL;
ALTER TABLE public."thetable" ADD CONSTRAINT thetable_unique UNIQUE (aggregateid);
[Configuration]
InplaceRename=0
Copilot oftewel Artificial Intelligence werkt erg goed tegenwoordig. Ik stel de volgende vraag:
"How to determine the byte position of an element in a C struct"
Vroeger kon je het vergeten dat je antwoord kreeg via Google. Tegenwoordig krijg je het antwoord:
#include <stdio.h> #include <stddef.h> // For offsetof macro struct MyStruct { int a; float b; char c; }; int main() { // Calculate and print the offset of each member printf("Offset of 'a': %zu bytes\n", offsetof(struct MyStruct, a)); printf("Offset of 'b': %zu bytes\n", offsetof(struct MyStruct, b)); printf("Offset of 'c': %zu bytes\n", offsetof(struct MyStruct, c)); return 0; }
En daarmee kon ik mijn oplossing gemakkelijk programmeren:
int theOffset = offsetof(SDL_KeyboardEvent, scancode);
AI werkt goed!
In C#, you can write an anonymous lambda which uses an instance variable of the class you are using:
Hello hello = new Hello(); hello.methodToCall((self) => { Console.WriteLine("hallo " + self.numberToReach); }); public class Hello { public int numberToReach = 3; public void methodToCall(Action<Hello> operation) { operation(this); } }
In Kotlin, the Hello instance is bound to this, which is nice (see my trailing lambda's post). In C#, the "this" needs to be transferred using a parameter, in this case called "self".
***************************** File Main ***************************** for (theUser in userService.getUsersByClassification("Class 1", pageNr = 0, pageSize = 10)) { println(theUser.displayName) } ***************************** File UserService ***************************** @Service class UserService @Autowired constructor(private val userPaging: UserPagingAndSortingRepository) { fun getUsersByClassification(classification: String, pageNr: Int, pageSize: Int): Page<User> { val pageable: Pageable = PageRequest.of(pageNr, pageSize) return userPaging.findByClassification(classificatie, pageable) } } ***************************** File UserPagingAndSortingRepository The Query annotation is JPQL, but in the case of JPA Hibernate, can also be HQL. ***************************** interface UserPagingAndSortingRepository : PagingAndSortingRepository<User, Long> { @Query("SELECT u FROM User u JOIN u.userExtradata um WHERE um.classification = :classification") fun findByClassification(@Param("classification") classification: String, pageable: Pageable): Page<User> } ***************************** File entity.User ***************************** @Entity @Table(name = "\"user\"") class User { @Id var id: Long = 0; @Column (name="display_name") var displayName: String = "" @OneToOne(mappedBy = "user", cascade = [CascadeType.ALL], fetch = FetchType.LAZY) val userExtradata: UserExtradata? = null } ***************************** File entity.UserExtradata ***************************** @Entity @Table(name = "\"user_extradata\"") class UserExtradata { @Id var user_id: Long = 0; var classification: String = "" var phonenumber: String? = "" @OneToOne @JoinColumn(name = "user_id", referencedColumnName = "id") val user: User? = null }
In Kotlin, you can do things like:
class Hello { val secretValue = 1; fun trailingLambda(trail: Hello.() -> Unit = {}) { trail() } } fun main() { val hallo: Hello = Hello() hallo.trailingLambda { println("trailingLambda ${this.secretValue}") } }
const myArray = [1, 2, 3]; const iterator = myArray[Symbol.iterator](); for (const value of myArray) { console.log(value); // Outputs: 1, 2, 3 } class MyCollection { constructor(items) { this.items = items; } [Symbol.iterator]() { let index = 0; const items = this.items; return { next() { if (index < items.length) { return { value: items[index++], done: false }; } else { return { done: true }; } } }; } } let tmp3 = new MyCollection([1,2,3,4,5]); for (const value of tmp3) { console.log(value); } Ofcourse you don't have the typechecking that typescript has:
function getValue<T extends keyof {yoho: string, "ho"?: number}>(item: T) { return item; } console.log(getValue<"ho">("ho"));