Skip to content

Commit

Permalink
Merge pull request #10 from anran758/develop
Browse files Browse the repository at this point in the history
Enhance io operations: support for bulk operations and improved type handling
  • Loading branch information
anran758 authored Mar 30, 2024
2 parents 535677a + adf0849 commit 161fa24
Show file tree
Hide file tree
Showing 36 changed files with 4,111 additions and 10,162 deletions.
1,183 changes: 0 additions & 1,183 deletions apps/faas-demo/_schema.json

This file was deleted.

2 changes: 1 addition & 1 deletion apps/faas-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"upload": "mincloudx faas upload",
"deploy": "mincloudx faas deploy",
"debug": "mincloudx faas debug",
"refresh": "mincloudx type"
"refresh": "mincloudx type --pull"
},
"bugs": {
"url": "https://github.com/anran758/mincloudx/issues"
Expand Down
4 changes: 1 addition & 3 deletions apps/faas-demo/src/function/channel/channelDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ interface EventParams {

export default createFaas<EventParams>(async function main(event) {
const { id } = event.data;
// const result = await io.channel.delete(id);
const result = await io.channel.delete(id);

const query = io.getQuery({ id });
const result = await io.channel.delete(query);
console.log('delete result:', result);

return result;
Expand Down
13 changes: 13 additions & 0 deletions apps/faas-demo/src/function/test/testOperationCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createFaas } from '@mincloudx/faas';
import io from '@/io';

export default createFaas(async function main() {
const query = io.getQuery({
description: 'This is description.',
});
const count = await io.product.count(query);

console.log('count: ', count);

return { count };
});
37 changes: 37 additions & 0 deletions apps/faas-demo/src/function/test/testOperationCreateMany.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createFaas } from '@mincloudx/faas';
import io from '@/io';

import { getCurrentDate } from '@/utils';

function generatorMockData() {
const rawData = {
name: `新书本-${getCurrentDate()}`,
cover:
'https://cloud-minapp-47549.cloud.ifanrusercontent.com/1rmlh9degSiaF4ua.jpg',
description: 'testOperationCreateMany create.',
};

return Array(6)
.fill(0)
.map((_, i) => {
return {
...rawData,
name: `${rawData.name}_${i}`,
};
});
}
export default createFaas(async function main() {
const list = generatorMockData();

const {
operation_result: result,
succeed,
total_count,
} = await io.product.createMany(list);

console.log('result:', result);
console.log('succeed: ', succeed);
console.log('total: ', total_count);

return result;
});
17 changes: 17 additions & 0 deletions apps/faas-demo/src/function/test/testOperationDeleteMany.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createFaas } from '@mincloudx/faas';
import io from '@/io';

export default createFaas(async function main() {
const result = await io.product.deleteMany(io.query, {
limit: 2,
});
console.log(
'result: ',
result.succeed,
result.offset,
result.limit,
result.next,
);

return result;
});
14 changes: 14 additions & 0 deletions apps/faas-demo/src/function/test/testOperationFindList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createFaas } from '@mincloudx/faas';
import io from '@/io';

export default createFaas(async function main() {
const query = io.getQuery({
description: 'This is description.',
});
const result = await io.product.find(query, {
select: ['id', 'name', 'description'],
plain: true,
});

return result;
});
17 changes: 17 additions & 0 deletions apps/faas-demo/src/function/test/testOperationUpdateMany.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createFaas } from '@mincloudx/faas';
import io from '@/io';

export default createFaas(async function main() {
const list = await io.product.updateMany({
query: io.getQuery({
created_at: 1711691446,
}),
data: {
description: `update date: ${new Date()}`,
},
});

console.log('result:', list);

return list;
});
2 changes: 1 addition & 1 deletion apps/faas-demo/src/io/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createIo } from '@mincloudx/io';

export default createIo({
tables: ['channel'],
tables: ['channel', 'product'],
});
20 changes: 20 additions & 0 deletions apps/faas-demo/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function getCurrentDate() {
const now = new Date();

// 分别获取日期和时间字符串
const dateString = now
.toLocaleDateString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
})
.replace(/\//g, '-');

const timeString = now.toLocaleTimeString('zh-CN', {
hour: '2-digit',
minute: '2-digit',
hour12: false, // 使用24小时制
});

return `${dateString} ${timeString}`;
}
Loading

0 comments on commit 161fa24

Please sign in to comment.