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

sheets-lucid

v0.1.1

Published

A Vue 3 friendly Google Sheets ORM inspired by AdonisJS Lucid.

Downloads

8

Readme

sheets-lucid

面向 Vue 3 的 Google Sheets ORM,靈感來自 AdonisJS Lucid。提供 Schema 驗證、Model/Query Builder、生命週期 Hooks 與雙認證 (API Key + OAuth2)。

安裝

npm install sheets-lucid gapi-script

vue 建議作為 peer 依賴 (^3.3 || ^3.4 || ^3.5)。

初始化步驟

  1. 在 Google Cloud 啟用「Sheets API」,建立 OAuth 2.0 用戶端 (Web) 及 API Key,允許的來源包含本地開發網址。
  2. 建立試算表,記下 Spreadsheet ID (網址中的 {SPREADSHEET_ID}) 並在第一列放入欄位名稱。
  3. 設定環境變數:
# .env.local (Vite 範例)
VITE_API_KEY=your-sheets-api-key
VITE_GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
VITE_SPREADSHEET_ID=your-spreadsheet-id

配置範例

sheets-orm.config.ts

import { Schema, defineConfig } from 'sheets-lucid'

export default defineConfig({
  spreadsheetId: import.meta.env.VITE_SPREADSHEET_ID,
  auth: {
    apiKey: import.meta.env.VITE_API_KEY,
    oauth: {
      clientId: import.meta.env.VITE_GOOGLE_CLIENT_ID,
      scopes: [
        'https://www.googleapis.com/auth/spreadsheets',
        'https://www.googleapis.com/auth/drive.readonly'
      ],
      // token: { expiresIn: 8 * 60 * 60, refreshThreshold: 10 * 60 * 1000 }
    },
    preferredMode: 'api_key' // 讀取優先用 API Key,寫入時自動升級 OAuth2
  },
  schemas: {
    users: Schema.create({
      id: Schema.number().primary().autoIncrement(),
      name: Schema.string().required(),
      email: Schema.string().required().unique().email(),
      status: Schema.enum(['active', 'inactive'] as const).default('active'),
      createdAt: Schema.dateTime(),
      updatedAt: Schema.dateTime(),
      deletedAt: Schema.dateTime().nullable()
    })
  },
  cache: { enabled: false, ttl: 5 * 60 * 1000 },
  debug: true,
  pagination: { perPage: 20, maxPerPage: 100 }
})

在 Vue 啟動

// main.ts
import { createApp } from 'vue'
import App from './App.vue'
import config from './config/sheets-orm.config'
import { createSheetsORM } from 'sheets-lucid'

const app = createApp(App)
const sheetsORM = createSheetsORM(config)

app.use(sheetsORM) // 提供 $db、useDatabase/useAuth
app.mount('#app')

定義 Model

// models/User.ts
import { BaseModel, column, beforeSave } from 'sheets-lucid'

export default class User extends BaseModel {
  static table = 'users'
  static softDeletes = true

  @column({ isPrimary: true }) declare id: number
  @column() declare name: string
  @column() declare email: string
  @column() declare status: 'active' | 'inactive'
  @column.dateTime({ autoCreate: true }) declare createdAt: Date
  @column.dateTime({ autoCreate: true, autoUpdate: true }) declare updatedAt: Date
  @column.dateTime() declare deletedAt: Date | null

  static scopes = {
    active: (query) => query.where('status', 'active')
  }

  @beforeSave()
  touchTimestamps() {
    if (this.isNew) this.createdAt = new Date()
    this.updatedAt = new Date()
  }
}

查詢與認證

import { useAuth } from 'sheets-lucid'
import User from './models/User'

const { isAuthenticated, signIn, signOut } = useAuth()
await signIn('oauth2') // 需要寫入時呼叫;讀取可用 API Key

const users = await User.query().apply('active').orderBy('createdAt', 'desc').paginate(1, 20)
const john = await User.find(1)
if (john) {
  john.status = 'inactive'
  await john.save()
}

useDatabase() 也可直接取得 db.from('table') Query Builder。

套件開發/發布

  • 產生編譯輸出:cd sheets-lucid && npm install && npm run build
  • dist/ 會輸出 ESM 與型別檔案。
  • 若要發布:npm login 之後執行 npm publish (需擁有 lu7766lu7766 帳號登入權限)。

附註

套件依賴瀏覽器環境與 Google gapi,請在前端專案中使用並確認 OAuth 同意畫面與來源網域皆已設定。