@triply/triplydb
    Preparing search index...

    Class Service

    A service that makes a Dataset queryable — a SPARQL endpoint or a search index.

    Obtain one with Dataset.getService, Dataset.addService or Dataset.ensureService. Services are never constructed directly.

    A newly created service is not immediately usable; wait for it with Service.waitUntilRunning.

    A service reloads the dataset only when Service.update is called, never on its own. That is what lets one dataset carry several services on different states of the data at once — an acceptance service on the new data beside a production service still on the old, or an endpoint held back for a consumer that has not migrated yet.

    const dataset = await account.getDataset("my-dataset");
    const service = await dataset.ensureService("my-service", { type: "virtuoso" });
    await service.waitUntilRunning();
    Index
    slug: string

    The service's short name, as it appears in its URL.

    • Creates this service on the instance.

      Returns Promise<Service>

      Dataset.addService and Dataset.ensureService call this for you; use it directly only for a service object you built yourself. The service starts out empty and syncs in the background, so follow it with Service.waitUntilRunning.

    • Deletes this service.

      Returns Promise<void>

      The dataset and its data are untouched — only the ability to query it goes away. Recreate one with Dataset.addService.

    • The dataset this service makes queryable.

      Returns Dataset

    • Which graphs this service has loaded, and how many statements each holds.

      Parameters

      • refresh: boolean = false

        Refetch rather than using the cached copy.

      Returns Promise<ServiceGraphInfo[]>

      Compare against the dataset's own graphs to see what an out-of-sync service is missing.

    • This service's metadata: its type, status, and whether it is in sync with the dataset.

      Parameters

      • refresh: boolean = false

      Returns Promise<ServiceInfo>

      Cached after the first call. Pass true to refetch — necessary when polling for a status change, since the cached copy never changes on its own.

    • Whether this service reflects the dataset's current contents.

      Returns Promise<boolean>

      A service goes out of sync when the dataset changes under it, and keeps answering queries from the older data until it is updated — so a query can succeed and still be stale. Bring it back in line with Service.update. Always refetches, so this costs a request.

    • Changes this service's name.

      Parameters

      • newName: string

      Returns Promise<Service>

      The name is part of the service's URL, so anything addressing it by URL must be updated.

      If the dataset already has a service with that name.

    • Runs a SPARQL query against this service.

      Parameters

      • queryString: string

        The query to run.

      Returns SparqlResults

      The service has to be running, and to offer a SPARQL endpoint — an Elasticsearch service does not. It answers from the data it was built with, so a service that has fallen out of sync answers from the older data until you bring it up to date with Service.update. To query the dataset's data directly, using speedy, use Dataset.sparqlQuery.

      Nothing is sent until you pick a result form on what this returns — see SparqlResults. Every form is a single request that returns the whole result set.

      SPARQL Update is not available through a service; it goes through Dataset.sparqlUpdate.

      From the awaited result form, if queryString is not valid SPARQL or is a SPARQL Update, or if this service cannot answer queries.

      const service = await dataset.ensureService("virtuoso", { type: "virtuoso" })
      await service.waitUntilRunning()
      const bindings = await service.sparqlQuery("select * { ?s ?p ?o } limit 10").bindings()
    • Brings this service back in sync with the dataset, with downtime.

      Parameters

      • Optionalopts: { rollingUpdate: false }

      Returns Promise<void>

      The service stops answering queries while it reloads. Use the rolling form when it is serving traffic.

      for await (const service of dataset.getServices()) {
      await service.update();
      }
      await Promise.all((await dataset.getServices().toArray()).map((service) => service.update()));
      
    • Brings this service back in sync with the dataset without downtime.

      Parameters

      • Optionalopts: {
            onProgress?: (
                opts?: { message: string; type: OnProgressUpdateType },
            ) => void;
            rollingUpdate: true;
        }

        Set rollingUpdate: true; onProgress reports each step as it happens.

      Returns Promise<void>

      Builds a replacement alongside the running service and swaps them once it is ready, so queries keep being answered throughout. It costs the resources of two services while it runs.

      If the service is already in sync with the dataset, or if its status is anything other than "running" — unlike the plain form, which reloads regardless. Read Service.getInfo's outOfSync and status first, or use the plain form.

    • Waits until this service can answer queries.

      Returns Promise<void>

      A newly created or updated service is not usable straight away, so this is the step between creating one and querying it. Polls until the service reports itself running, tolerating the unavailability that happens while it starts.

      If the service reports that it failed to start.