Skip to content

Commit

Permalink
initiate
Browse files Browse the repository at this point in the history
  • Loading branch information
r350178982 committed Dec 16, 2023
1 parent 857fec8 commit 94cd200
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

# lib
/lib

/.idea
29 changes: 29 additions & 0 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ class Base {
return this.req.get(url);
}

async getTables() {
const res = await this.getDTable();
return res.tables;
}

async getTableByName(table_name) {
const res = await this.getTables();
return res.find(table=> table.name === table_name);

}

getMetadata() {
const url = `/api/v1/dtables/${this.dtableUuid}/metadata/`;
return this.req.get(url);
Expand All @@ -89,6 +100,24 @@ class Base {
return this.req.post(url, {...data});
}

renameTable(old_name, new_name) {
const url = `/api/v1/dtables/${this.dtableUuid}/tables/`;
const data = {
table_name: old_name,
new_table_name: new_name
}
return this.req.put(url, {...data});
}

deleteTable(table_name) {
const url = `/api/v1/dtables/${this.dtableUuid}/tables/`;
const data = {
table_name: table_name,
}
return this.req.delete(url, {data:data});

}

listViews(table_name) {
const url = `api/v1/dtables/${this.dtableUuid}/views/`;
const params = {
Expand Down
9 changes: 5 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ const fs = require('fs')
const { Base } = require('../lib');

const config = {
server: 'http://127.0.0.1',
APIToken: 'acdf4e21d4a0f36686848d81523a2df4ab67bf2d'
server: 'https://dev.seatable.cn',
APIToken: 'e16880c58426d59d698143f1dfb8abc8bd5d2ecc'
};


async function testAPI() {
const base = new Base(config);
await base.auth();
const data = await base.query('select * from Table2');
fs.writeFileSync('./abc.json', JSON.stringify(data, null, 2))
const data = await base.deleteTable('Sheet1');
console.log(data, 'ssssssss')
// fs.writeFileSync('./abc.json', JSON.stringify(data, null, 2))
}

testAPI();

0 comments on commit 94cd200

Please sign in to comment.