0.15.1 • Published 6 months ago

@canvas-js/modeldb-sqlite v0.15.1

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

@canvas-js/modeldb-sqlite

ModelDB

  • Relational
  • Simple JSON schema
  • Dual SQLite and IndexdDB backends
  • Designed for p2p conlict resolution
  • "Mutable" and "immutable" models
import { ModelDB } from "@canvas-js/modeldb-sqlite"

const db = new ModelDB({
	user: {
		address: "string",
		encryptionPublicKey: "bytes",
		signingPublicKey: "bytes",
	},

	room: {
		creator: "@user",
		members: "@user[]",
		$indexes: ["members"],
	},

	message: {
		room: "@room",
		sender: "@user",
		content: "string",
		timestamp: "integer",
	},
})

const userId = modelDB.add("user", {
	address: "a",
	encryptionPublicKey: new Uint8Array([1, 2, 3]),
	signingPublicKey: new Uint8Array([4, 5, 6]),
})

ModelInit

type PrimitiveType = "integer" | "float" | "string" | "bytes"
type OptionalPrimitiveType = `${PrimitiveType}?`
type ReferenceType = `@${string}`
type OptionalReferenceType = `@${string}?`
type RelationType = `@${string}[]`

type PropertyType = PrimitiveType | OptionalPrimitiveType | ReferenceType | OptionalReferenceType | RelationType

type IndexInit = string | string[]

type ModelsInit = Record<
	string,
	{ $type?: "mutable" | "immutable"; $indexes?: IndexInit[] } & Record<string, PropertyType>
>

ModelDB

interface ModelDBOptions {
	dkLen?: number
	resolve?: (versionA: string, versionB: string) => string
}

declare class ModelDB {
	public constructor(path: string, models: ModelsInit, options?: ModelDBOptions)
	public close(): void

	public get(modelName: string, key: string): ModelValue | null
	public iterate(modelName: string): AsyncIterable<ModelValue>
	public query(modelName: string, query: {}): ModelValue[]

	// Mutable model methods
	public set(modelName: string, key: string, value: ModelValue, options?: { version?: string }): void
	public delete(modelName: string, key: string, options?: { version?: string }): void

	// Immutable model methods
	public add(modelName: string, value: ModelValue, options?: { namespace?: string }): string
	public remove(modelName: string, key: string): void
}
0.12.3-next.4

1 year ago

0.12.3-next.3

1 year ago

0.14.0-next.0

11 months ago

0.12.3-next.2

1 year ago

0.13.0-next.17

1 year ago

0.15.0-next.3

7 months ago

0.15.0-next.2

7 months ago

0.13.6

1 year ago

0.13.7

1 year ago

0.13.9

12 months ago

0.13.0

1 year ago

0.13.1

1 year ago

0.15.0

7 months ago

0.13.2

1 year ago

0.15.1

6 months ago

0.13.3

1 year ago

0.13.5

1 year ago

0.13.8-next.0

1 year ago

0.13.8-next.1

1 year ago

0.13.4-next.0

1 year ago

0.14.1-next.10

7 months ago

0.13.12

11 months ago

0.13.11

11 months ago

0.13.10

11 months ago

0.14.1-next.9

7 months ago

0.14.1-next.8

7 months ago

0.14.1-next.7

7 months ago

0.14.1-next.6

7 months ago

0.14.1-next.5

7 months ago

0.14.1-next.4

7 months ago

0.14.1-next.3

7 months ago

0.14.1-next.2

8 months ago

0.14.0-next.1

11 months ago

0.14.0-next.2

8 months ago

0.14.0-next.3

8 months ago

0.13.14

11 months ago

0.13.13

11 months ago

0.14.1-next.1

8 months ago

0.14.1-next.0

8 months ago

0.14.0

8 months ago

0.12.2

1 year ago

0.12.3

1 year ago

0.12.4

1 year ago

0.12.5

1 year ago

0.12.6

1 year ago

0.15.2-next.0

6 months ago

0.15.0-next.1

7 months ago

0.12.3-next.1

1 year ago

0.12.3-next.0

1 year ago

0.13.0-next.16

1 year ago

0.13.0-next.15

1 year ago

0.13.0-next.14

1 year ago

0.13.0-next.13

1 year ago

0.12.1

1 year ago

0.13.0-next.12

1 year ago

0.13.0-next.11

1 year ago

0.13.0-next.10

1 year ago

0.13.0-next.9

1 year ago

0.13.0-next.8

1 year ago

0.13.0-next.1

1 year ago

0.13.0-next.3

1 year ago

0.13.0-next.2

1 year ago

0.13.0-next.5

1 year ago

0.13.0-next.4

1 year ago

0.13.0-next.7

1 year ago

0.13.0-next.6

1 year ago

0.11.0

1 year ago

0.12.0

1 year ago

0.10.10

1 year ago

0.10.0

1 year ago

0.10.9

1 year ago

0.10.1

1 year ago

0.10.2

1 year ago

0.10.3

1 year ago

0.10.4

1 year ago

0.10.5

1 year ago

0.10.6

1 year ago

0.10.7

1 year ago

0.10.0-beta.4

1 year ago

0.10.8

1 year ago

0.6.0-alpha1

2 years ago