Skip to content

Commit 75eaf4c

Browse files
test script updated.
1 parent 020335e commit 75eaf4c

File tree

1 file changed

+38
-55
lines changed

1 file changed

+38
-55
lines changed

test/index.mjs

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// 🧪 PuddySQL Test Playground
2-
// ---------------------------
3-
// This test script initializes a SQLite3 database in memory,
4-
// creates a small test table, and runs various queries to demonstrate functionality.
2+
// ╔═══════════════════════════════════════════════╗
3+
// ║ 💾 Interactive SQL Test Suite ║
4+
// ║ Powered by: PuddySQL Engine 🍮 ║
5+
// ╚═══════════════════════════════════════════════╝
56

67
import stringify from 'safe-stable-stringify';
78
import { ColorSafeStringify } from 'tiny-essentials';
@@ -15,65 +16,55 @@ const colorSafeStringify = (json, space = 0) =>
1516
const db = new PuddySql.Instance();
1617

1718
(async () => {
18-
console.log('\n🔧 Initializing SQLite3...\n');
19+
console.log('\n🔧 \x1b[1mInitializing SQLite3...\x1b[0m\n');
1920
await db.initSqlite3();
2021

21-
// 🧱 Define table schema
2222
const table = await db.initTable({ name: 'tinytest', id: 'id', order: 'id ASC' }, [
2323
['id', 'TEXT', 'PRIMARY KEY'],
2424
['prompt', 'TEXT'],
2525
['yay', 'BOOLEAN'],
2626
]);
2727

28-
// 📦 Inserting Data
29-
console.log('\n📥 Inserting test data...\n');
30-
const insertResults = await Promise.all([
31-
table.set('1', { prompt: '🍮 pudding', yay: true }),
32-
table.set('2', { prompt: '🍪 cookie', yay: true }),
33-
table.set('3', { prompt: '🍫 brigadeiro', yay: true }),
34-
table.set('4', { prompt: '🍌 banana', yay: false }),
35-
table.set('5', { prompt: '🍫 chocolate', yay: true }),
36-
]);
37-
console.table(insertResults);
28+
console.log('\n📥 \x1b[36mInserting test data...\x1b[0m\n');
29+
console.table(
30+
await Promise.all([
31+
table.set('1', { prompt: '🍮 pudding', yay: true }),
32+
table.set('2', { prompt: '🍪 cookie', yay: true }),
33+
table.set('3', { prompt: '🍫 brigadeiro', yay: true }),
34+
table.set('4', { prompt: '🍌 banana', yay: false }),
35+
table.set('5', { prompt: '🍫 chocolate', yay: true }),
36+
]),
37+
);
3838

39-
// 📤 Fetching All Records
40-
console.log('\n📃 All Records:\n');
39+
console.log('\n📃 \x1b[1mAll Records:\x1b[0m\n');
4140
console.table(await table.getAll());
4241

43-
// 🔍 Find by ID
44-
console.log('\n🔍 Getting record with ID = 1\n');
42+
console.log('\n🔍 \x1b[33mGetting record with ID = 1\x1b[0m\n');
4543
console.log(colorSafeStringify(await table.get('1')));
4644

47-
// 🔁 Update an Entry
48-
console.log('\n📝 Updating ID = 4 (yay = true)\n');
45+
console.log('\n📝 \x1b[35mUpdating ID = 4 (yay = true)\x1b[0m\n');
4946
await table.set('4', { yay: true });
5047
console.log(colorSafeStringify(await table.get('4')));
5148

52-
console.log('\n📝 Updating ID = 4 (yay = false)\n');
49+
console.log('\n📝 \x1b[35mUpdating ID = 4 (yay = false)\x1b[0m\n');
5350
await table.set('4', { yay: false });
5451
console.log(colorSafeStringify(await table.get('4')));
5552

56-
// ❌ Delete an Entry
57-
console.log('\n🗑️ Deleting ID = 2\n');
53+
console.log('\n🗑️ \x1b[31mDeleting ID = 2\x1b[0m\n');
5854
await table.delete('2');
5955
console.table(await table.getAll());
6056

61-
// 🔎 Advanced Search: prompt = pudding
62-
console.log('\n🔎 Search: prompt = pudding\n');
57+
console.log('\n🔎 \x1b[1;34mSearch: prompt = pudding\x1b[0m\n');
6358
console.log(
6459
colorSafeStringify(
6560
await table.search({
66-
q: {
67-
group: 'AND',
68-
conditions: [{ column: 'prompt', value: '🍮 pudding' }],
69-
},
61+
q: { group: 'AND', conditions: [{ column: 'prompt', value: '🍮 pudding' }] },
7062
}),
7163
1,
7264
),
7365
);
7466

75-
// 🔎 OR Search: prompt = pudding OR yay = false
76-
console.log('\n🔎 OR Search: pudding or yay = false\n');
67+
console.log('\n🔎 \x1b[1;34mOR Search: pudding or yay = false\x1b[0m\n');
7768
console.log(
7869
colorSafeStringify(
7970
await table.search({
@@ -89,31 +80,27 @@ const db = new PuddySql.Instance();
8980
),
9081
);
9182

92-
// 📚 Paginated Search
93-
console.log('\n📚 Paginated Search (2 per page)\n');
83+
console.log('\n📚 \x1b[32mPaginated Search (2 per page)\x1b[0m\n');
9484
const page1 = await table.search({ q: {}, perPage: 2, page: 1, order: 'id ASC' });
9585
console.table(page1.items);
9686

97-
console.log('\n📚 Paginated Search (Page 2)\n');
87+
console.log('\n📚 \x1b[32mPaginated Search (Page 2)\x1b[0m\n');
9888
const page2 = await table.search({ q: {}, perPage: 2, page: 2, order: 'id ASC' });
9989
console.table(page2.items);
10090
console.table({ totalPages: page2.totalPages, totalItems: page2.totalItems });
10191

102-
// 📌 Get amount (first 3)
103-
console.log('\n📌 Getting first 3 records\n');
92+
console.log('\n📌 \x1b[36mGetting first 3 records\x1b[0m\n');
10493
console.table(await table.getAmount(3));
10594

106-
// 🧹 Advanced delete: delete all yay = false
107-
console.log('\n🧹 Deleting all yay = false...\n');
95+
console.log('\n🧹 \x1b[31mDeleting all yay = false...\x1b[0m\n');
10896
const deleted = await table.advancedDelete({ yay: { value: false } });
109-
console.log(`Deleted rows: ${deleted}`);
97+
console.log(`\x1b[33mDeleted rows: ${deleted}\x1b[0m`);
11098

111-
// 🧾 Final state
112-
console.log('\n🧾 Final Records:\n');
99+
console.log('\n🧾 \x1b[1mFinal Records:\x1b[0m\n');
113100
console.table(await table.getAll());
114101

115-
// 🏷️ Tags System Tests
116-
console.log('\n🏷️ Creating tagged_posts table...\n');
102+
// 🏷️ Tags Test
103+
console.log('\n🏷️ \x1b[1mCreating tagged_posts table...\x1b[0m\n');
117104
const tagTable = await db.initTable({ name: 'tagged_posts', id: 'id' }, [
118105
['id', 'TEXT', 'PRIMARY KEY'],
119106
['title', 'TEXT'],
@@ -125,24 +112,23 @@ const db = new PuddySql.Instance();
125112
await tagTable.set('a1', { title: 'Post 1', tags: ['cute', 'funny'] });
126113
await tagTable.set('a2', { title: 'Post 2', tags: ['serious'] });
127114
await tagTable.set('a3', { title: 'Post 3', tags: ['cute', 'deep'] });
128-
const tagItems = await tagTable.getAll();
129-
console.table(tagItems);
115+
console.table(await tagTable.getAll());
130116

131-
console.log('\n🔖 Search: has tag "cute"\n');
117+
console.log('\n🔖 \x1b[34mSearch: has tag "cute"\x1b[0m\n');
132118
console.table(
133119
await tagTable.search({
134120
tagsQ: { column: 'tags', include: ['cute'] },
135121
}),
136122
);
137123

138-
console.log('\n🧠 Advanced Tag Search: cute AND not serious\n');
124+
console.log('\n🧠 \x1b[34mAdvanced Tag Search: cute AND not serious\x1b[0m\n');
139125
console.table(
140126
await tagTable.search({
141127
tagsQ: { column: 'tags', include: ['cute', '!serious'] },
142128
}),
143129
);
144130

145-
console.log('\n⚡ Boosted Tag Search (cute *2, deep *3)\n');
131+
console.log('\n⚡ \x1b[35mBoosted Tag Search (cute *2, deep *3)\x1b[0m\n');
146132
console.table(
147133
await tagTable.search({
148134
select: {
@@ -154,13 +140,10 @@ const db = new PuddySql.Instance();
154140
],
155141
},
156142
},
157-
tagsQ: {
158-
column: 'tags',
159-
include: ['cute', 'deep'],
160-
},
143+
tagsQ: { column: 'tags', include: ['cute', 'deep'] },
161144
}),
162145
);
163146

164-
console.log('\n✅ All tag tests done.\n');
165-
console.log('\n✅ Done.\n');
147+
console.log('\n✅ \x1b[1;32mAll tag tests done.\x1b[0m');
148+
console.log('\n🎉 \x1b[1;32mDone. Everything looks delicious! 🍮\x1b[0m\n');
166149
})();

0 commit comments

Comments
 (0)