{
"charset": "CHARSET=utf8mb4",
"dialect": "mysql",
"engine": "InnoDB",
"columns": [
{
"full_type": "int(11)",
"nullable": false,
"auto_increment": true,
"precision": "",
"scale": "",
"default_value": "",
"primary_key": false,
"raw_definition": "`id` int(11) NOT NULL AUTO_INCREMENT",
"type_parameters": "11",
"collate": "",
"size": "11",
"unique": false,
"name": "id",
"data_type": "int"
},
{
"full_type": "varchar(255)",
"nullable": true,
"auto_increment": false,
"precision": "",
"scale": "",
"default_value": "NULL",
"primary_key": false,
"raw_definition": "`category_name` varchar(255) DEFAULT NULL",
"type_parameters": "255",
"collate": "",
"size": "255",
"unique": false,
"name": "category_name",
"data_type": "varchar"
},
{
"full_type": "timestamp",
"nullable": true,
"auto_increment": false,
"precision": "",
"scale": "",
"default_value": "current_timestamp()",
"primary_key": false,
"raw_definition": "`created_date` timestamp NULL DEFAULT current_timestamp()",
"type_parameters": "",
"collate": "",
"size": "",
"unique": false,
"name": "created_date",
"data_type": "timestamp"
},
{
"full_type": "datetime",
"nullable": true,
"auto_increment": false,
"precision": "",
"scale": "",
"default_value": "NULL",
"primary_key": false,
"raw_definition": "`modified_date` datetime DEFAULT NULL ON UPDATE current_timestamp()",
"type_parameters": "",
"collate": "",
"size": "",
"unique": false,
"name": "modified_date",
"data_type": "datetime"
},
{
"full_type": "datetime",
"nullable": true,
"auto_increment": false,
"precision": "",
"scale": "",
"default_value": "NULL",
"primary_key": false,
"raw_definition": "`deleted_date` datetime DEFAULT NULL",
"type_parameters": "",
"collate": "",
"size": "",
"unique": false,
"name": "deleted_date",
"data_type": "datetime"
}
],
"table_name": "TBL_CATEGORIES",
"constraints": [
{
"columns": [
"id"
],
"type": "PRIMARY_KEY",
"raw_definition": "PRIMARY KEY (`id`)"
}
]
}
Thanks Paul!Some "early" remarks on this table definition:
- id field: primary_key setting is false? Is this the primary key value? ; unique setting is false? for a primary key this should be true, right?
- category_name field: nullable setting is true? This is the only field in this table with actual values. Can you insert a record with no category name?
- if this table contains a lot of records then the category_name field should be indexed. There is no setting for it yet.
- in a more complex database structure the foreign key constraints play an important role when updating or deleting records. Maybe there could be a foreign_key setting?
CREATE TABLE `tbl_categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_name` varchar(255) DEFAULT NULL,
`created_date` timestamp NULL DEFAULT current_timestamp(),
`modified_date` datetime DEFAULT NULL ON UPDATE current_timestamp(),
`deleted_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
CREATE TABLE tbl_categories (id INTEGER,
category_name TEXT NULL,
created_date TEXT DEFAULT (datetime('now')),
modified_date TEXT,
deleted_date TEXT,
PRIMARY KEY(id AUTOINCREMENT))
Dim DB As MiniORM
DB.Initialize(Engine, Open)
DB.UseTimestamps = True
DB.Table = "tbl_categories"
DB.Columns.Add(DB.CreateColumn2(CreateMap("Name": "category_name")))
DB.Create
DB.Columns.Add(DB.CreateColumn2(CreateMap("Name": "category_name", "Nullable": False)))
DB.Table = "tbl_products"
DB.Columns.Add(DB.CreateColumn2(CreateMap("Name": "category_id", "Type": DB.INTEGER)))
DB.Columns.Add(DB.CreateColumn2(CreateMap("Name": "product_code", "Length": "12")))
DB.Columns.Add(DB.CreateColumn2(CreateMap("Name": "product_name")))
DB.Columns.Add(DB.CreateColumn2(CreateMap("Name": "product_price", "Type": DB.DECIMAL, "Length": "10,2", "Default": "0.00")))
DB.Columns.Add(DB.CreateColumn2(CreateMap("Name": "product_image", "Type": DB.BLOB)))
DB.Foreign("category_id", "id", "tbl_categories", "", "")
DB.Create