WireBootstrap
HomeDocsBuySupport
  • Introduction
  • Overview
  • Getting Started
  • Installation
  • Connecting to Data
    • Data Connectors
      • SQL Data
      • Custom Web Services
      • Local Data
      • Other Sources
    • Data Sources
    • Discovery
    • Building a Data Connector
  • Working With Queries
    • Select Queries
      • Query Extensions
    • Stored Procedures
    • Custom Web Services
    • Executing Queries
    • ORM
  • Writing Data
  • Updates
  • Deletes
  • Working with DataTables
    • Introduction
    • Filter and Sort
    • Select and Calculate
    • Joins
    • Rows
    • Columns
  • Working with DataSets
  • Introduction
  • Executing Queries
  • Transforms
  • Writing Data
  • Data Events
  • Working with Components
    • Introduction
    • Encapsulation
    • Configuration
      • Data
      • Events
      • Observables
      • Validation
      • Display
      • Vendor
      • Custom
    • Component
    • Web Frameworks
    • Building a Component
      • Hello World
      • Data Events
      • DataSets
  • Working With Data Events
    • Introduction
    • Event Basics
    • Event Data
    • Event Actions
  • Working with Themes
    • Introduction
    • Sample Data
    • Libraries
    • Pages
    • Building a Theme Project
  • Utilities
    • Formatting
    • Expressions
    • Collections
    • Spinners
    • Copy and Merge
    • Validation
    • Loading Assets
    • Service Calls
    • Download Files
    • Browser Location
    • Types
    • Promise
  • Reference
    • wire
      • wire.Collection
      • wire.download
      • wire.validate
    • wire.data
      • wire.data.DataEvent
      • wire.data.DataModel
      • wire.data.DataPromise
      • wire.data.DataSet
      • wire.data.DataSource
      • wire.data.DataTable
        • Columns
        • Rows
      • wire.data.StoredProcedure
      • wire.data.TableQuery
    • wire.ui
      • wire.ui.Component
      • wire.ui.validate
Powered by GitBook
On this page
  • Entity
  • Keys
  • Data
  • Refresh
  • Provider

Was this helpful?

Writing Data

PreviousTransformsNextData Events

Last updated 2 years ago

Was this helpful?

The process of persisting data in the data service using a dataset is similar to the one used for the same operation .

To turn on write-back functionality for the dataset, set the Write attribute on the dataset's configuration to true.

To check whether a data service supports write-back, check the allow.write attribute on the data source. Use the write method to send the data to be persisted.

const accountService = new wire.data.DataSource("sql", {
    Provider: {
        Server: "query-server"
    }
});

const query = wire.data.select().from("Users");
    
const dataset = new wire.data.DataSet({
    Source: accountService,
    Query: query,
    Write: true
});

const allowWrite = accountService.allow().write;

if(allowWrite) {

    const users = [
        { UserName: "mchermela", Active: true }
    ];

    dataset.write(users);
    
}

The Write attribute can also be set to allow optional configuration. These options are available for service providers that can support them. See the service provider documentation for details on write-back options support.

Entity

By default, the write call to the data service will use the entity specified in the select statement's from clause. Depending on the service provider, this could translate into the name of the method called on the data service, the name of a table in a relational database, or another structure that represents the update target.

To specify a different entity, use the Entity attribute. In the example below, the entity used in the call will be ActiveUsers instead of Users.

...

const query = wire.data.select().from("Users");

const dataset = new wire.data.DataSet({
    Source: accountService,
    Query: query,
    Write: { Entity: ["ActiveUsers"] }
});

Keys

The Keys attribute can be set for data services that need to know the fields that make the data to be updated unique.

...

const dataset = new wire.data.DataSet({
    Source: accountService,
    Query: query,
    Write: { Keys: ["UserName"] }
});

Data

The Data attribute is a transformation hook to change the data that is sent to the server to be persisted.

...

const dataset = new wire.data.DataSet({
    Source: accountService,
    Query: query,
    Write: { 
        Data: (rows) => {
            const table = new wire.data.DataTable(rows);
            return table.select("UserName", "Active").rows();
        }
    }
});

Refresh

By default, the dataset will not refresh its data after a write operation. Use the Refresh option to force a refresh of the data from the data service after the write operation. Note, this will update any of the dataset's data promises sending out notifications to all consumers waiting for changes.

...

const dataset = new wire.data.DataSet({
    Source: accountService,
    Query: query,
    Write: { Refresh: true }
});

Provider

const accountService = new wire.data.DataSource("sql", {
    Provider: {
        Server: "query-server"
    }
});

...

const dataset = new wire.data.DataSet({
    Source: accountService,
    Query: query,
    Write: { 
        Keys: ["UserName"], 
        Provider: { UpdateOnly: true } 
    }
});

In the example below, the data is trimmed to only include the UserName and Active fields using a data table. See for more on data tables.

specific options can be set up using the Provider attribute. These options are used by data source service providers to allow consumers to control persistence behavior for write operations by a data service.

In the example below, the is being told not to add any new records using the service provider's UpdateOnly option. Only records that currently have a UserName value will be updated.

For more on persisting data using datasets, visit the reference page.

using a data source
Working with DataTables
Service provider
WireBootstrap Query Service
DataSet