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: 5 additions & 5 deletions testing/PostgresDockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 ubuntu:22.04
FROM --platform=${BUILDPLATFORM} ubuntu:22.04

# install python, java, bats, git ruby, perl, cpan
ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -7,7 +7,7 @@ RUN apt update -y && \
curl \
gnupg \
software-properties-common && \
curl -sL https://deb.nodesource.com/setup_20.x | bash - && \
curl -sL https://deb.nodesource.com/setup_22.x | bash - && \
add-apt-repository ppa:deadsnakes/ppa -y && \
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
Expand Down Expand Up @@ -44,8 +44,8 @@ RUN apt update -y && \

# install go
WORKDIR /root
ENV GO_VERSION=1.23.3
ENV GOPATH=$HOME/go
ENV GO_VERSION=1.25.0
ENV GOPATH=/go
ENV PATH=$PATH:$GOPATH/bin
ENV PATH=$PATH:$GOPATH/bin:/usr/local/go/bin
RUN curl -O "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" && \
Expand All @@ -56,7 +56,7 @@ RUN curl -O "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" && \
go version

# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64/
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/

# install java postgres JDBC driver
RUN mkdir -p /postgres-client-tests/java
Expand Down
11 changes: 11 additions & 0 deletions testing/postgres-client-tests/drizzle/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
out: './drizzle',
schema: './src/db/schema.ts',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
tablesFilter: ["!dolt_*"], // IMPORTANT to filter out dolt system tables
});
9 changes: 9 additions & 0 deletions testing/postgres-client-tests/drizzle/src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { jsonb, integer, pgTable, varchar } from 'drizzle-orm/pg-core';

export const usersTable = pgTable("users", {
id: integer().primaryKey(),
name: varchar({ length: 255 }).notNull(),
age: integer().notNull(),
email: varchar({ length: 255 }).notNull().unique(),
render: jsonb('render'),
});
53 changes: 53 additions & 0 deletions testing/postgres-client-tests/drizzle/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'dotenv/config';
import { Pool } from 'pg';
import { drizzle } from 'drizzle-orm/node-postgres';
import { usersTable } from "./db/schema";
import { eq } from 'drizzle-orm';

const connectionString = process.env.DATABASE_URL!
const pool = new Pool({ connectionString });

const db = drizzle(pool);

async function main() {
const user: typeof usersTable.$inferInsert = {
id: 1,
name: 'John',
age: 30,
render: null,
email: 'john@example.com',
};
await db.insert(usersTable).values(user);
console.log('New user created!')
const users = await db.select().from(usersTable);
console.log('Getting all users from the database: ', users)
/*
const users: {
id: number;
name: string;
age: number;
email: string;
render: jsonb;
}[]
*/
await db
.update(usersTable)
.set({
age: 31,
})
.where(eq(usersTable.email, user.email));
console.log('User info updated!')

// Verify the update
const result = await db
.select()
.from(usersTable)
.where(eq(usersTable.age, 31));
console.log('Retrieved updated record:', result);

// Clean up
await db.delete(usersTable).where(eq(usersTable.email, user.email));
console.log('User deleted!')
}

main();
25 changes: 24 additions & 1 deletion testing/postgres-client-tests/postgres-client-tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,27 @@ teardown() {
@test "python postgres: sqlalcchemy client" {
cd $BATS_TEST_DIRNAME/python
python3 sqlalchemy-test.py $USER $PORT
}
}

@test "Drizzle ORM smoke test" {
# the schema should be empty
query_server -c "DROP TABLE IF EXISTS test_table" -t

cd $BATS_TEST_DIRNAME/drizzle

# Construct the string and append it to the .env file
touch .env
echo "DATABASE_URL=postgres://$USER:password@localhost:$PORT/postgres" >> .env

npm i drizzle-orm pg dotenv
npm i -D drizzle-kit tsx @types/pg
npx drizzle-kit push

# we can check if 'components table was created'
query_server -c "SELECT * FROM users" -t
run query_server -c "SELECT * FROM users" -t
[ "$status" -eq 0 ]

# this inserts and updates row and check its updated result
npx tsx src/index.ts
}