मुख्य सामग्री पर जाएं
SmartTablesSDK उन्नत क्वेरी, फ़िल्टरिंग, सॉर्टिंग और डेटा हेरफेर क्षमताओं के साथ संरचित डेटा तालिकाओं के प्रबंधन के लिए एक व्यापक समाधान प्रदान करता है। कस्टम दृश्यों, डेटा आयात/निर्यात और AI-संचालित डेटा प्रसंस्करण के समर्थन के साथ शक्तिशाली डेटा प्रबंधन अनुप्रयोग आसानी से बनाएँ।

इंस्टॉलेशन

npm install @odin-ai-staging/sdk

त्वरित आरंभ

इस उदाहरण में, आप EKB API के माध्यम से कार्यक्रम द्वारा संरचित डेटा तालिकाएँ बनाने और प्रबंधित करने के लिए SmartTablesSDK का उपयोग करना सीखेंगे।
import { SmartTablesSDK } from '@odin-ai-staging/sdk';

// SDK को आरंभ करें
const smartTablesSDK = new SmartTablesSDK({
  baseUrl: 'https://your-api-endpoint.com/',
  projectId: 'your-project-id',
  apiKey: 'your-api-key',
  apiSecret: 'your-api-secret'
});

// त्वरित उदाहरण: तालिका बनाएँ और डेटा जोड़ें
async function quickExample() {
  // एक नई तालिका बनाएँ
  const table = await smartTablesSDK.createTable(
    'ग्राहक डेटाबेस',
    'ग्राहक जानकारी प्रबंधित करें'
  );
  
  // कॉलम जोड़ें
  await smartTablesSDK.addColumn(table.id, {
    name: 'name',
    type: 'text',
    description: 'ग्राहक का नाम'
  });
  
  await smartTablesSDK.addColumn(table.id, {
    name: 'email',
    type: 'email',
    description: 'ग्राहक ईमेल पता'
  });
  
  // डेटा जोड़ें
  await smartTablesSDK.addRow(table.id, {
    name: 'जॉन डो',
    email: 'john@example.com'
  });
  
  // डेटा क्वेरी करें
  const results = await smartTablesSDK.queryTable(table.id, {
    filters: [{ column: 'name', operator: 'contains', value: 'जॉन' }],
    pagination: { limit: 10, page: 1 }
  });
  
  console.log('क्वेरी परिणाम:', results.data);
}

कॉन्फ़िगरेशन

SmartTablesSDKConfig इंटरफ़ेस

interface SmartTablesSDKConfig {
  baseUrl: string;          // API एंडपॉइंट URL
  projectId: string;        // आपका परियोजना पहचानकर्ता
  apiKey?: string;          // प्रमाणीकरण के लिए API key
  apiSecret?: string;       // प्रमाणीकरण के लिए API secret
  accessToken?: string;     // वेब ऐप उपयोग के लिए access token
}

मूल अवधारणाएँ

SmartTable

एक SmartTable स्कीमा, metadata और डेटा प्रबंधन क्षमताओं वाली एक संरचित डेटा तालिका का प्रतिनिधित्व करता है।
interface SmartTable {
  id: string;                    // अद्वितीय तालिका पहचानकर्ता
  project_id: string;            // यह तालिका किस परियोजना से संबंधित है
  title: string;                 // तालिका का प्रदर्शन नाम
  description: string;           // तालिका विवरण
  schema: SmartTableColumn[];    // कॉलम परिभाषाएँ
  table_name: string;           // आंतरिक तालिका नाम
  created_at?: number;          // निर्माण टाइमस्टैम्प
  updated_at?: number;          // अंतिम अपडेट टाइमस्टैम्प
}

SmartTableColumn

तालिका कॉलम की संरचना और गुण परिभाषित करता है।
interface SmartTableColumn {
  name: string;                           // कॉलम नाम
  type: ColumnType;                       // डेटा प्रकार
  description?: string;                   // कॉलम विवरण
  notNull?: boolean;                      // आवश्यक फ़ील्ड
  unique?: boolean;                       // अद्वितीय बाध्यता
  defaultValue?: string | number | boolean | null;  // डिफ़ॉल्ट मान
  options?: Record<string, unknown>;      // अतिरिक्त विकल्प
}

type ColumnType = 'text' | 'number' | 'boolean' | 'date' | 'email' | 'url' | 'json';

फ़िल्टरिंग और क्वेरी

बहु-ऑपरेटर और सॉर्टिंग विकल्पों के साथ उन्नत फ़िल्टरिंग सिस्टम।
interface TableFilter {
  column: string;
  operator: FilterOperator;
  value: string | number | boolean | null;
}

type FilterOperator = 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'contains' | 'startswith' | 'endswith';

interface TableSort {
  column: string;
  direction: 'asc' | 'desc';
}

interface TablePagination {
  page?: number;
  limit?: number;
  search?: string;
}

तालिका प्रबंधन

getAllTables()

परियोजना में सभी तालिकाएँ प्राप्त करें।
async getAllTables(): Promise<SmartTable[]>
उदाहरण:
const tables = await smartTablesSDK.getAllTables();
tables.forEach(table => {
  console.log(`तालिका: ${table.title} (${table.id})`);
  console.log(`कॉलम: ${table.schema.length}`);
});

getTable(tableId)

ID द्वारा विशिष्ट तालिका प्राप्त करें।
async getTable(tableId: string): Promise<SmartTable>
उदाहरण:
const table = await smartTablesSDK.getTable('table_123');
console.log('तालिका स्कीमा:', table.schema);

createTable(title, description, metadata?)

एक नई तालिका बनाएँ।
async createTable(
  title: string,
  description: string,
  metadata?: Record<string, unknown>
): Promise<SmartTable>
उदाहरण:
const table = await smartTablesSDK.createTable(
  'उत्पाद कैटलॉग',
  'उत्पाद जानकारी और इन्वेंट्री प्रबंधित करें',
  { category: 'inventory', owner: 'admin' }
);

updateTable(tableId, title, description?, metadata?)

तालिका metadata अपडेट करें।
async updateTable(
  tableId: string,
  title: string,
  description?: string,
  metadata?: Record<string, unknown>
): Promise<void>
उदाहरण:
await smartTablesSDK.updateTable(
  'table_123',
  'अपडेटेड उत्पाद कैटलॉग',
  'उन्नत उत्पाद प्रबंधन प्रणाली',
  { version: '2.0' }
);

deleteTable(tableId)

एक तालिका और उसका सभी डेटा स्थायी रूप से हटाएँ।
async deleteTable(tableId: string): Promise<void>
उदाहरण:
await smartTablesSDK.deleteTable('table_123');

कॉलम संचालन

addColumn(tableId, column)

तालिका में एक नया कॉलम जोड़ें।
async addColumn(tableId: string, column: SmartTableColumn): Promise<void>
उदाहरण:
await smartTablesSDK.addColumn('table_123', {
  name: 'product_name',
  type: 'text',
  description: 'उत्पाद का नाम',
  notNull: true
});

await smartTablesSDK.addColumn('table_123', {
  name: 'price',
  type: 'number',
  description: 'USD में उत्पाद मूल्य',
  defaultValue: 0,
  notNull: true
});

await smartTablesSDK.addColumn('table_123', {
  name: 'supplier_email',
  type: 'email',
  description: 'आपूर्तिकर्ता संपर्क ईमेल',
  unique: true
});

updateColumn(tableId, columnName, updates)

कॉलम गुण अपडेट करें।
async updateColumn(
  tableId: string,
  columnName: string,
  updates: Partial<SmartTableColumn>
): Promise<void>
उदाहरण:
await smartTablesSDK.updateColumn('table_123', 'product_name', {
  description: 'अपडेटेड उत्पाद नाम फ़ील्ड',
  notNull: true,
  unique: true
});

deleteColumn(tableId, columnName)

तालिका से एक कॉलम हटाएँ।
async deleteColumn(tableId: string, columnName: string): Promise<void>
उदाहरण:
await smartTablesSDK.deleteColumn('table_123', 'obsolete_column');

डेटा संचालन

addRow(tableId, data)

तालिका में एक नया पंक्ति जोड़ें।
async addRow(tableId: string, data: Record<string, any>): Promise<any>
उदाहरण:
const newRow = await smartTablesSDK.addRow('table_123', {
  product_name: 'वायरलेस हेडफोन',
  price: 99.99,
  supplier_email: 'supplier@example.com',
  in_stock: true
});

console.log('नई पंक्ति ID:', newRow.id);

updateRow(tableId, rowId, columnName, newValue)

तालिका में एक विशिष्ट सेल अपडेट करें।
async updateRow(
  tableId: string,
  rowId: string,
  columnName: string,
  newValue: any
): Promise<void>
उदाहरण:
await smartTablesSDK.updateRow(
  'table_123',
  'row_456',
  'price',
  89.99
);

await smartTablesSDK.updateRow(
  'table_123',
  'row_456',
  'in_stock',
  false
);

deleteRow(tableId, rowId)

तालिका से एक पंक्ति हटाएँ।
async deleteRow(tableId: string, rowId: string): Promise<void>
उदाहरण:
await smartTablesSDK.deleteRow('table_123', 'row_456');

क्वेरी और फ़िल्टरिंग

queryTable(tableId, options?)

उन्नत फ़िल्टरिंग, सॉर्टिंग और पेजिनेशन के साथ तालिका डेटा क्वेरी करें।
async queryTable(
  tableId: string,
  options?: TableQueryOptions
): Promise<TableQueryResponse>
TableQueryOptions:
interface TableQueryOptions {
  filters?: TableFilter[];      // फ़िल्टर शर्तें
  sort?: TableSort[];          // सॉर्ट कॉन्फ़िगरेशन
  pagination?: TablePagination; // पेजिनेशन सेटिंग्स
}
उदाहरण:

बुनियादी क्वेरी

const results = await smartTablesSDK.queryTable('table_123');
console.log('सभी डेटा:', results.data);

फ़िल्टर्ड क्वेरी

const results = await smartTablesSDK.queryTable('table_123', {
  filters: [
    { column: 'price', operator: 'gte', value: 50 },
    { column: 'in_stock', operator: 'eq', value: true },
    { column: 'product_name', operator: 'contains', value: 'headphones' }
  ]
});

पेजिनेशन के साथ सॉर्टेड क्वेरी

const results = await smartTablesSDK.queryTable('table_123', {
  sort: [
    { column: 'price', direction: 'desc' },
    { column: 'product_name', direction: 'asc' }
  ],
  pagination: {
    page: 2,
    limit: 20,
    search: 'wireless'
  }
});

console.log(`${results.total} आइटम मिले`);
console.log(`पेज ${results.page} / ${Math.ceil(results.total / results.limit)}`);

डेटा आयात/निर्यात

importTable(title, description, columnMappings, file)

CSV या Excel फ़ाइलों से डेटा आयात करें।
async importTable(
  title: string,
  description: string,
  columnMappings: ColumnMapping[],
  file: File
): Promise<ImportResult>
ColumnMapping इंटरफ़ेस:
interface ColumnMapping {
  sourceColumn: string;     // स्रोत फ़ाइल में कॉलम नाम
  targetColumn: string;     // लक्ष्य तालिका में कॉलम नाम
  dataType: string;         // लक्ष्य डेटा प्रकार
}
उदाहरण:
const fileInput = document.getElementById('csvFile') as HTMLInputElement;
const file = fileInput.files[0];

const columnMappings: ColumnMapping[] = [
  { sourceColumn: 'Name', targetColumn: 'product_name', dataType: 'text' },
  { sourceColumn: 'Price', targetColumn: 'price', dataType: 'number' },
  { sourceColumn: 'Email', targetColumn: 'supplier_email', dataType: 'email' }
];

const result = await smartTablesSDK.importTable(
  'आयातित उत्पाद',
  'CSV से आयातित उत्पाद',
  columnMappings,
  file
);

console.log(`${result.rows_imported} पंक्तियाँ आयातित`);
console.log(`तालिका ID: ${result.data_type_id}`);

AI-संचालित सुविधाएँ

computeRowColumns(dataTypeId, rowId, columnNames?)

विशिष्ट पंक्ति कॉलम के लिए AI गणना ट्रिगर करें।
async computeRowColumns(
  dataTypeId: string,
  rowId: string,
  columnNames?: string[]
): Promise<void>
उदाहरण:
await smartTablesSDK.computeRowColumns(
  'table_123',
  'row_456',
  ['ai_summary', 'sentiment_score']
);

computeAllRows(dataTypeId)

तालिका में सभी पंक्तियों के लिए AI गणना ट्रिगर करें।
async computeAllRows(dataTypeId: string): Promise<{
  message: string;
  total_rows_processed: number;
  total_columns_updated: number;
  updated_columns: string[];
  failed_rows: number[];
  stopped_due_to_failures: boolean;
  retry_attempts: Record<number, number>;
  computation_id?: string;
  history_table?: string;
}>
उदाहरण:
const result = await smartTablesSDK.computeAllRows('table_123');
console.log(`${result.total_rows_processed} पंक्तियाँ प्रोसेस`);
console.log(`${result.total_columns_updated} कॉलम अपडेट`);
console.log(`अपडेटेड कॉलम: ${result.updated_columns.join(', ')}`);

if (result.failed_rows.length > 0) {
  console.log(`विफल पंक्तियाँ: ${result.failed_rows.join(', ')}`);
}

त्रुटि हैंडलिंग

SmartTablesSDK अन्य SDK घटकों के समान त्रुटि हैंडलिंग का उपयोग करता है:
try {
  const table = await smartTablesSDK.createTable('मेरी तालिका', 'विवरण');
} catch (error) {
  if (error instanceof APIError) {
    console.error(`API त्रुटि ${error.status}: ${error.message}`);
    if (error.detail) {
      console.error('विवरण:', error.detail);
    }
  } else {
    console.error('अप्रत्याशित त्रुटि:', error);
  }
}

उदाहरण

संपूर्ण डेटा प्रबंधन अनुप्रयोग

इस उदाहरण में, आप SmartTablesSDK का उपयोग करके एक संपूर्ण उत्पाद प्रबंधन प्रणाली बनाना सीखेंगे।
import { SmartTablesSDK } from '@odin-ai-staging/sdk';

class ProductManager {
  private sdk: SmartTablesSDK;
  private tableId?: string;

  constructor() {
    this.sdk = new SmartTablesSDK({
      baseUrl: process.env.API_BASE_URL,
      projectId: process.env.PROJECT_ID,
      apiKey: process.env.API_KEY,
      apiSecret: process.env.API_SECRET
    });
  }

  async initializeTable() {
    try {
      const table = await this.sdk.createTable(
        'उत्पाद कैटलॉग',
        'उत्पाद इन्वेंट्री और जानकारी प्रबंधित करें'
      );
      this.tableId = table.id;
      await this.addColumns();
      console.log('तालिका आरंभ:', this.tableId);
      return table;
    } catch (error) {
      console.error('तालिका आरंभ करने में विफल:', error);
      throw error;
    }
  }

  private async addColumns() {
    const columns = [
      { name: 'name', type: 'text', description: 'उत्पाद का नाम', notNull: true },
      { name: 'description', type: 'text', description: 'उत्पाद विवरण' },
      { name: 'price', type: 'number', description: 'USD में मूल्य', notNull: true },
      { name: 'category', type: 'text', description: 'उत्पाद श्रेणी' },
      { name: 'in_stock', type: 'boolean', description: 'इन्वेंट्री उपलब्धता', defaultValue: true },
      { name: 'supplier_email', type: 'email', description: 'आपूर्तिकर्ता संपर्क' },
      { name: 'website', type: 'url', description: 'उत्पाद वेबसाइट' },
      { name: 'created_at', type: 'date', description: 'निर्माण तिथि' }
    ];

    for (const column of columns) {
      await this.sdk.addColumn(this.tableId!, column);
    }
  }

  async addProduct(productData: any) {
    if (!this.tableId) throw new Error('तालिका आरंभ नहीं हुई');
    
    try {
      const result = await this.sdk.addRow(this.tableId, {
        ...productData,
        created_at: new Date().toISOString()
      });
      console.log('उत्पाद जोड़ा:', result);
      return result;
    } catch (error) {
      console.error('उत्पाद जोड़ने में विफल:', error);
      throw error;
    }
  }

  async searchProducts(searchTerm: string, category?: string, minPrice?: number, maxPrice?: number) {
    if (!this.tableId) throw new Error('तालिका आरंभ नहीं हुई');

    const filters = [];
    
    if (category) {
      filters.push({ column: 'category', operator: 'eq', value: category });
    }
    if (minPrice !== undefined) {
      filters.push({ column: 'price', operator: 'gte', value: minPrice });
    }
    if (maxPrice !== undefined) {
      filters.push({ column: 'price', operator: 'lte', value: maxPrice });
    }

    try {
      const results = await this.sdk.queryTable(this.tableId, {
        filters,
        pagination: { search: searchTerm, limit: 50 },
        sort: [{ column: 'name', direction: 'asc' }]
      });
      return results;
    } catch (error) {
      console.error('खोज विफल:', error);
      throw error;
    }
  }
}

const productManager = new ProductManager();
await productManager.initializeTable();
await productManager.addProduct({
  name: 'वायरलेस हेडफोन',
  price: 199.99,
  category: 'इलेक्ट्रॉनिक्स'
});

सर्वोत्तम प्रथाएँ

कुशल क्वेरी

  • बड़े डेटा सेट के लिए पेजिनेशन का उपयोग करें
  • डेटा ट्रांसफ़र कम करने के लिए फ़िल्टर लागू करें
  • संभव हो तो कई संचालनों को संयोजित करें
// अच्छा: फ़िल्टर और पेजिनेशन के साथ कुशल क्वेरी
const results = await smartTablesSDK.queryTable(tableId, {
  filters: [{ column: 'status', operator: 'eq', value: 'active' }],
  pagination: { limit: 50, page: 1 },
  sort: [{ column: 'created_at', direction: 'desc' }]
});

// बुरा: फ़िल्टर के बिना सभी डेटा प्राप्त करना
const allResults = await smartTablesSDK.queryTable(tableId);

स्कीमा डिज़ाइन

  • उपयुक्त कॉलम प्रकार परिभाषित करें
  • बाध्यताओं (notNull, unique) का उचित उपयोग करें
  • सार्थक विवरण प्रदान करें
// अच्छा: अच्छी तरह परिभाषित कॉलम स्कीमा
await smartTablesSDK.addColumn(tableId, {
  name: 'email',
  type: 'email',
  description: 'ग्राहक ईमेल पता',
  notNull: true,
  unique: true
});

// बुरा: अस्पष्ट कॉलम परिभाषा
await smartTablesSDK.addColumn(tableId, {
  name: 'data',
  type: 'text'
});

त्रुटि हैंडलिंग और मान्यता

  • हमेशा त्रुटियों को विनम्रतापूर्वक हैंडल करें
  • संचालन से पहले डेटा मान्य करें
  • संबंधित संचालन के लिए ट्रांज़ैक्शन का उपयोग करें
async function safeTableOperation(tableId: string, data: any) {
  try {
    if (!data.email || !data.email.includes('@')) {
      throw new Error('अमान्य ईमेल प्रारूप');
    }
    
    const result = await smartTablesSDK.addRow(tableId, data);
    return result;
  } catch (error) {
    console.error('संचालन विफल:', error);
    if (error.message.includes('unique constraint')) {
      throw new Error('ईमेल पहले से मौजूद है');
    }
    throw error;
  }
}