# @markdown Please fill in the both the Google Cloud region and name of your Cloud SQL instance.REGION = "us-central1" # @param {type:"string"}INSTANCE = "test-instance" # @param {type:"string"}# @markdown Please fill in user name and password of your Cloud SQL instance.DB_USER = "sqlserver" # @param {type:"string"}DB_PASS = "password" # @param {type:"string"}# @markdown Please specify a database and a table for demo purpose.DATABASE = "test" # @param {type:"string"}TABLE_NAME = "test-default" # @param {type:"string"}
# # Automatically restart kernel after installs so that your environment can access the new packages# import IPython# app = IPython.Application.instance()# app.kernel.do_shutdown(True)
# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.PROJECT_ID = "my-project-id" # @param {type:"string"}# Set the project id!gcloud config set project {PROJECT_ID}
from langchain_google_cloud_sql_mssql import MSSQLLoaderloader = MSSQLLoader(engine=engine, table_name=TABLE_NAME)docs = loader.load()print("Documents before delete:", docs)saver.delete(onedoc)print("Documents after delete:", loader.load())
import sqlalchemywith engine.connect() as conn: conn.execute(sqlalchemy.text(f'DROP TABLE IF EXISTS "{TABLE_NAME}"')) conn.commit() conn.execute( sqlalchemy.text( f""" IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{TABLE_NAME}]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[{TABLE_NAME}]( fruit_id INT IDENTITY(1,1) PRIMARY KEY, fruit_name VARCHAR(100) NOT NULL, variety VARCHAR(50), quantity_in_stock INT NOT NULL, price_per_unit DECIMAL(6,2) NOT NULL, organic BIT NOT NULL ) END """ ) ) conn.execute( sqlalchemy.text( f""" INSERT INTO "{TABLE_NAME}" (fruit_name, variety, quantity_in_stock, price_per_unit, organic) VALUES ('Apple', 'Granny Smith', 150, 0.99, 1), ('Banana', 'Cavendish', 200, 0.59, 0), ('Orange', 'Navel', 80, 1.29, 1); """ ) ) conn.commit()