add get table columns
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/noco",
|
||||
"version": "0.0.7",
|
||||
"version": "0.0.8",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -53,7 +53,6 @@ export class Query {
|
||||
fetchOptions.body = JSON.stringify(options.data);
|
||||
}
|
||||
return fetch(url.href, fetchOptions).then(async (response) => {
|
||||
console.log('Response Status:', response.status, response);
|
||||
if (!response.ok) {
|
||||
return { code: response.status, message: response.statusText };
|
||||
}
|
||||
@@ -63,8 +62,8 @@ export class Query {
|
||||
if (isArray) {
|
||||
return {
|
||||
code: 200,
|
||||
list: result,
|
||||
} as ResponseList;
|
||||
data: { list: result },
|
||||
};
|
||||
} else if (result && typeof result === 'object' && !('code' in result)) {
|
||||
return {
|
||||
code: 200,
|
||||
@@ -81,6 +80,7 @@ export class Query {
|
||||
|
||||
export type ResponseList<T = any> = {
|
||||
code: number;
|
||||
data: {
|
||||
list: T[];
|
||||
pageInfo?: {
|
||||
totalRows?: number;
|
||||
@@ -89,4 +89,5 @@ export type ResponseList<T = any> = {
|
||||
isFirstPage?: boolean;
|
||||
isLastPage?: boolean;
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -19,9 +19,9 @@ export class NocoApi {
|
||||
const token = options?.token;
|
||||
const baseURL = options?.baseURL;
|
||||
this.query = new Query({ baseURL, token });
|
||||
this.record = new Record(this.query, table);
|
||||
this.meta = new Meta({ query: this.query });
|
||||
this.upload = new Upload(this.query);
|
||||
this.record = new Record({ query: this.query, table, meta: this.meta });
|
||||
}
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
import { Query } from './api.ts';
|
||||
import { Meta } from './meta/index.ts';
|
||||
type QueryParams = {
|
||||
/**
|
||||
* fields=field1,field2
|
||||
@@ -20,6 +21,7 @@ type QueryParams = {
|
||||
};
|
||||
type ResultList<T = any> = {
|
||||
code: number;
|
||||
data: {
|
||||
list: T[];
|
||||
pageInfo?: {
|
||||
totalRows?: number;
|
||||
@@ -28,6 +30,7 @@ type ResultList<T = any> = {
|
||||
isFirstPage?: boolean;
|
||||
isLastPage?: boolean;
|
||||
};
|
||||
}
|
||||
};
|
||||
type Id = string | number;
|
||||
/**
|
||||
@@ -36,9 +39,11 @@ type Id = string | number;
|
||||
export class Record {
|
||||
query: Query;
|
||||
table: string;
|
||||
constructor(query: Query, table: string) {
|
||||
meta: Meta
|
||||
constructor({ query, table, meta }: { query: Query, table: string, meta?: Meta }) {
|
||||
this.query = query;
|
||||
this.table = table;
|
||||
this.meta = meta;
|
||||
}
|
||||
list<T = any>(params: QueryParams = {}): Promise<ResultList<T>> {
|
||||
return this.query.makeRequest(`/api/v2/tables/${this.table}/records`, {
|
||||
@@ -90,6 +95,10 @@ export class Record {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
getTableMeta() {
|
||||
return this.meta.tables.getTableMeta(this.table);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { NocoApi } from './../src/main.ts';
|
||||
import { useConfig } from '@kevisual/use-config'
|
||||
import { CreateColumnData } from '../src/meta/index.ts';
|
||||
import { CreateBaseData } from '../src/meta/index.ts';
|
||||
export const config = useConfig()
|
||||
import util from 'node:util';
|
||||
import { writeFile, writeFileSync } from 'node:fs';
|
||||
// # 签到表
|
||||
// const table = 'mcby44q8zrayvn9'
|
||||
// 本地
|
||||
const table = 'mecdgojq151iwk9'
|
||||
const table = 'mecdgojq151iwk9' // gitstarred_repos
|
||||
export const nocoApi = new NocoApi({
|
||||
baseURL: config.NOCODB_URL || 'http://localhost:8080',
|
||||
token: config.NOCODB_API_KEY || '',
|
||||
@@ -14,5 +15,11 @@ export const nocoApi = new NocoApi({
|
||||
});
|
||||
|
||||
|
||||
// const list = await nocoApi.record.list()
|
||||
// console.log(util.inspect(list, { depth: null, colors: true }))
|
||||
// const res = await nocoApi.record.list()
|
||||
// console.log(util.inspect(res.data, { depth: null, colors: true }))
|
||||
|
||||
const res =await nocoApi.record.getTableMeta()
|
||||
// console.log(util.inspect(res, { depth: null, colors: true }))
|
||||
const keys = Object.keys(res.data || {})
|
||||
console.log('表字段列表:', keys);
|
||||
writeFileSync('table-metadata.json', JSON.stringify(res, null, 2));
|
||||
10
test/list-table.ts
Normal file
10
test/list-table.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
import { nocoApi } from './common.ts';
|
||||
import util from 'node:util';
|
||||
import { writeFileSync } from 'node:fs';
|
||||
|
||||
const res =await nocoApi.record.getTableMeta()
|
||||
// console.log(util.inspect(res, { depth: null, colors: true }))
|
||||
const keys = Object.keys(res.data || {})
|
||||
console.log('表字段列表:', keys);
|
||||
writeFileSync('table-metadata.json', JSON.stringify(res, null, 2));
|
||||
Reference in New Issue
Block a user