This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 16.9, “A quick look at the Slick database library.”
If you want to list all of the MySQL database table column names (field names) as a simple list of names, with each column name listed on a separate line, just follow these steps.
First, start MySQL with the
-sN options, like this:
$ mysql -sN -u root -p
Then execute a query like this:
1) Select the desired database
The first step is to select the database you want to search. Don’t select a table — just select the database you want to search. (If you select a table you’ll get a different search form in Step 2.)
I don’t know if there is a better way to do this yet, but if you want to select one record from a database table using the Play Framework and Anorm, I do know that this code works:
As I get back into working with a MySQL database in a Java (Scala, actually) development project and also in adding functionality to Cato, I found these MySQL to Java data type mappings, via this link:
As a quick example, if you need to see some code for a Play Framework Anorm method that inserts an object into a relational database table and returns the auto-into (MySQL auto_increment) ID field on success, here you go:
Just a quick note here today that if you need some example MySQL database tables, you can use these. I created them for some experiments I ran last night. They show the MySQL
primary key, and
foreign key syntax:
I used to use MySQL every day for years, but over the last two years I haven't used it much. Today I needed to create a MySQL database table, and had to wonder for a few moments what the MySQL CREATE TABLE syntax was. Fortunately I have plenty of examples out here.
Here's a quick example of a MySQL "users" table:
SQLite FAQ - How do I create a UNIQUE constraint on multiple fields in a SQLite database table?
Just specify the unique constraint in your create table declaration, as shown here: