Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ Pongo uses the following table structure for storing collections:

```sql
CREATE TABLE IF NOT EXISTS "YourCollectionName" (
_id UUID PRIMARY KEY,
data JSONB
_id TEXT PRIMARY KEY,
data JSONB NOT NULL,
metadata JSONB NOT NULL DEFAULT '{}',
_version BIGINT NOT NULL DEFAULT 1,
_partition TEXT NOT NULL DEFAULT 'png_global',
_archived BOOLEAN NOT NULL DEFAULT FALSE,
_created TIMESTAMPTZ NOT NULL DEFAULT now(),
_updated TIMESTAMPTZ NOT NULL DEFAULT now()
)
```

Expand Down
10 changes: 8 additions & 2 deletions src/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ Pongo uses the following table structure for storing collections:

```sql
CREATE TABLE IF NOT EXISTS "YourCollectionName" (
_id UUID PRIMARY KEY,
data JSONB
_id TEXT PRIMARY KEY,
data JSONB NOT NULL,
metadata JSONB NOT NULL DEFAULT '{}',
_version BIGINT NOT NULL DEFAULT 1,
_partition TEXT NOT NULL DEFAULT 'png_global',
_archived BOOLEAN NOT NULL DEFAULT FALSE,
_created TIMESTAMPTZ NOT NULL DEFAULT now(),
_updated TIMESTAMPTZ NOT NULL DEFAULT now()
)
```

Expand Down
11 changes: 10 additions & 1 deletion src/packages/pongo/src/postgres/postgresCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,16 @@ export const postgresCollection = <T extends PongoDocument>(
export const collectionSQLBuilder = (collectionName: string) => ({
createCollection: (): SQL =>
sql(
'CREATE TABLE IF NOT EXISTS %I (_id UUID PRIMARY KEY, data JSONB)',
`CREATE TABLE IF NOT EXISTS %I (
_id TEXT PRIMARY KEY,
data JSONB NOT NULL,
metadata JSONB NOT NULL DEFAULT '{}',
_version BIGINT NOT NULL DEFAULT 1,
_partition TEXT NOT NULL DEFAULT 'png_global',
_archived BOOLEAN NOT NULL DEFAULT FALSE,
_created TIMESTAMPTZ NOT NULL DEFAULT now(),
_updated TIMESTAMPTZ NOT NULL DEFAULT now()
)`,
collectionName,
),
insertOne: <T>(document: WithId<T>): SQL =>
Expand Down