messages
listlengths
3
3
category
stringlengths
5
25
function_name
stringlengths
9
26
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for works with advanced sql operations", "role": "user" }, { "content": "const sqlCasesOperations = async () => {\n const model = await p.getModel('product');\n \n // Prepare data for SQL cases\n const items = [\n { id: 1, name: 'Product A', category: 'electronics', price: 299.99 },\n { id: 2, name: 'Product B', category: 'books', price: 19.99 },\n { id: 3, name: 'Product C', category: 'clothing', price: 49.99 }\n ];\n \n try {\n // Build SQL cases for bulk update\n const sqlCases = await p.utils.buildSqlCasesQuery(items, {\n key: 'id',\n model: 'product'\n });\n \n // Apply bulk update with SQL cases\n const updatedCount = await model\n .find({ id: [1, 2, 3] })\n .update(sqlCases);\n \n return { sqlCases, updatedCount };", "role": "assistant" } ]
ADVANCED SQL OPERATIONS
sqlCasesOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I works with raw data queries with SL2 Query API?", "role": "user" }, { "content": "const basicRawQueries = async () => {\n const model = await p.getModel('stats');\n \n // Simple raw query\n const rawStats = await model\n .find({ date: { '>': new Date('2024-01-01') } })\n .raw();\n \n // Raw with field selection\n const rawUserData = await model\n .find({ active: true })\n .fields(['id', 'name', 'created_at'])\n .raw();\n \n // Raw with ordering\n const rawOrderedData = await model\n .find({ status: 'completed' })\n .order({ created_at: 'desc' })\n .raw();\n \n return { rawStats, rawUserData, rawOrderedData };", "role": "assistant" } ]
RAW DATA QUERIES
basicRawQueries
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Show me how to works with error handling patterns using SL2 Query API", "role": "user" }, { "content": "const errorHandlingBasic = async () => {\n const model = await p.getModel('user');\n const results = {\n success: [],\n errors: []\n };", "role": "assistant" } ]
ERROR HANDLING PATTERNS
errorHandlingBasic
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for limits query results with offset", "role": "user" }, { "content": "const advancedPagination = async () => {\n const model = await p.getModel('product');\n \n // Pagination with complex conditions\n const paginatedProducts = await model\n .find({ category: 'electronics' })\n .orFind({ featured: true })\n .order({ rating: 'desc', price: 'asc' })\n .limit(20, 40); // Page 3, 20 per page\n \n // Large dataset pagination\n const batchData = await model\n .find({ needs_processing: true })\n .order({ created_at: 'asc' })\n .limit(1000, 0);\n \n return { paginatedProducts, batchData };", "role": "assistant" } ]
PAGINATION AND LIMITS
advancedPagination
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for performs bulk updates on multiple records", "role": "user" }, { "content": "const bulkDeleteOperations = async () => {\n const model = await p.getModel('log');\n \n // Basic bulk delete\n const deletedCount = await model\n .find({ \n created_at: { '<': new Date('2023-01-01') },\n level: 'debug'\n })\n .delete();\n \n // Bulk delete with complex conditions\n const cleanupCount = await model\n .find({ processed: true })\n .orFind({ \n created_at: { '<': new Date('2024-01-01') },\n level: { 'NOTIN': ['error', 'warning'] }\n })\n .delete();\n \n return { deletedCount, cleanupCount };", "role": "assistant" } ]
BULK OPERATIONS
bulkDeleteOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a JavaScript function using SL2 Query API to works with count operations", "role": "user" }, { "content": "const advancedCountOperations = async () => {\n const model = await p.getModel('order');\n \n // Count with complex conditions\n const recentOrdersCount = await model\n .find({ \n status: 'completed',\n created_at: { '>': new Date('2024-01-01') }\n })\n .count();\n \n // Count with array conditions\n const urgentOrdersCount = await model\n .find({ \n priority: ['high', 'urgent'],\n status: { '!=': 'cancelled' }\n })\n .count();\n \n return { recentOrdersCount, urgentOrdersCount };", "role": "assistant" } ]
COUNT OPERATIONS
advancedCountOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that works with field selection using the SL2 JavaScript API", "role": "user" }, { "content": "const basicFieldSelection = async () => {\n const model = await p.getModel('user');\n \n // Select specific fields\n const userNames = await model\n .find({ active: true })\n .fields(['id', 'name', 'email']);\n \n // Select fields with conditions\n const adminInfo = await model\n .find({ role: 'admin' })\n .fields(['id', 'name', 'email', 'last_login']);\n \n // Minimal field selection\n const userIds = await model\n .find({ active: true })\n .fields(['id']);\n \n return { userNames, adminInfo, userIds };", "role": "assistant" } ]
FIELD SELECTION
basicFieldSelection
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for calculates statistics using GROUP BY", "role": "user" }, { "content": "const advancedGrouping = async () => {\n const model = await p.getModel('analytics');\n \n // Multiple aggregations\n const salesStats = await model\n .find({ status: 'completed' })\n .group('region', {\n 'total_sales': { 'SUM': 'amount' },\n 'avg_sale': { 'AVG': 'amount' },\n 'sale_count': { 'COUNT': 'id' },\n 'max_sale': { 'MAX': 'amount' },\n 'min_sale': { 'MIN': 'amount' }\n });\n \n // First and Last aggregations\n const timeStats = await model\n .find({ type: 'transaction' })\n .order({ created_at: 'asc' })\n .group('category', {\n 'first_transaction': { 'FIRST': 'amount' },\n 'last_transaction': { 'LAST': 'amount' }\n });\n \n return { salesStats, timeStats };", "role": "assistant" } ]
GROUPING OPERATIONS
advancedGrouping
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I performs complex multi-table operations with SL2 Query API?", "role": "user" }, { "content": "const advancedJoins = async () => {\n const orderModel = await p.getModel('order');\n const customerModel = await p.getModel('customer');\n const productModel = await p.getModel('product');\n \n // Multiple joins\n const orderDetails = await orderModel\n .join(customerModel, 'id', orderModel, 'customer_id')\n .join(productModel, 'id', orderModel, 'product_id')\n .find({ \n status: 'completed',\n created_at: { '>': new Date('2024-01-01') }\n }, orderModel)\n .orFind({ premium: true }, customerModel)\n .fields(['id', 'total', 'created_at'], orderModel)\n .fields(['name', 'email'], customerModel)\n .fields(['name', 'category'], productModel)\n .order({ total: 'desc' }, orderModel);\n \n return { orderDetails };", "role": "assistant" } ]
JOINS
advancedJoins
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that executes mass delete operations using the SL2 JavaScript API", "role": "user" }, { "content": "const bulkUpdateOperations = async () => {\n const model = await p.getModel('user');\n \n // Basic bulk update\n const updatedCount = await model\n .find({ last_login: { '<': new Date('2023-01-01') } })\n .update({ status: 'inactive' });\n \n // Bulk update with multiple fields\n const archiveCount = await model\n .find({ \n status: 'inactive',\n last_login: { '<': new Date('2022-01-01') }\n })\n .update({ \n status: 'archived',\n archived_at: new Date(),\n active: false\n });\n \n return { updatedCount, archiveCount };", "role": "assistant" } ]
BULK OPERATIONS
bulkUpdateOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I handles batch data operations efficiently with SL2 Query API?", "role": "user" }, { "content": "const massInsertOperations = async () => {\n const model = await p.getModel('user');\n \n // Basic mass insert\n const insertedIds = await model.massInsert([\n { name: 'John Doe', email: '[email protected]', active: true },\n { name: 'Jane Smith', email: '[email protected]', active: true },\n { name: 'Bob Johnson', email: '[email protected]', active: false }\n ]);\n \n // Mass insert with complex data\n const productIds = await model.massInsert([\n { \n name: 'Laptop Pro', \n category: 'electronics', \n price: 1299.99,\n features: ['high-performance', 'portable']\n },\n { \n name: 'Wireless Mouse', \n category: 'accessories', \n price: 29.99,\n features: ['wireless', 'ergonomic']\n }\n ]);\n \n return { insertedIds, productIds };", "role": "assistant" } ]
BULK OPERATIONS
massInsertOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I works with testing and debugging with SL2 Query API?", "role": "user" }, { "content": "const executeExamples = async () => {\n try {\n // Test a few key functions\n const basicResults = await basicFind();\n const operatorResults = await comparisonOperators();\n const countResults = await basicCountOperations();\n \n p.log.info({\n basicResults: basicResults ? 'success' : 'failed',\n operatorResults: operatorResults ? 'success' : 'failed', \n countResults: countResults ? 'success' : 'failed'\n }, 'SL2 Query Examples Test');\n \n return {\n status: 'completed',\n timestamp: new Date().toISOString()\n };", "role": "assistant" } ]
TESTING AND DEBUGGING
executeExamples
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that works with iterator operations", "role": "user" }, { "content": "const iteratorEachExamples = async () => {\n const model = await p.getModel('large_dataset');\n const results = [];\n \n // Process records one by one\n await p.iterEach(\n model\n .find({ processed: false })\n .order({ id: 'asc' })\n .fields(['id', 'data']),\n 1000, // batch size\n (record) => {\n // Process each record\n results.push(`Processed record ${record.id}`);\n // Add your processing logic here\n }\n );\n \n return { processedCount: results.length };", "role": "assistant" } ]
ITERATOR OPERATIONS
iteratorEachExamples
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that works with count operations using the SL2 JavaScript API", "role": "user" }, { "content": "const basicCountOperations = async () => {\n const model = await p.getModel('user');\n \n // Simple count\n const totalUsers = await model\n .find({ active: true })\n .count();\n \n // Count with conditions\n const adminCount = await model\n .find({ role: 'admin' })\n .count();\n \n // Count with OR conditions\n const privilegedUsersCount = await model\n .find({ role: 'admin' })\n .orFind({ role: 'manager' })\n .count();\n \n return { totalUsers, adminCount, privilegedUsersCount };", "role": "assistant" } ]
COUNT OPERATIONS
basicCountOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a JavaScript function using SL2 Query API to works with reference queries", "role": "user" }, { "content": "const referenceQueries = async () => {\n const model = await p.getModel('document');\n \n // Reference by ID\n const documentsByModel = await model.find({\n model: 1\n });\n \n // Reference NOT IN\n const documentsNotInModels = await model.find({\n model: { NOTIN: [1, 2, 3] }\n });\n \n // Reference by alias\n const userDocuments = await model.find({\n model: { alias: 'user' }\n });\n \n return { documentsByModel, documentsNotInModels, userDocuments };", "role": "assistant" } ]
REFERENCE QUERIES
referenceQueries
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Show me how to works with array operators using SL2 Query API", "role": "user" }, { "content": "const arrayEqualityOperators = async () => {\n const model = await p.getModel('project');\n \n // Array equal to\n const exactTagsProjects = await model.find({\n tags: { '=': ['web', 'mobile'] }\n });\n \n // Array is contained by\n const projectsContainedBy = await model.find({\n tags: { '<@': ['javascript', 'python', 'java', 'web', 'mobile'] }\n });\n \n // Empty array check\n const projectsWithoutTags = await model.find({\n tags: 'ISNULL'\n });\n \n return { exactTagsProjects, projectsContainedBy, projectsWithoutTags };", "role": "assistant" } ]
ARRAY OPERATORS
arrayEqualityOperators
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I works with complex queries with SL2 Query API?", "role": "user" }, { "content": "const complexFilteringQuery = async () => {\n const projectModel = await p.getModel('project');\n \n // Complex filtering with multiple OR conditions\n const filteredProjects = await projectModel\n .find({\n status: 'active',\n priority: ['high', 'urgent']\n })\n .orFind({\n featured: true,\n created_at: { '>': new Date('2024-06-01') }\n })\n .orFind({\n tags: { '@>': ['critical', 'important'] },\n assigned_to: 'ISNOTNULL'\n })\n .fields(['id', 'name', 'status', 'priority', 'tags'])\n .order({ priority: 'desc', created_at: 'desc' })\n .limit(50);\n \n return { filteredProjects };", "role": "assistant" } ]
COMPLEX QUERIES
complexFilteringQuery
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that works with rtl bulk operations using the SL2 JavaScript API", "role": "user" }, { "content": "const rtlBulkOperations = async () => {\n const model = await p.getModel('user');\n \n // RTL replace operation\n const replacedCount = await model\n .find({ id: [1, 2, 3] })\n .update({\n user_groups: [5, 6, 7] // Replace existing RTL values\n });\n \n // RTL append operation\n const appendedCount = await model\n .find({ active: true })\n .update({\n user_groups: { append: [8, 9] } // Add to existing RTL\n });\n \n // RTL remove operation\n const removedCount = await model\n .find({ status: 'inactive' })\n .update({\n user_groups: { remove: [1, 2] } // Remove from RTL\n });\n \n return { replacedCount, appendedCount, removedCount };", "role": "assistant" } ]
RTL BULK OPERATIONS
rtlBulkOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a SL2 query function to joins multiple tables in queries", "role": "user" }, { "content": "const joinWithGrouping = async () => {\n const salesModel = await p.getModel('sales');\n const customerModel = await p.getModel('customer');\n \n // Join with grouping\n const customerSalesStats = await salesModel\n .join(customerModel, 'id', salesModel, 'customer_id')\n .find({ status: 'completed' }, salesModel)\n .group('customer_type', {\n 'total_sales': { 'SUM': { 'amount': salesModel } },\n 'avg_sale': { 'AVG': { 'amount': salesModel } },\n 'sale_count': { 'COUNT': { 'id': salesModel } }\n }, customerModel);\n \n return { customerSalesStats };", "role": "assistant" } ]
JOINS
joinWithGrouping
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that combines data from related models using the SL2 JavaScript API", "role": "user" }, { "content": "const basicJoins = async () => {\n const userModel = await p.getModel('user');\n const profileModel = await p.getModel('profile');\n \n // Simple join\n const usersWithProfiles = await userModel\n .join(profileModel, 'user_id', userModel, 'id')\n .find({ active: true }, userModel)\n .order({ name: 'asc' }, userModel);\n \n // Join with field selection\n const userProfileData = await userModel\n .join(profileModel, 'user_id', userModel, 'id')\n .find({ active: true }, userModel)\n .fields(['id', 'name', 'email'], userModel)\n .fields(['bio', 'avatar'], profileModel);\n \n return { usersWithProfiles, userProfileData };", "role": "assistant" } ]
JOINS
basicJoins
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that works with reference queries", "role": "user" }, { "content": "const referenceAdvancedQueries = async () => {\n const model = await p.getModel('permission');\n \n // Multiple reference aliases\n const permissionsForModels = await model.find({\n model: { alias: ['user', 'document', 'project'] }\n });\n \n // Reference NOTIN with aliases\n const permissionsNotForModels = await model.find({\n model: { alias: { NOTIN: ['system', 'internal'] } }\n });\n \n // Reference with other conditions\n const activePermissions = await model.find({\n active: true,\n model: { alias: 'user' }\n });\n \n return { permissionsForModels, permissionsNotForModels, activePermissions };", "role": "assistant" } ]
REFERENCE QUERIES
referenceAdvancedQueries
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I executes mass delete operations with SL2 Query API?", "role": "user" }, { "content": "const bulkUpdateWithSQL = async () => {\n const model = await p.getModel('product');\n \n // Bulk update with SQL raw values\n const updatedWithSQL = await model\n .find({ id: [1, 2, 3] })\n .update({\n name: { \n __type: 'sql_raw', \n sql: `CONCAT('Product_', id)` \n },\n status: { \n __type: 'sql_raw', \n sql: `(CASE WHEN id = 1 THEN ? WHEN id = 2 THEN ? ELSE ? END)`, \n bindings: ['active', 'pending', 'inactive'] \n }\n });\n \n // Complex SQL update\n const complexUpdate = await model\n .find({ category: 'electronics' })\n .update({\n price: {\n __type: 'sql_raw',\n sql: `price * 1.1` // 10% price increase\n }\n });\n \n return { updatedWithSQL, complexUpdate };", "role": "assistant" } ]
BULK OPERATIONS
bulkUpdateWithSQL
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Show me how to implements pagination for large datasets using SL2 Query API", "role": "user" }, { "content": "const basicPagination = async () => {\n const model = await p.getModel('article');\n \n // First page (10 records)\n const firstPage = await model\n .find({ published: true })\n .order({ created_at: 'desc' })\n .limit(10, 0);\n \n // Second page (next 10 records)\n const secondPage = await model\n .find({ published: true })\n .order({ created_at: 'desc' })\n .limit(10, 10);\n \n // Just limit without offset\n const topTen = await model\n .find({ featured: true })\n .order({ views: 'desc' })\n .limit(10);\n \n return { firstPage, secondPage, topTen };", "role": "assistant" } ]
PAGINATION AND LIMITS
basicPagination
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for joins multiple tables in queries", "role": "user" }, { "content": "const advancedJoins = async () => {\n const orderModel = await p.getModel('order');\n const customerModel = await p.getModel('customer');\n const productModel = await p.getModel('product');\n \n // Multiple joins\n const orderDetails = await orderModel\n .join(customerModel, 'id', orderModel, 'customer_id')\n .join(productModel, 'id', orderModel, 'product_id')\n .find({ \n status: 'completed',\n created_at: { '>': new Date('2024-01-01') }\n }, orderModel)\n .orFind({ premium: true }, customerModel)\n .fields(['id', 'total', 'created_at'], orderModel)\n .fields(['name', 'email'], customerModel)\n .fields(['name', 'category'], productModel)\n .order({ total: 'desc' }, orderModel);\n \n return { orderDetails };", "role": "assistant" } ]
JOINS
advancedJoins
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for performs data aggregation with MAX, MIN, SUM, COUNT, AVG", "role": "user" }, { "content": "const basicGrouping = async () => {\n const model = await p.getModel('sales');\n \n // MAX aggregation\n const maxSalesByCategory = await model\n .find({ status: 'completed' })\n .group('category', { 'max_amount': { 'MAX': 'amount' } });\n \n // MIN aggregation\n const minSalesByCategory = await model\n .find({ status: 'completed' })\n .group('category', { 'min_amount': { 'MIN': 'amount' } });\n \n // SUM aggregation\n const totalSalesByCategory = await model\n .find({ status: 'completed' })\n .group('category', { 'total_amount': { 'SUM': 'amount' } });\n \n return { maxSalesByCategory, minSalesByCategory, totalSalesByCategory };", "role": "assistant" } ]
GROUPING OPERATIONS
basicGrouping
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for works with integration patterns", "role": "user" }, { "content": "const integrationWithWebServices = async () => {\n // Example of using queries in web service context\n const params = p.getRequest();\n const model = await p.getModel(params.modelAlias);\n \n // API endpoint for data retrieval\n const apiData = await model\n .find({ \n active: true,\n api_enabled: true\n })\n .fields(['id', 'name', 'api_key', 'endpoint'])\n .order({ name: 'asc' });\n \n // Format for API response\n const formattedData = apiData.map(record => ({\n id: record.getValue('id'),\n name: record.getValue('name'),\n endpoint: record.getValue('endpoint'),\n // Don't expose sensitive data like api_key in public API\n }));\n \n return {\n success: true,\n data: formattedData,\n total: formattedData.length,\n timestamp: new Date().toISOString()\n };", "role": "assistant" } ]
INTEGRATION PATTERNS
integrationWithWebServices
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I works with integration patterns with SL2 Query API?", "role": "user" }, { "content": "const integrationWithForms = async () => {\n // Example of using queries in form context\n const currentRecord = p.record;\n const model = await p.getModel(currentRecord.getModel().getValue('alias'));\n \n // Find related records based on current form data\n const relatedRecords = await model\n .find({ \n category: currentRecord.getValue('category'),\n id: { '!=': currentRecord.getValue('id') }\n })\n .order({ created_at: 'desc' })\n .limit(5);\n \n // Find records for dropdown population\n const dropdownOptions = await model\n .find({ \n active: true,\n type: currentRecord.getValue('type')\n })\n .fields(['id', 'name'])\n .order({ name: 'asc' });\n \n return { relatedRecords, dropdownOptions };", "role": "assistant" } ]
INTEGRATION PATTERNS
integrationWithForms
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that works with complex queries using the SL2 JavaScript API", "role": "user" }, { "content": "const complexGroupingQuery = async () => {\n const salesModel = await p.getModel('sales');\n const regionModel = await p.getModel('region');\n \n // Complex grouping with joins\n const regionalStats = await salesModel\n .join(regionModel, 'id', salesModel, 'region_id')\n .find({ \n status: 'completed',\n created_at: { '>': new Date('2024-01-01') }\n }, salesModel)\n .group('name', {\n 'total_revenue': { 'SUM': { 'amount': salesModel } },\n 'avg_sale': { 'AVG': { 'amount': salesModel } },\n 'max_sale': { 'MAX': { 'amount': salesModel } },\n 'min_sale': { 'MIN': { 'amount': salesModel } },\n 'sale_count': { 'COUNT': { 'id': salesModel } },\n 'first_sale': { 'FIRST': { 'amount': salesModel } },\n 'last_sale': { 'LAST': { 'amount': salesModel } }\n }, regionModel)\n .order({ 'total_revenue': 'desc' });\n \n return { regionalStats };", "role": "assistant" } ]
COMPLEX QUERIES
complexGroupingQuery
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a SL2 query function to calculates statistics using GROUP BY", "role": "user" }, { "content": "const basicGrouping = async () => {\n const model = await p.getModel('sales');\n \n // MAX aggregation\n const maxSalesByCategory = await model\n .find({ status: 'completed' })\n .group('category', { 'max_amount': { 'MAX': 'amount' } });\n \n // MIN aggregation\n const minSalesByCategory = await model\n .find({ status: 'completed' })\n .group('category', { 'min_amount': { 'MIN': 'amount' } });\n \n // SUM aggregation\n const totalSalesByCategory = await model\n .find({ status: 'completed' })\n .group('category', { 'total_amount': { 'SUM': 'amount' } });\n \n return { maxSalesByCategory, minSalesByCategory, totalSalesByCategory };", "role": "assistant" } ]
GROUPING OPERATIONS
basicGrouping
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for works with date time operations", "role": "user" }, { "content": "const dateTimeBasicQueries = async () => {\n const model = await p.getModel('event');\n \n // Basic date comparisons\n const recentEvents = await model\n .find({ \n created_at: { '>': new Date('2024-01-01') }\n });\n \n // Date range queries\n const thisMonthEvents = await model\n .find({\n created_at: { \n '>=': new Date('2024-08-01'),\n '<': new Date('2024-09-01')\n }\n });\n \n return { recentEvents, thisMonthEvents };", "role": "assistant" } ]
DATE TIME OPERATIONS
dateTimeBasicQueries
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for performs basic database queries with conditions", "role": "user" }, { "content": "const basicFind = async () => {\n const model = await p.getModel('user');\n \n // Find with simple condition\n const users = await model.find({ active: true });\n \n // Find with multiple conditions (AND)\n const activeAdmins = await model.find({ \n active: true, \n role: 'admin' \n });\n \n // Find with OR conditions\n const adminOrManager = await model\n .find({ role: 'admin' })\n .orFind({ role: 'manager' });\n \n return { users, activeAdmins, adminOrManager };", "role": "assistant" } ]
BASIC FIND OPERATIONS
basicFind
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Show me how to performs basic database queries with conditions using SL2 Query API", "role": "user" }, { "content": "const findWithConditions = async () => {\n const model = await p.getModel('product');\n \n // Complex conditions\n const products = await model\n .find({ \n category: 'electronics',\n price: { '>': 100 }\n })\n .orFind({ \n featured: true,\n stock: { '>': 0 }\n });\n \n return products;\n};", "role": "assistant" } ]
BASIC FIND OPERATIONS
findWithConditions
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for performs bulk updates on multiple records", "role": "user" }, { "content": "const bulkUpdateWithSQL = async () => {\n const model = await p.getModel('product');\n \n // Bulk update with SQL raw values\n const updatedWithSQL = await model\n .find({ id: [1, 2, 3] })\n .update({\n name: { \n __type: 'sql_raw', \n sql: `CONCAT('Product_', id)` \n },\n status: { \n __type: 'sql_raw', \n sql: `(CASE WHEN id = 1 THEN ? WHEN id = 2 THEN ? ELSE ? END)`, \n bindings: ['active', 'pending', 'inactive'] \n }\n });\n \n // Complex SQL update\n const complexUpdate = await model\n .find({ category: 'electronics' })\n .update({\n price: {\n __type: 'sql_raw',\n sql: `price * 1.1` // 10% price increase\n }\n });\n \n return { updatedWithSQL, complexUpdate };", "role": "assistant" } ]
BULK OPERATIONS
bulkUpdateWithSQL
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for executes mass delete operations", "role": "user" }, { "content": "const bulkDeleteOperations = async () => {\n const model = await p.getModel('log');\n \n // Basic bulk delete\n const deletedCount = await model\n .find({ \n created_at: { '<': new Date('2023-01-01') },\n level: 'debug'\n })\n .delete();\n \n // Bulk delete with complex conditions\n const cleanupCount = await model\n .find({ processed: true })\n .orFind({ \n created_at: { '<': new Date('2024-01-01') },\n level: { 'NOTIN': ['error', 'warning'] }\n })\n .delete();\n \n return { deletedCount, cleanupCount };", "role": "assistant" } ]
BULK OPERATIONS
bulkDeleteOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that works with advanced sql operations using the SL2 JavaScript API", "role": "user" }, { "content": "const rawSQLOperations = async () => {\n const model = await p.getModel('analytics');\n \n // Raw SQL in bulk updates\n const updatedWithRawSQL = await model\n .find({ category: 'electronics' })\n .update({\n // Concatenate strings\n display_name: {\n __type: 'sql_raw',\n sql: `CONCAT(category, ' - ', name)`\n },\n // Mathematical operations\n discounted_price: {\n __type: 'sql_raw', \n sql: `price * 0.9` // 10% discount\n },\n // Conditional updates\n status: {\n __type: 'sql_raw',\n sql: `(CASE WHEN price > 100 THEN ? WHEN price > 50 THEN ? ELSE ? END)`,\n bindings: ['premium', 'standard', 'basic']\n }\n });\n \n return { updatedWithRawSQL };", "role": "assistant" } ]
ADVANCED SQL OPERATIONS
rawSQLOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for works with performance optimizations", "role": "user" }, { "content": "const optimizedQueries = async () => {\n const model = await p.getModel('large_table');\n \n // Use raw for better performance with large datasets\n const rawData = await model\n .find({ status: 'active' })\n .fields(['id', 'name', 'key_field'])\n .order({ id: 'asc' })\n .limit(1000)\n .raw();\n \n // Optimized field selection for performance\n const minimalData = await model\n .find({ processed: false })\n .fields(['id']) // Only select what you need\n .raw();\n \n return { rawDataCount: rawData.length, minimalDataCount: minimalData.length };", "role": "assistant" } ]
PERFORMANCE OPTIMIZATIONS
optimizedQueries
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that combines data from related models", "role": "user" }, { "content": "const joinWithGrouping = async () => {\n const salesModel = await p.getModel('sales');\n const customerModel = await p.getModel('customer');\n \n // Join with grouping\n const customerSalesStats = await salesModel\n .join(customerModel, 'id', salesModel, 'customer_id')\n .find({ status: 'completed' }, salesModel)\n .group('customer_type', {\n 'total_sales': { 'SUM': { 'amount': salesModel } },\n 'avg_sale': { 'AVG': { 'amount': salesModel } },\n 'sale_count': { 'COUNT': { 'id': salesModel } }\n }, customerModel);\n \n return { customerSalesStats };", "role": "assistant" } ]
JOINS
joinWithGrouping
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for searches for records using AND/OR conditions", "role": "user" }, { "content": "const findOneExample = async () => {\n const model = await p.getModel('user');\n \n // Find single record\n const admin = await model.findOne({ role: 'admin' });\n \n // Find first match with ordering\n const newestUser = await model\n .find({ active: true })\n .order({ created_at: 'desc' })\n .findOne();\n \n return { admin, newestUser };", "role": "assistant" } ]
BASIC FIND OPERATIONS
findOneExample
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that finds records with simple and complex filters", "role": "user" }, { "content": "const basicFind = async () => {\n const model = await p.getModel('user');\n \n // Find with simple condition\n const users = await model.find({ active: true });\n \n // Find with multiple conditions (AND)\n const activeAdmins = await model.find({ \n active: true, \n role: 'admin' \n });\n \n // Find with OR conditions\n const adminOrManager = await model\n .find({ role: 'admin' })\n .orFind({ role: 'manager' });\n \n return { users, activeAdmins, adminOrManager };", "role": "assistant" } ]
BASIC FIND OPERATIONS
basicFind
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a JavaScript function using SL2 Query API to executes mass delete operations", "role": "user" }, { "content": "const massInsertOperations = async () => {\n const model = await p.getModel('user');\n \n // Basic mass insert\n const insertedIds = await model.massInsert([\n { name: 'John Doe', email: '[email protected]', active: true },\n { name: 'Jane Smith', email: '[email protected]', active: true },\n { name: 'Bob Johnson', email: '[email protected]', active: false }\n ]);\n \n // Mass insert with complex data\n const productIds = await model.massInsert([\n { \n name: 'Laptop Pro', \n category: 'electronics', \n price: 1299.99,\n features: ['high-performance', 'portable']\n },\n { \n name: 'Wireless Mouse', \n category: 'accessories', \n price: 29.99,\n features: ['wireless', 'ergonomic']\n }\n ]);\n \n return { insertedIds, productIds };", "role": "assistant" } ]
BULK OPERATIONS
massInsertOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a JavaScript function using SL2 Query API to works with comparison operators", "role": "user" }, { "content": "const comparisonOperators = async () => {\n const model = await p.getModel('product');\n \n // Greater than, less than\n const expensiveProducts = await model.find({\n price: { '>': 100 }\n });\n \n // Greater than or equal\n const premiumProducts = await model.find({\n rating: { '>=': 4.5 }\n });\n \n // Range (between)\n const midRangeProducts = await model.find({\n price: { '>': 50, '<': 200 }\n });\n \n // Not equal\n const notDiscontinued = await model.find({\n status: { '!=': 'discontinued' }\n });\n \n return { expensiveProducts, premiumProducts, midRangeProducts, notDiscontinued };", "role": "assistant" } ]
COMPARISON OPERATORS
comparisonOperators
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a SL2 query function to performs complex multi-table operations", "role": "user" }, { "content": "const joinWithGrouping = async () => {\n const salesModel = await p.getModel('sales');\n const customerModel = await p.getModel('customer');\n \n // Join with grouping\n const customerSalesStats = await salesModel\n .join(customerModel, 'id', salesModel, 'customer_id')\n .find({ status: 'completed' }, salesModel)\n .group('customer_type', {\n 'total_sales': { 'SUM': { 'amount': salesModel } },\n 'avg_sale': { 'AVG': { 'amount': salesModel } },\n 'sale_count': { 'COUNT': { 'id': salesModel } }\n }, customerModel);\n \n return { customerSalesStats };", "role": "assistant" } ]
JOINS
joinWithGrouping
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I works with testing and debugging with SL2 Query API?", "role": "user" }, { "content": "const debuggingQueryHelpers = async () => {\n const model = await p.getModel('debug_data');\n \n // Enable SQL debugging\n const debugResults = await model\n .find({ test_field: 'debug_value' })\n .setOptions({ sqlDebug: true });\n \n const sqlQuery = model.getSQL();\n \n // Test different query patterns\n const patterns = {\n simple: await model.find({ id: 1 }).count(),\n complex: await model\n .find({ field1: 'value1' })\n .orFind({ field2: 'value2' })\n .count(),\n withJoin: await model\n .join(await p.getModel('related'), 'id', model, 'related_id')\n .find({ active: true })\n .count()\n };", "role": "assistant" } ]
TESTING AND DEBUGGING
debuggingQueryHelpers
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for implements pagination for large datasets", "role": "user" }, { "content": "const advancedPagination = async () => {\n const model = await p.getModel('product');\n \n // Pagination with complex conditions\n const paginatedProducts = await model\n .find({ category: 'electronics' })\n .orFind({ featured: true })\n .order({ rating: 'desc', price: 'asc' })\n .limit(20, 40); // Page 3, 20 per page\n \n // Large dataset pagination\n const batchData = await model\n .find({ needs_processing: true })\n .order({ created_at: 'asc' })\n .limit(1000, 0);\n \n return { paginatedProducts, batchData };", "role": "assistant" } ]
PAGINATION AND LIMITS
advancedPagination
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for groups data and applies aggregation functions", "role": "user" }, { "content": "const basicGrouping = async () => {\n const model = await p.getModel('sales');\n \n // MAX aggregation\n const maxSalesByCategory = await model\n .find({ status: 'completed' })\n .group('category', { 'max_amount': { 'MAX': 'amount' } });\n \n // MIN aggregation\n const minSalesByCategory = await model\n .find({ status: 'completed' })\n .group('category', { 'min_amount': { 'MIN': 'amount' } });\n \n // SUM aggregation\n const totalSalesByCategory = await model\n .find({ status: 'completed' })\n .group('category', { 'total_amount': { 'SUM': 'amount' } });\n \n return { maxSalesByCategory, minSalesByCategory, totalSalesByCategory };", "role": "assistant" } ]
GROUPING OPERATIONS
basicGrouping
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a SL2 query function to works with comparison operators", "role": "user" }, { "content": "const inAndNotInOperators = async () => {\n const model = await p.getModel('product');\n \n // IN operator\n const specificCategories = await model.find({\n category: ['electronics', 'books', 'clothing']\n });\n \n // NOTIN operator\n const excludeCategories = await model.find({\n category: { 'NOTIN': ['restricted', 'banned'] }\n });\n \n // Multiple IN conditions\n const filteredProducts = await model.find({\n category: ['electronics', 'software'],\n status: ['active', 'featured']\n });\n \n return { specificCategories, excludeCategories, filteredProducts };", "role": "assistant" } ]
COMPARISON OPERATORS
inAndNotInOperators
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that joins multiple tables in queries", "role": "user" }, { "content": "const basicJoins = async () => {\n const userModel = await p.getModel('user');\n const profileModel = await p.getModel('profile');\n \n // Simple join\n const usersWithProfiles = await userModel\n .join(profileModel, 'user_id', userModel, 'id')\n .find({ active: true }, userModel)\n .order({ name: 'asc' }, userModel);\n \n // Join with field selection\n const userProfileData = await userModel\n .join(profileModel, 'user_id', userModel, 'id')\n .find({ active: true }, userModel)\n .fields(['id', 'name', 'email'], userModel)\n .fields(['bio', 'avatar'], profileModel);\n \n return { usersWithProfiles, userProfileData };", "role": "assistant" } ]
JOINS
basicJoins
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that works with globalref queries using the SL2 JavaScript API", "role": "user" }, { "content": "const globalRefAdvancedQueries = async () => {\n const model = await p.getModel('comment');\n \n // GlobalRef for specific model type\n const userComments = await model.find({\n global_ref: { model: 1 } // All records from model 1\n });\n \n // GlobalRef null check\n const orphanedComments = await model.find({\n global_ref: 'ISNULL'\n });\n \n // GlobalRef not null\n const linkedComments = await model.find({\n global_ref: 'ISNOTNULL'\n });\n \n return { userComments, orphanedComments, linkedComments };", "role": "assistant" } ]
GLOBALREF QUERIES
globalRefAdvancedQueries
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a JavaScript function using SL2 Query API to works with ordering and sorting", "role": "user" }, { "content": "const basicOrdering = async () => {\n const model = await p.getModel('article');\n \n // Simple ascending order\n const articlesByTitle = await model\n .find({ published: true })\n .order({ title: 'asc' });\n \n // Simple descending order\n const articlesByDate = await model\n .find({ published: true })\n .order({ created_at: 'desc' });\n \n // Multiple field ordering\n const articlesByPriorityAndDate = await model\n .find({ status: 'active' })\n .order({ priority: 'desc', created_at: 'asc' });\n \n return { articlesByTitle, articlesByDate, articlesByPriorityAndDate };", "role": "assistant" } ]
ORDERING AND SORTING
basicOrdering
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a JavaScript function using SL2 Query API to works with integration patterns", "role": "user" }, { "content": "const integrationWithActions = async () => {\n // Example of using queries in action context\n const requestParams = p.getRequest();\n const model = await p.getModel(requestParams.modelAlias);\n \n // Process selected records from view\n const selectedIds = requestParams.selectedIds || [];\n \n if (selectedIds.length > 0) {\n // Bulk operation on selected records\n const updatedCount = await model\n .find({ id: selectedIds })\n .update({ \n processed: true,\n processed_at: new Date(),\n processed_by: p.currentUser.getValue('id')\n });\n \n // Log the operation\n p.log.info({\n action: 'bulk_process',\n recordCount: updatedCount,\n userId: p.currentUser.getValue('id')\n }, 'Bulk Processing Completed');\n \n return { updatedCount };", "role": "assistant" } ]
INTEGRATION PATTERNS
integrationWithActions
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a SL2 query function to combines data from related models", "role": "user" }, { "content": "const advancedJoins = async () => {\n const orderModel = await p.getModel('order');\n const customerModel = await p.getModel('customer');\n const productModel = await p.getModel('product');\n \n // Multiple joins\n const orderDetails = await orderModel\n .join(customerModel, 'id', orderModel, 'customer_id')\n .join(productModel, 'id', orderModel, 'product_id')\n .find({ \n status: 'completed',\n created_at: { '>': new Date('2024-01-01') }\n }, orderModel)\n .orFind({ premium: true }, customerModel)\n .fields(['id', 'total', 'created_at'], orderModel)\n .fields(['name', 'email'], customerModel)\n .fields(['name', 'category'], productModel)\n .order({ total: 'desc' }, orderModel);\n \n return { orderDetails };", "role": "assistant" } ]
JOINS
advancedJoins
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for handles batch data operations efficiently", "role": "user" }, { "content": "const bulkUpdateWithSQL = async () => {\n const model = await p.getModel('product');\n \n // Bulk update with SQL raw values\n const updatedWithSQL = await model\n .find({ id: [1, 2, 3] })\n .update({\n name: { \n __type: 'sql_raw', \n sql: `CONCAT('Product_', id)` \n },\n status: { \n __type: 'sql_raw', \n sql: `(CASE WHEN id = 1 THEN ? WHEN id = 2 THEN ? ELSE ? END)`, \n bindings: ['active', 'pending', 'inactive'] \n }\n });\n \n // Complex SQL update\n const complexUpdate = await model\n .find({ category: 'electronics' })\n .update({\n price: {\n __type: 'sql_raw',\n sql: `price * 1.1` // 10% price increase\n }\n });\n \n return { updatedWithSQL, complexUpdate };", "role": "assistant" } ]
BULK OPERATIONS
bulkUpdateWithSQL
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that works with rtl bulk operations", "role": "user" }, { "content": "const rtlAdvancedBulkOperations = async () => {\n const model = await p.getModel('project');\n \n // RTL operations with conditions\n const teamUpdate = await model\n .find({ \n status: 'active',\n team_members: { '@>': [1, 2] } // Has specific members\n })\n .update({\n team_members: { append: [10, 11] } // Add new members\n });\n \n // RTL cleanup operation\n const cleanupUpdate = await model\n .find({ status: 'completed' })\n .update({\n assigned_users: { remove: [] }, // Remove all assignments\n tags: { append: ['completed'] } // Add completion tag\n });\n \n return { teamUpdate, cleanupUpdate };", "role": "assistant" } ]
RTL BULK OPERATIONS
rtlAdvancedBulkOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that finds records with simple and complex filters using the SL2 JavaScript API", "role": "user" }, { "content": "const findWithConditions = async () => {\n const model = await p.getModel('product');\n \n // Complex conditions\n const products = await model\n .find({ \n category: 'electronics',\n price: { '>': 100 }\n })\n .orFind({ \n featured: true,\n stock: { '>': 0 }\n });\n \n return products;\n};", "role": "assistant" } ]
BASIC FIND OPERATIONS
findWithConditions
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that works with iterator operations using the SL2 JavaScript API", "role": "user" }, { "content": "const iteratorMapExamples = async () => {\n const model = await p.getModel('analytics');\n \n // Map over records and transform data\n const transformedData = await p.iterMap(\n model\n .find({ status: 'active' })\n .fields(['id', 'value', 'multiplier']),\n 500, // batch size\n (record) => {\n return {\n id: record.id,\n originalValue: record.value,\n calculatedValue: record.value * (record.multiplier || 1),\n processed: true\n };", "role": "assistant" } ]
ITERATOR OPERATIONS
iteratorMapExamples
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that performs bulk updates on multiple records using the SL2 JavaScript API", "role": "user" }, { "content": "const massInsertOperations = async () => {\n const model = await p.getModel('user');\n \n // Basic mass insert\n const insertedIds = await model.massInsert([\n { name: 'John Doe', email: '[email protected]', active: true },\n { name: 'Jane Smith', email: '[email protected]', active: true },\n { name: 'Bob Johnson', email: '[email protected]', active: false }\n ]);\n \n // Mass insert with complex data\n const productIds = await model.massInsert([\n { \n name: 'Laptop Pro', \n category: 'electronics', \n price: 1299.99,\n features: ['high-performance', 'portable']\n },\n { \n name: 'Wireless Mouse', \n category: 'accessories', \n price: 29.99,\n features: ['wireless', 'ergonomic']\n }\n ]);\n \n return { insertedIds, productIds };", "role": "assistant" } ]
BULK OPERATIONS
massInsertOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Show me how to works with ordering and sorting using SL2 Query API", "role": "user" }, { "content": "const advancedOrdering = async () => {\n const model = await p.getModel('product');\n \n // Order by calculated fields\n const productsByPopularity = await model\n .find({ active: true })\n .order({ \n featured: 'desc',\n rating: 'desc', \n price: 'asc' \n });\n \n // Order with conditions\n const sortedProducts = await model\n .find({ category: 'electronics' })\n .orFind({ category: 'software' })\n .order({ \n category: 'asc',\n name: 'asc' \n });\n \n return { productsByPopularity, sortedProducts };", "role": "assistant" } ]
ORDERING AND SORTING
advancedOrdering
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that works with array operators", "role": "user" }, { "content": "const arrayContainsOperators = async () => {\n const model = await p.getModel('project');\n \n // Array contains one of\n const projectsWithTags = await model.find({\n tags: ['urgent', 'high-priority']\n });\n \n // Array contains (strict) - all specified values\n const projectsWithAllTags = await model.find({\n tags: { '@>': ['javascript', 'frontend'] }\n });\n \n // Array contains one of (explicit syntax)\n const projectsWithAnyTag = await model.find({\n tags: { '@~': ['react', 'vue', 'angular'] }\n });\n \n return { projectsWithTags, projectsWithAllTags, projectsWithAnyTag };", "role": "assistant" } ]
ARRAY OPERATORS
arrayContainsOperators
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for works with rtl queries", "role": "user" }, { "content": "const rtlAdvancedQueries = async () => {\n const model = await p.getModel('employee');\n \n // RTL with multiple aliases\n const employeesInDepartments = await model.find({\n departments: { alias: ['sales', 'marketing', 'development'] }\n });\n \n // RTL NOTIN with aliases\n const employeesNotInDepartments = await model.find({\n departments: { alias: { NOTIN: ['hr', 'finance'] } }\n });\n \n // RTL complex conditions\n const activeEmployeesInTechDepts = await model.find({\n active: true,\n departments: { alias: ['development', 'qa', 'devops'] }\n });\n \n return { employeesInDepartments, employeesNotInDepartments, activeEmployeesInTechDepts };", "role": "assistant" } ]
RTL QUERIES
rtlAdvancedQueries
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for works with error handling patterns", "role": "user" }, { "content": "const errorHandlingAdvanced = async () => {\n const model = await p.getModel('complex_data');\n let results = [];\n \n // Graceful error handling with fallbacks\n try {\n // Try complex query first\n results = await model\n .find({ \n complex_field: { 'CUSTOM': 'value' },\n nested_data: { '@>': ['specific', 'values'] }\n })\n .order({ calculated_field: 'desc' });\n \n } catch (complexError) {\n p.log.warn(`Complex query failed: ${complexError.message}. Trying fallback.`);\n \n try {\n // Fallback to simpler query\n results = await model\n .find({ status: 'active' })\n .order({ created_at: 'desc' })\n .limit(100);\n \n } catch (fallbackError) {\n p.log.error(fallbackError, 'Fallback query also failed');\n \n // Final fallback - return empty with error logged\n results = [];\n }\n }\n \n return { results, resultCount: results.length };", "role": "assistant" } ]
ERROR HANDLING PATTERNS
errorHandlingAdvanced
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I handles batch data operations efficiently with SL2 Query API?", "role": "user" }, { "content": "const bulkUpdateOperations = async () => {\n const model = await p.getModel('user');\n \n // Basic bulk update\n const updatedCount = await model\n .find({ last_login: { '<': new Date('2023-01-01') } })\n .update({ status: 'inactive' });\n \n // Bulk update with multiple fields\n const archiveCount = await model\n .find({ \n status: 'inactive',\n last_login: { '<': new Date('2022-01-01') }\n })\n .update({ \n status: 'archived',\n archived_at: new Date(),\n active: false\n });\n \n return { updatedCount, archiveCount };", "role": "assistant" } ]
BULK OPERATIONS
bulkUpdateOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a JavaScript function using SL2 Query API to works with text search operators", "role": "user" }, { "content": "const textSearchOperators = async () => {\n const model = await p.getModel('product');\n \n // STARTSWITH operator\n const appleProducts = await model.find({\n name: { 'STARTSWITH': 'Apple' }\n });\n \n // ENDSWITH operator\n const proProducts = await model.find({\n name: { 'ENDSWITH': 'Pro' }\n });\n \n // LIKE (contains) operator\n const smartphoneProducts = await model.find({\n description: { 'LIKE': 'smartphone' }\n });\n \n // NOTLIKE operator\n const notDiscontinuedProducts = await model.find({\n description: { 'NOTLIKE': 'discontinued' }\n });\n \n return { appleProducts, proProducts, smartphoneProducts, notDiscontinuedProducts };", "role": "assistant" } ]
TEXT SEARCH OPERATORS
textSearchOperators
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Generate SL2 Query API code for works with field selection", "role": "user" }, { "content": "const advancedFieldSelection = async () => {\n const model = await p.getModel('product');\n \n // Fields with ordering\n const productSummary = await model\n .find({ active: true })\n .fields(['id', 'name', 'price', 'rating'])\n .order({ rating: 'desc' })\n .limit(10);\n \n // Fields with complex conditions\n const featuredProductInfo = await model\n .find({ featured: true })\n .orFind({ rating: { '>=': 4.5 } })\n .fields(['id', 'name', 'category', 'price'])\n .order({ price: 'desc' });\n \n return { productSummary, featuredProductInfo };", "role": "assistant" } ]
FIELD SELECTION
advancedFieldSelection
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "How do I works with advanced sql operations with SL2 Query API?", "role": "user" }, { "content": "const conditionalSQLOperations = async () => {\n const model = await p.getModel('user');\n \n // Complex conditional SQL updates\n const userUpdates = await model\n .find({ active: true })\n .update({\n user_level: {\n __type: 'sql_raw',\n sql: `(CASE \n WHEN login_count > 100 THEN ? \n WHEN login_count > 50 THEN ? \n WHEN login_count > 10 THEN ? \n ELSE ? \n END)`,\n bindings: ['expert', 'advanced', 'intermediate', 'beginner']\n },\n last_activity_summary: {\n __type: 'sql_raw',\n sql: `CONCAT('Last login: ', COALESCE(last_login, 'Never'), ' - Status: ', status)`\n }\n });\n \n return { userUpdates };", "role": "assistant" } ]
ADVANCED SQL OPERATIONS
conditionalSQLOperations
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that works with raw data queries using the SL2 JavaScript API", "role": "user" }, { "content": "const advancedRawQueries = async () => {\n const model = await p.getModel('analytics');\n \n // Raw data for processing\n const processingData = await model\n .find({ \n processed: false,\n created_at: { '>': new Date('2024-01-01') }\n })\n .fields(['id', 'data', 'type'])\n .order({ created_at: 'asc' })\n .raw();\n \n // Raw data with complex conditions\n const reportData = await model\n .find({ report_type: 'monthly' })\n .orFind({ report_type: 'quarterly' })\n .fields(['id', 'data', 'period', 'metrics'])\n .raw();\n \n return { processingData, reportData };", "role": "assistant" } ]
RAW DATA QUERIES
advancedRawQueries
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that works with iterator operations using the SL2 JavaScript API", "role": "user" }, { "content": "const iteratorFeedExamples = async () => {\n const model = await p.getModel('metrics');\n let totalSum = 0;\n let processedBatches = 0;\n \n // Process batches of records\n await p.iterFeed(\n model\n .find({ type: 'numeric' })\n .fields(['value', 'weight']),\n 1000, // batch size\n (records) => {\n // Process entire batch at once\n const batchSum = records.reduce((sum, record) => {\n return sum + (record.value * (record.weight || 1));\n }, 0);\n \n totalSum += batchSum;\n processedBatches++;\n }\n );\n \n return { totalSum, processedBatches };", "role": "assistant" } ]
ITERATOR OPERATIONS
iteratorFeedExamples
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that groups data and applies aggregation functions", "role": "user" }, { "content": "const advancedGrouping = async () => {\n const model = await p.getModel('analytics');\n \n // Multiple aggregations\n const salesStats = await model\n .find({ status: 'completed' })\n .group('region', {\n 'total_sales': { 'SUM': 'amount' },\n 'avg_sale': { 'AVG': 'amount' },\n 'sale_count': { 'COUNT': 'id' },\n 'max_sale': { 'MAX': 'amount' },\n 'min_sale': { 'MIN': 'amount' }\n });\n \n // First and Last aggregations\n const timeStats = await model\n .find({ type: 'transaction' })\n .order({ created_at: 'asc' })\n .group('category', {\n 'first_transaction': { 'FIRST': 'amount' },\n 'last_transaction': { 'LAST': 'amount' }\n });\n \n return { salesStats, timeStats };", "role": "assistant" } ]
GROUPING OPERATIONS
advancedGrouping
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a function that searches for records using AND/OR conditions using the SL2 JavaScript API", "role": "user" }, { "content": "const findWithConditions = async () => {\n const model = await p.getModel('product');\n \n // Complex conditions\n const products = await model\n .find({ \n category: 'electronics',\n price: { '>': 100 }\n })\n .orFind({ \n featured: true,\n stock: { '>': 0 }\n });\n \n return products;\n};", "role": "assistant" } ]
BASIC FIND OPERATIONS
findWithConditions
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Create a JavaScript function using SL2 Query API to handles data pagination efficiently", "role": "user" }, { "content": "const basicPagination = async () => {\n const model = await p.getModel('article');\n \n // First page (10 records)\n const firstPage = await model\n .find({ published: true })\n .order({ created_at: 'desc' })\n .limit(10, 0);\n \n // Second page (next 10 records)\n const secondPage = await model\n .find({ published: true })\n .order({ created_at: 'desc' })\n .limit(10, 10);\n \n // Just limit without offset\n const topTen = await model\n .find({ featured: true })\n .order({ views: 'desc' })\n .limit(10);\n \n return { firstPage, secondPage, topTen };", "role": "assistant" } ]
PAGINATION AND LIMITS
basicPagination
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that handles data pagination efficiently", "role": "user" }, { "content": "const advancedPagination = async () => {\n const model = await p.getModel('product');\n \n // Pagination with complex conditions\n const paginatedProducts = await model\n .find({ category: 'electronics' })\n .orFind({ featured: true })\n .order({ rating: 'desc', price: 'asc' })\n .limit(20, 40); // Page 3, 20 per page\n \n // Large dataset pagination\n const batchData = await model\n .find({ needs_processing: true })\n .order({ created_at: 'asc' })\n .limit(1000, 0);\n \n return { paginatedProducts, batchData };", "role": "assistant" } ]
PAGINATION AND LIMITS
advancedPagination
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Implement a SL2 database query function that works with rtl queries", "role": "user" }, { "content": "const rtlBasicQueries = async () => {\n const model = await p.getModel('user');\n \n // RTL by IDs\n const usersInGroups = await model.find({\n user_groups: [1, 2, 3]\n });\n \n // RTL NOT IN\n const usersNotInGroups = await model.find({\n user_groups: { NOTIN: [4, 5, 6] }\n });\n \n // RTL by alias\n const usersByGroupAlias = await model.find({\n user_groups: { alias: ['admin', 'manager'] }\n });\n \n return { usersInGroups, usersNotInGroups, usersByGroupAlias };", "role": "assistant" } ]
RTL QUERIES
rtlBasicQueries
[ { "content": "You are an expert JavaScript developer specializing in SL2 Query API. You write clean, efficient, and well-documented code following SL2 best practices.", "role": "system" }, { "content": "Write a SL2 Query API function for performs bulk updates on multiple records", "role": "user" }, { "content": "const bulkUpdateOperations = async () => {\n const model = await p.getModel('user');\n \n // Basic bulk update\n const updatedCount = await model\n .find({ last_login: { '<': new Date('2023-01-01') } })\n .update({ status: 'inactive' });\n \n // Bulk update with multiple fields\n const archiveCount = await model\n .find({ \n status: 'inactive',\n last_login: { '<': new Date('2022-01-01') }\n })\n .update({ \n status: 'archived',\n archived_at: new Date(),\n active: false\n });\n \n return { updatedCount, archiveCount };", "role": "assistant" } ]
BULK OPERATIONS
bulkUpdateOperations