Objective
Create an image library that supports multiple image formats. AIDB natively supports JPEG, PNG, WEBP, GIF, and BMP formats with explicit type declarations.
Step 1: Create Multi-Format Image Table
Create a table that can store images in different formats.
CREATE TABLE image_library (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
category VARCHAR(100),
format VARCHAR(10) NOT NULL,
jpeg_image IMAGE(JPEG),
png_image IMAGE(PNG),
webp_image IMAGE(WEBP),
gif_image IMAGE(GIF),
bmp_image IMAGE(BMP),
file_size BIGINT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 2: Create Format-Specific Tables
For better organization, create separate tables per format.
-- JPEG photos (best for photographs)
CREATE TABLE jpeg_photos (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
photo IMAGE(JPEG) NOT NULL,
quality_level VARCHAR(20) DEFAULT 'high',
file_size BIGINT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- PNG images (best for graphics with transparency)
CREATE TABLE png_graphics (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
graphic IMAGE(PNG) NOT NULL,
has_transparency BOOLEAN DEFAULT FALSE,
file_size BIGINT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- WEBP images (modern web format)
CREATE TABLE webp_images (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
image IMAGE(WEBP) NOT NULL,
is_animated BOOLEAN DEFAULT FALSE,
file_size BIGINT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- GIF animations
CREATE TABLE gif_animations (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
animation IMAGE(GIF) NOT NULL,
frame_count INTEGER,
duration_ms INTEGER,
file_size BIGINT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 3: Insert Sample Records
Insert records for each format type.
INSERT INTO jpeg_photos (id, name, quality_level, file_size) VALUES
(1, 'landscape_mountain.jpg', 'high', 2048000),
(2, 'portrait_studio.jpg', 'high', 1536000),
(3, 'product_photo.jpg', 'medium', 512000);
INSERT INTO png_graphics (id, name, has_transparency, file_size) VALUES
(1, 'company_logo.png', TRUE, 45000),
(2, 'app_icon.png', TRUE, 12000),
(3, 'diagram_architecture.png', FALSE, 156000);
INSERT INTO webp_images (id, name, is_animated, file_size) VALUES
(1, 'hero_banner.webp', FALSE, 85000),
(2, 'product_gallery.webp', FALSE, 62000),
(3, 'animated_loading.webp', TRUE, 24000);
INSERT INTO gif_animations (id, name, frame_count, duration_ms, file_size) VALUES
(1, 'loading_spinner.gif', 12, 1000, 8000),
(2, 'success_checkmark.gif', 24, 800, 15000),
(3, 'tutorial_demo.gif', 60, 5000, 450000);