Send to Printer

st4u

ST 4U 167: Deleting with Glorp

December 7, 2011 9:47:23.191

Today's Smalltalk 4 Yougoes through deleting objects using Glorp - which requires us to specify a primary key in our table mapping. The initial setup used is described here. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Deleting.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll look at how to delete data from a database using Glorp - which means that we need to make a small modification to our #tableForEMP: method in class EmpSystem:


tableForEMP: aTable 
	aTable 
		createFieldNamed: 'first_name' 
		type: (platform varChar: 50).
	(aTable 
		createFieldNamed: 'last_name' 
		type: (platform varChar: 50)) bePrimaryKey.

Note the small change - we've designated one column as the primary key. Ideally, that column would be more sensible than the one in this example, but the point is, you need to specify that. From here on out, Glorp will treat that column as the primary key, even if it's not specified that way in the database. Now we can actually do a deletion:


"deleting"
myEmp := session readOneOf: Emp where: [:each | each firstName = 'Wilma3'].
session delete: myEmp.

Executing that now works, and wraps the #delete: in a transaction for us. We can verify this by executing a query:


session readOneOf: Emp where: [:each | each firstName = 'Wilma3'].

And inspecting the results:

Deletion

And that's about it for today.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u167-iPhone.m4v ( Size: 4667584 )]

posted by James Robertson

 Share Tweet This