npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bishen/tauri-plugin-pg-sync

v0.1.11

Published

Offline-first PostgreSQL sync plugin for Tauri apps

Readme

@bishen/tauri-plugin-pg-sync

npm crates.io

An offline-first PostgreSQL sync plugin for Tauri apps.

Features

  • Offline-First: Local SQLite database, fully functional offline
  • PostgreSQL Sync: Automatic synchronization with remote PostgreSQL
  • Conflict Resolution: HLC (Hybrid Logical Clock) based conflict resolution
  • Cross-Platform: Windows, macOS, Linux, Android, iOS

Installation

npm install @bishen/tauri-plugin-pg-sync
# or
yarn add @bishen/tauri-plugin-pg-sync
# or
pnpm add @bishen/tauri-plugin-pg-sync

Also add the Rust plugin to your src-tauri/Cargo.toml:

[dependencies]
tauri-plugin-pg-sync = "0.1"

Setup

Register the plugin in your Tauri app:

// src-tauri/src/main.rs
fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_pg_sync::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Documentation

Usage

Smart Initialization (Recommended)

import { smartInit, table, sync } from '@bishen/tauri-plugin-pg-sync';

// Smart init: auto-detect local/remote state
const result = await smartInit({
  remoteUrl: 'postgres://user:pass@host:5432/db'
});

console.log('Mode:', result.mode);
// 'local_only' | 'offline' | 'pulled_from_remote' | 'pushed_to_remote' | 'synced'

const users = table('users', {
  columns: [['name', 'TEXT'], ['age', 'INTEGER']]
});

await users.insert({ name: 'Alice', age: 25 });
await sync.now();

Smart Sync Manager

import { syncManager, smartInit } from '@bishen/tauri-plugin-pg-sync';

await smartInit({ remoteUrl: 'postgres://...' });

await syncManager.start({
  pollInterval: 30000,
  enableRealtime: true,
  onSync: (result) => {
    if (result.pulled > 0) refreshUI();
  },
  onStateChange: ({ mode }) => {
    console.log('State:', mode); // 'offline' | 'online' | 'syncing' | 'error'
  }
});

syncManager.stop();

Basic Usage

import {
  initDatabase,
  connectRemote,
  ensureTable,
  insert,
  findAll,
  findWhere,
  update,
  delete as deleteRecord,
  syncNow,
  isOnline,
} from '@bishen/tauri-plugin-pg-sync';

// Initialize local database
const nodeId = await initDatabase();

// Connect to remote PostgreSQL (optional)
await connectRemote('postgres://user:pass@host:5432/db');

// Create a table
await ensureTable('users', [
  { name: 'name', type: 'TEXT' },
  { name: 'email', type: 'TEXT' },
  { name: 'age', type: 'INTEGER' },
]);

// Insert data
const id = await insert('users', {
  name: 'Alice',
  email: '[email protected]',
  age: 30,
});

// Query data
const allUsers = await findAll('users');
const adults = await findWhere('users', 'age >= 18');

// Update data
await update('users', id, { age: 31 });

// Delete data (soft delete)
await deleteRecord('users', id);

// Sync with remote
const result = await syncNow();
console.log(`Pushed: ${result.pushed}, Pulled: ${result.pulled}`);

// Check online status
const online = await isOnline();

API Reference

Database Initialization

| Function | Description | |----------|-------------| | smartInit(options) | Smart initialization (Recommended) | | initDatabase() | Initialize local SQLite database | | initDatabaseMobile(path) | Initialize for mobile with custom path | | getDbPath() | Get current database file path |

Remote Connection

| Function | Description | |----------|-------------| | connectRemote(url) | Connect to PostgreSQL | | connectRemoteWithRetry(url, retries, delay) | Connect with retry logic | | disconnectRemote() | Disconnect from remote | | isOnline() | Check connection status |

CRUD Operations

| Function | Description | |----------|-------------| | insert(table, data) | Insert a record | | insertMany(table, records) | Batch insert | | update(table, id, data) | Update a record | | updateMany(table, updates) | Batch update | | delete(table, id) | Soft delete a record | | deleteMany(table, ids) | Batch soft delete | | findById(table, id) | Find by ID | | findAll(table, options?) | Find all records | | findWhere(table, condition, options?) | Find with condition | | query(sql, params?) | Execute raw SQL | | count(table, condition?) | Count records |

Sync Operations

| Function | Description | |----------|-------------| | syncNow() | Trigger immediate sync | | startAutoReconnect(interval) | Start auto-reconnect |

Table Management

| Function | Description | |----------|-------------| | ensureTable(name, columns) | Create table if not exists | | listLocalTables() | List local tables | | listRemoteTables() | List remote tables | | getLocalSchema(table) | Get table schema | | pushTableSchema(table) | Push schema to remote | | pullTableSchema(table) | Pull schema from remote |

License

MIT © BiShen

算金山™ (https://www.suanjinshan.com/)